38 #include <sys/types.h>
40 #include "safec_lib.h"
47 #ifdef ENABLE_SD_NOTIFY
48 #include <systemd/sd-daemon.h>
52 static pthread_mutex_t tMutexLock;
54 static void _sysEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
56 static volatile int initialized = 0;
59 static char *ntp_filename =
"/tmp/stt_received";
61 static char *profile_1_filename =
"/opt/.hdcp_profile_1";
65 static IARM_Result_t _SetHDCPProfile(
void *arg);
69 static int keyLogStatus = 1;
70 static int getKeyCodeLoggingPref(
void);
71 static void setKeyCodeLoggingPref(
int logStatus);
72 static IARM_Result_t _GetKeyCodeLoggingPref(
void *arg);
73 static IARM_Result_t _SetKeyCodeLoggingPref(
void *arg);
75 IARM_Result_t SYSMgr_Start()
79 setvbuf(stdout, NULL, _IOLBF, 0);
82 LOG(
"I-ARM Sys Mgr: %d\r\n", __LINE__);
83 pthread_mutex_init (&tMutexLock, NULL);
85 pthread_mutex_lock(&tMutexLock);
98 #ifdef ENABLE_SD_NOTIFY
99 sd_notifyf(0,
"READY=1\n"
100 "STATUS=sysMgr is Successfully Initialized\n"
102 (
unsigned long) getpid());
106 #define xstr(s) str(s)
124 systemStates.disconnect_mgr_state = {0};
125 systemStates.TuneReadyStatus = {0};
126 systemStates.exit_ok_key_sequence = {0};
127 systemStates.cmac = {0};
128 systemStates.card_moto_entitlements = {0};
129 systemStates.card_moto_hrv_rx = {0};
130 systemStates.dac_init_timestamp = {0};
131 systemStates.card_cisco_status = {0};
132 systemStates.video_presenting = {0};
133 systemStates.hdmi_out = {0};
134 systemStates.hdcp_enabled = {0};
135 systemStates.hdmi_edid_read = {0};
136 systemStates.firmware_download = {0};
137 systemStates.firmware_update_state = {0};
138 systemStates.time_source = {0};
139 systemStates.time_zone_available = {0};
140 systemStates.ca_system = {0};
141 systemStates.estb_ip = {0};
142 systemStates.ecm_ip = {0};
143 systemStates.lan_ip = {0};
144 systemStates.moca = {0};
145 systemStates.docsis = {0};
146 systemStates.dsg_broadcast_tunnel = {0};
147 systemStates.dsg_ca_tunnel = {0};
148 systemStates.cable_card = {0};
149 systemStates.cable_card_download = {0};
150 systemStates.cvr_subsystem = {0};
151 systemStates.download = {0};
152 systemStates.vod_ad = {0};
153 systemStates.card_serial_no ={0};
154 systemStates.ecm_mac ={0};
155 systemStates.dac_id = {0};
156 systemStates.plant_id = {0};
157 systemStates.stb_serial_no={0};
158 systemStates.bootup = {0};
159 systemStates.hdcp_enabled.state = 1;
160 systemStates.dst_offset = {0};
161 systemStates.ip_mode = {0};
162 systemStates.qam_ready_status = {0};
164 pthread_mutex_unlock(&tMutexLock);
165 LOG(
"I-ARM Sys Mgr: %d\r\n", __LINE__);
166 return IARM_RESULT_SUCCESS;
169 LOG(
"VENU: I-ARM Sys Mgr Error case: %d\r\n", __LINE__);
170 return IARM_RESULT_INVALID_STATE;
180 LOG(
"I-ARM Sys Mgr: HeartBeat at %s\r\n", ctime(&curr));
183 return IARM_RESULT_SUCCESS;
190 pthread_mutex_lock(&tMutexLock);
193 pthread_mutex_unlock(&tMutexLock);
194 pthread_mutex_destroy (&tMutexLock);
196 return IARM_RESULT_SUCCESS;
199 return IARM_RESULT_INVALID_STATE;
216 int ret = lstat(profile_1_filename, &st);
226 static IARM_Result_t _SetHDCPProfile(
void *arg)
234 if ((
CheckHdcpProfile() != new_profile) && (new_profile == 0 || new_profile == 1)) {
236 if (new_profile == 0) {
237 unlink(profile_1_filename);
240 fd = open(profile_1_filename, O_WRONLY|O_CREAT, 0666);
247 __TIMESTAMP(); printf (
"The hdcp profile is set to %d\n", new_profile);
249 eventData.data.hdcpProfileData.hdcpProfile = new_profile;
250 __TIMESTAMP(); printf(
"<<<<<<< Send HDCP Profile UPdate Event is %d>>>>>>>>",eventData.data.hdcpProfileData.hdcpProfile);
254 return IARM_RESULT_SUCCESS;
268 __TIMESTAMP(); printf (
"The hdcp profile is %d\n", param->
HdcpProfile);
269 return IARM_RESULT_SUCCESS;
285 #ifdef USE_MFR_FOR_SERIAL
288 pthread_mutex_lock(&tMutexLock);
289 static int current_channel_map_state = 0;
292 if(current_channel_map_state != systemStates.
channel_map.state) {
293 __TIMESTAMP();LOG(
"_GetSystemStates return ChannelMapState = %d\r\n", systemStates.
channel_map.state);
294 current_channel_map_state = systemStates.
channel_map.state;
299 systemStates.TuneReadyStatus.state=1;
300 if(systemStates.time_source.state==0) {
301 if( access( ntp_filename, F_OK ) != -1 ) {
302 systemStates.time_source.state=1;
306 *param = systemStates;
307 pthread_mutex_unlock(&tMutexLock);
308 return IARM_RESULT_SUCCESS;
311 static void _sysEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
315 if (eventId != IARM_BUS_SYSMGR_EVENT_SYSTEMSTATE)
return;
322 pthread_mutex_lock(&tMutexLock);
325 IARM_Bus_SYSMgr_SystemState_t stateId = sysEventData->data.systemStates.stateId;
326 int state = sysEventData->data.systemStates.state;
327 int error = sysEventData->data.systemStates.error;
328 char* payload=sysEventData->data.systemStates.payload;
329 __TIMESTAMP();LOG(
"_sysEventHandler invoked for stateid %d of state %d and error %d\r\n", stateId, state,error);
331 case IARM_BUS_SYSMGR_SYSSTATE_CHANNELMAP:
342 LOG(
"Got IARM_BUS_SYSMGR_SYSSTATE_CHANNELMAP ID = %s", systemStates.
channel_map.payload );
344 case IARM_BUS_SYSMGR_SYSSTATE_DISCONNECTMGR:
345 systemStates.disconnect_mgr_state.state = state;
346 systemStates.disconnect_mgr_state.error = error;
347 LOG(
"Got IARM_BUS_SYSMGR_SYSSTATE_DISCONNECTMGR state = %d\n", state );
349 case IARM_BUS_SYSMGR_SYSSTATE_TUNEREADY:
350 systemStates.TuneReadyStatus.state = state;
351 systemStates.TuneReadyStatus.error = error;
353 case IARM_BUS_SYSMGR_SYSSTATE_EXIT_OK :
354 systemStates.exit_ok_key_sequence.state = state;
355 systemStates.exit_ok_key_sequence.error = error;
357 case IARM_BUS_SYSMGR_SYSSTATE_CMAC :
358 systemStates.cmac.state = state;
359 systemStates.cmac.error = error;
361 case IARM_BUS_SYSMGR_SYSSTATE_MOTO_ENTITLEMENT :
362 systemStates.card_moto_entitlements.state = state;
363 systemStates.card_moto_entitlements.error = error;
365 case IARM_BUS_SYSMGR_SYSSTATE_MOTO_HRV_RX :
366 systemStates.card_moto_hrv_rx.state = state;
367 systemStates.card_moto_hrv_rx.error = error;
368 case IARM_BUS_SYSMGR_SYSSTATE_DAC_INIT_TIMESTAMP :
369 systemStates.dac_init_timestamp.state = state;
370 systemStates.dac_init_timestamp.error = error;
371 strncpy(systemStates.dac_init_timestamp.payload,payload,strlen(payload));
372 systemStates.dac_init_timestamp.payload[strlen(payload)]=
'\0';
373 printf(
"systemStates.dac_init_timestamp.payload=%s\n",systemStates.dac_init_timestamp.payload);
375 case IARM_BUS_SYSMGR_SYSSTATE_CARD_CISCO_STATUS :
376 systemStates.card_cisco_status.state = state;
377 systemStates.card_cisco_status.error = error;
379 case IARM_BUS_SYSMGR_SYSSTATE_VIDEO_PRESENTING :
380 systemStates.video_presenting.state = state;
381 systemStates.video_presenting.error = error;
383 case IARM_BUS_SYSMGR_SYSSTATE_HDMI_OUT :
384 systemStates.hdmi_out.state = state;
385 systemStates.hdmi_out.error = error;
387 case IARM_BUS_SYSMGR_SYSSTATE_HDCP_ENABLED :
388 systemStates.hdcp_enabled.state = state;
389 systemStates.hdcp_enabled.error = error;
391 case IARM_BUS_SYSMGR_SYSSTATE_HDMI_EDID_READ :
392 systemStates.hdmi_edid_read.state = state;
393 systemStates.hdmi_edid_read.error = error;
395 case IARM_BUS_SYSMGR_SYSSTATE_FIRMWARE_DWNLD :
396 systemStates.firmware_download.state = state;
397 systemStates.firmware_download.error = error;
399 case IARM_BUS_SYSMGR_SYSSTATE_FIRMWARE_UPDATE_STATE :
400 systemStates.firmware_update_state.state = state;
401 systemStates.firmware_update_state.error = error;
403 case IARM_BUS_SYSMGR_SYSSTATE_TIME_SOURCE :
404 systemStates.time_source.state = state;
405 systemStates.time_source.error = error;
418 case IARM_BUS_SYSMGR_SYSSTATE_TIME_ZONE :
419 systemStates.time_zone_available.state = state;
420 systemStates.time_zone_available.error = error;
422 rc = memcpy_s( systemStates.time_zone_available.payload,
sizeof(systemStates.time_zone_available.payload), payload,
sizeof( systemStates.time_zone_available.payload ) );
427 systemStates.time_zone_available.payload[
sizeof( systemStates.time_zone_available.payload ) - 1] = 0;
428 LOG(
"Got IARM_BUS_SYSMGR_SYSSTATE_TIME_ZONE = %s\n", systemStates.time_zone_available.payload );
430 case IARM_BUS_SYSMGR_SYSSTATE_CA_SYSTEM :
431 systemStates.ca_system.state = state;
432 systemStates.ca_system.error = error;
434 case IARM_BUS_SYSMGR_SYSSTATE_ESTB_IP :
435 systemStates.estb_ip.state = state;
436 systemStates.estb_ip.error = error;
438 case IARM_BUS_SYSMGR_SYSSTATE_ECM_IP :
439 systemStates.ecm_ip.state = state;
440 systemStates.ecm_ip.error = error;
442 case IARM_BUS_SYSMGR_SYSSTATE_LAN_IP :
443 systemStates.lan_ip.state = state;
444 systemStates.lan_ip.error = error;
446 case IARM_BUS_SYSMGR_SYSSTATE_MOCA :
447 systemStates.moca.state = state;
448 systemStates.moca.error = error;
450 case IARM_BUS_SYSMGR_SYSSTATE_DOCSIS :
451 systemStates.docsis.state = state;
452 systemStates.docsis.error = error;
454 case IARM_BUS_SYSMGR_SYSSTATE_DSG_BROADCAST_CHANNEL :
455 systemStates.dsg_broadcast_tunnel.state = state;
456 systemStates.dsg_broadcast_tunnel.error = error;
458 case IARM_BUS_SYSMGR_SYSSTATE_DSG_CA_TUNNEL :
459 systemStates.dsg_ca_tunnel.state = state;
460 systemStates.dsg_ca_tunnel.error = error;
462 case IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD :
463 systemStates.cable_card.state = state;
464 systemStates.cable_card.error = error;
466 case IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD_DWNLD :
467 systemStates.cable_card_download.state = state;
468 systemStates.cable_card_download.error = error;
470 case IARM_BUS_SYSMGR_SYSSTATE_CVR_SUBSYSTEM :
471 systemStates.cvr_subsystem.state = state;
472 systemStates.cvr_subsystem.error = error;
474 case IARM_BUS_SYSMGR_SYSSTATE_DOWNLOAD :
475 systemStates.download.state = state;
476 systemStates.download.error = error;
478 case IARM_BUS_SYSMGR_SYSSTATE_VOD_AD :
479 systemStates.vod_ad.state = state;
480 systemStates.vod_ad.error = error;
482 rc = memcpy_s( systemStates.vod_ad.payload,
sizeof(systemStates.vod_ad.payload), payload,
sizeof( systemStates.vod_ad.payload ) );
487 systemStates.vod_ad.payload[
sizeof( systemStates.vod_ad.payload ) -1 ] =0;
488 LOG(
"Got IARM_BUS_SYSMGR_SYSSTATE_VOD_AD = %s\n", systemStates.vod_ad.payload );
490 case IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD_SERIAL_NO:
491 systemStates.card_serial_no.error =error;
492 strncpy(systemStates.card_serial_no.payload,payload,strlen(payload));
493 systemStates.card_serial_no.payload[strlen(payload)]=
'\0';
494 printf(
"systemStates.card.serial.no.payload=%s\n",systemStates.card_serial_no.payload);
496 case IARM_BUS_SYSMGR_SYSSTATE_ECM_MAC:
497 systemStates.ecm_mac.error =error;
498 strncpy(systemStates.ecm_mac.payload,payload,strlen(payload));
499 systemStates.ecm_mac.payload[strlen(payload)]=
'\0';
500 printf(
"systemStates.ecm.mac.payload=%s\n",systemStates.ecm_mac.payload);
502 case IARM_BUS_SYSMGR_SYSSTATE_DAC_ID :
503 systemStates.dac_id.state = state;
504 systemStates.dac_id.error = error;
505 assert ( (
sizeof(systemStates.dac_id.payload) -1 ) > strlen(payload) );
506 rc = strcpy_s( systemStates.dac_id.payload,
sizeof(systemStates.dac_id.payload), payload );
511 LOG(
"Got IARM_BUS_SYSMGR_SYSSTATE_DAC_ID = %s\n", systemStates.dac_id.payload );
513 case IARM_BUS_SYSMGR_SYSSTATE_PLANT_ID :
514 systemStates.plant_id.state = state;
515 systemStates.plant_id.error = error;
516 assert ( (
sizeof(systemStates.plant_id.payload) -1 ) > strlen(payload) );
517 rc = strcpy_s( systemStates.plant_id.payload,
sizeof(systemStates.plant_id.payload), payload );
522 LOG(
"Got IARM_BUS_SYSMGR_SYSSTATE_PLANT_ID = %s\n", systemStates.plant_id.payload );
524 case IARM_BUS_SYSMGR_SYSSTATE_STB_SERIAL_NO:
525 systemStates.stb_serial_no.error =error;
526 strncpy(systemStates.stb_serial_no.payload,payload,strlen(payload));
527 systemStates.stb_serial_no.payload[strlen(payload)]=
'\0';
528 printf(
"systemStates.stb.serial.payload=%s\n",systemStates.stb_serial_no.payload);
530 case IARM_BUS_SYSMGR_SYSSTATE_BOOTUP :
531 systemStates.bootup.state = state;
532 systemStates.bootup.error = error;
534 case IARM_BUS_SYSMGR_SYSSTATE_DST_OFFSET :
535 systemStates.dst_offset.state = state;
536 strncpy( systemStates.dst_offset.payload,payload,strlen(payload));
537 systemStates.dst_offset.payload[ strlen(payload) ] =
'\0';
538 systemStates.dst_offset.error = error;
541 case IARM_BUS_SYSMGR_SYSSTATE_RF_CONNECTED :
542 systemStates.rf_connected.state = state;
543 systemStates.rf_connected.error = error;
544 LOG(
"Got IARM_BUS_SYSMGR_SYSSTATE_RF_CONNECTED,State = %d, Error = %d\n", systemStates.rf_connected.state,systemStates.rf_connected.error );
546 case IARM_BUS_SYSMGR_SYSSTATE_IP_MODE:
547 systemStates.ip_mode.state=state;
548 systemStates.ip_mode.error =error;
549 strncpy(systemStates.ip_mode.payload,payload,strlen(payload));
550 systemStates.ip_mode.payload[strlen(payload)]=
'\0';
551 printf(
"Got IARM_BUS_SYSMGR_SYSSTATE_IP_MODE systemStates.ip_mode.payload=%s\n",systemStates.ip_mode.payload);
553 case IARM_BUS_SYSMGR_SYSSTATE_QAM_READY:
554 systemStates.qam_ready_status.state = state;
555 systemStates.qam_ready_status.error = error;
556 LOG(
"Got IARM_BUS_SYSMGR_SYSSTATE_QAM_READY,State = %d, Error = %d\n", systemStates.qam_ready_status.state,systemStates.qam_ready_status.error );
561 pthread_mutex_unlock(&tMutexLock);
578 IARM_Result_t iarm_ret = IARM_RESULT_IPCCORE_FAIL;
580 if(strlen(systemStates.stb_serial_no.payload) > 0)
585 param.
type = mfrSERIALIZED_TYPE_SERIALNUMBER;
590 pthread_mutex_lock(&tMutexLock);
591 if(iarm_ret == IARM_RESULT_SUCCESS)
593 memset(systemStates.stb_serial_no.payload, 0,
sizeof(systemStates.stb_serial_no.payload));
594 strncpy(systemStates.stb_serial_no.payload, param.
buffer,
sizeof(systemStates.stb_serial_no.payload)-1);
595 systemStates.stb_serial_no.error = 0;
599 systemStates.stb_serial_no.error = 1;
601 pthread_mutex_unlock(&tMutexLock);
604 static int getKeyCodeLoggingPref(
void)
610 static void setKeyCodeLoggingPref(
int logStatus)
612 int prevKeyLogStatus = keyLogStatus;
618 else if(1 == logStatus)
627 if(prevKeyLogStatus != keyLogStatus)
629 __TIMESTAMP(); printf (
"The Key Code Logging Preference is set to %d\n", keyLogStatus);
631 eventData.data.keyCodeLogData.logStatus = keyLogStatus;
632 __TIMESTAMP(); printf(
"<<<<<<< Send KEYCODE LOGGING CHANGED Event with log status %d>>>>>>>>", eventData.data.keyCodeLogData.logStatus);
637 __TIMESTAMP(); printf (
"Key Code Log status set to previous value itself!!\n");
643 static IARM_Result_t _GetKeyCodeLoggingPref(
void *arg)
647 param->
logStatus = getKeyCodeLoggingPref();
649 __TIMESTAMP(); printf (
"_GetKeyCodeLoggingPref : Key Code Log status is %d\n", param->
logStatus);
650 return IARM_RESULT_SUCCESS;
653 static IARM_Result_t _SetKeyCodeLoggingPref(
void *arg)
657 __TIMESTAMP(); printf (
"_SetKeyCodeLoggingPref : Key Code Log status is %d\n", param->
logStatus);
660 return IARM_RESULT_SUCCESS;