2929#include "NWK_INTERFACE/Include/protocol.h"
3030#include "6LoWPAN/Bootstraps/protocol_6lowpan.h"
3131#include "6LoWPAN/Bootstraps/protocol_6lowpan_interface.h"
32+ #include "ipv6_stack/protocol_ipv6.h"
3233#include "6LoWPAN/MAC/mac_helper.h"
3334#include "6LoWPAN/MAC/mac_data_poll.h"
3435#include "6LoWPAN/MAC/mpx_api.h"
5758#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
5859#include "Service_Libs/nd_proxy/nd_proxy.h"
5960#include "platform/topo_trace.h"
60-
61+ #include "DHCPv6_client/dhcpv6_client_api.h"
6162#include "net_rpl.h"
6263#include "mac_api.h"
6364
@@ -127,7 +128,7 @@ static void ws_bootstrap_address_notification_cb(struct protocol_interface_info_
127128 }
128129 if (reason == ADDR_CALLBACK_DAD_COMPLETE ) {
129130 //Trig Address Registartion only when Bootstrap is ready
130- if (interface -> nwk_bootstrap_state == ER_BOOTSRAP_DONE ) {
131+ if (interface -> nwk_bootstrap_state == ER_BOOTSRAP_DONE || addr -> source == ADDR_SOURCE_DHCP ) {
131132 ws_bootsrap_event_trig (WS_ADDRESS_ADDED , interface -> bootStrapId , ARM_LIB_LOW_PRIORITY_EVENT , (void * )addr );
132133 }
133134 if (addr_ipv6_scope (addr -> address ,interface ) > IPV6_SCOPE_LINK_LOCAL ) {
@@ -604,6 +605,7 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
604605 cur -> ipv6_neighbour_cache .omit_aro_success = true;
605606 /* Disable NUD Probes */
606607 cur -> ipv6_neighbour_cache .send_nud_probes = false;
608+ dhcp_client_init (cur -> id );
607609
608610 ws_nud_table_reset (cur );
609611
@@ -627,6 +629,7 @@ static int8_t ws_bootstrap_down(protocol_interface_info_entry_t *cur)
627629 ws_llc_reset (cur );
628630 nd_proxy_downstream_interface_unregister (cur -> id );
629631 ws_nud_table_reset (cur );
632+ dhcp_client_delete (cur -> id );
630633
631634 return nwk_6lowpan_down (cur );
632635}
@@ -1491,6 +1494,14 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
14911494 if (event == RPL_EVENT_DAO_DONE ) {
14921495 // Trigger statemachine check
14931496 cur -> bootsrap_state_machine_cnt = 1 ;
1497+ rpl_dodag_info_t dodag_info ;
1498+ struct rpl_instance * instance = rpl_control_enumerate_instances (cur -> rpl_domain , NULL );
1499+
1500+ if (instance && rpl_control_read_dodag_info (instance , & dodag_info )) {
1501+ tr_debug ("Enable DHCPv6 relay" );
1502+ dhcp_relay_agent_enable (cur -> id , dodag_info .dodag_id );
1503+ }
1504+
14941505 ws_set_fhss_hop (cur );
14951506
14961507 } else if (event == RPL_EVENT_LOCAL_REPAIR_NO_MORE_DIS ) {
@@ -1509,6 +1520,51 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
15091520 tr_info ("RPL event %d" , event );
15101521}
15111522
1523+ static void ws_dhcp_client_global_adress_cb (int8_t interface , uint8_t dhcp_addr [static 16 ], uint8_t prefix [static 16 ], bool register_status )
1524+ {
1525+ (void )prefix ;
1526+ (void )interface ;
1527+ //TODO add handler for negative status
1528+ tr_debug ("DHCPv6 %s status %u" ,trace_ipv6 (dhcp_addr ), register_status );
1529+ }
1530+
1531+ static bool ws_address_entry_available (uint8_t * prefixPtr , if_address_list_t * list )
1532+ {
1533+ bool addressReady = false;
1534+ ns_list_foreach (if_address_entry_t , entry , list ) {
1535+ if (memcmp (entry -> address , prefixPtr , 8 ) == 0 ) {
1536+ addressReady = true;
1537+ break ;
1538+ }
1539+ }
1540+ return addressReady ;
1541+ }
1542+
1543+ void ws_dhcp_client_address_request (protocol_interface_info_entry_t * cur , uint8_t * prefix , uint8_t * parent_link_local )
1544+ {
1545+ if (!ws_address_entry_available (prefix , & cur -> ip_addresses )) {
1546+ if (dhcp_client_get_global_address (cur -> id , parent_link_local , prefix , cur -> mac , ws_dhcp_client_global_adress_cb ) != 0 ) {
1547+ tr_error ("DHCPp client request fail" );
1548+ }
1549+ }
1550+ }
1551+
1552+ static void ws_rpl_prefix_callback (prefix_entry_t * prefix , void * handle , uint8_t * parent_link_local )
1553+ {
1554+ protocol_interface_info_entry_t * cur = (protocol_interface_info_entry_t * ) handle ;
1555+ /* Check if A-Flag.
1556+ * A RPL node may use this option for the purpose of Stateless Address Autoconfiguration (SLAAC)
1557+ * from a prefix advertised by a parent.
1558+ */
1559+ if (prefix -> options & PIO_A ) {
1560+ if (icmpv6_slaac_prefix_update (cur , prefix -> prefix , prefix -> prefix_len , prefix -> lifetime , prefix -> preftime ) != 0 ) {
1561+ ipv6_interface_slaac_handler (cur , prefix -> prefix , prefix -> prefix_len , prefix -> lifetime , prefix -> preftime );
1562+ }
1563+ } else if (prefix -> prefix_len ) {
1564+ ws_dhcp_client_address_request (cur , prefix -> prefix , parent_link_local );
1565+ }
1566+ }
1567+
15121568static void ws_bootstrap_rpl_activate (protocol_interface_info_entry_t * cur )
15131569{
15141570 tr_debug ("RPL Activate" );
@@ -1517,7 +1573,7 @@ static void ws_bootstrap_rpl_activate(protocol_interface_info_entry_t *cur)
15171573
15181574 addr_add_router_groups (cur );
15191575 rpl_control_set_domain_on_interface (cur , protocol_6lowpan_rpl_domain , downstream );
1520- rpl_control_set_callback (protocol_6lowpan_rpl_domain , ws_bootstrap_rpl_callback , cur );
1576+ rpl_control_set_callback (protocol_6lowpan_rpl_domain , ws_bootstrap_rpl_callback , ws_rpl_prefix_callback , cur );
15211577 // If i am router I Do this
15221578 rpl_control_force_leaf (protocol_6lowpan_rpl_domain , leaf );
15231579
0 commit comments