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     GScanGetCachedResultsRspParams      *mGetCachedResultsRspParams;
    105     GScanCallbackHandler                mHandler;
    106     int                                 mRequestId;
    107     int                                 *mChannels;
    108     int                                 mMaxChannels;
    109     int                                 *mNumChannelsPtr;
    110 
    111 public:
    112     GScanCommand(wifi_handle handle, int id, u32 vendor_id, u32 subcmd);
    113     virtual ~GScanCommand();
    114 
    115     /* This function implements creation of GSCAN specific Request
    116      * based on  the request type.
    117      */
    118     virtual int create();
    119     virtual int requestResponse();
    120     virtual int handleResponse(WifiEvent &reply);
    121     virtual void setMaxChannels(int max_channels);
    122     virtual void setChannels(int *channels);
    123     virtual void setNumChannelsPtr(int *num_channels);
    124     virtual int allocRspParams(eGScanRspRarams cmd);
    125     virtual void freeRspParams(eGScanRspRarams cmd);
    126     virtual wifi_error copyCachedScanResults(int *numResults,
    127                                              wifi_cached_scan_results *cached_results);
    128     virtual int gscan_get_cached_results(wifi_cached_scan_results *results,
    129                                          struct nlattr **tb_vendor);
    130     wifi_error validateGscanConfig(wifi_scan_cmd_params params);
    131     wifi_error validateSignificantChangeParams(
    132             wifi_significant_change_params params);
    133     virtual int allocCachedResultsTemp(int max,
    134                                        wifi_cached_scan_results *results);
    135 };
    136 
    137 #define GSCAN_BASE_PERIOD_MIN 1
    138 #define GSCAN_MAX_AP_PER_SCAN_MIN 1
    139 #define GSCAN_REPORT_THRESHOLD_MIN 1
    140 #define GSCAN_NUM_BUCKETS_MIN 1
    141 #define GSCAN_BUCKET_INDEX_MIN 0
    142 #define GSCAN_REPORT_EVENT0 0
    143 #define GSCAN_REPORT_EVENT1 1
    144 #define GSCAN_REPORT_EVENT2 2
    145 #define GSCAN_MIN_CHANNELS 0
    146 #define GSCAN_ACTIVE_SCAN 0
    147 #define GSCAN_PASSIVE_SCAN 1
    148 
    149 #define BSSID_HOTLIST_NUM_AP_MIN 1
    150 
    151 #define RSSI_SAMPLE_SIZE_MIN 1
    152 #define LOSTAP_SAMPLE_SIZE_MIN 1
    153 #define MIN_BREACHING_MIN 1
    154 #define SIGNIFICANT_CHANGE_NUM_AP_MIN 1
    155 
    156 #ifdef __cplusplus
    157 }
    158 #endif /* __cplusplus */
    159 #endif
    160