1 /*
2  ** Licensed under the Apache License, Version 2.0 (the "License");
3  ** you may not use this file except in compliance with the License.
4  ** You may obtain a copy of the License at
5  **
6  ** http://www.apache.org/licenses/LICENSE-2.0
7  **
8  ** Unless required by applicable law or agreed to in writing, software
9  ** distributed under the License is distributed on an "AS IS" BASIS,
10  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  ** See the License for the specific language governing permissions and
12  ** limitations under the License.
13  **
14  ** Copyright 2022-2023 NXP
15  **
16  */
17 #pragma once
18 
19 #include <fstream>
20 
21 #define ESE_CONNECTIVITY_PACKET 0x96
22 #define EUICC_CONNECTIVITY_PACKET 0xAB
23 #define ESE_DPD_EVENT 0x70
24 
25 enum class LogEventType { kLogSMBEvent = 0, kLogDPDEvent };
26 
27 // Store NTF/Event to filesystem under /data
28 // Currently being used to store SMB debug ntf and eSE DPD
29 // monitor events
30 
31 class PhNxpEventLogger {
32  public:
33   // Mark copy constructor deleted
34   PhNxpEventLogger(const PhNxpEventLogger&) = delete;
35 
36   // Get singleton instance of EventLogger.
37   static PhNxpEventLogger& GetInstance();
38 
39   // Open  output file(s) for logging.
40   void Initialize();
41 
42   // Write ntf/event to respective logfile.
43   //   Event Type SMB: write SMB ntf to SMB logfile
44   //   Event Type DPD: write DPD events DPD logfile
45   void Log(uint8_t* p_ntf, uint16_t p_len, LogEventType event);
46 
47   // Close opened file(s).
48   void Finalize();
49 
50  private:
51   PhNxpEventLogger();
52   bool logging_enabled_;
53   std::ofstream smb_logFile_;
54   std::ofstream dpd_logFile_;
55   const char* kSMBLogFilePath = "/data/vendor/nfc/NxpNfcSmbLogDump.txt";
56   const char* kDPDEventFilePath = "/data/vendor/nfc/debug/DPD_debug.txt";
57 };
58