1 /******************************************************************************
2  *
3  *  Copyright (C) 2017 Google Inc.
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 #ifndef _DEBUG_NFCSNOOP_
19 #define _DEBUG_NFCSNOOP_
20 
21 #include <stdint.h>
22 
23 #include <string>
24 
25 #include "nfc_target.h"
26 #include "nfc_types.h"
27 
28 #define NFCSNOOZ_CURRENT_VERSION 0x01
29 
30 // The preamble is stored un-encrypted as the first part
31 // of the file.
32 typedef struct nfcsnooz_preamble_t {
33   uint8_t version;
34   uint64_t last_timestamp_ms;
35 } __attribute__((__packed__)) nfcsnooz_preamble_t;
36 
37 // One header for each NCI packet
38 typedef struct nfcsnooz_header_t {
39   uint16_t length;
40   uint32_t delta_time_ms;
41   uint8_t is_received;
42 } __attribute__((__packed__)) nfcsnooz_header_t;
43 
44 // Initializes nfcsnoop memory logging and registers
45 void debug_nfcsnoop_init(void);
46 
47 // Writes nfcsnoop data base64 encoded to fd
48 void debug_nfcsnoop_dump(int fd);
49 
50 // capture the packet
51 void nfcsnoop_capture(const NFC_HDR* packet, bool is_received);
52 
53 // store NCI log to file
54 bool storeNfcSnoopLogs(std::string filepath, off_t maxFileSize);
55 
56 // check whether either buffer is under memory threshold
57 bool buffers_under_threshold();
58 #endif /* _DEBUG_NFCSNOOP_ */
59