• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define MAX_SUPL_SERVER_URL_LENGTH (256)
41 
42 /* GPS.conf support */
43 /* NOTE: the implementaiton of the parser casts number
44    fields to 32 bit. To ensure all 'n' fields working,
45    they must all be 32 bit fields. */
46 typedef struct loc_gps_cfg_s
47 {
48     uint32_t       INTERMEDIATE_POS;
49     uint32_t       ACCURACY_THRES;
50     uint32_t       SUPL_VER;
51     uint32_t       SUPL_MODE;
52     uint32_t       SUPL_ES;
53     uint32_t       CAPABILITIES;
54     uint32_t       LPP_PROFILE;
55     uint32_t       XTRA_VERSION_CHECK;
56     char           XTRA_SERVER_1[MAX_XTRA_SERVER_URL_LENGTH];
57     char           XTRA_SERVER_2[MAX_XTRA_SERVER_URL_LENGTH];
58     char           XTRA_SERVER_3[MAX_XTRA_SERVER_URL_LENGTH];
59     uint32_t       USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL;
60     uint32_t       NMEA_PROVIDER;
61     uint32_t       GPS_LOCK;
62     uint32_t       A_GLONASS_POS_PROTOCOL_SELECT;
63     uint32_t       AGPS_CERT_WRITABLE_MASK;
64     uint32_t       AGPS_CONFIG_INJECT;
65     uint32_t       LPPE_CP_TECHNOLOGY;
66     uint32_t       LPPE_UP_TECHNOLOGY;
67     uint32_t       EXTERNAL_DR_ENABLED;
68     char           SUPL_HOST[MAX_SUPL_SERVER_URL_LENGTH];
69     uint32_t       SUPL_PORT;
70 } loc_gps_cfg_s_type;
71 
72 /* NOTE: the implementaiton of the parser casts number
73    fields to 32 bit. To ensure all 'n' fields working,
74    they must all be 32 bit fields. */
75 /* Meanwhile, *_valid fields are 8 bit fields, and 'f'
76    fields are double. Rigid as they are, it is the
77    the status quo, until the parsing mechanism is
78    change, that is. */
79 typedef struct
80 {
81     uint8_t        GYRO_BIAS_RANDOM_WALK_VALID;
82     double         GYRO_BIAS_RANDOM_WALK;
83     uint32_t       SENSOR_ACCEL_BATCHES_PER_SEC;
84     uint32_t       SENSOR_ACCEL_SAMPLES_PER_BATCH;
85     uint32_t       SENSOR_GYRO_BATCHES_PER_SEC;
86     uint32_t       SENSOR_GYRO_SAMPLES_PER_BATCH;
87     uint32_t       SENSOR_ACCEL_BATCHES_PER_SEC_HIGH;
88     uint32_t       SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH;
89     uint32_t       SENSOR_GYRO_BATCHES_PER_SEC_HIGH;
90     uint32_t       SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH;
91     uint32_t       SENSOR_CONTROL_MODE;
92     uint32_t       SENSOR_USAGE;
93     uint32_t       SENSOR_ALGORITHM_CONFIG_MASK;
94     uint8_t        ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
95     double         ACCEL_RANDOM_WALK_SPECTRAL_DENSITY;
96     uint8_t        ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
97     double         ANGLE_RANDOM_WALK_SPECTRAL_DENSITY;
98     uint8_t        RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
99     double         RATE_RANDOM_WALK_SPECTRAL_DENSITY;
100     uint8_t        VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
101     double         VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY;
102     uint32_t       SENSOR_PROVIDER;
103 } loc_sap_cfg_s_type;
104 
105 namespace loc_core {
106 
107 class LocAdapterBase;
108 
109 class ContextBase {
110     static LBSProxyBase* getLBSProxy(const char* libName);
111     LocApiBase* createLocApi(LOC_API_ADAPTER_EVENT_MASK_T excludedMask);
112     static const loc_param_s_type mGps_conf_table[];
113     static const loc_param_s_type mSap_conf_table[];
114 protected:
115     const LBSProxyBase* mLBSProxy;
116     const MsgTask* mMsgTask;
117     LocApiBase* mLocApi;
118     LocApiProxyBase *mLocApiProxy;
119 public:
120     ContextBase(const MsgTask* msgTask,
121                 LOC_API_ADAPTER_EVENT_MASK_T exMask,
122                 const char* libName);
~ContextBase()123     inline virtual ~ContextBase() { delete mLocApi; delete mLBSProxy; }
124 
getMsgTask()125     inline const MsgTask* getMsgTask() { return mMsgTask; }
getLocApi()126     inline LocApiBase* getLocApi() { return mLocApi; }
getLocApiProxy()127     inline LocApiProxyBase* getLocApiProxy() { return mLocApiProxy; }
hasAgpsExtendedCapabilities()128     inline bool hasAgpsExtendedCapabilities() { return mLBSProxy->hasAgpsExtendedCapabilities(); }
hasCPIExtendedCapabilities()129     inline bool hasCPIExtendedCapabilities() { return mLBSProxy->hasCPIExtendedCapabilities(); }
hasNativeXtraClient()130     inline bool hasNativeXtraClient() { return mLBSProxy->hasNativeXtraClient(); }
modemPowerVote(bool power)131     inline void modemPowerVote(bool power) const { return mLBSProxy->modemPowerVote(power); }
requestUlp(LocAdapterBase * adapter,unsigned long capabilities)132     inline void requestUlp(LocAdapterBase* adapter,
133                            unsigned long capabilities) {
134         mLBSProxy->requestUlp(adapter, capabilities);
135     }
getIzatDevId()136     inline IzatDevId_t getIzatDevId() const {
137         return mLBSProxy->getIzatDevId();
138     }
sendMsg(const LocMsg * msg)139     inline void sendMsg(const LocMsg *msg) { getMsgTask()->sendMsg(msg); }
140 
141     static loc_gps_cfg_s_type mGps_conf;
142     static loc_sap_cfg_s_type mSap_conf;
143 
144     void readConfig();
145     static uint32_t getCarrierCapabilities();
146 
147 };
148 
149 } // namespace loc_core
150 
151 #endif //__LOC_CONTEXT_BASE__
152