• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 #include "TrustyStatus.h"
18 #include "../RpcState.h"
19 
20 namespace android {
21 
statusFromTrusty(int rc)22 status_t statusFromTrusty(int rc) {
23     LOG_RPC_DETAIL("Trusty error: %d", rc);
24     switch (rc) {
25         case NO_ERROR:
26             return OK;
27         case ERR_NOT_FOUND:
28             return NAME_NOT_FOUND;
29         case ERR_NOT_READY:
30             // We get this error if we try to perform an IPC operation when the
31             // channel is not ready
32             return INVALID_OPERATION;
33         case ERR_NO_MSG:
34             return WOULD_BLOCK;
35         case ERR_NO_MEMORY:
36             return NO_MEMORY;
37         case ERR_INVALID_ARGS:
38             return BAD_VALUE;
39         case ERR_NOT_ENOUGH_BUFFER:
40             return WOULD_BLOCK;
41         case ERR_TIMED_OUT:
42             return TIMED_OUT;
43         case ERR_ALREADY_EXISTS:
44             return ALREADY_EXISTS;
45         case ERR_CHANNEL_CLOSED:
46             return DEAD_OBJECT;
47         case ERR_NOT_ALLOWED:
48             return INVALID_OPERATION;
49         case ERR_NOT_SUPPORTED:
50             return INVALID_OPERATION;
51         case ERR_TOO_BIG:
52             return BAD_INDEX;
53         case ERR_CMD_UNKNOWN:
54             return UNKNOWN_TRANSACTION;
55         case ERR_BAD_STATE:
56             return INVALID_OPERATION;
57         case ERR_BAD_LEN:
58             return NOT_ENOUGH_DATA;
59         case ERR_BAD_HANDLE:
60             return BAD_VALUE;
61         case ERR_ACCESS_DENIED:
62             return PERMISSION_DENIED;
63         default:
64             return UNKNOWN_ERROR;
65     }
66 }
67 
statusToTrusty(status_t status)68 int statusToTrusty(status_t status) {
69     switch (status) {
70         case OK:
71             return NO_ERROR;
72         case NO_MEMORY:
73             return ERR_NO_MEMORY;
74         case INVALID_OPERATION:
75         case BAD_VALUE:
76         case BAD_TYPE:
77             return ERR_NOT_VALID;
78         case NAME_NOT_FOUND:
79             return ERR_NOT_FOUND;
80         case PERMISSION_DENIED:
81             return ERR_ACCESS_DENIED;
82         case NO_INIT:
83             return ERR_NOT_CONFIGURED;
84         case ALREADY_EXISTS:
85             return ERR_ALREADY_EXISTS;
86         case DEAD_OBJECT:
87             return ERR_CHANNEL_CLOSED;
88         case BAD_INDEX:
89             return ERR_TOO_BIG;
90         case NOT_ENOUGH_DATA:
91             return ERR_BAD_LEN;
92         case WOULD_BLOCK:
93             return ERR_NO_MSG;
94         case TIMED_OUT:
95             return ERR_TIMED_OUT;
96         case UNKNOWN_TRANSACTION:
97             return ERR_CMD_UNKNOWN;
98         case FDS_NOT_ALLOWED:
99             return ERR_NOT_SUPPORTED;
100         case UNEXPECTED_NULL:
101             return ERR_NOT_VALID;
102         default:
103             return ERR_GENERIC;
104     }
105 }
106 
107 } // namespace android
108