• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2011-2014, 2016 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_API_BASE_H
30 #define LOC_API_BASE_H
31 
32 #include <stddef.h>
33 #include <ctype.h>
34 #include <gps_extended.h>
35 #include <MsgTask.h>
36 #include <platform_lib_log_util.h>
37 
38 namespace loc_core {
39 class ContextBase;
40 
41 int hexcode(char *hexstring, int string_size,
42             const char *data, int data_size);
43 int decodeAddress(char *addr_string, int string_size,
44                   const char *data, int data_size);
45 
46 #define MAX_ADAPTERS          10
47 #define MAX_FEATURE_LENGTH    100
48 
49 #define TO_ALL_ADAPTERS(adapters, call)                                \
50     for (int i = 0; i < MAX_ADAPTERS && NULL != (adapters)[i]; i++) {  \
51         call;                                                          \
52     }
53 
54 #define TO_1ST_HANDLING_ADAPTER(adapters, call)                              \
55     for (int i = 0; i <MAX_ADAPTERS && NULL != (adapters)[i] && !(call); i++);
56 
57 enum xtra_version_check {
58     DISABLED,
59     AUTO,
60     XTRA2,
61     XTRA3
62 };
63 
64 class LocAdapterBase;
65 struct LocSsrMsg;
66 struct LocOpenMsg;
67 
68 class LocApiProxyBase {
69 public:
LocApiProxyBase()70     inline LocApiProxyBase() {}
~LocApiProxyBase()71     inline virtual ~LocApiProxyBase() {}
getSibling2()72     inline virtual void* getSibling2() { return NULL; }
73 };
74 
75 class LocApiBase {
76     friend struct LocSsrMsg;
77     //LocOpenMsg calls open() which makes it necessary to declare
78     //it as a friend
79     friend struct LocOpenMsg;
80     friend class ContextBase;
81     const MsgTask* mMsgTask;
82     ContextBase *mContext;
83     LocAdapterBase* mLocAdapters[MAX_ADAPTERS];
84     uint64_t mSupportedMsg;
85     uint8_t mFeaturesSupported[MAX_FEATURE_LENGTH];
86 
87 protected:
88     virtual enum loc_api_adapter_err
89         open(LOC_API_ADAPTER_EVENT_MASK_T mask);
90     virtual enum loc_api_adapter_err
91         close();
92     LOC_API_ADAPTER_EVENT_MASK_T getEvtMask();
93     LOC_API_ADAPTER_EVENT_MASK_T mMask;
94     LocApiBase(const MsgTask* msgTask,
95                LOC_API_ADAPTER_EVENT_MASK_T excludedMask,
96                ContextBase* context = NULL);
~LocApiBase()97     inline virtual ~LocApiBase() { close(); }
98     bool isInSession();
99     const LOC_API_ADAPTER_EVENT_MASK_T mExcludedMask;
100 
101 public:
sendMsg(const LocMsg * msg)102     inline void sendMsg(const LocMsg* msg) const {
103         mMsgTask->sendMsg(msg);
104     }
105 
106     void addAdapter(LocAdapterBase* adapter);
107     void removeAdapter(LocAdapterBase* adapter);
108 
109     // upward calls
110     void handleEngineUpEvent();
111     void handleEngineDownEvent();
112     void reportPosition(UlpLocation &location,
113                         GpsLocationExtended &locationExtended,
114                         void* locationExt,
115                         enum loc_sess_status status,
116                         LocPosTechMask loc_technology_mask =
117                                   LOC_POS_TECH_MASK_DEFAULT);
118     void reportSv(GnssSvStatus &svStatus,
119                   GpsLocationExtended &locationExtended,
120                   void* svExt);
121     void reportSvMeasurement(GnssSvMeasurementSet &svMeasurementSet);
122     void reportSvPolynomial(GnssSvPolynomial &svPolynomial);
123     void reportStatus(GpsStatusValue status);
124     void reportNmea(const char* nmea, int length);
125     void reportXtraServer(const char* url1, const char* url2,
126                           const char* url3, const int maxlength);
127     void requestXtraData();
128     void requestTime();
129     void requestLocation();
130     void requestATL(int connHandle, AGpsType agps_type);
131     void releaseATL(int connHandle);
132     void requestSuplES(int connHandle);
133     void reportDataCallOpened();
134     void reportDataCallClosed();
135     void requestNiNotify(GpsNiNotification &notify, const void* data);
136     void saveSupportedMsgList(uint64_t supportedMsgList);
137     void reportGnssMeasurementData(GnssData &gnssMeasurementData);
138     void saveSupportedFeatureList(uint8_t *featureList);
139     void reportWwanZppFix(GpsLocation &zppLoc);
140 
141     // downward calls
142     // All below functions are to be defined by adapter specific modules:
143     // RPC, QMI, etc.  The default implementation is empty.
144 
145     virtual void* getSibling();
146     virtual LocApiProxyBase* getLocApiProxy();
147     virtual enum loc_api_adapter_err
148         startFix(const LocPosMode& posMode);
149     virtual enum loc_api_adapter_err
150         stopFix();
151     virtual enum loc_api_adapter_err
152         deleteAidingData(GpsAidingData f);
153     virtual enum loc_api_adapter_err
154         enableData(int enable);
155     virtual enum loc_api_adapter_err
156         setAPN(char* apn, int len);
157     virtual enum loc_api_adapter_err
158         injectPosition(double latitude, double longitude, float accuracy);
159     virtual enum loc_api_adapter_err
160         setTime(GpsUtcTime time, int64_t timeReference, int uncertainty);
161     virtual enum loc_api_adapter_err
162         setXtraData(char* data, int length);
163     virtual enum loc_api_adapter_err
164         requestXtraServer();
165     virtual enum loc_api_adapter_err
166         atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bear, AGpsType agpsType);
167     virtual enum loc_api_adapter_err
168         atlCloseStatus(int handle, int is_succ);
169     virtual enum loc_api_adapter_err
170         setPositionMode(const LocPosMode& posMode);
171     virtual enum loc_api_adapter_err
172         setServer(const char* url, int len);
173     virtual enum loc_api_adapter_err
174         setServer(unsigned int ip, int port,
175                   LocServerType type);
176     virtual enum loc_api_adapter_err
177         informNiResponse(GpsUserResponseType userResponse, const void* passThroughData);
178     virtual enum loc_api_adapter_err
179         setSUPLVersion(uint32_t version);
180     virtual enum loc_api_adapter_err
181         setNMEATypes (uint32_t typesMask);
182     virtual enum loc_api_adapter_err
183         setLPPConfig(uint32_t profile);
184     virtual enum loc_api_adapter_err
185         setSensorControlConfig(int sensorUsage, int sensorProvider);
186     virtual enum loc_api_adapter_err
187         setSensorProperties(bool gyroBiasVarianceRandomWalk_valid,
188                             float gyroBiasVarianceRandomWalk,
189                             bool accelBiasVarianceRandomWalk_valid,
190                             float accelBiasVarianceRandomWalk,
191                             bool angleBiasVarianceRandomWalk_valid,
192                             float angleBiasVarianceRandomWalk,
193                             bool rateBiasVarianceRandomWalk_valid,
194                             float rateBiasVarianceRandomWalk,
195                             bool velocityBiasVarianceRandomWalk_valid,
196                             float velocityBiasVarianceRandomWalk);
197     virtual enum loc_api_adapter_err
198         setSensorPerfControlConfig(int controlMode,
199                                int accelSamplesPerBatch,
200                                int accelBatchesPerSec,
201                                int gyroSamplesPerBatch,
202                                int gyroBatchesPerSec,
203                                int accelSamplesPerBatchHigh,
204                                int accelBatchesPerSecHigh,
205                                int gyroSamplesPerBatchHigh,
206                                int gyroBatchesPerSecHigh,
207                                int algorithmConfig);
208     virtual enum loc_api_adapter_err
209         setAGLONASSProtocol(unsigned long aGlonassProtocol);
210     virtual enum loc_api_adapter_err
211         setLPPeProtocol(unsigned long lppeCP, unsigned long lppeUP);
212     virtual enum loc_api_adapter_err
213         getWwanZppFix();
214     virtual enum loc_api_adapter_err
215         getBestAvailableZppFix(GpsLocation & zppLoc);
216     virtual enum loc_api_adapter_err
217         getBestAvailableZppFix(GpsLocation & zppLoc, LocPosTechMask & tech_mask);
218     virtual int initDataServiceClient(bool isDueToSsr);
219     virtual int openAndStartDataCall();
220     virtual void stopDataCall();
221     virtual void closeDataCall();
222     virtual void releaseDataServiceClient();
223     virtual void installAGpsCert(const DerEncodedCertificate* pData,
224                                  size_t length,
225                                  uint32_t slotBitMask);
setInSession(bool inSession)226     inline virtual void setInSession(bool inSession) {
227 
228         (void)inSession;
229     }
isMessageSupported(LocCheckingMessagesID msgID)230     inline bool isMessageSupported (LocCheckingMessagesID msgID) const {
231 
232         // confirm if msgID is not larger than the number of bits in
233         // mSupportedMsg
234         if ((uint64_t)msgID > (sizeof(mSupportedMsg) << 3)) {
235             return false;
236         } else {
237             uint32_t messageChecker = 1 << msgID;
238             return (messageChecker & mSupportedMsg) == messageChecker;
239         }
240     }
241     void updateEvtMask();
242 
243     /*Values for lock
244       1 = Do not lock any position sessions
245       2 = Lock MI position sessions
246       3 = Lock MT position sessions
247       4 = Lock all position sessions
248      */
249     virtual int setGpsLock(LOC_GPS_LOCK_MASK lock);
250     /*
251       Returns
252       Current value of GPS Lock on success
253       -1 on failure
254      */
255     virtual int getGpsLock(void);
256 
257     virtual enum loc_api_adapter_err setXtraVersionCheck(enum xtra_version_check check);
258 
259     /*
260       Check if the modem support the service
261      */
262     virtual bool gnssConstellationConfig();
263 
264     /*
265        Check if a feature is supported
266       */
267     bool isFeatureSupported(uint8_t featureVal);
268 };
269 
270 typedef LocApiBase* (getLocApi_t)(const MsgTask* msgTask,
271                                   LOC_API_ADAPTER_EVENT_MASK_T exMask,
272                                   ContextBase *context);
273 
274 } // namespace loc_core
275 
276 #endif //LOC_API_BASE_H
277