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