xref: /aosp_15_r20/system/nfc/src/include/debug_nfcsnoop.h (revision 7eba2f3b06c51ae21384f6a4f14577b668a869b3)
1*7eba2f3bSAndroid Build Coastguard Worker /******************************************************************************
2*7eba2f3bSAndroid Build Coastguard Worker  *
3*7eba2f3bSAndroid Build Coastguard Worker  *  Copyright (C) 2017 Google Inc.
4*7eba2f3bSAndroid Build Coastguard Worker  *
5*7eba2f3bSAndroid Build Coastguard Worker  *  Licensed under the Apache License, Version 2.0 (the "License");
6*7eba2f3bSAndroid Build Coastguard Worker  *  you may not use this file except in compliance with the License.
7*7eba2f3bSAndroid Build Coastguard Worker  *  You may obtain a copy of the License at:
8*7eba2f3bSAndroid Build Coastguard Worker  *
9*7eba2f3bSAndroid Build Coastguard Worker  *  http://www.apache.org/licenses/LICENSE-2.0
10*7eba2f3bSAndroid Build Coastguard Worker  *
11*7eba2f3bSAndroid Build Coastguard Worker  *  Unless required by applicable law or agreed to in writing, software
12*7eba2f3bSAndroid Build Coastguard Worker  *  distributed under the License is distributed on an "AS IS" BASIS,
13*7eba2f3bSAndroid Build Coastguard Worker  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*7eba2f3bSAndroid Build Coastguard Worker  *  See the License for the specific language governing permissions and
15*7eba2f3bSAndroid Build Coastguard Worker  *  limitations under the License.
16*7eba2f3bSAndroid Build Coastguard Worker  *
17*7eba2f3bSAndroid Build Coastguard Worker  ******************************************************************************/
18*7eba2f3bSAndroid Build Coastguard Worker #ifndef _DEBUG_NFCSNOOP_
19*7eba2f3bSAndroid Build Coastguard Worker #define _DEBUG_NFCSNOOP_
20*7eba2f3bSAndroid Build Coastguard Worker 
21*7eba2f3bSAndroid Build Coastguard Worker #include <stdint.h>
22*7eba2f3bSAndroid Build Coastguard Worker 
23*7eba2f3bSAndroid Build Coastguard Worker #include <string>
24*7eba2f3bSAndroid Build Coastguard Worker 
25*7eba2f3bSAndroid Build Coastguard Worker #include "nfc_target.h"
26*7eba2f3bSAndroid Build Coastguard Worker #include "nfc_types.h"
27*7eba2f3bSAndroid Build Coastguard Worker 
28*7eba2f3bSAndroid Build Coastguard Worker #define NFCSNOOZ_CURRENT_VERSION 0x01
29*7eba2f3bSAndroid Build Coastguard Worker 
30*7eba2f3bSAndroid Build Coastguard Worker // The preamble is stored un-encrypted as the first part
31*7eba2f3bSAndroid Build Coastguard Worker // of the file.
32*7eba2f3bSAndroid Build Coastguard Worker typedef struct nfcsnooz_preamble_t {
33*7eba2f3bSAndroid Build Coastguard Worker   uint8_t version;
34*7eba2f3bSAndroid Build Coastguard Worker   uint64_t last_timestamp_ms;
35*7eba2f3bSAndroid Build Coastguard Worker } __attribute__((__packed__)) nfcsnooz_preamble_t;
36*7eba2f3bSAndroid Build Coastguard Worker 
37*7eba2f3bSAndroid Build Coastguard Worker // One header for each NCI packet
38*7eba2f3bSAndroid Build Coastguard Worker typedef struct nfcsnooz_header_t {
39*7eba2f3bSAndroid Build Coastguard Worker   uint16_t length;
40*7eba2f3bSAndroid Build Coastguard Worker   uint32_t delta_time_ms;
41*7eba2f3bSAndroid Build Coastguard Worker   uint8_t is_received;
42*7eba2f3bSAndroid Build Coastguard Worker } __attribute__((__packed__)) nfcsnooz_header_t;
43*7eba2f3bSAndroid Build Coastguard Worker 
44*7eba2f3bSAndroid Build Coastguard Worker // Initializes nfcsnoop memory logging and registers
45*7eba2f3bSAndroid Build Coastguard Worker void debug_nfcsnoop_init(void);
46*7eba2f3bSAndroid Build Coastguard Worker 
47*7eba2f3bSAndroid Build Coastguard Worker // Writes nfcsnoop data base64 encoded to fd
48*7eba2f3bSAndroid Build Coastguard Worker void debug_nfcsnoop_dump(int fd);
49*7eba2f3bSAndroid Build Coastguard Worker 
50*7eba2f3bSAndroid Build Coastguard Worker // capture the packet
51*7eba2f3bSAndroid Build Coastguard Worker void nfcsnoop_capture(const NFC_HDR* packet, bool is_received);
52*7eba2f3bSAndroid Build Coastguard Worker 
53*7eba2f3bSAndroid Build Coastguard Worker // store NCI log to file
54*7eba2f3bSAndroid Build Coastguard Worker bool storeNfcSnoopLogs(std::string filepath, off_t maxFileSize);
55*7eba2f3bSAndroid Build Coastguard Worker 
56*7eba2f3bSAndroid Build Coastguard Worker // check whether either buffer is under memory threshold
57*7eba2f3bSAndroid Build Coastguard Worker bool buffers_under_threshold();
58*7eba2f3bSAndroid Build Coastguard Worker #endif /* _DEBUG_NFCSNOOP_ */
59