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 "gscan.h"
30 
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif /* __cplusplus */
35 
36 typedef struct{
37     u32 status;
38     u32 num_channels;
39     wifi_channel channels[];
40 } GScanGetValidChannelsRspParams;
41 
42 typedef struct{
43     wifi_gscan_capabilities capabilities;
44 } GScanGetCapabilitiesRspParams;
45 
46 typedef struct{
47     u8  more_data;
48     u32 num_cached_results;
49     u32 cachedResultsStartingIndex; /* Used in filling cached scan results */
50     int lastProcessedScanId; /* Last scan id in gscan cached results block */
51     u32 wifiScanResultsStartingIndex; /* For the lastProcessedScanId */
52     u32 max;                /* max num of cached results specified by caller */
53     wifi_cached_scan_results *cached_results;
54 } GScanGetCachedResultsRspParams;
55 
56 typedef struct {
57     int max_channels;
58     wifi_channel *channels;
59     int *number_channels;
60 } GScan_get_valid_channels_cb_data;
61 
62 typedef enum{
63     eGScanRspParamsInvalid = 0,
64     eGScanGetValidChannelsRspParams,
65     eGScanGetCapabilitiesRspParams,
66     eGScanGetCachedResultsRspParams,
67 } eGScanRspRarams;
68 
69 /* Response and Event Callbacks */
70 typedef struct {
71     /* Various Events Callback */
72     void (*on_hotlist_ap_found)(wifi_request_id id,
73         unsigned num_results, wifi_scan_result *results);
74     void (*on_hotlist_ap_lost)(wifi_request_id id,
75         unsigned num_results, wifi_scan_result *results);
76     void (*on_significant_change)(wifi_request_id id,
77                 unsigned num_results,
78                 wifi_significant_change_result **results);
79     /* Reported when each probe response is received, if report_events
80      * enabled in wifi_scan_cmd_params
81      */
82     void (*on_full_scan_result) (wifi_request_id id, wifi_scan_result *result,
83                                                    unsigned buckets_scanned);
84     /* Optional event - indicates progress of scanning statemachine */
85     void (*on_scan_event) (wifi_request_id id, wifi_scan_event event);
86     void (*on_hotlist_ssid_found)(wifi_request_id id,
87             unsigned num_results, wifi_scan_result *results);
88     void (*on_hotlist_ssid_lost)(wifi_request_id id,
89             unsigned num_results, wifi_scan_result *results);
90     void (*on_pno_network_found)(wifi_request_id id,
91             unsigned num_results, wifi_scan_result *results);
92     void (*on_passpoint_network_found)(wifi_request_id id,
93                                        int net_id,
94                                        wifi_scan_result *result,
95                                        int anqp_len,
96                                        byte *anqp
97                                        );
98 } GScanCallbackHandler;
99 
100 class GScanCommand: public WifiVendorCommand
101 {
102 private:
103     GScanGetCachedResultsRspParams      *mGetCachedResultsRspParams;
104     GScanCallbackHandler                mHandler;
105     int                                 mRequestId;
106     int                                 *mChannels;
107     int                                 mMaxChannels;
108     int                                 *mNumChannelsPtr;
109 
110 public:
111     GScanCommand(wifi_handle handle, int id, u32 vendor_id, u32 subcmd);
112     virtual ~GScanCommand();
113 
114     /* This function implements creation of GSCAN specific Request
115      * based on  the request type.
116      */
117     virtual wifi_error create();
118     virtual wifi_error requestResponse();
119     virtual int handleResponse(WifiEvent &reply);
120     virtual void setMaxChannels(int max_channels);
121     virtual void setChannels(int *channels);
122     virtual void setNumChannelsPtr(int *num_channels);
123     virtual wifi_error allocRspParams(eGScanRspRarams cmd);
124     virtual void freeRspParams(eGScanRspRarams cmd);
125     virtual wifi_error copyCachedScanResults(int *numResults,
126                                              wifi_cached_scan_results *cached_results);
127     virtual wifi_error gscan_get_cached_results(wifi_cached_scan_results *results,
128                                          struct nlattr **tb_vendor);
129     wifi_error validateGscanConfig(wifi_scan_cmd_params params);
130     wifi_error validateSignificantChangeParams(
131             wifi_significant_change_params params);
132     virtual wifi_error allocCachedResultsTemp(int max,
133                                        wifi_cached_scan_results *results);
134 };
135 
136 #define GSCAN_BASE_PERIOD_MIN 1
137 #define GSCAN_MAX_AP_PER_SCAN_MIN 1
138 #define GSCAN_REPORT_THRESHOLD_MIN 1
139 #define GSCAN_NUM_BUCKETS_MIN 1
140 #define GSCAN_BUCKET_INDEX_MIN 0
141 #define GSCAN_REPORT_EVENT0 0
142 #define GSCAN_REPORT_EVENT1 1
143 #define GSCAN_REPORT_EVENT2 2
144 #define GSCAN_MIN_CHANNELS 0
145 #define GSCAN_ACTIVE_SCAN 0
146 #define GSCAN_PASSIVE_SCAN 1
147 
148 #define BSSID_HOTLIST_NUM_AP_MIN 1
149 
150 #define RSSI_SAMPLE_SIZE_MIN 1
151 #define LOSTAP_SAMPLE_SIZE_MIN 1
152 #define MIN_BREACHING_MIN 1
153 #define SIGNIFICANT_CHANGE_NUM_AP_MIN 1
154 
155 #ifdef __cplusplus
156 }
157 #endif /* __cplusplus */
158 #endif
159