1 #include "fuzz_cmn.h"
2 
3 // These are the functions implemented elsewhere in the NFC code. Our fuzzing
4 // doesn't need them. To avoid pulling into more source code we simply stub
5 // them out.
6 
7 tNFA_PROPRIETARY_CFG nfa_proprietary_cfg = {
8     0x80, /* NCI_PROTOCOL_18092_ACTIVE */
9     0x81, /* NCI_PROTOCOL_B_PRIME */
10     0x82, /* NCI_PROTOCOL_DUAL */
11     0x83, /* NCI_PROTOCOL_15693 */
12     0x8A, /* NCI_PROTOCOL_KOVIO */
13     0xFF, /* NCI_PROTOCOL_MIFARE */
14     0x77, /* NCI_DISCOVERY_TYPE_POLL_KOVIO */
15     0x74, /* NCI_DISCOVERY_TYPE_POLL_B_PRIME */
16     0xF4, /* NCI_DISCOVERY_TYPE_LISTEN_B_PRIME */
17 };
18 
19 tNFA_PROPRIETARY_CFG* p_nfa_proprietary_cfg =
20     (tNFA_PROPRIETARY_CFG*)&nfa_proprietary_cfg;
21 
nfc_start_quick_timer(TIMER_LIST_ENT *,uint16_t,uint32_t)22 void nfc_start_quick_timer(TIMER_LIST_ENT*, uint16_t, uint32_t) {}
nfc_stop_timer(TIMER_LIST_ENT *)23 void nfc_stop_timer(TIMER_LIST_ENT*) {}
nfc_stop_quick_timer(TIMER_LIST_ENT *)24 void nfc_stop_quick_timer(TIMER_LIST_ENT*) {}
NFC_GetNCIVersion()25 uint8_t NFC_GetNCIVersion() { return NCI_VERSION_2_0; }
26 
NFC_SendData(uint8_t conn_id,NFC_HDR * p_data)27 tNFC_STATUS NFC_SendData(uint8_t conn_id, NFC_HDR* p_data) {
28   uint8_t* p = (uint8_t*)(p_data + 1) + p_data->offset;
29   uint8_t len = (uint8_t)p_data->len;
30 
31   FUZZLOG("conn_id=%d, data=%s", conn_id, BytesToHex(p, len).c_str());
32   GKI_freebuf(p_data);
33   return NFC_STATUS_OK;
34 }
35 
nci_snd_t3t_polling(uint16_t system_code,uint8_t rc,uint8_t tsn)36 uint8_t nci_snd_t3t_polling(uint16_t system_code, uint8_t rc, uint8_t tsn) {
37   FUZZLOG("sc=%04X, rc=%02X, tsn=%02X", system_code, rc, tsn);
38   return NFC_STATUS_OK;
39 }
40 
41 tNFC_CONN_CBACK* rf_cback = nullptr;
NFC_SetStaticRfCback(tNFC_CONN_CBACK * p_cback)42 void NFC_SetStaticRfCback(tNFC_CONN_CBACK* p_cback) { rf_cback = p_cback; }
43 
NFC_ISODEPNakPresCheck()44 tNFC_STATUS NFC_ISODEPNakPresCheck() { return NFC_STATUS_OK; }
45 
NFC_GetStatusName(tNFC_STATUS status)46 std::string NFC_GetStatusName(tNFC_STATUS status) {
47   switch (status) {
48     case NFC_STATUS_OK:
49       return "OK";
50     case NFC_STATUS_REJECTED:
51       return "REJECTED";
52     case NFC_STATUS_MSG_CORRUPTED:
53       return "CORRUPTED";
54     case NFC_STATUS_BUFFER_FULL:
55       return "BUFFER_FULL";
56     case NFC_STATUS_FAILED:
57       return "FAILED";
58     case NFC_STATUS_NOT_INITIALIZED:
59       return "NOT_INITIALIZED";
60     case NFC_STATUS_SYNTAX_ERROR:
61       return "SYNTAX_ERROR";
62     case NFC_STATUS_SEMANTIC_ERROR:
63       return "SEMANTIC_ERROR";
64     case NFC_STATUS_UNKNOWN_GID:
65       return "UNKNOWN_GID";
66     case NFC_STATUS_UNKNOWN_OID:
67       return "UNKNOWN_OID";
68     case NFC_STATUS_INVALID_PARAM:
69       return "INVALID_PARAM";
70     case NFC_STATUS_MSG_SIZE_TOO_BIG:
71       return "MSG_SIZE_TOO_BIG";
72     case NFC_STATUS_ALREADY_STARTED:
73       return "ALREADY_STARTED";
74     case NFC_STATUS_ACTIVATION_FAILED:
75       return "ACTIVATION_FAILED";
76     case NFC_STATUS_TEAR_DOWN:
77       return "TEAR_DOWN";
78     case NFC_STATUS_RF_TRANSMISSION_ERR:
79       return "RF_TRANSMISSION_ERR";
80     case NFC_STATUS_RF_PROTOCOL_ERR:
81       return "RF_PROTOCOL_ERR";
82     case NFC_STATUS_TIMEOUT:
83       return "TIMEOUT";
84     case NFC_STATUS_EE_INTF_ACTIVE_FAIL:
85       return "EE_INTF_ACTIVE_FAIL";
86     case NFC_STATUS_EE_TRANSMISSION_ERR:
87       return "EE_TRANSMISSION_ERR";
88     case NFC_STATUS_EE_PROTOCOL_ERR:
89       return "EE_PROTOCOL_ERR";
90     case NFC_STATUS_EE_TIMEOUT:
91       return "EE_TIMEOUT";
92     case NFC_STATUS_CMD_STARTED:
93       return "CMD_STARTED";
94     case NFC_STATUS_HW_TIMEOUT:
95       return "HW_TIMEOUT";
96     case NFC_STATUS_CONTINUE:
97       return "CONTINUE";
98     case NFC_STATUS_REFUSED:
99       return "REFUSED";
100     case NFC_STATUS_BAD_RESP:
101       return "BAD_RESP";
102     case NFC_STATUS_CMD_NOT_CMPLTD:
103       return "CMD_CMPLTD";
104     case NFC_STATUS_NO_BUFFERS:
105       return "NO_BUFFERS";
106     case NFC_STATUS_WRONG_PROTOCOL:
107       return "WRONG_PROTOCOL";
108     case NFC_STATUS_BUSY:
109       return "BUSY";
110     case NFC_STATUS_LINK_LOSS:
111       return "LINK_LOSS";
112     case NFC_STATUS_BAD_LENGTH:
113       return "BAD_LENGTH";
114     case NFC_STATUS_BAD_HANDLE:
115       return "BAD_HANDLE";
116     case NFC_STATUS_CONGESTED:
117       return "CONGESTED";
118     default:
119       return "UNKNOWN";
120   }
121 }