2424#include "sm_cache.h"
2525#include "sm_report.h"
2626#include "wifi_hal.h"
27+ #include "wifi_ctrl.h"
2728#include "wifi_mgr.h"
2829#include "wifi_sm.h"
2930#include "const.h"
3031#include "sm_utils.h"
3132
3233#define DCA_TO_APP 1
3334#define APP_TO_DCA 2
35+ #define BUS_SM_APP_ENABLE "Device.X_RDK_MeshAgent.SM_APP.Enable"
36+ #define SM_APP_ENABLE_TIMER_INTERVAL_SEC 5
3437
3538typedef struct {
3639 sta_data_t assoc_stats [BSS_MAX_NUM_STATIONS ];
@@ -43,6 +46,9 @@ typedef struct {
4346 unsigned int req_stats_vap_mask ;
4447} client_assoc_stats_t ;
4548
49+ static int sm_stats_to_monitor_set (wifi_app_t * app , bool enable );
50+ static void sm_events_subscribe (wifi_app_t * app );
51+
4652client_assoc_stats_t client_assoc_stats [MAX_NUM_RADIOS ];
4753
4854int sm_survey_type_conversion (wifi_neighborScanMode_t * halw_scan_type , survey_type_t * app_stat_type , unsigned int conv_type )
@@ -556,7 +562,7 @@ int handle_sm_command_event(wifi_app_t *app, wifi_event_t *event)
556562 wifi_mgr_t * g_wifi_mgr = get_wifimgr_obj ();
557563 stats_config_t * cur_stats_cfg = NULL ;
558564 hash_map_t * cur_app_stats_cfg_map = app -> data .u .sm_data .sm_stats_config_map ;
559- bool off_scan_rfc = g_wifi_mgr -> rfc_dml_parameters .wifi_offchannelscan_sm_rfc ;
565+ bool sm_app_enable , off_scan_rfc = g_wifi_mgr -> rfc_dml_parameters .wifi_offchannelscan_sm_rfc ;
560566
561567 wifi_util_dbg_print (WIFI_SM , "inside %s:%d off_scan_rfc:%d\n" ,__func__ , __LINE__ ,off_scan_rfc );
562568 if (event -> sub_type == wifi_event_type_wifi_offchannelscan_sm_rfc )
@@ -583,6 +589,17 @@ int handle_sm_command_event(wifi_app_t *app, wifi_event_t *event)
583589 cur_stats_cfg = hash_map_get_next (cur_app_stats_cfg_map , cur_stats_cfg );
584590 }
585591 }
592+ } else if (event -> sub_type == wifi_event_type_sm_app_enable ) {
593+ if (event -> u .core_data .msg ) {
594+ sm_app_enable = * (bool * )event -> u .core_data .msg ;
595+ wifi_util_dbg_print (WIFI_SM , "%s:%d: Received SM app enable event. sm_app_enable=%d\n" ,
596+ __func__ , __LINE__ , sm_app_enable );
597+ sm_stats_to_monitor_set (app , sm_app_enable );
598+ } else {
599+ wifi_util_error_print (WIFI_SM ,
600+ "inside %s:%d sub_type: wifi_event_type_sm_app_enable sm_app_enable=NULL\n" ,
601+ __func__ , __LINE__ );
602+ }
586603 }
587604 return RETURN_OK ;
588605}
@@ -797,14 +814,66 @@ int sm_event(wifi_app_t *app, wifi_event_t *event)
797814 monitor_event_sm (app , event );
798815 break ;
799816 case wifi_event_type_command :
800- handle_sm_command_event (app ,event );
817+ handle_sm_command_event (app , event );
801818 break ;
802819 default :
803820 break ;
804821 }
805822 return RETURN_OK ;
806823}
807824
825+ static void sm_app_enable_handler (char * event_name , raw_data_t * p_data )
826+ {
827+ bool sm_app_enable ;
828+
829+ wifi_util_dbg_print (WIFI_SM , "%s:%d recvd event\n" , __func__ , __LINE__ );
830+
831+ if ((strcmp (event_name , BUS_SM_APP_ENABLE ) != 0 ) ||
832+ (p_data -> data_type != bus_data_type_boolean )) {
833+ wifi_util_error_print (WIFI_SM , "%s:%d invalid event received,%s:%x\n" , __func__ , __LINE__ ,
834+ event_name , p_data -> data_type );
835+ return ;
836+ }
837+
838+ sm_app_enable = p_data -> raw_data .b ;
839+
840+ push_event_to_ctrl_queue (& sm_app_enable , sizeof (sm_app_enable ), wifi_event_type_command ,
841+ wifi_event_type_sm_app_enable , NULL );
842+ }
843+
844+ static int sm_events_timer_task (void * args )
845+ {
846+ sm_events_subscribe ((wifi_app_t * )args );
847+ return TIMER_TASK_COMPLETE ;
848+ }
849+
850+ static void sm_events_subscribe (wifi_app_t * app )
851+ {
852+ wifi_ctrl_t * ctrl = (wifi_ctrl_t * )get_wifictrl_obj ();
853+ wifi_bus_desc_t * bus_desc = get_bus_descriptor ();
854+ static int task_id = 0 ;
855+ bool add_timer_task = false;
856+
857+ if (app -> data .u .sm_data .sm_app_enable_subscribed == false) {
858+ if (bus_desc -> bus_event_subs_fn (& ctrl -> handle , BUS_SM_APP_ENABLE , sm_app_enable_handler ,
859+ NULL , 0 ) != bus_error_success ) {
860+ wifi_util_dbg_print (WIFI_SM , "%s:%d: event:%s subscribe failed\n" , __FUNCTION__ ,
861+ __LINE__ , BUS_SM_APP_ENABLE );
862+ add_timer_task = true;
863+ } else {
864+ app -> data .u .sm_data .sm_app_enable_subscribed = true;
865+ wifi_util_info_print (WIFI_SM , "%s:%d: event:%s subscribe success\n" , __FUNCTION__ ,
866+ __LINE__ , BUS_SM_APP_ENABLE );
867+ }
868+ }
869+
870+ if (add_timer_task && task_id == 0 ) {
871+ scheduler_add_timer_task (ctrl -> sched , FALSE, & task_id , sm_events_timer_task , app ,
872+ (SM_APP_ENABLE_TIMER_INTERVAL_SEC * MSEC_IN_SEC ), 0 , FALSE);
873+ } else if (!add_timer_task && task_id != 0 ) {
874+ scheduler_cancel_timer_task (ctrl -> sched , task_id );
875+ }
876+ }
808877
809878int sm_init (wifi_app_t * app , unsigned int create_flag )
810879{
@@ -814,14 +883,16 @@ int sm_init(wifi_app_t *app, unsigned int create_flag)
814883 }
815884
816885 dpp_init ();
886+ sm_events_subscribe (app );
817887
818- app -> data .u .sm_data .sm_stats_config_map = hash_map_create ();
819- app -> data .u .sm_data .report_tasks_map = hash_map_create ();
888+ app -> data .u .sm_data .sm_stats_config_map = hash_map_create ();
889+ app -> data .u .sm_data .report_tasks_map = hash_map_create ();
820890
821891 memset (client_assoc_stats , 0 , sizeof (client_assoc_stats ));
822892 rc = sm_report_init (app );
823893
824- wifi_util_info_print (WIFI_SM , "%s:%d: Init SM app %s\n" , __func__ , __LINE__ , rc ? "failure" : "success" );
894+ wifi_util_info_print (WIFI_SM , "%s:%d: Init SM app %s\n" , __func__ , __LINE__ ,
895+ rc ? "failure" : "success" );
825896
826897 return rc ;
827898}
0 commit comments