42
42
#include "ws_management_api.h"
43
43
#include "net_rpl.h"
44
44
#include "Service_Libs/nd_proxy/nd_proxy.h"
45
+ #include "Service_Libs/utils/ns_time.h"
45
46
#include "6LoWPAN/ws/ws_bbr_api_internal.h"
46
47
#include "6LoWPAN/ws/ws_pae_controller.h"
47
48
#include "6LoWPAN/lowpan_adaptation_interface.h"
@@ -96,9 +97,6 @@ static uint8_t current_global_prefix[16] = {0}; // DHCP requires 16 bytes prefix
96
97
static uint32_t bbr_delay_timer = BBR_CHECK_INTERVAL ; // initial delay.
97
98
static uint32_t global_prefix_unavailable_timer = 0 ; // initial delay.
98
99
99
- static uint8_t * dhcp_vendor_data_ptr = NULL ;
100
- static uint8_t dhcp_vendor_data_len = 0 ;
101
-
102
100
static rpl_dodag_conf_t rpl_conf = {
103
101
// Lifetime values
104
102
.default_lifetime = 120 ,
@@ -485,9 +483,38 @@ static bool wisun_dhcp_address_add_cb(int8_t interfaceId, dhcp_address_cache_upd
485
483
return true;
486
484
}
487
485
486
+ static uint8_t * ws_bbr_dhcp_server_dynamic_vendor_data_write (int8_t interfaceId , uint8_t * ptr , uint16_t * data_len )
487
+ {
488
+ // If local time is not available vendor data is not written and data_len is not modified
489
+ (void )interfaceId ;
490
+
491
+ uint64_t time_read ;
492
+
493
+ if (0 != ns_time_system_time_read (& time_read )) {
494
+ return ptr ;
495
+ }
496
+
497
+ if (data_len ) {
498
+ * data_len += net_vendor_option_current_time_length ();
499
+ }
500
+ if (!ptr ) {
501
+ return ptr ;
502
+ }
503
+ time_read += 2208988800 ; // Time starts now from the 0 era instead of First day of Unix (1 Jan 1970)
504
+
505
+ uint32_t era = time_read / (uint64_t )(4294967296 );
506
+ uint32_t timestamp = time_read - (era * (uint64_t )(4294967296 ));
507
+ ptr = net_vendor_option_current_time_write (ptr , era , timestamp , 0 );
508
+
509
+ return ptr ;
510
+ }
511
+
512
+
488
513
static void ws_bbr_dhcp_server_dns_info_update (protocol_interface_info_entry_t * cur , uint8_t * global_id )
489
514
{
490
515
//add DNS server information to DHCP server that is learned from the backbone interface.
516
+ uint8_t * dhcp_vendor_data_ptr = NULL ;
517
+ uint8_t dhcp_vendor_data_len = 0 ;
491
518
uint8_t dns_server_address [16 ];
492
519
uint8_t * dns_search_list_ptr = NULL ;
493
520
uint8_t dns_search_list_len = 0 ;
@@ -497,33 +524,40 @@ static void ws_bbr_dhcp_server_dns_info_update(protocol_interface_info_entry_t *
497
524
DHCPv6_server_service_set_dns_server (cur -> id , global_id , dns_server_address , dns_search_list_ptr , dns_search_list_len );
498
525
}
499
526
500
- //TODO Generate vendor data in Wi-SUN network include the cached DNS query results in some sort of TLV format
527
+ //Generate ARM specific vendor data in Wi-SUN network
528
+ // Cached DNS query results
529
+ // Network Time
530
+
501
531
int vendor_data_len = 0 ;
502
532
for (int n = 0 ; n < MAX_DNS_RESOLUTIONS ; n ++ ) {
503
533
if (pre_resolved_dns_queries [n ].domain_name != NULL ) {
504
534
vendor_data_len += net_dns_option_vendor_option_data_dns_query_length (pre_resolved_dns_queries [n ].domain_name );
505
535
}
506
536
}
537
+
507
538
if (vendor_data_len ) {
508
- ns_dyn_mem_free (dhcp_vendor_data_ptr );
509
- dhcp_vendor_data_ptr = ns_dyn_mem_alloc (vendor_data_len );
539
+ dhcp_vendor_data_ptr = ns_dyn_mem_temporary_alloc (vendor_data_len );
510
540
if (!dhcp_vendor_data_ptr ) {
511
541
tr_warn ("Vendor info set fail" );
512
542
return ;
513
543
}
514
544
dhcp_vendor_data_len = vendor_data_len ;
515
545
}
546
+ // Write ARM vendor data
547
+ uint8_t * ptr = dhcp_vendor_data_ptr ;
548
+
516
549
if (dhcp_vendor_data_ptr ) {
517
550
// Write vendor data
518
- uint8_t * ptr = dhcp_vendor_data_ptr ;
519
551
for (int n = 0 ; n < MAX_DNS_RESOLUTIONS ; n ++ ) {
520
552
if (pre_resolved_dns_queries [n ].domain_name != NULL ) {
521
553
ptr = net_dns_option_vendor_option_data_dns_query_write (ptr , pre_resolved_dns_queries [n ].address , pre_resolved_dns_queries [n ].domain_name );
522
554
}
523
555
}
524
556
}
557
+ DHCPv6_server_service_set_vendor_data_callback (cur -> id , global_id , ARM_ENTERPRISE_NUMBER , ws_bbr_dhcp_server_dynamic_vendor_data_write );
525
558
526
559
DHCPv6_server_service_set_vendor_data (cur -> id , global_id , ARM_ENTERPRISE_NUMBER , dhcp_vendor_data_ptr , dhcp_vendor_data_len );
560
+ ns_dyn_mem_free (dhcp_vendor_data_ptr );
527
561
}
528
562
529
563
static void wisun_dhcp_address_remove_cb (int8_t interfaceId , uint8_t * targetAddress , void * prefix_info )
0 commit comments