2929#include "sw_mac.h"
3030#include "ns_list.h"
3131#include "net_interface.h"
32+ #include "nwk_stats_api.h"
3233#include "ws_management_api.h" //ws_management_node_init
3334#ifdef MBED_CONF_MBED_MESH_API_CERTIFICATE_HEADER
3435#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;
8990static wisun_certificates_t * wisun_certificates_ptr = NULL ;
9091static mac_api_t * mac_api = NULL ;
9192
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+
92102extern fhss_timer_t fhss_functions ;
93103
94104/* private function prototypes */
@@ -99,6 +109,7 @@ static void wisun_tasklet_configure_and_connect_to_network(void);
99109static void wisun_tasklet_clear_stored_certificates (void ) ;
100110static 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 );
101111static int wisun_tasklet_add_stored_certificates (void ) ;
112+ static void wisun_tasklet_statistics_do_start (void );
102113
103114/*
104115 * \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver.
@@ -300,6 +311,10 @@ static void wisun_tasklet_configure_and_connect_to_network(void)
300311 arm_network_own_certificate_add ((const arm_certificate_entry_s * )& own_cert );
301312#endif
302313
314+ if (statistics_started ) {
315+ wisun_tasklet_statistics_do_start ();
316+ }
317+
303318 status = arm_nwk_interface_up (wisun_tasklet_data_ptr -> network_interface_id );
304319 if (status >= 0 ) {
305320 wisun_tasklet_data_ptr -> tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED ;
@@ -566,3 +581,66 @@ int wisun_tasklet_set_trusted_certificate(uint8_t *cert, uint16_t cert_len)
566581 }
567582 return wisun_tasklet_store_certificate_data (cert , cert_len , NULL , 0 , false, false, true);
568583}
584+
585+ int wisun_tasklet_statistics_start (void )
586+ {
587+ statistics_started = true;
588+
589+ if (statistics == NULL ) {
590+ statistics = ns_dyn_mem_alloc (sizeof (wisun_statistics_t ));
591+ }
592+ if (statistics == NULL ) {
593+ return -1 ;
594+ }
595+ memset (statistics , 0 , sizeof (wisun_statistics_t ));
596+
597+ wisun_tasklet_statistics_do_start ();
598+
599+ return 0 ;
600+ }
601+
602+ static void wisun_tasklet_statistics_do_start (void )
603+ {
604+ if (!wisun_tasklet_data_ptr || wisun_tasklet_data_ptr -> network_interface_id < 0 || !mac_api ) {
605+ return ;
606+ }
607+
608+ protocol_stats_start (& statistics -> nwk_stats );
609+ ns_sw_mac_statistics_start (mac_api , & statistics -> mac_statistics );
610+ ws_statistics_start (wisun_tasklet_data_ptr -> network_interface_id , & statistics -> ws_statistics );
611+ }
612+
613+ int wisun_tasklet_statistics_nw_read (mesh_nw_statistics_t * stats )
614+ {
615+ if (!statistics || !stats ) {
616+ return -1 ;
617+ }
618+
619+ stats -> rpl_total_memory = statistics -> nwk_stats .rpl_total_memory ;
620+ stats -> etx_1st_parent = statistics -> nwk_stats .etx_1st_parent ;
621+ stats -> etx_2nd_parent = statistics -> nwk_stats .etx_2nd_parent ;
622+ stats -> asynch_tx_count = statistics -> ws_statistics .asynch_tx_count ;
623+ stats -> asynch_rx_count = statistics -> ws_statistics .asynch_rx_count ;
624+
625+ return 0 ;
626+ }
627+
628+ int wisun_tasklet_statistics_mac_read (mesh_mac_statistics_t * stats )
629+ {
630+ if (!statistics || !stats ) {
631+ return -1 ;
632+ }
633+
634+ stats -> mac_rx_count = statistics -> mac_statistics .mac_rx_count ;
635+ stats -> mac_tx_count = statistics -> mac_statistics .mac_tx_count ;
636+ stats -> mac_bc_rx_count = statistics -> mac_statistics .mac_bc_rx_count ;
637+ stats -> mac_bc_tx_count = statistics -> mac_statistics .mac_bc_tx_count ;
638+ stats -> mac_tx_bytes = statistics -> mac_statistics .mac_tx_bytes ;
639+ stats -> mac_rx_bytes = statistics -> mac_statistics .mac_rx_bytes ;
640+ stats -> mac_tx_failed_count = statistics -> mac_statistics .mac_tx_failed_count ;
641+ stats -> mac_retry_count = statistics -> mac_statistics .mac_retry_count ;
642+ stats -> mac_cca_attempts_count = statistics -> mac_statistics .mac_cca_attempts_count ;
643+ stats -> mac_failed_cca_count = statistics -> mac_statistics .mac_failed_cca_count ;
644+
645+ return 0 ;
646+ }
0 commit comments