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 len = (uint8_t)p_data->len;
48
49 FUZZLOG("conn_id=%d data=[%d]", conn_id, len);
50 GKI_freebuf(p_data);
51 return NFC_STATUS_OK;
52 }
53
nci_snd_t3t_polling(uint16_t system_code,uint8_t rc,uint8_t tsn)54 uint8_t nci_snd_t3t_polling(uint16_t system_code, uint8_t rc, uint8_t tsn) {
55 FUZZLOG("sc=%04X, rc=%02X, tsn=%02X", system_code, rc, tsn);
56 return NFC_STATUS_OK;
57 }
58
59 tNFC_CONN_CBACK* rf_cback = nullptr;
NFC_SetStaticRfCback(tNFC_CONN_CBACK * p_cback)60 void NFC_SetStaticRfCback(tNFC_CONN_CBACK* p_cback) {
61 rf_cback = p_cback;
62 }
63
NFC_ISODEPNakPresCheck()64 tNFC_STATUS NFC_ISODEPNakPresCheck() {
65 return NFC_STATUS_OK;
66 }
67
NFC_GetStatusName(tNFC_STATUS status)68 std::string NFC_GetStatusName(tNFC_STATUS status) {
69 switch (status) {
70 case NFC_STATUS_OK:
71 return "OK";
72 case NFC_STATUS_REJECTED:
73 return "REJECTED";
74 case NFC_STATUS_MSG_CORRUPTED:
75 return "CORRUPTED";
76 case NFC_STATUS_BUFFER_FULL:
77 return "BUFFER_FULL";
78 case NFC_STATUS_FAILED:
79 return "FAILED";
80 case NFC_STATUS_NOT_INITIALIZED:
81 return "NOT_INITIALIZED";
82 case NFC_STATUS_SYNTAX_ERROR:
83 return "SYNTAX_ERROR";
84 case NFC_STATUS_SEMANTIC_ERROR:
85 return "SEMANTIC_ERROR";
86 case NFC_STATUS_UNKNOWN_GID:
87 return "UNKNOWN_GID";
88 case NFC_STATUS_UNKNOWN_OID:
89 return "UNKNOWN_OID";
90 case NFC_STATUS_INVALID_PARAM:
91 return "INVALID_PARAM";
92 case NFC_STATUS_MSG_SIZE_TOO_BIG:
93 return "MSG_SIZE_TOO_BIG";
94 case NFC_STATUS_ALREADY_STARTED:
95 return "ALREADY_STARTED";
96 case NFC_STATUS_ACTIVATION_FAILED:
97 return "ACTIVATION_FAILED";
98 case NFC_STATUS_TEAR_DOWN:
99 return "TEAR_DOWN";
100 case NFC_STATUS_RF_TRANSMISSION_ERR:
101 return "RF_TRANSMISSION_ERR";
102 case NFC_STATUS_RF_PROTOCOL_ERR:
103 return "RF_PROTOCOL_ERR";
104 case NFC_STATUS_TIMEOUT:
105 return "TIMEOUT";
106 case NFC_STATUS_EE_INTF_ACTIVE_FAIL:
107 return "EE_INTF_ACTIVE_FAIL";
108 case NFC_STATUS_EE_TRANSMISSION_ERR:
109 return "EE_TRANSMISSION_ERR";
110 case NFC_STATUS_EE_PROTOCOL_ERR:
111 return "EE_PROTOCOL_ERR";
112 case NFC_STATUS_EE_TIMEOUT:
113 return "EE_TIMEOUT";
114 case NFC_STATUS_CMD_STARTED:
115 return "CMD_STARTED";
116 case NFC_STATUS_HW_TIMEOUT:
117 return "HW_TIMEOUT";
118 case NFC_STATUS_CONTINUE:
119 return "CONTINUE";
120 case NFC_STATUS_REFUSED:
121 return "REFUSED";
122 case NFC_STATUS_BAD_RESP:
123 return "BAD_RESP";
124 case NFC_STATUS_CMD_NOT_CMPLTD:
125 return "CMD_CMPLTD";
126 case NFC_STATUS_NO_BUFFERS:
127 return "NO_BUFFERS";
128 case NFC_STATUS_WRONG_PROTOCOL:
129 return "WRONG_PROTOCOL";
130 case NFC_STATUS_BUSY:
131 return "BUSY";
132 case NFC_STATUS_LINK_LOSS:
133 return "LINK_LOSS";
134 case NFC_STATUS_BAD_LENGTH:
135 return "BAD_LENGTH";
136 case NFC_STATUS_BAD_HANDLE:
137 return "BAD_HANDLE";
138 case NFC_STATUS_CONGESTED:
139 return "CONGESTED";
140 default:
141 return "UNKNOWN";
142 }
143 }
144