1 #include "android/hardware/nfc/1.0/Nfc.vts.h"
2 #include "vts_measurement.h"
3 #include <android-base/logging.h>
4 #include <android/hidl/allocator/1.0/IAllocator.h>
5 #include <fcntl.h>
6 #include <fmq/MessageQueue.h>
7 #include <sys/stat.h>
8 #include <unistd.h>
9 
10 
11 using namespace android::hardware::nfc::V1_0;
12 namespace android {
13 namespace vts {
GetService(bool get_stub,const char * service_name)14 bool FuzzerExtended_android_hardware_nfc_V1_0_INfc::GetService(bool get_stub, const char* service_name) {
15     static bool initialized = false;
16     if (!initialized) {
17         LOG(INFO) << "HIDL getService";
18         if (service_name) {
19           LOG(INFO) << "  - service name: " << service_name;
20         }
21         hw_binder_proxy_ = ::android::hardware::nfc::V1_0::INfc::getService(service_name, get_stub);
22         if (hw_binder_proxy_ == nullptr) {
23             LOG(ERROR) << "getService() returned a null pointer.";
24             return false;
25         }
26         LOG(DEBUG) << "hw_binder_proxy_ = " << hw_binder_proxy_.get();
27         initialized = true;
28     }
29     return true;
30 }
31 
32 
open(const sp<::android::hardware::nfc::V1_0::INfcClientCallback> & arg0)33 ::android::hardware::Return<::android::hardware::nfc::V1_0::NfcStatus> Vts_android_hardware_nfc_V1_0_INfc::open(
34     const sp<::android::hardware::nfc::V1_0::INfcClientCallback>& arg0 __attribute__((__unused__))) {
35     LOG(INFO) << "open called";
36     AndroidSystemCallbackRequestMessage callback_message;
37     callback_message.set_id(GetCallbackID("open"));
38     callback_message.set_name("Vts_android_hardware_nfc_V1_0_INfc::open");
39     VariableSpecificationMessage* var_msg0 = callback_message.add_arg();
40     var_msg0->set_type(TYPE_HIDL_CALLBACK);
41     LOG(ERROR) << "TYPE HIDL_CALLBACK is not supported yet. ";
42     RpcCallToAgent(callback_message, callback_socket_name_);
43     return ::android::hardware::nfc::V1_0::NfcStatus();
44 }
45 
write(const::android::hardware::hidl_vec<uint8_t> & arg0)46 ::android::hardware::Return<uint32_t> Vts_android_hardware_nfc_V1_0_INfc::write(
47     const ::android::hardware::hidl_vec<uint8_t>& arg0 __attribute__((__unused__))) {
48     LOG(INFO) << "write called";
49     AndroidSystemCallbackRequestMessage callback_message;
50     callback_message.set_id(GetCallbackID("write"));
51     callback_message.set_name("Vts_android_hardware_nfc_V1_0_INfc::write");
52     VariableSpecificationMessage* var_msg0 = callback_message.add_arg();
53     var_msg0->set_type(TYPE_VECTOR);
54     var_msg0->set_vector_size(arg0.size());
55     for (int i = 0; i < (int)arg0.size(); i++) {
56         auto *var_msg0_vector_i = var_msg0->add_vector_value();
57         var_msg0_vector_i->set_type(TYPE_SCALAR);
58         var_msg0_vector_i->set_scalar_type("uint8_t");
59         var_msg0_vector_i->mutable_scalar_value()->set_uint8_t(arg0[i]);
60     }
61     RpcCallToAgent(callback_message, callback_socket_name_);
62     return static_cast<uint32_t>(0);
63 }
64 
coreInitialized(const::android::hardware::hidl_vec<uint8_t> & arg0)65 ::android::hardware::Return<::android::hardware::nfc::V1_0::NfcStatus> Vts_android_hardware_nfc_V1_0_INfc::coreInitialized(
66     const ::android::hardware::hidl_vec<uint8_t>& arg0 __attribute__((__unused__))) {
67     LOG(INFO) << "coreInitialized called";
68     AndroidSystemCallbackRequestMessage callback_message;
69     callback_message.set_id(GetCallbackID("coreInitialized"));
70     callback_message.set_name("Vts_android_hardware_nfc_V1_0_INfc::coreInitialized");
71     VariableSpecificationMessage* var_msg0 = callback_message.add_arg();
72     var_msg0->set_type(TYPE_VECTOR);
73     var_msg0->set_vector_size(arg0.size());
74     for (int i = 0; i < (int)arg0.size(); i++) {
75         auto *var_msg0_vector_i = var_msg0->add_vector_value();
76         var_msg0_vector_i->set_type(TYPE_SCALAR);
77         var_msg0_vector_i->set_scalar_type("uint8_t");
78         var_msg0_vector_i->mutable_scalar_value()->set_uint8_t(arg0[i]);
79     }
80     RpcCallToAgent(callback_message, callback_socket_name_);
81     return ::android::hardware::nfc::V1_0::NfcStatus();
82 }
83 
prediscover()84 ::android::hardware::Return<::android::hardware::nfc::V1_0::NfcStatus> Vts_android_hardware_nfc_V1_0_INfc::prediscover(
85     ) {
86     LOG(INFO) << "prediscover called";
87     AndroidSystemCallbackRequestMessage callback_message;
88     callback_message.set_id(GetCallbackID("prediscover"));
89     callback_message.set_name("Vts_android_hardware_nfc_V1_0_INfc::prediscover");
90     RpcCallToAgent(callback_message, callback_socket_name_);
91     return ::android::hardware::nfc::V1_0::NfcStatus();
92 }
93 
close()94 ::android::hardware::Return<::android::hardware::nfc::V1_0::NfcStatus> Vts_android_hardware_nfc_V1_0_INfc::close(
95     ) {
96     LOG(INFO) << "close called";
97     AndroidSystemCallbackRequestMessage callback_message;
98     callback_message.set_id(GetCallbackID("close"));
99     callback_message.set_name("Vts_android_hardware_nfc_V1_0_INfc::close");
100     RpcCallToAgent(callback_message, callback_socket_name_);
101     return ::android::hardware::nfc::V1_0::NfcStatus();
102 }
103 
controlGranted()104 ::android::hardware::Return<::android::hardware::nfc::V1_0::NfcStatus> Vts_android_hardware_nfc_V1_0_INfc::controlGranted(
105     ) {
106     LOG(INFO) << "controlGranted called";
107     AndroidSystemCallbackRequestMessage callback_message;
108     callback_message.set_id(GetCallbackID("controlGranted"));
109     callback_message.set_name("Vts_android_hardware_nfc_V1_0_INfc::controlGranted");
110     RpcCallToAgent(callback_message, callback_socket_name_);
111     return ::android::hardware::nfc::V1_0::NfcStatus();
112 }
113 
powerCycle()114 ::android::hardware::Return<::android::hardware::nfc::V1_0::NfcStatus> Vts_android_hardware_nfc_V1_0_INfc::powerCycle(
115     ) {
116     LOG(INFO) << "powerCycle called";
117     AndroidSystemCallbackRequestMessage callback_message;
118     callback_message.set_id(GetCallbackID("powerCycle"));
119     callback_message.set_name("Vts_android_hardware_nfc_V1_0_INfc::powerCycle");
120     RpcCallToAgent(callback_message, callback_socket_name_);
121     return ::android::hardware::nfc::V1_0::NfcStatus();
122 }
123 
VtsFuzzerCreateVts_android_hardware_nfc_V1_0_INfc(const string & callback_socket_name)124 sp<::android::hardware::nfc::V1_0::INfc> VtsFuzzerCreateVts_android_hardware_nfc_V1_0_INfc(const string& callback_socket_name) {
125     static sp<::android::hardware::nfc::V1_0::INfc> result;
126     result = new Vts_android_hardware_nfc_V1_0_INfc(callback_socket_name);
127     return result;
128 }
129 
Fuzz(FunctionSpecificationMessage *,void **,const string &)130 bool FuzzerExtended_android_hardware_nfc_V1_0_INfc::Fuzz(
131     FunctionSpecificationMessage* /*func_msg*/,
132     void** /*result*/, const string& /*callback_socket_name*/) {
133     return true;
134 }
GetAttribute(FunctionSpecificationMessage *,void **)135 bool FuzzerExtended_android_hardware_nfc_V1_0_INfc::GetAttribute(
136     FunctionSpecificationMessage* /*func_msg*/,
137     void** /*result*/) {
138     LOG(ERROR) << "attribute not found.";
139     return false;
140 }
CallFunction(const FunctionSpecificationMessage & func_msg,const string & callback_socket_name,FunctionSpecificationMessage * result_msg)141 bool FuzzerExtended_android_hardware_nfc_V1_0_INfc::CallFunction(
142     const FunctionSpecificationMessage& func_msg,
143     const string& callback_socket_name __attribute__((__unused__)),
144     FunctionSpecificationMessage* result_msg) {
145     const char* func_name = func_msg.name().c_str();
146     if (hw_binder_proxy_ == nullptr) {
147         LOG(ERROR) << "hw_binder_proxy_ is null. ";
148         return false;
149     }
150     if (!strcmp(func_name, "open")) {
151         sp<::android::hardware::nfc::V1_0::INfcClientCallback> arg0;
152         arg0 = VtsFuzzerCreateVts_android_hardware_nfc_V1_0_INfcClientCallback(callback_socket_name);
153         static_cast<Vts_android_hardware_nfc_V1_0_INfcClientCallback*>(arg0.get())->Register(func_msg.arg(0));
154         LOG(DEBUG) << "local_device = " << hw_binder_proxy_.get();
155         ::android::hardware::nfc::V1_0::NfcStatus result0 = hw_binder_proxy_->open(arg0);
156         result_msg->set_name("open");
157         VariableSpecificationMessage* result_val_0 = result_msg->add_return_type_hidl();
158         result_val_0->set_type(TYPE_ENUM);
159         SetResult__android__hardware__nfc__V1_0__NfcStatus(result_val_0, result0);
160         return true;
161     }
162     if (!strcmp(func_name, "write")) {
163         ::android::hardware::hidl_vec<uint8_t> arg0;
164         arg0.resize(func_msg.arg(0).vector_value_size());
165         for (int arg0_index = 0; arg0_index < func_msg.arg(0).vector_value_size(); arg0_index++) {
166             arg0[arg0_index] = func_msg.arg(0).vector_value(arg0_index).scalar_value().uint8_t();
167         }
168         LOG(DEBUG) << "local_device = " << hw_binder_proxy_.get();
169         uint32_t result0 = hw_binder_proxy_->write(arg0);
170         result_msg->set_name("write");
171         VariableSpecificationMessage* result_val_0 = result_msg->add_return_type_hidl();
172         result_val_0->set_type(TYPE_SCALAR);
173         result_val_0->set_scalar_type("uint32_t");
174         result_val_0->mutable_scalar_value()->set_uint32_t(result0);
175         return true;
176     }
177     if (!strcmp(func_name, "coreInitialized")) {
178         ::android::hardware::hidl_vec<uint8_t> arg0;
179         arg0.resize(func_msg.arg(0).vector_value_size());
180         for (int arg0_index = 0; arg0_index < func_msg.arg(0).vector_value_size(); arg0_index++) {
181             arg0[arg0_index] = func_msg.arg(0).vector_value(arg0_index).scalar_value().uint8_t();
182         }
183         LOG(DEBUG) << "local_device = " << hw_binder_proxy_.get();
184         ::android::hardware::nfc::V1_0::NfcStatus result0 = hw_binder_proxy_->coreInitialized(arg0);
185         result_msg->set_name("coreInitialized");
186         VariableSpecificationMessage* result_val_0 = result_msg->add_return_type_hidl();
187         result_val_0->set_type(TYPE_ENUM);
188         SetResult__android__hardware__nfc__V1_0__NfcStatus(result_val_0, result0);
189         return true;
190     }
191     if (!strcmp(func_name, "prediscover")) {
192         LOG(DEBUG) << "local_device = " << hw_binder_proxy_.get();
193         ::android::hardware::nfc::V1_0::NfcStatus result0 = hw_binder_proxy_->prediscover();
194         result_msg->set_name("prediscover");
195         VariableSpecificationMessage* result_val_0 = result_msg->add_return_type_hidl();
196         result_val_0->set_type(TYPE_ENUM);
197         SetResult__android__hardware__nfc__V1_0__NfcStatus(result_val_0, result0);
198         return true;
199     }
200     if (!strcmp(func_name, "close")) {
201         LOG(DEBUG) << "local_device = " << hw_binder_proxy_.get();
202         ::android::hardware::nfc::V1_0::NfcStatus result0 = hw_binder_proxy_->close();
203         result_msg->set_name("close");
204         VariableSpecificationMessage* result_val_0 = result_msg->add_return_type_hidl();
205         result_val_0->set_type(TYPE_ENUM);
206         SetResult__android__hardware__nfc__V1_0__NfcStatus(result_val_0, result0);
207         return true;
208     }
209     if (!strcmp(func_name, "controlGranted")) {
210         LOG(DEBUG) << "local_device = " << hw_binder_proxy_.get();
211         ::android::hardware::nfc::V1_0::NfcStatus result0 = hw_binder_proxy_->controlGranted();
212         result_msg->set_name("controlGranted");
213         VariableSpecificationMessage* result_val_0 = result_msg->add_return_type_hidl();
214         result_val_0->set_type(TYPE_ENUM);
215         SetResult__android__hardware__nfc__V1_0__NfcStatus(result_val_0, result0);
216         return true;
217     }
218     if (!strcmp(func_name, "powerCycle")) {
219         LOG(DEBUG) << "local_device = " << hw_binder_proxy_.get();
220         ::android::hardware::nfc::V1_0::NfcStatus result0 = hw_binder_proxy_->powerCycle();
221         result_msg->set_name("powerCycle");
222         VariableSpecificationMessage* result_val_0 = result_msg->add_return_type_hidl();
223         result_val_0->set_type(TYPE_ENUM);
224         SetResult__android__hardware__nfc__V1_0__NfcStatus(result_val_0, result0);
225         return true;
226     }
227     if (!strcmp(func_name, "notifySyspropsChanged")) {
228         LOG(INFO) << "Call notifySyspropsChanged";
229         hw_binder_proxy_->notifySyspropsChanged();
230         result_msg->set_name("notifySyspropsChanged");
231         return true;
232     }
233     return false;
234 }
235 
VerifyResults(const FunctionSpecificationMessage & expected_result,const FunctionSpecificationMessage & actual_result)236 bool FuzzerExtended_android_hardware_nfc_V1_0_INfc::VerifyResults(const FunctionSpecificationMessage& expected_result __attribute__((__unused__)),
237     const FunctionSpecificationMessage& actual_result __attribute__((__unused__))) {
238     if (!strcmp(actual_result.name().c_str(), "open")) {
239         if (actual_result.return_type_hidl_size() != expected_result.return_type_hidl_size() ) { return false; }
240         if(!Verify__android__hardware__nfc__V1_0__NfcStatus(expected_result.return_type_hidl(0), actual_result.return_type_hidl(0))) { return false; }
241         return true;
242     }
243     if (!strcmp(actual_result.name().c_str(), "write")) {
244         if (actual_result.return_type_hidl_size() != expected_result.return_type_hidl_size() ) { return false; }
245         if (actual_result.return_type_hidl(0).scalar_value().uint32_t() != expected_result.return_type_hidl(0).scalar_value().uint32_t()) { return false; }
246         return true;
247     }
248     if (!strcmp(actual_result.name().c_str(), "coreInitialized")) {
249         if (actual_result.return_type_hidl_size() != expected_result.return_type_hidl_size() ) { return false; }
250         if(!Verify__android__hardware__nfc__V1_0__NfcStatus(expected_result.return_type_hidl(0), actual_result.return_type_hidl(0))) { return false; }
251         return true;
252     }
253     if (!strcmp(actual_result.name().c_str(), "prediscover")) {
254         if (actual_result.return_type_hidl_size() != expected_result.return_type_hidl_size() ) { return false; }
255         if(!Verify__android__hardware__nfc__V1_0__NfcStatus(expected_result.return_type_hidl(0), actual_result.return_type_hidl(0))) { return false; }
256         return true;
257     }
258     if (!strcmp(actual_result.name().c_str(), "close")) {
259         if (actual_result.return_type_hidl_size() != expected_result.return_type_hidl_size() ) { return false; }
260         if(!Verify__android__hardware__nfc__V1_0__NfcStatus(expected_result.return_type_hidl(0), actual_result.return_type_hidl(0))) { return false; }
261         return true;
262     }
263     if (!strcmp(actual_result.name().c_str(), "controlGranted")) {
264         if (actual_result.return_type_hidl_size() != expected_result.return_type_hidl_size() ) { return false; }
265         if(!Verify__android__hardware__nfc__V1_0__NfcStatus(expected_result.return_type_hidl(0), actual_result.return_type_hidl(0))) { return false; }
266         return true;
267     }
268     if (!strcmp(actual_result.name().c_str(), "powerCycle")) {
269         if (actual_result.return_type_hidl_size() != expected_result.return_type_hidl_size() ) { return false; }
270         if(!Verify__android__hardware__nfc__V1_0__NfcStatus(expected_result.return_type_hidl(0), actual_result.return_type_hidl(0))) { return false; }
271         return true;
272     }
273     return false;
274 }
275 
276 extern "C" {
vts_func_4_android_hardware_nfc_V1_0_INfc_()277 android::vts::DriverBase* vts_func_4_android_hardware_nfc_V1_0_INfc_() {
278     return (android::vts::DriverBase*) new android::vts::FuzzerExtended_android_hardware_nfc_V1_0_INfc();
279 }
280 
vts_func_4_android_hardware_nfc_V1_0_INfc_with_arg(uint64_t hw_binder_proxy)281 android::vts::DriverBase* vts_func_4_android_hardware_nfc_V1_0_INfc_with_arg(uint64_t hw_binder_proxy) {
282     ::android::hardware::nfc::V1_0::INfc* arg = nullptr;
283     if (hw_binder_proxy) {
284         arg = reinterpret_cast<::android::hardware::nfc::V1_0::INfc*>(hw_binder_proxy);
285     } else {
286         LOG(INFO) << " Creating DriverBase with null proxy.";
287     }
288     android::vts::DriverBase* result =
289         new android::vts::FuzzerExtended_android_hardware_nfc_V1_0_INfc(
290             arg);
291     if (arg != nullptr) {
292         arg->decStrong(arg);
293     }
294     return result;
295 }
296 
297 }
298 }  // namespace vts
299 }  // namespace android
300