1/* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 *     * Redistributions of source code must retain the above copyright
7 *       notice, this list of conditions and the following disclaimer.
8 *     * Redistributions in binary form must reproduce the above
9 *       copyright notice, this list of conditions and the following
10 *       disclaimer in the documentation and/or other materials provided
11 *       with the distribution.
12 *     * Neither the name of The Linux Foundation, nor the names of its
13 *       contributors may be used to endorse or promote products derived
14 *       from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29#ifndef __LOC_CONTEXT_BASE__
30#define __LOC_CONTEXT_BASE__
31
32#include <stdbool.h>
33#include <ctype.h>
34#include <MsgTask.h>
35#include <LocApiBase.h>
36#include <LBSProxyBase.h>
37#include <loc_cfg.h>
38
39#define MAX_XTRA_SERVER_URL_LENGTH 256
40
41/* GPS.conf support */
42/* NOTE: the implementaiton of the parser casts number
43   fields to 32 bit. To ensure all 'n' fields working,
44   they must all be 32 bit fields. */
45typedef struct loc_gps_cfg_s
46{
47    uint32_t       INTERMEDIATE_POS;
48    uint32_t       ACCURACY_THRES;
49    uint32_t       SUPL_VER;
50    uint32_t       SUPL_MODE;
51    uint32_t       SUPL_ES;
52    uint32_t       CAPABILITIES;
53    uint32_t       LPP_PROFILE;
54    uint32_t       XTRA_VERSION_CHECK;
55    char           XTRA_SERVER_1[MAX_XTRA_SERVER_URL_LENGTH];
56    char           XTRA_SERVER_2[MAX_XTRA_SERVER_URL_LENGTH];
57    char           XTRA_SERVER_3[MAX_XTRA_SERVER_URL_LENGTH];
58    uint32_t       USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL;
59    uint32_t       NMEA_PROVIDER;
60    uint32_t       GPS_LOCK;
61    uint32_t       A_GLONASS_POS_PROTOCOL_SELECT;
62    uint32_t       AGPS_CERT_WRITABLE_MASK;
63    uint32_t       AGPS_CONFIG_INJECT;
64    uint32_t       LPPE_CP_TECHNOLOGY;
65    uint32_t       LPPE_UP_TECHNOLOGY;
66    uint32_t       EXTERNAL_DR_ENABLED;
67} loc_gps_cfg_s_type;
68
69/* NOTE: the implementaiton of the parser casts number
70   fields to 32 bit. To ensure all 'n' fields working,
71   they must all be 32 bit fields. */
72/* Meanwhile, *_valid fields are 8 bit fields, and 'f'
73   fields are double. Rigid as they are, it is the
74   the status quo, until the parsing mechanism is
75   change, that is. */
76typedef struct
77{
78    uint8_t        GYRO_BIAS_RANDOM_WALK_VALID;
79    double         GYRO_BIAS_RANDOM_WALK;
80    uint32_t       SENSOR_ACCEL_BATCHES_PER_SEC;
81    uint32_t       SENSOR_ACCEL_SAMPLES_PER_BATCH;
82    uint32_t       SENSOR_GYRO_BATCHES_PER_SEC;
83    uint32_t       SENSOR_GYRO_SAMPLES_PER_BATCH;
84    uint32_t       SENSOR_ACCEL_BATCHES_PER_SEC_HIGH;
85    uint32_t       SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH;
86    uint32_t       SENSOR_GYRO_BATCHES_PER_SEC_HIGH;
87    uint32_t       SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH;
88    uint32_t       SENSOR_CONTROL_MODE;
89    uint32_t       SENSOR_USAGE;
90    uint32_t       SENSOR_ALGORITHM_CONFIG_MASK;
91    uint8_t        ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
92    double         ACCEL_RANDOM_WALK_SPECTRAL_DENSITY;
93    uint8_t        ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
94    double         ANGLE_RANDOM_WALK_SPECTRAL_DENSITY;
95    uint8_t        RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
96    double         RATE_RANDOM_WALK_SPECTRAL_DENSITY;
97    uint8_t        VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
98    double         VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY;
99    uint32_t       SENSOR_PROVIDER;
100} loc_sap_cfg_s_type;
101
102namespace loc_core {
103
104class LocAdapterBase;
105
106class ContextBase {
107    static LBSProxyBase* getLBSProxy(const char* libName);
108    LocApiBase* createLocApi(LOC_API_ADAPTER_EVENT_MASK_T excludedMask);
109    static const loc_param_s_type mGps_conf_table[];
110    static const loc_param_s_type mSap_conf_table[];
111protected:
112    const LBSProxyBase* mLBSProxy;
113    const MsgTask* mMsgTask;
114    LocApiBase* mLocApi;
115    LocApiProxyBase *mLocApiProxy;
116public:
117    ContextBase(const MsgTask* msgTask,
118                LOC_API_ADAPTER_EVENT_MASK_T exMask,
119                const char* libName);
120    inline virtual ~ContextBase() { delete mLocApi; delete mLBSProxy; }
121
122    inline const MsgTask* getMsgTask() { return mMsgTask; }
123    inline LocApiBase* getLocApi() { return mLocApi; }
124    inline LocApiProxyBase* getLocApiProxy() { return mLocApiProxy; }
125    inline bool hasAgpsExtendedCapabilities() { return mLBSProxy->hasAgpsExtendedCapabilities(); }
126    inline bool hasCPIExtendedCapabilities() { return mLBSProxy->hasCPIExtendedCapabilities(); }
127    inline bool hasNativeXtraClient() { return mLBSProxy->hasNativeXtraClient(); }
128    inline void modemPowerVote(bool power) const { return mLBSProxy->modemPowerVote(power); }
129    inline void requestUlp(LocAdapterBase* adapter,
130                           unsigned long capabilities) {
131        mLBSProxy->requestUlp(adapter, capabilities);
132    }
133    inline IzatDevId_t getIzatDevId() const {
134        return mLBSProxy->getIzatDevId();
135    }
136    inline void sendMsg(const LocMsg *msg) { getMsgTask()->sendMsg(msg); }
137
138    static loc_gps_cfg_s_type mGps_conf;
139    static loc_sap_cfg_s_type mSap_conf;
140
141    void readConfig();
142    static uint32_t getCarrierCapabilities();
143
144};
145
146} // namespace loc_core
147
148#endif //__LOC_CONTEXT_BASE__
149