• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "distribution.h"
17 #include "securec.h"
18 #include "log.h"
19 #include "pake_client.h"
20 #include "pake_server.h"
21 #include "sts_server.h"
22 #include "exchange_auth_info.h"
23 #include "exchange_auth_info_client.h"
24 #include "add_auth_info.h"
25 #include "remove_auth_info.h"
26 #include "add_auth_info_client.h"
27 #include "remove_auth_info_client.h"
28 
29 #ifdef DESC
30 #undef DESC
31 #endif
32 #define DESC(...) 1
33 
34 static int32_t proc_pake_request_message(struct hichain *handle, struct header_analysis *nav,
35     struct message *receive, struct message *send);
36 static int32_t proc_pake_response_message(struct hichain *handle, struct header_analysis *nav,
37     struct message *receive, struct message *send);
38 static int32_t proc_sts_request_message(struct hichain *handle, struct header_analysis *nav,
39     struct message *receive, struct message *send);
40 static int32_t proc_exchange_request_message(struct hichain *handle, struct header_analysis *nav,
41     struct message *receive, struct message *send);
42 static int32_t proc_exchange_response_message(struct hichain *handle, struct header_analysis *nav,
43     struct message *receive, struct message *send);
44 static int32_t proc_add_request_message(struct hichain *handle, struct header_analysis *nav,
45     struct message *receive, struct message *send);
46 static int32_t proc_remove_request_message(struct hichain *handle, struct header_analysis *nav,
47     struct message *receive, struct message *send);
48 static int32_t proc_add_response_message(struct hichain *handle, struct header_analysis *nav,
49     struct message *receive, struct message *send);
50 static int32_t proc_remove_response_message(struct hichain *handle, struct header_analysis *nav,
51     struct message *receive, struct message *send);
52 static int32_t proc_sec_clone_request_message(struct hichain *handle, struct header_analysis *nav,
53     struct message *receive, struct message *send);
54 static int32_t proc_inform_message(struct hichain *handle, struct header_analysis *nav,
55     struct message *receive, struct message *send);
56 static bool check_hichain_state_is_success(struct hichain *hichain, const struct header_analysis *nav);
57 static int32_t get_operation_code(const struct header_analysis *nav, const struct message *receive);
58 static bool is_message_illegal(int32_t operation_code, int32_t modular);
59 static int32_t proc_sts_response_message(struct hichain *handle, struct header_analysis *nav,
60     struct message *receive, struct message *send);
61 
62 typedef int32_t (*proc_message_func)(struct hichain *handle, struct header_analysis *nav,
63     struct message *receive, struct message *send);
64 
65 struct message_code_map {
66     uint32_t code;
67     int32_t modular;
68     bool is_request_msg;
69 };
70 
71 struct distribution_message {
72     int32_t modular;
73     bool is_request_msg;
74     proc_message_func func;
75 };
76 
77 struct check_message_powered {
78     int32_t operation_code;
79     int32_t modular;
80 };
81 
82 static const struct message_code_map G_MESSAGE_CODE_MAP[] = {
83     { PAKE_REQUEST, PAKE_MODULAR, true },
84     { PAKE_CLIENT_CONFIRM, PAKE_MODULAR, true },
85     { EXCHANGE_REQUEST, EXCHANGE_MODULAR, true },
86     { AUTH_START_REQUEST, STS_MODULAR, true },
87     { AUTH_ACK_REQUEST, STS_MODULAR, true },
88     { ADD_AUTHINFO_REQUEST, ADD_MODULAR, true },
89     { REMOVE_AUTHINFO_REQUEST, REMOVE_MODULAR, true },
90     { SEC_CLONE_START_REQUEST, SEC_CLONE_MODULAR, true },
91     { SEC_CLONE_ACK_REQUEST, SEC_CLONE_MODULAR, true },
92     { PAKE_RESPONSE, PAKE_MODULAR, false },
93     { PAKE_SERVER_CONFIRM_RESPONSE, PAKE_MODULAR, false },
94     { EXCHANGE_RESPONSE, EXCHANGE_MODULAR, false },
95     { AUTH_START_RESPONSE, STS_MODULAR, false },
96     { AUTH_ACK_RESPONSE, STS_MODULAR, false },
97     { ADD_AUTHINFO_RESPONSE, ADD_MODULAR, false },
98     { REMOVE_AUTHINFO_RESPONSE, REMOVE_MODULAR, false },
99     { SEC_CLONE_START_RESPONSE, SEC_CLONE_MODULAR, false },
100     { SEC_CLONE_ACK_RESPONSE, SEC_CLONE_MODULAR, false },
101     { INFORM_MESSAGE, INFORM_MODULAR, true }
102 };
103 
104 static const struct distribution_message G_DISTRIBUTION_MESSAGE[] = {
105     { PAKE_MODULAR, true, proc_pake_request_message },
106     { PAKE_MODULAR, false, proc_pake_response_message },
107     { STS_MODULAR, true, proc_sts_request_message },
108     { EXCHANGE_MODULAR, true, proc_exchange_request_message },
109     { EXCHANGE_MODULAR, false, proc_exchange_response_message },
110     { ADD_MODULAR, true, proc_add_request_message },
111     { REMOVE_MODULAR, true, proc_remove_request_message },
112     { SEC_CLONE_MODULAR, true, proc_sec_clone_request_message },
113     { INFORM_MODULAR, false, proc_inform_message },
114     { STS_MODULAR, false, proc_sts_response_message },
115     { ADD_MODULAR, false, proc_add_response_message },
116     { REMOVE_MODULAR, false, proc_remove_response_message },
117 };
118 
119 #if DESC("interface")
navigate_message(uint32_t message_code)120 struct header_analysis navigate_message(uint32_t message_code)
121 {
122     struct header_analysis nav = { INVALID_MODULAR, 0, 0 };
123 
124     for (uint32_t i = 0; i < sizeof(G_MESSAGE_CODE_MAP) / sizeof(G_MESSAGE_CODE_MAP[0]); i++) {
125         if (G_MESSAGE_CODE_MAP[i].code == message_code) {
126             nav.modular = G_MESSAGE_CODE_MAP[i].modular;
127             nav.msg_type = message_code & 0xf; /* message_code & 0xf get low four bits of message code */
128             nav.is_request_msg = G_MESSAGE_CODE_MAP[i].is_request_msg;
129             break;
130         }
131     }
132     LOGI("Message code %u, nav is %d, %d, %d", message_code, nav.modular, nav.msg_type, nav.is_request_msg);
133     return nav;
134 }
135 
check_message_support(struct hichain * hichain,const struct header_analysis * nav,const struct message * receive)136 int32_t check_message_support(struct hichain *hichain, const struct header_analysis *nav,
137     const struct message *receive)
138 {
139     if (nav->modular == 0) {
140         LOGE("Receive unknow message, message code is 0x%04x", receive->msg_code);
141         return HC_UNKNOW_MESSAGE;
142     }
143 
144     if (!check_hichain_state_is_success(hichain, nav)) {
145         return HC_STATE_ERROR;
146     }
147 
148     int32_t operation_code = get_operation_code(nav, receive);
149     if (operation_code == INVALID_OPERATION_CODE) {
150         return HC_OPERATION_CODE_ERROR;
151     } else if (operation_code == NO_OPERATION_CODE) {
152         /* compare with recorded operation code and verify */
153         if (is_message_illegal(hichain->operation_code, nav->modular)) {
154             LOGE("Operation code is %d, message code is %u, it is inconsistency",
155                 hichain->operation_code, receive->msg_code);
156             return HC_MESSAGE_INCONSISTENCY;
157         }
158     } else {
159         int32_t ret = hichain->cb.confirm_receive_request(&hichain->identity, operation_code);
160         if (ret != 0) {
161             LOGE("Service does not allow response %d", operation_code);
162             return HC_SERVICE_CONFIRM_ERROR;
163         }
164         hichain->operation_code = operation_code;
165     }
166 
167     return HC_OK;
168 }
169 
proc_message(struct hichain * handle,struct header_analysis * nav,struct message * receive,struct message * send)170 int32_t proc_message(struct hichain *handle, struct header_analysis *nav,
171     struct message *receive, struct message *send)
172 {
173     for (uint32_t i = 0; i < sizeof(G_DISTRIBUTION_MESSAGE) / sizeof(G_DISTRIBUTION_MESSAGE[0]); i++) {
174         if ((nav->modular == G_DISTRIBUTION_MESSAGE[i].modular) &&
175             (nav->is_request_msg == G_DISTRIBUTION_MESSAGE[i].is_request_msg)) {
176             int32_t ret = G_DISTRIBUTION_MESSAGE[i].func(handle, nav, receive, send);
177             LOGI("Proc_message return code is %d", ret);
178             return ret;
179         }
180     }
181     return HC_UNKNOW_MESSAGE;
182 }
183 
connect_message(struct hichain * handle,struct header_analysis * nav,struct message * send)184 int32_t connect_message(struct hichain *handle, struct header_analysis *nav, struct message *send)
185 {
186     if (nav->modular != STS_MODULAR && nav->modular != PAKE_MODULAR) {
187         return HC_OK;
188     }
189     if (nav->msg_type != STS_END_MSG) {
190         return HC_OK;
191     }
192     if (nav->is_request_msg) { /* server does not need message connection */
193         return HC_OK;
194     }
195 
196     int32_t ret;
197 
198     switch (handle->operation_code) {
199         case BIND:
200             ret = send_exchange_request(handle, send);
201             LOGI("Client build exchange request message return value is %d", ret);
202             return ret;
203         case AUTHENTICATE:
204             send->msg_code = INVALID_MESSAGE;
205             return HC_OK;
206         case ADD_AUTHINFO:
207             ret = send_add_request(handle, send);
208             LOGI("Client build add auth info request message return value is %d", ret);
209             return ret;
210         case REMOVE_AUTHINFO:
211             ret = send_remove_request(handle, send);
212             LOGI("Client build remove auth info request message return value is %d", ret);
213             return ret;
214         default:
215             return HC_INNER_ERROR;
216     }
217 
218     return HC_OK;
219 }
220 #endif /* DESC */
221 
check_hichain_state_is_success(struct hichain * hichain,const struct header_analysis * nav)222 static bool check_hichain_state_is_success(struct hichain *hichain, const struct header_analysis *nav)
223 {
224     if ((nav->modular == PAKE_MODULAR) || (nav->modular == STS_MODULAR)) {
225         if ((hichain->state != INIT_STATE) && (hichain->state != KEY_AGREEMENT_STATE) &&
226             (hichain->last_state != INIT_STATE) && (hichain->last_state != KEY_AGREEMENT_STATE)) {
227             goto error;
228         }
229     } else {
230         if ((hichain->state != KEY_AGREEMENT_STATE) && (hichain->state != OPERATION_STATE) &&
231             (hichain->last_state != KEY_AGREEMENT_STATE) && (hichain->last_state != OPERATION_STATE)) {
232             goto error;
233         }
234     }
235     return true;
236 
237 error:
238     LOGE("Check hichain state failed, state is %d, message nav is %d-%d-%d", hichain->state, nav->modular,
239         nav->msg_type, nav->is_request_msg);
240     return false;
241 }
242 
243 static int32_t get_operation_from_pake(void *payload);
244 static int32_t get_operation_from_sts(void *payload);
get_operation_code(const struct header_analysis * nav,const struct message * receive)245 static int32_t get_operation_code(const struct header_analysis *nav, const struct message *receive)
246 {
247     int32_t operation_code = NO_OPERATION_CODE;
248 
249     if ((nav->modular == PAKE_MODULAR) && (nav->msg_type == PAKE_START_MSG) && nav->is_request_msg) {
250         operation_code = get_operation_from_pake(receive->payload);
251     } else if ((nav->modular == STS_MODULAR) && (nav->msg_type == STS_START_MSG) && nav->is_request_msg) {
252         operation_code = get_operation_from_sts(receive->payload);
253     }
254     LOGI("Receive message had operation code is %d", operation_code);
255     return operation_code;
256 }
257 
is_message_illegal(int32_t operation_code,int32_t modular)258 static bool is_message_illegal(int32_t operation_code, int32_t modular)
259 {
260     struct check_message_powered table[] = { { BIND, PAKE_MODULAR },
261                                              { BIND, EXCHANGE_MODULAR },
262                                              { AUTH_KEY_AGREEMENT, PAKE_MODULAR },
263                                              { UNBIND, STS_MODULAR },
264                                              { UNBIND, REMOVE_MODULAR },
265                                              { AUTHENTICATE, STS_MODULAR },
266                                              { ADD_AUTHINFO, STS_MODULAR },
267                                              { ADD_AUTHINFO, ADD_MODULAR },
268                                              { REMOVE_AUTHINFO, STS_MODULAR },
269                                              { REMOVE_AUTHINFO, REMOVE_MODULAR },
270                                              { SEC_CLONE_OP, STS_MODULAR },
271                                              { SEC_CLONE_OP, SEC_CLONE_MODULAR } };
272 
273     for (uint32_t i = 0; i < sizeof(table) / sizeof(table[0]); i++) {
274         if ((modular == table[i].modular) && (operation_code == table[i].operation_code)) {
275             return false;
276         }
277     }
278     return true;
279 }
280 
get_operation_from_pake(void * payload)281 static int32_t get_operation_from_pake(void *payload)
282 #if !(defined(_CUT_PAKE_) || defined(_CUT_PAKE_SERVER_))
283 {
284     int32_t permissible_code[] = { BIND, AUTH_KEY_AGREEMENT };
285     struct pake_start_request_data *data = payload;
286 
287     for (uint32_t i = 0; i < sizeof(permissible_code) / sizeof(int32_t); i++) {
288         if (permissible_code[i] == data->operation_code) {
289             return data->operation_code;
290         }
291     }
292     LOGE("Receive operation code %d is error", data->operation_code);
293     return INVALID_OPERATION_CODE;
294 }
295 #else /* _CUT_XXX_ */
296 {
297     (void)payload;
298     return HC_UNSUPPORT;
299 }
300 #endif /* _CUT_XXX_ */
301 
get_operation_from_sts(void * payload)302 static int32_t get_operation_from_sts(void *payload)
303 #if !(defined(_CUT_STS_) || defined(_CUT_STS_SERVER_))
304 {
305     int32_t permissible_code[] = { AUTHENTICATE, ADD_AUTHINFO, REMOVE_AUTHINFO, UNBIND, SEC_CLONE_OP };
306     struct sts_start_request_data *data = payload;
307 
308     for (uint32_t i = 0; i < sizeof(permissible_code) / sizeof(int32_t); i++) {
309         if (permissible_code[i] == data->operation_code) {
310             return data->operation_code;
311         }
312     }
313     LOGE("Receive operation code %d is error", data->operation_code);
314     return INVALID_OPERATION_CODE;
315 }
316 #else /* _CUT_XXX_ */
317 {
318     (void)payload;
319     return HC_UNSUPPORT;
320 }
321 #endif /* _CUT_XXX_ */
322 
323 /* function macro which is not called in functions */
324 #define CUT_EMPTY_FUNC(d_name, handle, nav, receive) \
325     { \
326         LOGE("Receive %s message, but do not support %s", d_name, d_name); \
327         (void)handle; \
328         (void)nav; \
329         (void)receive; \
330         send->msg_code = INVALID_MESSAGE; \
331         return HC_UNSUPPORT; \
332     }
333 
proc_pake_request_message(struct hichain * handle,struct header_analysis * nav,struct message * receive,struct message * send)334 static int32_t proc_pake_request_message(struct hichain *handle, struct header_analysis *nav,
335     struct message *receive, struct message *send)
336 #if !(defined(_CUT_PAKE_) || defined(_CUT_PAKE_SERVER_))
337 {
338     DBG_OUT("Object %u proc pake %d request message", pake_server_sn(handle->pake_server), nav->msg_type);
339     int32_t ret;
340 
341     if (nav->msg_type == PAKE_START_MSG) {
342         ret = send_pake_start_response(handle->pake_server, receive, send);
343     } else if (nav->msg_type == PAKE_END_MSG) {
344         ret = send_pake_end_response(handle->pake_server, receive, send);
345         if (ret == HC_OK) {
346             handle->cb.set_session_key(&handle->identity, &handle->pake_server->service_key);
347             (void)memset_s(handle->pake_server->service_key.session_key, HC_SESSION_KEY_LEN, 0, HC_SESSION_KEY_LEN);
348         }
349     } else {
350         return HC_UNKNOW_MESSAGE;
351     }
352     return ret;
353 }
354 #else /* _CUT_XXX_ */
355 CUT_EMPTY_FUNC("pake request", handle, nav, receive);
356 #endif /* _CUT_XXX_ */
357 
proc_pake_response_message(struct hichain * handle,struct header_analysis * nav,struct message * receive,struct message * send)358 static int32_t proc_pake_response_message(struct hichain *handle, struct header_analysis *nav,
359     struct message *receive, struct message *send)
360 #if !(defined(_CUT_PAKE_) || defined(_CUT_PAKE_CLIENT_))
361 {
362     DBG_OUT("Object %u proc pake %d response message", pake_client_sn(handle->pake_client), nav->msg_type);
363     int32_t ret;
364 
365     if (nav->msg_type == PAKE_START_MSG) {
366         ret = send_pake_end_request(handle->pake_client, receive, send);
367     } else if (nav->msg_type == PAKE_END_MSG) {
368         ret = receive_pake_end_response(handle->pake_client, receive);
369         if (ret == HC_OK) {
370             handle->cb.set_session_key(&handle->identity, &handle->pake_client->service_key);
371             (void)memset_s(handle->pake_client->service_key.session_key, HC_SESSION_KEY_LEN, 0, HC_SESSION_KEY_LEN);
372         }
373     } else {
374         return HC_UNKNOW_MESSAGE;
375     }
376     return ret;
377 }
378 #else /* _CUT_XXX_ */
379 CUT_EMPTY_FUNC("pake response", handle, nav, receive);
380 #endif /* _CUT_XXX_ */
381 
proc_exchange_request_message(struct hichain * handle,struct header_analysis * nav,struct message * receive,struct message * send)382 static int32_t proc_exchange_request_message(struct hichain *handle, struct header_analysis *nav,
383     struct message *receive, struct message *send)
384 #if !(defined(_CUT_PAKE_) || defined(_CUT_PAKE_SERVER_) || defined(_CUT_EXCHANGE_) || defined(_CUT_EXCHANGE_SERVER_))
385 {
386     DBG_OUT("Object %u proc exchange auth info request message", pake_server_sn(handle->pake_server));
387     (void)nav;
388     int32_t ret = send_exchange_response(handle, receive, send);
389 
390     DBG_OUT("Object %u proc exchange message, error code is %d", pake_server_sn(handle->pake_server), ret);
391     return ret;
392 }
393 #else /* _CUT_XXX_ */
394 CUT_EMPTY_FUNC("exchange request", handle, nav, receive);
395 #endif /* _CUT_XXX_ */
396 
proc_exchange_response_message(struct hichain * handle,struct header_analysis * nav,struct message * receive,struct message * send)397 static int32_t proc_exchange_response_message(struct hichain *handle, struct header_analysis *nav,
398     struct message *receive, struct message *send)
399 #if !(defined(_CUT_PAKE_) || defined(_CUT_PAKE_CLIENT_) || defined(_CUT_EXCHANGE_) || defined(_CUT_EXCHANGE_CLIENT_))
400 {
401     DBG_OUT("Object %u proc exchange auth info response message", pake_client_sn(handle->pake_client));
402     (void)nav;
403     (void)send;
404     int32_t ret = receive_exchange_response(handle, receive);
405 
406     send->msg_code = INVALID_MESSAGE;
407     DBG_OUT("Object %u proc exchange message, error code is %d", pake_client_sn(handle->pake_client), ret);
408     return ret;
409 }
410 #else /* _CUT_XXX_ */
411 CUT_EMPTY_FUNC("exchange response", handle, nav, receive);
412 #endif /* _CUT_XXX_ */
413 
proc_sts_request_message(struct hichain * handle,struct header_analysis * nav,struct message * receive,struct message * send)414 static int32_t proc_sts_request_message(struct hichain *handle, struct header_analysis *nav,
415     struct message *receive, struct message *send)
416 #if !(defined(_CUT_STS_) || defined(_CUT_STS_SERVER_))
417 {
418     DBG_OUT("Object %u proc sts %d request message", sts_server_sn(handle->sts_server), nav->msg_type);
419     int32_t ret;
420 
421     if (nav->msg_type == STS_START_MSG) {
422         ret = send_sts_start_response(handle->sts_server, receive, send);
423     } else if (nav->msg_type == STS_END_MSG) {
424         ret = send_sts_end_response(handle->sts_server, receive, send);
425         if (ret == HC_OK) {
426             handle->cb.set_session_key(&handle->identity, &handle->sts_server->service_key);
427             (void)memset_s(handle->sts_server->service_key.session_key, HC_SESSION_KEY_LEN, 0, HC_SESSION_KEY_LEN);
428         }
429     } else {
430         return HC_UNKNOW_MESSAGE;
431     }
432     return ret;
433 }
434 #else /* _CUT_XXX_ */
435 CUT_EMPTY_FUNC("sts request", handle, nav, receive);
436 #endif /* _CUT_XXX_ */
437 
proc_sts_response_message(struct hichain * handle,struct header_analysis * nav,struct message * receive,struct message * send)438 static int32_t proc_sts_response_message(struct hichain *handle, struct header_analysis *nav,
439     struct message *receive, struct message *send)
440 #if !(defined(_CUT_STS_) || defined(_CUT_STS_CLIENT_))
441 {
442     DBG_OUT("Object %u proc sts %d response message.", sts_client_sn(handle->sts_client), nav->msg_type);
443     int32_t ret;
444 
445     if (nav->msg_type == STS_START_MSG) {
446         ret = send_sts_end_request(handle->sts_client, receive, send);
447     } else if (nav->msg_type == STS_END_MSG) {
448         ret = receive_sts_end_response(handle->sts_client, receive);
449         if (ret == HC_OK) {
450             handle->cb.set_session_key(&handle->identity, &handle->sts_client->service_key);
451         }
452     } else {
453         return HC_UNKNOW_MESSAGE;
454     }
455     return ret;
456 }
457 #else /* _CUT_XXX_ */
458 CUT_EMPTY_FUNC("sts request", handle, nav, receive);
459 #endif /* _CUT_XXX_ */
460 
proc_add_request_message(struct hichain * handle,struct header_analysis * nav,struct message * receive,struct message * send)461 static int32_t proc_add_request_message(struct hichain *handle, struct header_analysis *nav,
462     struct message *receive, struct message *send)
463 #if !(defined(_CUT_STS_) || defined(_CUT_STS_SERVER_) || defined(_CUT_ADD_) || defined(_CUT_ADD_SERVER_))
464 {
465     DBG_OUT("Object %u proc add auth info request message", sts_server_sn(handle->sts_server));
466     (void)nav;
467     int32_t ret = send_add_response(handle, receive, send);
468 
469     DBG_OUT("Object %u proc add auth info request message, error code is %d",
470         sts_server_sn(handle->sts_server), ret);
471     return ret;
472 }
473 #else /* _CUT_XXX_ */
474 CUT_EMPTY_FUNC("add auth info request", handle, nav, receive);
475 #endif /* _CUT_XXX_ */
476 
proc_remove_request_message(struct hichain * handle,struct header_analysis * nav,struct message * receive,struct message * send)477 static int32_t proc_remove_request_message(struct hichain *handle, struct header_analysis *nav,
478     struct message *receive, struct message *send)
479 #if !(defined(_CUT_STS_) || defined(_CUT_STS_SERVER_) || defined(_CUT_REMOVE_) || defined(_CUT_REMOVE_SERVER_))
480 {
481     DBG_OUT("Object %u proc remove auth info request message", sts_server_sn(handle->sts_server));
482     (void)nav;
483     int32_t ret = send_remove_response(handle, receive, send);
484 
485     DBG_OUT("Object %u proc remove auth info message, error code is %d", sts_server_sn(handle->sts_server), ret);
486     return ret;
487 }
488 #else /* _CUT_XXX_ */
489 CUT_EMPTY_FUNC("remove auth info request", handle, nav, receive);
490 #endif /* _CUT_XXX_ */
491 
proc_add_response_message(struct hichain * handle,struct header_analysis * nav,struct message * receive,struct message * send)492 static int32_t proc_add_response_message(struct hichain *handle, struct header_analysis *nav,
493     struct message *receive, struct message *send)
494 #if !(defined(_CUT_STS_) || defined(_CUT_STS_CLIENT_) || defined(_CUT_ADD_) || defined(_CUT_ADD_CLIENT_))
495 {
496     (void)nav;
497     int32_t ret = receive_add_response(handle, receive);
498     if (ret != HC_OK) {
499         LOGE("Object %u proc add auth info request message, error code is %d",
500              sts_client_sn(handle->sts_client), ret);
501         return ret;
502     }
503     send->msg_code = INVALID_MESSAGE; /* add_auth_info receives data and process ends, does not need to send */
504 
505     return HC_OK;
506 }
507 #else /* _CUT_XXX_ */
508 CUT_EMPTY_FUNC("add auth info response", handle, nav, receive);
509 #endif /* _CUT_XXX_ */
510 
proc_remove_response_message(struct hichain * handle,struct header_analysis * nav,struct message * receive,struct message * send)511 static int32_t proc_remove_response_message(struct hichain *handle, struct header_analysis *nav,
512                                             struct message *receive, struct message *send)
513 #if !(defined(_CUT_STS_) || defined(_CUT_STS_CLIENT_) || defined(_CUT_REMOVE_) || defined(_CUT_REMOVE_CLIENT_))
514 {
515     (void)nav;
516     int32_t ret = receive_remove_response(handle, receive);
517     if (ret != HC_OK) {
518         LOGE("Object %u proc add auth info request message, error code is %d",
519              sts_client_sn(handle->sts_client), ret);
520         return ret;
521     }
522     send->msg_code = INVALID_MESSAGE; /* remove_auth_info receives data and process ends, does not need to send */
523 
524     return HC_OK;
525 }
526 #else /* _CUT_XXX_ */
527 CUT_EMPTY_FUNC("remove auth info response", handle, nav, receive);
528 #endif /* _CUT_XXX_ */
529 
proc_sec_clone_request_message(struct hichain * handle,struct header_analysis * nav,struct message * receive,struct message * send)530 static int32_t proc_sec_clone_request_message(struct hichain *handle, struct header_analysis *nav,
531     struct message *receive, struct message *send)
532 #if (defined(_SUPPORT_SEC_CLONE_) || defined(_SUPPORT_SEC_CLONE_SERVER_))
533 {
534     int32_t ret;
535 
536     if (nav->msg_type == SEC_CLONE_START_MSG) {
537         ret = send_sec_clone_start_response(handle->sec_clone_server, receive, send);
538     } else if (nav->msg_type == SEC_CLONE_END_MSG) {
539         ret = send_sec_clone_end_response(handle->sec_clone_server, receive, send);
540     } else {
541         return HC_UNKNOW_MESSAGE;
542     }
543 
544     return ret;
545 }
546 #else /* _SUPPORT_SEC_ */
547 CUT_EMPTY_FUNC("sec clone request", handle, nav, receive);
548 #endif /* _SUPPORT_SEC_ */
549 
proc_inform_message(struct hichain * handle,struct header_analysis * nav,struct message * receive,struct message * send)550 static int32_t proc_inform_message(struct hichain *handle, struct header_analysis *nav, struct message *receive,
551     struct message *send)
552 {
553     (void)handle;
554     (void)nav;
555     (void)receive;
556     send->msg_code = INVALID_MESSAGE;
557     LOGE("Receive inform message");
558     return HC_OK;
559 }
560