1 /****************************************************************************** 2 * 3 * Copyright 2020-2023 NXP 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #pragma once 20 #include <android-base/logging.h> 21 #include <android-base/stringprintf.h> 22 #include <string.h> 23 24 #include "phNxpEse_Api.h" 25 26 #define OSU_PROP_CLA 0x80 27 #define OSU_PROP_INS 0xDF 28 #define OSU_PROP_RST_P1 0xEF 29 30 #define ISO7816_BASIC_CHANNEL 0x00 31 #define ISO7816_CLA_OFFSET 0 32 #define ISO7816_INS_OFFSET 1 33 #define ISO7816_P1_OFFSET 2 34 #define ISO7816_P2_OFFSET 3 35 #define ISO7816_LC_OFFSET 4 36 #define ISO7816_EXTENDED_LC_VALUE 0 37 #define ISO7816_SHORT_APDU_HEADER 5 38 #define ISO7816_EXTENDED_APDU_HEADER 7 39 #define ISO7816_CLA_CHN_MASK 0x03 40 #define IS_OSU_MODE(...) (OsuHalExtn::getInstance().isOsuMode(__VA_ARGS__)) 41 42 class OsuHalExtn { 43 public: 44 typedef enum { 45 NON_OSU_MODE, // Normal Mode : All HAL APIs allowed 46 OSU_PROP_MODE, // OSU mode : Only OSU JAR command allowed 47 OSU_GP_MODE, // OSU Mode : GP command in the OSU mode 48 OSU_RST_MODE, // OSU mode : Proprietary HARD reset 49 OSU_BLOCKED_MODE, // OSU mode : Command not allowed return error 50 } OsuApduMode; 51 52 typedef enum { 53 INIT, 54 OPENBASIC, 55 OPENLOGICAL, 56 GETATR, 57 TRANSMIT, 58 CLOSE, 59 } SecureElementAPI; 60 61 static OsuHalExtn& getInstance(); 62 63 OsuApduMode isOsuMode(const std::vector<uint8_t>& evt, uint8_t type, 64 phNxpEse_data* pCmdData = nullptr); 65 bool isOsuMode(uint8_t type, uint8_t channel = 0xFF); 66 virtual ~OsuHalExtn(); 67 OsuHalExtn() noexcept; 68 void checkAndUpdateOsuMode(); 69 unsigned long int getOSUMaxWtxCount(); 70 71 private: 72 bool isAppOSUMode; 73 bool isJcopOSUMode; 74 static const std::vector<uint8_t> osu_aid[10]; 75 OsuApduMode checkTransmit(uint8_t* input, uint32_t* outLength, 76 const std::vector<uint8_t>& data); 77 bool isOsuMode(); 78 }; 79