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_SIM_UTILS_H 17 #define OHOS_SIM_UTILS_H 18 19 #include <stdlib.h> 20 #include <string> 21 22 #include "event_handler.h" 23 #include "event_runner.h" 24 #include "string_ex.h" 25 #include "telephony_log_wrapper.h" 26 #include "sim_char_decode.h" 27 28 namespace OHOS { 29 namespace Telephony { 30 static const int DECIMAL_MAX = 10; 31 static const int HALF_LEN = 2; 32 static const int HALF_BYTE_LEN = 4; 33 static const int UCS_FLAG = 0x81; 34 static const int UCS_WIDE_FLAG = 0x82; 35 // Full Name IEI from TS 24.008 36 static const int LONG_NAME_FLAG = 0x43; 37 // Short Name IEI from TS 24.008 38 static const int SHORT_NAME_FLAG = 0x45; 39 static const int CHAR_GSM_7BIT = 7; 40 static const int START_POS = 3; 41 static const int END_POS = 4; 42 static const int POS_NOT_BLANK = 1; 43 static char HEX_CHARS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; 44 // TS 24.008 Section 10.5.3.5a Network Name 45 enum { 46 NETWORK_NAME_IEI, 47 NETWORK_NAME_LENGTH, 48 NETWORK_NAME_CODING_SCHEME, 49 NETWORK_NAME_TEXT_STRING 50 }; 51 // TS 31.102 Section 4.2.59. 52 enum { 53 BCD_PLMN_MCC2, 54 BCD_PLMN_MCC1, 55 BCD_PLMN_MNC3, 56 BCD_PLMN_MCC3, 57 BCD_PLMN_MNC2, 58 BCD_PLMN_MNC1, 59 MCCMNC_LEN 60 }; 61 62 class SIMUtils { 63 public: 64 static unsigned char HexCharConvertToInt(char c); 65 static std::shared_ptr<unsigned char> HexStringConvertToBytes(const std::string &s, int &byteslen); 66 static std::string BytesConvertToHexString(const unsigned char *bytes, int byteLen); 67 static void ArrayCopy(const unsigned char *src, int srcPos, unsigned char *dest, int destPos, int length); 68 static bool IsShowableAscii(char c); 69 static bool IsShowableAsciiOnly(const std::string &str); 70 static std::string BcdPlmnConvertToString(const std::string &data, int offset); 71 static std::string DiallingNumberStringFieldConvertToString( 72 std::shared_ptr<unsigned char> array, int offset, int length, int offPos); 73 static std::shared_ptr<char16_t> CharsConvertToChar16( 74 const unsigned char *charBytes, int charBytesLen, int &outChar16Len, bool bigEndian); 75 static std::string Trim(std::string& str); 76 static std::string Gsm7bitConvertToString(const unsigned char *bytes, int byteLen); 77 78 private: 79 static std::string UcsCodeConvertToString( 80 std::shared_ptr<unsigned char> array, int offset, int length, int offPos); 81 }; 82 } // namespace Telephony 83 } // namespace OHOS 84 #endif // OHOS_SIM_UTILS_H