xunchang | 34690ce | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | #include <stdint.h> |
| 20 | |
| 21 | // The message between recovery and minadbd is 8 bytes in size unless the length is explicitly |
| 22 | // specified. Both the command and status has the format |prefix(4 bytes) + encoded enum(4 bytes)|. |
| 23 | constexpr size_t kMinadbdMessageSize = 8; |
| 24 | constexpr char const kMinadbdCommandPrefix[] = "COMD"; |
| 25 | constexpr char const kMinadbdStatusPrefix[] = "STAT"; |
| 26 | |
| 27 | enum MinadbdErrorCode : int { |
| 28 | kMinadbdSuccess = 0, |
| 29 | kMinadbdArgumentsParsingError = 1, |
| 30 | kMinadbdSocketIOError = 2, |
| 31 | kMinadbdMessageFormatError = 3, |
| 32 | kMinadbdAdbVersionError = 4, |
xunchang | fedeef6 | 2019-04-22 12:18:14 -0700 | [diff] [blame] | 33 | kMinadbdHostCommandArgumentError = 5, |
xunchang | 34690ce | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 34 | kMinadbdFuseStartError = 6, |
| 35 | kMinadbdUnsupportedCommandError = 7, |
| 36 | kMinadbdCommandExecutionError = 8, |
| 37 | kMinadbdErrorUnknown = 9, |
Tao Bao | ed717ca | 2019-04-04 18:37:58 -0700 | [diff] [blame] | 38 | kMinadbdHostSocketIOError = 10, |
xunchang | 34690ce | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | enum class MinadbdCommandStatus : uint32_t { |
| 42 | kSuccess = 0, |
| 43 | kFailure = 1, |
| 44 | }; |
| 45 | |
Tao Bao | 10f441a | 2019-04-19 15:22:15 -0700 | [diff] [blame] | 46 | enum class MinadbdCommand : uint32_t { |
xunchang | 34690ce | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 47 | kInstall = 0, |
| 48 | kUiPrint = 1, |
Tao Bao | 10f441a | 2019-04-19 15:22:15 -0700 | [diff] [blame] | 49 | kRebootAndroid = 2, |
| 50 | kRebootBootloader = 3, |
| 51 | kRebootFastboot = 4, |
| 52 | kRebootRecovery = 5, |
| 53 | kRebootRescue = 6, |
xunchang | fedeef6 | 2019-04-22 12:18:14 -0700 | [diff] [blame] | 54 | kWipeCache = 7, |
| 55 | kWipeData = 8, |
Tao Bao | 10f441a | 2019-04-19 15:22:15 -0700 | [diff] [blame] | 56 | |
| 57 | // Last but invalid command. |
| 58 | kError, |
xunchang | 34690ce | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Tao Bao | 10f441a | 2019-04-19 15:22:15 -0700 | [diff] [blame] | 61 | static_assert(kMinadbdMessageSize == sizeof(kMinadbdCommandPrefix) - 1 + sizeof(MinadbdCommand)); |
xunchang | 34690ce | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 62 | static_assert(kMinadbdMessageSize == |
| 63 | sizeof(kMinadbdStatusPrefix) - 1 + sizeof(MinadbdCommandStatus)); |