1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /* 'system/nfc/src/fuzzers/ce/stubs.cc' is used as reference to come up with file */
18
19 #include "fuzz_cmn.h"
20
21 // These are the functions implemented elsewhere in the NFC code. Our fuzzing
22 // doesn't need them. To avoid pulling into more source code we simply stub
23 // them out.
24
25 tNFA_PROPRIETARY_CFG nfa_proprietary_cfg = {
26 0x80, /* NCI_PROTOCOL_18092_ACTIVE */
27 0x81, /* NCI_PROTOCOL_B_PRIME */
28 0x82, /* NCI_PROTOCOL_DUAL */
29 0x83, /* NCI_PROTOCOL_15693 */
30 0x8A, /* NCI_PROTOCOL_KOVIO */
31 0xFF, /* NCI_PROTOCOL_MIFARE */
32 0x77, /* NCI_DISCOVERY_TYPE_POLL_KOVIO */
33 0x74, /* NCI_DISCOVERY_TYPE_POLL_B_PRIME */
34 0xF4, /* NCI_DISCOVERY_TYPE_LISTEN_B_PRIME */
35 };
36
37 tNFA_PROPRIETARY_CFG* p_nfa_proprietary_cfg = (tNFA_PROPRIETARY_CFG*)&nfa_proprietary_cfg;
38
nfc_start_quick_timer(TIMER_LIST_ENT *,uint16_t,uint32_t)39 void nfc_start_quick_timer(TIMER_LIST_ENT*, uint16_t, uint32_t) {}
nfc_stop_timer(TIMER_LIST_ENT *)40 void nfc_stop_timer(TIMER_LIST_ENT*) {}
nfc_stop_quick_timer(TIMER_LIST_ENT *)41 void nfc_stop_quick_timer(TIMER_LIST_ENT*) {}
NFC_GetNCIVersion()42 uint8_t NFC_GetNCIVersion() {
43 return NCI_VERSION_2_0;
44 }
45
NFC_SendData(uint8_t conn_id,NFC_HDR * p_data)46 tNFC_STATUS NFC_SendData(uint8_t conn_id, NFC_HDR* p_data) {
47 uint8_t* p = (uint8_t*)(p_data + 1) + p_data->offset;
48 uint8_t len = (uint8_t)p_data->len;
49
50 FUZZLOG("conn_id=%d, data=%s", conn_id, BytesToHex(p, len).c_str());
51 GKI_freebuf(p_data);
52 return NFC_STATUS_OK;
53 }
54
nci_snd_t3t_polling(uint16_t system_code,uint8_t rc,uint8_t tsn)55 uint8_t nci_snd_t3t_polling(uint16_t system_code, uint8_t rc, uint8_t tsn) {
56 FUZZLOG("sc=%04X, rc=%02X, tsn=%02X", system_code, rc, tsn);
57 return NFC_STATUS_OK;
58 }
59
60 tNFC_CONN_CBACK* rf_cback = nullptr;
NFC_SetStaticRfCback(tNFC_CONN_CBACK * p_cback)61 void NFC_SetStaticRfCback(tNFC_CONN_CBACK* p_cback) {
62 rf_cback = p_cback;
63 }
64
NFC_ISODEPNakPresCheck()65 tNFC_STATUS NFC_ISODEPNakPresCheck() {
66 return NFC_STATUS_OK;
67 }
68
NFC_GetStatusName(tNFC_STATUS status)69 std::string NFC_GetStatusName(tNFC_STATUS status) {
70 switch (status) {
71 case NFC_STATUS_OK:
72 return "OK";
73 case NFC_STATUS_REJECTED:
74 return "REJECTED";
75 case NFC_STATUS_MSG_CORRUPTED:
76 return "CORRUPTED";
77 case NFC_STATUS_BUFFER_FULL:
78 return "BUFFER_FULL";
79 case NFC_STATUS_FAILED:
80 return "FAILED";
81 case NFC_STATUS_NOT_INITIALIZED:
82 return "NOT_INITIALIZED";
83 case NFC_STATUS_SYNTAX_ERROR:
84 return "SYNTAX_ERROR";
85 case NFC_STATUS_SEMANTIC_ERROR:
86 return "SEMANTIC_ERROR";
87 case NFC_STATUS_UNKNOWN_GID:
88 return "UNKNOWN_GID";
89 case NFC_STATUS_UNKNOWN_OID:
90 return "UNKNOWN_OID";
91 case NFC_STATUS_INVALID_PARAM:
92 return "INVALID_PARAM";
93 case NFC_STATUS_MSG_SIZE_TOO_BIG:
94 return "MSG_SIZE_TOO_BIG";
95 case NFC_STATUS_ALREADY_STARTED:
96 return "ALREADY_STARTED";
97 case NFC_STATUS_ACTIVATION_FAILED:
98 return "ACTIVATION_FAILED";
99 case NFC_STATUS_TEAR_DOWN:
100 return "TEAR_DOWN";
101 case NFC_STATUS_RF_TRANSMISSION_ERR:
102 return "RF_TRANSMISSION_ERR";
103 case NFC_STATUS_RF_PROTOCOL_ERR:
104 return "RF_PROTOCOL_ERR";
105 case NFC_STATUS_TIMEOUT:
106 return "TIMEOUT";
107 case NFC_STATUS_EE_INTF_ACTIVE_FAIL:
108 return "EE_INTF_ACTIVE_FAIL";
109 case NFC_STATUS_EE_TRANSMISSION_ERR:
110 return "EE_TRANSMISSION_ERR";
111 case NFC_STATUS_EE_PROTOCOL_ERR:
112 return "EE_PROTOCOL_ERR";
113 case NFC_STATUS_EE_TIMEOUT:
114 return "EE_TIMEOUT";
115 case NFC_STATUS_CMD_STARTED:
116 return "CMD_STARTED";
117 case NFC_STATUS_HW_TIMEOUT:
118 return "HW_TIMEOUT";
119 case NFC_STATUS_CONTINUE:
120 return "CONTINUE";
121 case NFC_STATUS_REFUSED:
122 return "REFUSED";
123 case NFC_STATUS_BAD_RESP:
124 return "BAD_RESP";
125 case NFC_STATUS_CMD_NOT_CMPLTD:
126 return "CMD_CMPLTD";
127 case NFC_STATUS_NO_BUFFERS:
128 return "NO_BUFFERS";
129 case NFC_STATUS_WRONG_PROTOCOL:
130 return "WRONG_PROTOCOL";
131 case NFC_STATUS_BUSY:
132 return "BUSY";
133 case NFC_STATUS_LINK_LOSS:
134 return "LINK_LOSS";
135 case NFC_STATUS_BAD_LENGTH:
136 return "BAD_LENGTH";
137 case NFC_STATUS_BAD_HANDLE:
138 return "BAD_HANDLE";
139 case NFC_STATUS_CONGESTED:
140 return "CONGESTED";
141 default:
142 return "UNKNOWN";
143 }
144 }
145