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 ESE_DPD_EVENT 0x70
23 
24 enum class LogEventType { kLogSMBEvent = 0, kLogDPDEvent };
25 
26 // Store NTF/Event to filesystem under /data
27 // Currently being used to store SMB debug ntf and eSE DPD
28 // monitor events
29 
30 class PhNxpEventLogger {
31  public:
32   // Mark copy constructor deleted
33   PhNxpEventLogger(const PhNxpEventLogger&) = delete;
34 
35   // Get singleton instance of EventLogger.
36   static PhNxpEventLogger& GetInstance();
37 
38   // Open  output file(s) for logging.
39   void Initialize();
40 
41   // Write ntf/event to respective logfile.
42   //   Event Type SMB: write SMB ntf to SMB logfile
43   //   Event Type DPD: write DPD events DPD logfile
44   void Log(uint8_t* p_ntf, uint16_t p_len, LogEventType event);
45 
46   // Close opened file(s).
47   void Finalize();
48 
49  private:
50   PhNxpEventLogger();
51   bool logging_enabled_;
52   std::ofstream smb_logFile_;
53   std::ofstream dpd_logFile_;
54   const char* kSMBLogFilePath = "/data/vendor/nfc/NxpNfcSmbLogDump.txt";
55   const char* kDPDEventFilePath = "/data/vendor/nfc/debug/DPD_debug.txt";
56 };
57