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 #define DEFAULT_NFCSNOOP_FILE_SIZE 32 * 1024 * 1024 30 31 // The preamble is stored un-encrypted as the first part 32 // of the file. 33 typedef struct nfcsnooz_preamble_t { 34 uint8_t version; 35 uint64_t last_timestamp_ms; 36 } __attribute__((__packed__)) nfcsnooz_preamble_t; 37 38 // One header for each NCI packet 39 typedef struct nfcsnooz_header_t { 40 uint16_t length; 41 uint32_t delta_time_ms; 42 uint8_t is_received; 43 } __attribute__((__packed__)) nfcsnooz_header_t; 44 45 // Initializes nfcsnoop memory logging and registers 46 void debug_nfcsnoop_init(void); 47 48 // Writes nfcsnoop data base64 encoded to fd 49 void debug_nfcsnoop_dump(int fd); 50 51 // capture the packet 52 void nfcsnoop_capture(const NFC_HDR* packet, bool is_received); 53 54 // store NCI log to file 55 bool storeNfcSnoopLogs(std::string filepath, off_t maxFileSize); 56 57 // check whether either buffer is under memory threshold 58 bool buffers_under_threshold(); 59 #endif /* _DEBUG_NFCSNOOP_ */ 60