1 /*
2  * Copyright 2016 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 #ifndef __VTS_FUZZER_TCP_CLIENT_H_
18 #define __VTS_FUZZER_TCP_CLIENT_H_
19 
20 #include <string>
21 #include <vector>
22 
23 #include <VtsDriverCommUtil.h>
24 #include "test/vts/proto/VtsDriverControlMessage.pb.h"
25 #include "test/vts/proto/VtsResourceControllerMessage.pb.h"
26 
27 using namespace std;
28 
29 namespace android {
30 namespace vts {
31 
32 // Socket client instance for an agent to control a driver.
33 class VtsDriverSocketClient : public VtsDriverCommUtil {
34  public:
VtsDriverSocketClient()35   explicit VtsDriverSocketClient() : VtsDriverCommUtil() {}
36 
37   // closes the socket.
38   void Close();
39 
40   // Sends a EXIT request;
41   bool Exit();
42 
43   // Sends a LOAD_HAL request.
44   // Args:
45   //   target_version_major: int, hal major version
46   //   target_version_minor: int, hal minor version
47   int32_t LoadHal(const string& file_path, int target_class, int target_type,
48                   int target_version_major, int target_version_minor,
49                   const string& target_package,
50                   const string& target_component_name,
51                   const string& hw_binder_service_name,
52                   const string& module_name);
53 
54   // Sends a LIST_FUNCTIONS request.
55   string GetFunctions();
56 
57   // Sends a VTS_DRIVER_COMMAND_READ_SPECIFICATION request.
58   // Args:
59   //   target_version_major: int, hal major version
60   //   target_version_minor: int, hal minor version
61   string ReadSpecification(const string& component_name, int target_class,
62                            int target_type, int target_version_major,
63                            int target_version_minor,
64                            const string& target_package);
65 
66   // Sends a CALL_FUNCTION request.
67   string Call(const string& arg, const string& uid);
68 
69   // Sends a GET_ATTRIBUTE request.
70   string GetAttribute(const string& arg);
71 
72   // Sends a GET_STATUS request.
73   int32_t Status(int32_t type);
74 
75   // Sends a EXECUTE request.
76   unique_ptr<VtsDriverControlResponseMessage> ExecuteShellCommand(
77       const ::google::protobuf::RepeatedPtrField<::std::string> shell_command);
78 
79   // Processes the command for a FMQ request, stores the result in fmq_response.
80   //
81   // @param fmq_request  contains arguments in a request message for FMQ driver.
82   // @param fmq_response pointer to the message that will be sent back to host.
83   //
84   // @return true if api is called successfully and data have been transferred
85   //              without error,
86   //         false otherwise.
87   bool ProcessFmqCommand(const FmqRequestMessage& fmq_request,
88                          FmqResponseMessage* fmq_response);
89 
90   // Processes the command for a hidl_memory request, stores the result in
91   // hidl_memory_response.
92   //
93   // @param hidl_memory_request  contains arguments in a request message for
94   //                             hidl_memory driver.
95   // @param hidl_memory_response pointer to message sent back to host.
96   //
97   // @return true if api is called successfully and data have been transferred
98   //              without error,
99   //         false otherwise.
100   bool ProcessHidlMemoryCommand(
101       const HidlMemoryRequestMessage& hidl_memory_request,
102       HidlMemoryResponseMessage* hidl_memory_response);
103 
104   // Processes the command for a hidl_handle request, stores the result in
105   // hidl_handle_response.
106   //
107   // @param hidl_handle_request  contains arguments in a request message for
108   //                             hidl_handle driver.
109   // @param hidl_handle_response pointer to message sent back to host.
110   //
111   // @return true if api is called successfully and data have been transferred
112   //              without error,
113   //         false otherwise.
114   bool ProcessHidlHandleCommand(
115       const HidlHandleRequestMessage& hidl_handle_request,
116       HidlHandleResponseMessage* hidl_handle_response);
117 };
118 
119 // returns the socket port file's path for the given service_name.
120 extern string GetSocketPortFilePath(const string& service_name);
121 
122 // returns true if the specified driver is running.
123 bool IsDriverRunning(const string& service_name, int retry_count);
124 
125 // creates and returns VtsDriverSocketClient of the given service_name.
126 extern VtsDriverSocketClient* GetDriverSocketClient(const string& service_name);
127 
128 }  // namespace vts
129 }  // namespace android
130 
131 #endif  // __VTS_FUZZER_TCP_CLIENT_H_
132