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