2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <agl_thread.h>
20 #include <other_service/VP_GetEnv.h>
22 #include <system_service/ss_templates.h>
23 #include <system_service/ss_sm_ram_access.h>
24 #include <system_service/ss_ver.h>
26 #include "system_service/ss_package.h"
27 #include "system_service/ss_access_if_private.h"
28 #include "system_service/ss_system_manager_conf.h"
31 #define ZONE_WARN ZONEMASK(30)
34 #define ZONE_INFO ZONEMASK(29)
37 /* Environment variable name */
38 const CHAR LaunchConfigFileNameEnvVariable[] = "APPS_CONFIG_FILENAME";
39 const CHAR AreaTypeEnvVariable[] = "VEHICLEPARAMETERLIBRARY_AREA";
40 const CHAR BrandTypeEnvVariable[] = "VEHICLEPARAMETERLIBRARY_BRAND";
41 const CHAR GradeEnvVariable[] = "VP_VEHICLEPARAMETERLIBRARY_grade";
43 /* Environment variable value */
44 const CHAR EnvValueYes[] = "y";
45 const CHAR EnvValueNo[] = "n";
47 const CHAR EnvValueAvailable[] = "available";
48 const CHAR EnvValueUnavailable[] = "unavailable";
52 * Define areas, brands, and grades by the vendor.
53 * For example, an area is a destination of a product.
54 * Examples of areas : JP(Japan), EU, etc.
56 const CHAR EnvValueArea1[] = "Area1";
57 const CHAR EnvValueArea2[] = "Area2";
58 const CHAR EnvValueArea3[] = "Area3";
59 const CHAR EnvValueArea4[] = "Area4";
60 const CHAR EnvValueBrand1[] = "Brand1";
61 const CHAR EnvValueBrand2[] = "Brand2";
62 const CHAR EnvValueGrade1[] = "Grade1";
63 const CHAR EnvValueGrade2[] = "Grade2";
64 const CHAR EnvValueGrade3[] = "Grade3";
66 /* Package information */
67 const CHAR PkgInfoGen2[] = "Gen2";
70 typedef struct T_SS_SM_CONF_CTX {
71 EFrameworkunifiedStatus (*cbRebootNoticeFunc)(HANDLE hApp);
73 : cbRebootNoticeFunc(NULL) {
75 } T_SS_SM_CONF_CTX_INFO;
77 static T_SS_SM_CONF_CTX_INFO s_confCtx;
79 /***********************************************************************
81 ***********************************************************************/
82 static void registProtectSvcs(std::vector<std::string> & protectedSvcs) {
83 protectedSvcs.push_back(MN_NS_SHAREDMEM);
84 protectedSvcs.push_back(MN_NS_NPPSERVICE);
85 protectedSvcs.push_back(MN_NS_BACKUPMGR);
86 protectedSvcs.push_back(MN_SS_LOGGERSRV);
87 protectedSvcs.push_back(MN_COMMUNICATION);
88 protectedSvcs.push_back(MN_PS_PSMSHADOW);
89 protectedSvcs.push_back(MN_SS_POWERSERVICE);
92 /***********************************************************************
93 * registGroupRelaunchSvcs
94 ***********************************************************************/
95 static void registGroupRelaunchSvcs(
96 std::vector<std::string> & groupRelaunchSvcs) {
97 groupRelaunchSvcs.push_back(MN_ENFORMSERVICE);
98 groupRelaunchSvcs.push_back(MN_NAVIPROXY);
99 groupRelaunchSvcs.push_back(MN_AWBPROXY);
100 groupRelaunchSvcs.push_back(MN_TFFPROXY);
101 groupRelaunchSvcs.push_back(MN_AWNPRIMARY);
102 groupRelaunchSvcs.push_back(MN_AWMPRIMARY);
103 groupRelaunchSvcs.push_back(MN_AWBPRIMARY);
104 groupRelaunchSvcs.push_back(MN_AWTPRIMARY);
107 /***********************************************************************
108 * setEvnVariableForLaunchConfigFile
109 ***********************************************************************/
110 static EFrameworkunifiedStatus setEvnVariableForLaunchConfigFile(std::string f_sEnvFile,
111 std::string f_sEnvBrand,
112 std::string f_sEnvGrade,
114 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
115 const CHAR VupLaunchConfigFileName[] = "sm_launch_vup.cfg";
116 const CHAR LaunchConfigFileName1[] = "sm_launch.cfg";
117 const CHAR LaunchConfigFileName2[] = "sm_launch.cfg";
119 // If an environment variable is set, that value is used, so set only when it is not set
120 if (f_sEnvFile.empty()) {
121 const CHAR *l_pLaunchConfigFile = NULL;
124 l_pLaunchConfigFile = VupLaunchConfigFileName;
126 // Change the file read by Brand and Grade
127 if ((f_sEnvBrand == EnvValueBrand2) && (f_sEnvGrade != EnvValueGrade1)) {
128 l_pLaunchConfigFile = LaunchConfigFileName1;
130 l_pLaunchConfigFile = LaunchConfigFileName2;
133 std::string cnfPath = "/etc/basesystem/BS/ss/system_manager/rwdata/";
134 cnfPath += l_pLaunchConfigFile;
135 if (access(cnfPath.c_str(), F_OK) != 0) {
136 l_pLaunchConfigFile = LaunchConfigFileName1;
140 if (0 != setenv(LaunchConfigFileNameEnvVariable, l_pLaunchConfigFile, 1)) {
142 l_eStatus = eFrameworkunifiedStatusFail;
149 /***********************************************************************
150 * setEvnVariableForLaunchCus
151 ***********************************************************************/
152 static EFrameworkunifiedStatus setEvnVariableForLaunchCus(std::string f_sEnvArea) {
153 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
154 const CHAR LaunchCusEnvVariable[] = "SM_CONF_LAUNCH_CUS";
156 const CHAR *l_pSetValue =
157 (EnvValueArea1 == f_sEnvArea || EnvValueArea2 == f_sEnvArea) ?
158 EnvValueYes : EnvValueNo;
160 if (0 != setenv(LaunchCusEnvVariable, l_pSetValue, 1)) {
162 l_eStatus = eFrameworkunifiedStatusFail;
168 /***********************************************************************
169 * setEvnVariableForLaunchTFF
170 ***********************************************************************/
171 static EFrameworkunifiedStatus setEvnVariableForLaunchTFF(std::string f_sEnvArea) {
172 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
173 const CHAR LaunchTFFEnvVariable[] = "SM_CONF_LAUNCH_TFF";
175 const CHAR *l_pSetValue = EnvValueNo;
177 BOOL l_bArea1 = (f_sEnvArea == EnvValueArea1) ? TRUE : FALSE;
178 BOOL l_bArea2 = (f_sEnvArea == EnvValueArea2) ? TRUE : FALSE;
180 if (l_bArea1 || l_bArea2) {
181 l_pSetValue = EnvValueYes;
183 l_pSetValue = EnvValueNo;
186 if (0 != setenv(LaunchTFFEnvVariable, l_pSetValue, 1)) {
188 l_eStatus = eFrameworkunifiedStatusFail;
194 /***********************************************************************
195 * getEnvValiavleWithDefault
196 ***********************************************************************/
197 static std::string getEnvValiavleWithDefault(const CHAR *f_pEnvName,
198 const CHAR *f_pDefault) {
199 std::string l_sReturnValue;
200 char buf[VP_MAX_LENGTH];
202 VP_GetEnv(f_pEnvName, buf);
203 if (buf[0] == '\0') {
204 l_sReturnValue = (NULL != f_pDefault) ? f_pDefault : "";
206 l_sReturnValue = buf;
208 return l_sReturnValue;
212 /***********************************************************************
213 * getPkgInfoWithDefault
214 ***********************************************************************/
216 getPkgInfoWithDefault(const CHAR *f_pPkgName, const CHAR *f_pDefault){
217 std::string l_sReturnValue = (NULL != f_pDefault) ? f_pDefault : "";
220 SSVER_PkgInfo pkgInfo = {0};
223 if(!cVersion.empty()){
224 EFrameworkunifiedStatus ret = cVersion.getPkgInfo(f_pPkgName, &pkgInfo);
225 if((ret == eFrameworkunifiedStatusOK) && ('\0' != pkgInfo.version[0])){
226 l_sReturnValue = pkgInfo.version;
229 } catch(EFrameworkunifiedStatus ee){
233 return l_sReturnValue;
236 /***********************************************************************
237 * setEvnVariableForPkgSeriesInfo
238 ***********************************************************************/
239 static EFrameworkunifiedStatus
240 setEvnVariableForPkgSeriesInfo(std::string f_sPkgSeriesInfo){
241 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
242 const CHAR PkgSeriesEnvVariable[] = "SM_CONF_PKG_SERIES";
244 if (f_sPkgSeriesInfo.empty()) {
248 if (0 != setenv(PkgSeriesEnvVariable, f_sPkgSeriesInfo.c_str(), 1)) {
250 l_eStatus = eFrameworkunifiedStatusFail;
256 /***********************************************************************
257 * setVersionInfo subfunction(version,date settings)
258 ***********************************************************************/
259 static EFrameworkunifiedStatus setVerInfo_version_date(const char* VerPath) {
260 EFrameworkunifiedStatus configRet = eFrameworkunifiedStatusOK;
262 SSVER_PkgInfo pkgInfo;
264 bzero(&pkgInfo, sizeof(pkgInfo));
266 std::ifstream verFin(VerPath);
268 if (std::getline(verFin, line)) {
269 snprintf(pkgInfo.version, sizeof(pkgInfo.version), "%s",
273 if (std::getline(verFin, line)) {
274 snprintf(pkgInfo.date, sizeof(pkgInfo.date), "%s", line.c_str());
277 configRet = ver.setPkgInfo(SS_PKG_MAIN_LPF_SI, pkgInfo);
278 SS_ASERT(configRet == eFrameworkunifiedStatusOK);
285 /***********************************************************************
286 * Set version information
287 ***********************************************************************/
288 static EFrameworkunifiedStatus setVersionInfo(void) {
289 EFrameworkunifiedStatus configRet = eFrameworkunifiedStatusOK;
293 SSVER_PkgInfo pkgInfo;
294 const char targetEnv[] = "TARGET_BOARD";
297 snprintf(pkgInfo.version, sizeof(pkgInfo.version), "%s",
298 getEnvValiavleWithDefault(targetEnv, NULL).c_str());
299 pkgInfo.date[0] = '\0';
300 configRet = ver.setPkgInfo(SS_PKG_TARGETBOARD, pkgInfo);
301 SS_ASERT(configRet == eFrameworkunifiedStatusOK);
303 // Set PRODUCT version information
304 const char prdVersion[] = "/usr/share/basesystem/BS/ss/system_manager/rodata/version.txt";
307 std::ifstream prdFin(prdVersion);
309 bzero(&pkgInfo, sizeof(pkgInfo));
310 if (std::getline(prdFin, line)) {
311 snprintf(pkgInfo.version, sizeof(pkgInfo.version), "%s",
314 configRet = ver.setPkgInfo(SS_PKG_MAIN_EMMC, pkgInfo);
315 SS_ASERT(configRet == eFrameworkunifiedStatusOK);
317 bzero(&pkgInfo, sizeof(pkgInfo));
318 if (std::getline(prdFin, line)) {
319 snprintf(pkgInfo.version, sizeof(pkgInfo.version), "%s",
322 configRet = ver.setPkgInfo(SS_PKG_MAIN_PRODUCT_SI, pkgInfo);
323 SS_ASERT(configRet == eFrameworkunifiedStatusOK);
330 const char phaseVersion[] = "/usr/share/basesystem/BS/ss/system_manager/rodata/PhaseInfo.txt";
332 configRet = setVerInfo_version_date(phaseVersion);
335 } catch (EFrameworkunifiedStatus ee) {
342 // If _CWORD83_ common header is added, replace with century definition
343 #define NTFY_PSMShadowService_Availability MN_PS_PSMSHADOW"/Availability"
345 EFrameworkunifiedStatus cbPsmNotificationFunc(HANDLE hApp) {
346 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
348 if (MSG_PSM_REBOOT_NOTIFY != FrameworkunifiedGetMsgProtocol(hApp)) {
353 if (NULL != s_confCtx.cbRebootNoticeFunc) {
354 l_eStatus = s_confCtx.cbRebootNoticeFunc(hApp);
355 if (l_eStatus != eFrameworkunifiedStatusOK) {
368 EFrameworkunifiedStatus cbServiceNotificationFunc(HANDLE hApp) {
369 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
370 PCSTR l_availabilityName;
371 BOOL l_serviceAvailability;
373 l_availabilityName = FrameworkunifiedGetLastNotification(hApp);
374 if (l_availabilityName == NULL) {
378 l_serviceAvailability = FrameworkunifiedIsServiceAvailable(hApp);
380 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "%s : %s", l_availabilityName,
381 l_serviceAvailability ? "TRUE" : "FALSE");
383 // Since it is necessary to guarantee SYNC of RAMD at _CWORD71_
384 // within 200msec after receiving reboot notice from SYS mcu,
385 // do UMOUNT RAMD immediately after receiving reboot notice by SystemManager.
386 if ((strcmp(NTFY_PSMShadowService_Availability, l_availabilityName) == 0)
387 && (l_serviceAvailability)) {
388 l_eStatus = FrameworkunifiedAttachCallbackToDispatcher(hApp, FRAMEWORKUNIFIED_ANY_SOURCE,
389 MSG_PSM_REBOOT_NOTIFY,
390 cbPsmNotificationFunc);
391 if (eFrameworkunifiedStatusOK != l_eStatus) {
401 /***********************************************************************
403 ***********************************************************************/
404 EFrameworkunifiedStatus ss_sm_initHook(HANDLE hApp, const T_SS_SM_INIT_HOOK_IN_PARAM *inPrm,
405 T_SS_SM_INIT_HOOK_OUT_PARAM *outPrm) {
406 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
407 std::string l_sEnvFile;
408 std::string l_sEnvArea;
409 std::string l_sEnvBrand;
410 std::string l_sEnvGrade;
412 std::string l_sPkgSeriesInfo;
414 // Register non-recoverable services for OOM Killer
415 registProtectSvcs(outPrm->protectedSvcs);
417 // Register services for Group Relaunch
418 registGroupRelaunchSvcs(outPrm->groupRelaunchSvcs);
420 if (NULL == inPrm->cbRebootNoticeFunc) {
423 s_confCtx.cbRebootNoticeFunc = inPrm->cbRebootNoticeFunc;
426 /** Set Version information **/
427 if (eFrameworkunifiedStatusOK != setVersionInfo()) {
431 /** Get environment variable **/
433 // APPS_CONFIG_FILENAME (not set by default)
434 l_sEnvFile = getEnvValiavleWithDefault(LaunchConfigFileNameEnvVariable, NULL);
436 // VEHICLEPARAMETERLIBRARY_AREA
437 l_sEnvArea = getEnvValiavleWithDefault(AreaTypeEnvVariable, EnvValueArea1);
439 // VEHICLEPARAMETERLIBRARY_BRAND
440 l_sEnvBrand = getEnvValiavleWithDefault(BrandTypeEnvVariable, NULL);
442 // VEHICLEPARAMETERLIBRARY_grade
443 l_sEnvGrade = getEnvValiavleWithDefault(GradeEnvVariable, NULL);
446 /** Get Package information **/
449 l_sPkgSeriesInfo = getPkgInfoWithDefault(SS_PKG_SERIES_INFO, NULL);
452 /** Set environment variable **/
453 // APPS_CONFIG_FILENAME
454 if (eFrameworkunifiedStatusOK
455 != setEvnVariableForLaunchConfigFile(l_sEnvFile, l_sEnvBrand,
456 l_sEnvGrade, inPrm->bIsVupMode)) {
460 // SM_CONF_PKG_SERIES
461 if (eFrameworkunifiedStatusOK != setEvnVariableForPkgSeriesInfo(l_sPkgSeriesInfo)) {
466 // SM_CONF_LAUNCH_CUS
467 if (eFrameworkunifiedStatusOK != setEvnVariableForLaunchCus(l_sEnvArea)) {
471 // SM_CONF_LAUNCH_TFF
472 if (eFrameworkunifiedStatusOK
473 != setEvnVariableForLaunchTFF(l_sEnvArea)) {
477 if (eFrameworkunifiedStatusOK
478 != (l_eStatus = FrameworkunifiedSubscribeNotificationWithCallback(
479 hApp, NTFY_PSMShadowService_Availability, cbServiceNotificationFunc))) {
483 " Error: FrameworkunifiedSubscribeNotificationWithCallback(" "hApp, %s) errored: %d/'%s'",
484 NTFY_PSMShadowService_Availability, l_eStatus, GetStr(l_eStatus).c_str());