1 /*
2  * Copyright (C) 2014 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 __WIFI_HAL_GSCAN_COMMAND_H__
18 #define __WIFI_HAL_GSCAN_COMMAND_H__
19 
20 #include "common.h"
21 #include "cpp_bindings.h"
22 #ifdef __GNUC__
23 #define PRINTF_FORMAT(a,b) __attribute__ ((format (printf, (a), (b))))
24 #define STRUCT_PACKED __attribute__ ((packed))
25 #else
26 #define PRINTF_FORMAT(a,b)
27 #define STRUCT_PACKED
28 #endif
29 #include "qca-vendor.h"
30 #include "vendor_definitions.h"
31 #include "gscan.h"
32 
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif /* __cplusplus */
37 
38 typedef struct{
39     u32 status;
40     u32 num_channels;
41     wifi_channel channels[];
42 } GScanGetValidChannelsRspParams;
43 
44 typedef struct{
45     u32 status;
46     wifi_gscan_capabilities capabilities;
47 } GScanGetCapabilitiesRspParams;
48 
49 typedef struct{
50     u32 status;
51 } GScanStartRspParams;
52 
53 typedef struct{
54     u32 status;
55 } GScanStopRspParams;
56 
57 typedef struct{
58     u32 status;
59 } GScanSetBssidHotlistRspParams;
60 
61 typedef struct{
62     u32 status;
63 } GScanResetBssidHotlistRspParams;
64 
65 typedef struct{
66     u8  more_data;
67     u32 num_results;
68     wifi_scan_result *results;
69 } GScanGetCachedResultsRspParams;
70 
71 typedef struct{
72     u32 status;
73 } GScanSetSignificantChangeRspParams;
74 
75 typedef struct{
76     u32 status;
77 } GScanResetSignificantChangeRspParams;
78 
79 typedef struct {
80     int max_channels;
81     wifi_channel *channels;
82     int *number_channels;
83 } GScan_get_valid_channels_cb_data;
84 
85 typedef enum{
86     eGScanRspParamsInvalid = 0,
87     eGScanGetValidChannelsRspParams,
88     eGScanGetCapabilitiesRspParams,
89     eGScanGetCachedResultsRspParams,
90     eGScanStartRspParams,
91     eGScanStopRspParams,
92     eGScanSetBssidHotlistRspParams,
93     eGScanResetBssidHotlistRspParams,
94     eGScanSetSignificantChangeRspParams,
95     eGScanResetSignificantChangeRspParams,
96 } eGScanRspRarams;
97 
98 /* Response and Event Callbacks */
99 typedef struct {
100     /* Various Events Callback */
101     void (*get_capabilities)(int status, wifi_gscan_capabilities capabilities);
102     void (*start)(int status);
103     void (*stop)(int status);
104     void (*set_bssid_hotlist)(int status);
105     void (*reset_bssid_hotlist)(int status);
106     void (*set_significant_change)(int status);
107     void (*reset_significant_change)(int status);
108     void (*on_hotlist_ap_found)(wifi_request_id id,
109         unsigned num_results, wifi_scan_result *results);
110     void (*get_cached_results)(u8 more_data, u32 num_results);
111     void (*on_significant_change)(wifi_request_id id,
112                 unsigned num_results,
113                 wifi_significant_change_result **results);
114     /* Reported when report_threshold is reached in scan cache */
115     void (*on_scan_results_available) (wifi_request_id id,
116                                     unsigned num_results_available);
117     /* Reported when each probe response is received, if report_events
118      * enabled in wifi_scan_cmd_params
119      */
120     void (*on_full_scan_result) (wifi_request_id id, wifi_scan_result *result);
121     /* Optional event - indicates progress of scanning statemachine */
122     void (*on_scan_event) (wifi_scan_event event, unsigned status);
123 } GScanCallbackHandler;
124 
125 class GScanCommand: public WifiVendorCommand
126 {
127 private:
128     GScanStopRspParams                  *mStopGScanRspParams;
129     GScanStartRspParams                 *mStartGScanRspParams;
130     GScanSetBssidHotlistRspParams       *mSetBssidHotlistRspParams;
131     GScanResetBssidHotlistRspParams     *mResetBssidHotlistRspParams;
132     GScanSetSignificantChangeRspParams  *mSetSignificantChangeRspParams;
133     GScanResetSignificantChangeRspParams*mResetSignificantChangeRspParams;
134     GScanGetCapabilitiesRspParams       *mGetCapabilitiesRspParams;
135     GScanGetCachedResultsRspParams      *mGetCachedResultsRspParams;
136     u32                                 mGetCachedResultsNumResults;
137     GScanCallbackHandler                mHandler;
138     int                                 mRequestId;
139     int                                 *mChannels;
140     int                                 mMaxChannels;
141     int                                 *mNumChannelsPtr;
142     bool                                mWaitforRsp;
143 
144 public:
145     GScanCommand(wifi_handle handle, int id, u32 vendor_id, u32 subcmd);
146     virtual ~GScanCommand();
147 
148     /* This function implements creation of GSCAN specific Request
149      * based on  the request type.
150      */
151     virtual int create();
152     virtual int requestEvent();
153     virtual int requestResponse();
154     virtual int handleResponse(WifiEvent &reply);
155     virtual int handleEvent(WifiEvent &event);
156     virtual int setCallbackHandler(GScanCallbackHandler nHandler);
157     virtual void setMaxChannels(int max_channels);
158     virtual void setChannels(int *channels);
159     virtual void setNumChannelsPtr(int *num_channels);
160     virtual int allocRspParams(eGScanRspRarams cmd);
161     virtual void freeRspParams(eGScanRspRarams cmd);
162     virtual void getGetCapabilitiesRspParams(
163                     wifi_gscan_capabilities *capabilities,
164                     u32 *status);
165     virtual void getStartGScanRspParams(u32 *status);
166     virtual void getStopGScanRspParams(u32 *status);
167     virtual void getSetBssidHotlistRspParams(u32 *status);
168     virtual void getResetBssidHotlistRspParams(u32 *status);
169     virtual void getSetSignificantChangeRspParams(u32 *status);
170     virtual void getResetSignificantChangeRspParams(u32 *status);
171     virtual wifi_error getGetCachedResultsRspParams(int max,
172                                                     u8 *moreData,
173                                                     int *numResults,
174                                                     wifi_scan_result *results);
175     /* Takes wait time in seconds. */
176     virtual int timed_wait(u16 wait_time);
177     virtual void waitForRsp(bool wait);
178 };
179 
180 #ifdef __cplusplus
181 }
182 #endif /* __cplusplus */
183 #endif
184