[FIX] wrong pack size of system memory total/used
[platform/core/system/swap-manager.git] / daemon / da_protocol_check.c
1 /*
2  *  DA manager
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Cherepanov Vitaliy <v.cherepanov@samsung.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  * Contributors:
23  * - Samsung RnD Institute Russia
24  *
25  */
26 #include "debug.h"
27 #include "da_protocol.h"
28 #include "da_protocol_check.h"
29
30 #include <stdint.h>
31 #include <string.h>
32
33 //application checking functions
34 int check_app_type(uint32_t app_type)
35 {
36         if ((app_type >= APP_INFO_TYPE_MIN) &&
37                 (app_type <= APP_INFO_TYPE_MAX)) {
38                 return 1;
39         } else {
40                 LOGE("wrong value\n");
41                 return 0;
42         }
43 }
44
45 int check_app_id(uint32_t app_type, char *app_id)
46 {
47         int res = 0;
48         char *p;
49         switch (app_type){
50                 case APP_TYPE_TIZEN:
51                         res = 1;
52                         break;
53                 case APP_TYPE_RUNNING:
54                         strtol(app_id, &p, 10);
55                         if ((*app_id != 0) && (*p == 0))
56                                 res = 1;
57                         else
58                                 LOGE("wrong app id for APP_RUNNING\n");
59                         break;
60                 case APP_TYPE_COMMON:
61                         res = (strlen(app_id) == 0);
62                         if (!res)
63                                 LOGE("wrong app id for APP_COMMON\n");
64                         break;
65                 default :
66                         LOGE("wrong app type\n");
67                         return 0;
68                         break;
69         }
70         return res;
71 }
72
73 int check_exec_path(char *path)
74 {
75         int res = 1;
76         struct stat buffer;
77
78         if (!(res = (stat (path, &buffer) == 0)))
79                 LOGE("wrong exec path <%s>\n", path);
80
81         return res;
82 }
83
84 //config checking functions
85 int check_conf_features(uint64_t feature0, uint64_t feature1)
86 {
87         int res = 1;
88
89         feature0 &= ~(uint64_t)FL_ALL_FEATURES;
90
91         if (feature0 != 0) {
92                 LOGE("wrong features0 0x%016llX mask %016llX\n", feature0, (uint64_t)FL_ALL_FEATURES);
93                 res = 0;
94         }
95
96         feature1 &= ~(uint64_t)0;
97
98         if (feature1 != 0) {
99                 LOGE("wrong features1 0x%016llX mask %016llX\n", feature1, (uint64_t)0);
100                 res = 0;
101         }
102
103         return res;
104 }
105
106
107 int check_conf_systrace_period(uint32_t system_trace_period)
108 {
109         int res = 1;
110         if ((system_trace_period < CONF_SYSTRACE_PERIOD_MIN) ||
111                 (system_trace_period > CONF_SYSTRACE_PERIOD_MAX))
112         {
113                 LOGE("wrong system trace period value %lu (0x%08X)\n",
114                                 system_trace_period, system_trace_period);
115                 res = 0;
116         }
117
118         return res;
119 }
120
121 int check_conf_datamsg_period(uint32_t data_message_period)
122 {
123         int res = 1;
124         if ((data_message_period < CONF_DATA_MSG_PERIOD_MIN) ||
125                 (data_message_period > CONF_DATA_MSG_PERIOD_MAX))
126         {
127                 LOGE("wrong data message period value %lu (0x%08X)\n",
128                                 data_message_period, data_message_period);
129                 res = 0;
130         }
131
132         return res;
133 }
134
135 //User space check functions
136 int check_us_app_count(uint32_t app_count)
137 {
138         int res = 1;
139         if ((app_count < US_APP_COUNT_MIN) ||
140                 (app_count > US_APP_COUNT_MAX))
141         {
142                 LOGE("wrong user space app count %lu (0x%08X)\n", app_count, app_count);
143                 res = 0;
144         }
145
146         return res;
147 }
148 //User space app inst check function
149 int check_us_app_inst_func_count(uint32_t func_count)
150 {
151         int res = 1;
152         if ((func_count < US_APP_INST_FUNC_MIN) ||
153                 (func_count > US_APP_INST_FUNC_MAX))
154         {
155                 LOGE("wrong US app inst func count %lu (0x%08X)\n",
156                                 func_count, func_count);
157                 res = 0;
158         }
159
160         return res;
161 }
162
163 static char *args_avail = US_FUNC_ARGS;
164 int check_us_inst_func_args(char *args)
165 {
166         char *p;
167         for (p = args; *p != 0; p++)
168                 if (strchr(args_avail, (int)*p) == NULL){
169                         LOGE("wrong args <%s> char <%c> <0x%02X>\n", args, (int)*p, (char)*p);
170                         return 0;
171                 }
172         return 1;
173 }
174
175 int check_lib_inst_count(uint32_t lib_count)
176 {
177         int res = 1;
178         if ((lib_count < US_APP_INST_LIB_MIN) ||
179                 (lib_count > US_APP_INST_LIB_MAX))
180         {
181                 LOGE("wrong US app inst lib count %lu (0x%08X)\n",
182                                 lib_count, lib_count);
183                 res = 0;
184         }
185
186         return res;
187 }
188
189 int check_conf(struct conf_t *conf)
190 {
191         //Check features value
192         if (!check_conf_features(conf->use_features0, conf->use_features1)) {
193                 LOGE("check features fail\n");
194                 return 0;
195         }
196
197         if (!check_conf_systrace_period(conf->system_trace_period)) {
198                 LOGE("system trace period error\n");
199                 return 0;
200         }
201
202         if (!check_conf_datamsg_period(conf->data_message_period)) {
203                 LOGE("data message period error\n");
204                 return 0;
205         }
206
207         return 1;
208 }