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 #pragma once
18 
19 #if defined(__QL_TIPC__)
20 #include <trusty/sysdeps.h>
21 #else
22 #include <uapi/err.h>
23 #endif
24 
25 __BEGIN_CDECLS
lk_strerror(int errnum)26 static __ALWAYS_INLINE char* lk_strerror(int errnum) {
27     switch (errnum) {
28     case NO_ERROR:
29         return (char*)"NO_ERROR";
30 
31     case ERR_ALREADY_EXISTS:
32         return (char*)"ERR_ALREADY_EXISTS";
33 
34     case ERR_CHANNEL_CLOSED:
35         return (char*)"ERR_CHANNEL_CLOSED";
36 
37     case ERR_OFFLINE:
38         return (char*)"ERR_OFFLINE";
39 
40     case ERR_NOT_ALLOWED:
41         return (char*)"ERR_NOT_ALLOWED";
42 
43     case ERR_BAD_PATH:
44         return (char*)"ERR_BAD_PATH";
45 
46     case ERR_ALREADY_MOUNTED:
47         return (char*)"ERR_ALREADY_MOUNTED";
48 
49     case ERR_IO:
50         return (char*)"ERR_IO";
51 
52     case ERR_NOT_DIR:
53         return (char*)"ERR_NOT_DIR";
54 
55     case ERR_NOT_FILE:
56         return (char*)"ERR_NOT_FILE";
57 
58     case ERR_RECURSE_TOO_DEEP:
59         return (char*)"ERR_RECURSE_TOO_DEEP";
60 
61     case ERR_NOT_SUPPORTED:
62         return (char*)"ERR_NOT_SUPPORTED";
63 
64     case ERR_TOO_BIG:
65         return (char*)"ERR_TOO_BIG";
66 
67     case ERR_CANCELLED:
68         return (char*)"ERR_CANCELLED";
69 
70     case ERR_NOT_IMPLEMENTED:
71         return (char*)"ERR_NOT_IMPLEMENTED";
72 
73     case ERR_CHECKSUM_FAIL:
74         return (char*)"ERR_CHECKSUM_FAIL";
75 
76     case ERR_CRC_FAIL:
77         return (char*)"ERR_CRC_FAIL";
78 
79     case ERR_CMD_UNKNOWN:
80         return (char*)"ERR_CMD_UNKNOWN";
81 
82     case ERR_BAD_STATE:
83         return (char*)"ERR_BAD_STATE";
84 
85     case ERR_BAD_LEN:
86         return (char*)"ERR_BAD_LEN";
87 
88     case ERR_BUSY:
89         return (char*)"ERR_BUSY";
90 
91     case ERR_THREAD_DETACHED:
92         return (char*)"ERR_THREAD_DETACHED";
93 
94     case ERR_I2C_NACK:
95         return (char*)"ERR_I2C_NACK";
96 
97     case ERR_ALREADY_EXPIRED:
98         return (char*)"ERR_ALREADY_EXPIRED";
99 
100     case ERR_OUT_OF_RANGE:
101         return (char*)"ERR_OUT_OF_RANGE";
102 
103     case ERR_NOT_CONFIGURED:
104         return (char*)"ERR_NOT_CONFIGURED";
105 
106     case ERR_NOT_MOUNTED:
107         return (char*)"ERR_NOT_MOUNTED";
108 
109     case ERR_FAULT:
110         return (char*)"ERR_FAULT";
111 
112     case ERR_NO_RESOURCES:
113         return (char*)"ERR_NO_RESOURCES";
114 
115     case ERR_BAD_HANDLE:
116         return (char*)"ERR_BAD_HANDLE";
117 
118     case ERR_ACCESS_DENIED:
119         return (char*)"ERR_ACCESS_DENIED";
120 
121     case ERR_PARTIAL_WRITE:
122         return (char*)"ERR_PARTIAL_WRITE";
123 
124     default:
125         if (errnum < ERR_USER_BASE) {
126             return (char*)"User Error";
127         } else {
128             return (char*)"General Error";
129         }
130     }
131 };
132 
133 __END_CDECLS
134