29
29
#include "sw_mac.h"
30
30
#include "ns_list.h"
31
31
#include "net_interface.h"
32
+ #include "nwk_stats_api.h"
32
33
#include "ws_management_api.h" //ws_management_node_init
33
34
#ifdef MBED_CONF_MBED_MESH_API_CERTIFICATE_HEADER
34
35
#if !defined(MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE ) || !defined(MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE ) || \
@@ -89,6 +90,15 @@ static wisun_tasklet_data_str_t *wisun_tasklet_data_ptr = NULL;
89
90
static wisun_certificates_t * wisun_certificates_ptr = NULL ;
90
91
static mac_api_t * mac_api = NULL ;
91
92
93
+ typedef struct {
94
+ nwk_stats_t nwk_stats ;
95
+ mac_statistics_t mac_statistics ;
96
+ ws_statistics_t ws_statistics ;
97
+ } wisun_statistics_t ;
98
+
99
+ static bool statistics_started = false;
100
+ static wisun_statistics_t * statistics = NULL ;
101
+
92
102
extern fhss_timer_t fhss_functions ;
93
103
94
104
/* private function prototypes */
@@ -99,6 +109,7 @@ static void wisun_tasklet_configure_and_connect_to_network(void);
99
109
static void wisun_tasklet_clear_stored_certificates (void ) ;
100
110
static int wisun_tasklet_store_certificate_data (const uint8_t * cert , uint16_t cert_len , const uint8_t * cert_key , uint16_t cert_key_len , bool remove_own , bool remove_trusted , bool trusted_cert );
101
111
static int wisun_tasklet_add_stored_certificates (void ) ;
112
+ static void wisun_tasklet_statistics_do_start (void );
102
113
103
114
/*
104
115
* \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver.
@@ -301,6 +312,10 @@ static void wisun_tasklet_configure_and_connect_to_network(void)
301
312
arm_network_own_certificate_add ((const arm_certificate_entry_s * )& own_cert );
302
313
#endif
303
314
315
+ if (statistics_started ) {
316
+ wisun_tasklet_statistics_do_start ();
317
+ }
318
+
304
319
status = arm_nwk_interface_up (wisun_tasklet_data_ptr -> network_interface_id );
305
320
if (status >= 0 ) {
306
321
wisun_tasklet_data_ptr -> tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED ;
@@ -564,3 +579,66 @@ int wisun_tasklet_set_trusted_certificate(uint8_t *cert, uint16_t cert_len)
564
579
// Stack is inactive store the certificates and activate when connect() called
565
580
return wisun_tasklet_store_certificate_data (cert , cert_len , NULL , 0 , false, false, true);
566
581
}
582
+
583
+ int wisun_tasklet_statistics_start (void )
584
+ {
585
+ statistics_started = true;
586
+
587
+ if (statistics == NULL ) {
588
+ statistics = ns_dyn_mem_alloc (sizeof (wisun_statistics_t ));
589
+ }
590
+ if (statistics == NULL ) {
591
+ return -1 ;
592
+ }
593
+ memset (statistics , 0 , sizeof (wisun_statistics_t ));
594
+
595
+ wisun_tasklet_statistics_do_start ();
596
+
597
+ return 0 ;
598
+ }
599
+
600
+ static void wisun_tasklet_statistics_do_start (void )
601
+ {
602
+ if (!wisun_tasklet_data_ptr || wisun_tasklet_data_ptr -> network_interface_id < 0 || !mac_api ) {
603
+ return ;
604
+ }
605
+
606
+ protocol_stats_start (& statistics -> nwk_stats );
607
+ ns_sw_mac_statistics_start (mac_api , & statistics -> mac_statistics );
608
+ ws_statistics_start (wisun_tasklet_data_ptr -> network_interface_id , & statistics -> ws_statistics );
609
+ }
610
+
611
+ int wisun_tasklet_statistics_nw_read (mesh_nw_statistics_t * stats )
612
+ {
613
+ if (!statistics || !stats ) {
614
+ return -1 ;
615
+ }
616
+
617
+ stats -> rpl_total_memory = statistics -> nwk_stats .rpl_total_memory ;
618
+ stats -> etx_1st_parent = statistics -> nwk_stats .etx_1st_parent ;
619
+ stats -> etx_2nd_parent = statistics -> nwk_stats .etx_2nd_parent ;
620
+ stats -> asynch_tx_count = statistics -> ws_statistics .asynch_tx_count ;
621
+ stats -> asynch_rx_count = statistics -> ws_statistics .asynch_rx_count ;
622
+
623
+ return 0 ;
624
+ }
625
+
626
+ int wisun_tasklet_statistics_mac_read (mesh_mac_statistics_t * stats )
627
+ {
628
+ if (!statistics || !stats ) {
629
+ return -1 ;
630
+ }
631
+
632
+ stats -> mac_rx_count = statistics -> mac_statistics .mac_rx_count ;
633
+ stats -> mac_tx_count = statistics -> mac_statistics .mac_tx_count ;
634
+ stats -> mac_bc_rx_count = statistics -> mac_statistics .mac_bc_rx_count ;
635
+ stats -> mac_bc_tx_count = statistics -> mac_statistics .mac_bc_tx_count ;
636
+ stats -> mac_tx_bytes = statistics -> mac_statistics .mac_tx_bytes ;
637
+ stats -> mac_rx_bytes = statistics -> mac_statistics .mac_rx_bytes ;
638
+ stats -> mac_tx_failed_count = statistics -> mac_statistics .mac_tx_failed_count ;
639
+ stats -> mac_retry_count = statistics -> mac_statistics .mac_retry_count ;
640
+ stats -> mac_cca_attempts_count = statistics -> mac_statistics .mac_cca_attempts_count ;
641
+ stats -> mac_failed_cca_count = statistics -> mac_statistics .mac_failed_cca_count ;
642
+
643
+ return 0 ;
644
+ }
0 commit comments