1 /* 2 * Copyright (C) 2021 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 #ifndef OHOS_VENDOR_UTIL_H 17 #define OHOS_VENDOR_UTIL_H 18 19 #include <sys/time.h> 20 21 #include <securec.h> 22 #include <time.h> 23 24 #include "at_support.h" 25 #include "hril.h" 26 #include "telephony_log_c.h" 27 28 #define MAX_RESPONSE_LEN (8 * 1024) 29 30 #define INT_DEFAULT_VALUE (-1) 31 #define STR_DEFAULT_VALUE "" 32 33 typedef enum { 34 VENDOR_FAIL = -1, 35 VENDOR_SUCCESS, 36 VENDOR_ERR_PROCESS, 37 AT_ERR_TIMEOUT, 38 AT_ERR_COMMAND_PENDING, 39 AT_ERR_CHANNEL_CLOSED, 40 AT_ERR_GENERIC, 41 AT_ERR_WAITING, 42 AT_ERR_INVALID_THREAD 43 } VendorErrorType; 44 45 typedef enum { 46 AT_RESPONSE_SIM_PIN_REQUIRE = 11, 47 AT_RESPONSE_SIM_FAILURE = 13, 48 AT_RESPONSE_INCORRECT_PASSWORD = 16, 49 } ATPesponseCMEErr; 50 51 int32_t GenerateCommand(char *buffer, size_t bufferLen, const char *fmt, ...); 52 53 int32_t ReportStrWith(const char *line, const char *prefix); 54 55 int32_t IsResponseSuccess(const char *line); 56 57 int32_t IsResponseError(const char *line); 58 59 int32_t IsSms(const char *line); 60 61 int32_t IsSmsNotify(const char *line); 62 63 void SetWaitTimeout(struct timespec *time, long long msec); 64 65 int32_t SkipATPrefix(char **s); 66 67 void SkipSpace(char **s); 68 69 int32_t NextInt(char **s, int32_t *out); 70 71 int64_t NextInt64(char **s, int64_t *out); 72 73 int32_t NextIntNotSkipNextComma(char **s, int32_t *out); 74 75 int32_t NextIntByRightBracket(char **s, int32_t *out); 76 77 int32_t NextIntFromHex(char **s, int32_t *out); 78 79 int32_t NextStr(char **s, char **out); 80 81 int32_t NextTxtStr(char **s, char **out); 82 83 int32_t NextBool(char **s, char *out); 84 85 int32_t ParseReportError(char *str); 86 87 int32_t NextULongFromHex(char **s, uint64_t *out); 88 89 ModemReportErrorInfo GetReportErrorInfo(const ResponseInfo *response); 90 91 ModemReportErrorInfo InitModemReportErrorInfo(void); 92 93 int32_t ConvertCharToInt32(const char *s); 94 95 int32_t FindCommaCharNum(const char *srcStr); 96 97 int32_t GetSimSlotCount(void); 98 99 int32_t GetSlotId(const ReqDataInfo *requestInfo); 100 #endif // OHOS_VENDOR_UTIL_H 101