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