Home | History | Annotate | Download | only in libloc_api_50001
      1 /* Copyright (c) 2011-2015, 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_ENG_ADAPTER_H
     30 #define LOC_API_ENG_ADAPTER_H
     31 
     32 #include <ctype.h>
     33 #include <hardware/gps.h>
     34 #include <loc.h>
     35 #include <loc_eng_log.h>
     36 #include <log_util.h>
     37 #include <LocAdapterBase.h>
     38 #include <LocDualContext.h>
     39 #include <UlpProxyBase.h>
     40 #include <platform_lib_includes.h>
     41 
     42 #define MAX_URL_LEN 256
     43 
     44 using namespace loc_core;
     45 
     46 class LocEngAdapter;
     47 
     48 class LocInternalAdapter : public LocAdapterBase {
     49     LocEngAdapter* mLocEngAdapter;
     50 public:
     51     LocInternalAdapter(LocEngAdapter* adapter);
     52 
     53     virtual void reportPosition(UlpLocation &location,
     54                                 GpsLocationExtended &locationExtended,
     55                                 void* locationExt,
     56                                 enum loc_sess_status status,
     57                                 LocPosTechMask loc_technology_mask);
     58     virtual void reportSv(QtiGnssSvStatus &svStatus,
     59                           GpsLocationExtended &locationExtended,
     60                           void* svExt);
     61     virtual void reportStatus(GpsStatusValue status);
     62     virtual void setPositionModeInt(LocPosMode& posMode);
     63     virtual void startFixInt();
     64     virtual void stopFixInt();
     65     virtual void getZppInt();
     66     virtual void setUlpProxy(UlpProxyBase* ulp);
     67 };
     68 
     69 typedef void (*loc_msg_sender)(void* loc_eng_data_p, void* msgp);
     70 
     71 class LocEngAdapter : public LocAdapterBase {
     72     void* mOwner;
     73     LocInternalAdapter* mInternalAdapter;
     74     UlpProxyBase* mUlp;
     75     LocPosMode mFixCriteria;
     76     bool mNavigating;
     77     // mPowerVote is encoded as
     78     // mPowerVote & 0x20 -- powerVoteRight
     79     // mPowerVote & 0x10 -- power On / Off
     80     unsigned int mPowerVote;
     81     static const unsigned int POWER_VOTE_RIGHT = 0x20;
     82     static const unsigned int POWER_VOTE_VALUE = 0x10;
     83 
     84 public:
     85     bool mSupportsAgpsRequests;
     86     bool mSupportsPositionInjection;
     87     bool mSupportsTimeInjection;
     88 
     89     LocEngAdapter(LOC_API_ADAPTER_EVENT_MASK_T mask,
     90                   void* owner, ContextBase* context,
     91                   LocThread::tCreate tCreator);
     92     virtual ~LocEngAdapter();
     93 
     94     virtual void setUlpProxy(UlpProxyBase* ulp);
     95     void setXtraUserAgent();
     96     inline void requestUlp(unsigned long capabilities) {
     97         mContext->requestUlp(mInternalAdapter, capabilities);
     98     }
     99     inline LocInternalAdapter* getInternalAdapter() { return mInternalAdapter; }
    100     inline UlpProxyBase* getUlpProxy() { return mUlp; }
    101     inline void* getOwner() { return mOwner; }
    102     inline bool hasAgpsExtendedCapabilities() {
    103         return mContext->hasAgpsExtendedCapabilities();
    104     }
    105     inline bool hasCPIExtendedCapabilities() {
    106         return mContext->hasCPIExtendedCapabilities();
    107     }
    108     inline const MsgTask* getMsgTask() { return mMsgTask; }
    109 
    110     inline enum loc_api_adapter_err
    111         startFix()
    112     {
    113         return mLocApi->startFix(mFixCriteria);
    114     }
    115     inline enum loc_api_adapter_err
    116         stopFix()
    117     {
    118         return mLocApi->stopFix();
    119     }
    120     inline enum loc_api_adapter_err
    121         deleteAidingData(GpsAidingData f)
    122     {
    123         return mLocApi->deleteAidingData(f);
    124     }
    125     inline enum loc_api_adapter_err
    126         enableData(int enable)
    127     {
    128         return mLocApi->enableData(enable);
    129     }
    130     inline enum loc_api_adapter_err
    131         setAPN(char* apn, int len)
    132     {
    133         return mLocApi->setAPN(apn, len);
    134     }
    135     inline enum loc_api_adapter_err
    136         injectPosition(double latitude, double longitude, float accuracy)
    137     {
    138         return mLocApi->injectPosition(latitude, longitude, accuracy);
    139     }
    140     inline enum loc_api_adapter_err
    141         setXtraData(char* data, int length)
    142     {
    143         return mLocApi->setXtraData(data, length);
    144     }
    145     inline enum loc_api_adapter_err
    146         requestXtraServer()
    147     {
    148         return mLocApi->requestXtraServer();
    149     }
    150     inline enum loc_api_adapter_err
    151         atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bearer, AGpsType agpsType)
    152     {
    153         return mLocApi->atlOpenStatus(handle, is_succ, apn, bearer, agpsType);
    154     }
    155     inline enum loc_api_adapter_err
    156         atlCloseStatus(int handle, int is_succ)
    157     {
    158         return mLocApi->atlCloseStatus(handle, is_succ);
    159     }
    160     inline enum loc_api_adapter_err
    161         setPositionMode(const LocPosMode *posMode)
    162     {
    163         if (NULL != posMode) {
    164             mFixCriteria = *posMode;
    165         }
    166         return mLocApi->setPositionMode(mFixCriteria);
    167     }
    168     inline enum loc_api_adapter_err
    169         setServer(const char* url, int len)
    170     {
    171         return mLocApi->setServer(url, len);
    172     }
    173     inline enum loc_api_adapter_err
    174         setServer(unsigned int ip, int port,
    175                   LocServerType type)
    176     {
    177         return mLocApi->setServer(ip, port, type);
    178     }
    179     inline enum loc_api_adapter_err
    180         informNiResponse(GpsUserResponseType userResponse, const void* passThroughData)
    181     {
    182         return mLocApi->informNiResponse(userResponse, passThroughData);
    183     }
    184     inline enum loc_api_adapter_err
    185         setSUPLVersion(uint32_t version)
    186     {
    187         return mLocApi->setSUPLVersion(version);
    188     }
    189     inline enum loc_api_adapter_err
    190         setLPPConfig(uint32_t profile)
    191     {
    192         return mLocApi->setLPPConfig(profile);
    193     }
    194     inline enum loc_api_adapter_err
    195         setSensorControlConfig(int sensorUsage, int sensorProvider)
    196     {
    197         return mLocApi->setSensorControlConfig(sensorUsage, sensorProvider);
    198     }
    199     inline enum loc_api_adapter_err
    200         setSensorProperties(bool gyroBiasVarianceRandomWalk_valid, float gyroBiasVarianceRandomWalk,
    201                             bool accelBiasVarianceRandomWalk_valid, float accelBiasVarianceRandomWalk,
    202                             bool angleBiasVarianceRandomWalk_valid, float angleBiasVarianceRandomWalk,
    203                             bool rateBiasVarianceRandomWalk_valid, float rateBiasVarianceRandomWalk,
    204                             bool velocityBiasVarianceRandomWalk_valid, float velocityBiasVarianceRandomWalk)
    205     {
    206         return mLocApi->setSensorProperties(gyroBiasVarianceRandomWalk_valid, gyroBiasVarianceRandomWalk,
    207                                            accelBiasVarianceRandomWalk_valid, accelBiasVarianceRandomWalk,
    208                                            angleBiasVarianceRandomWalk_valid, angleBiasVarianceRandomWalk,
    209                                            rateBiasVarianceRandomWalk_valid, rateBiasVarianceRandomWalk,
    210                                            velocityBiasVarianceRandomWalk_valid, velocityBiasVarianceRandomWalk);
    211     }
    212     inline virtual enum loc_api_adapter_err
    213         setSensorPerfControlConfig(int controlMode, int accelSamplesPerBatch, int accelBatchesPerSec,
    214                             int gyroSamplesPerBatch, int gyroBatchesPerSec,
    215                             int accelSamplesPerBatchHigh, int accelBatchesPerSecHigh,
    216                             int gyroSamplesPerBatchHigh, int gyroBatchesPerSecHigh, int algorithmConfig)
    217     {
    218         return mLocApi->setSensorPerfControlConfig(controlMode, accelSamplesPerBatch, accelBatchesPerSec,
    219                                                   gyroSamplesPerBatch, gyroBatchesPerSec,
    220                                                   accelSamplesPerBatchHigh, accelBatchesPerSecHigh,
    221                                                   gyroSamplesPerBatchHigh, gyroBatchesPerSecHigh,
    222                                                   algorithmConfig);
    223     }
    224     inline virtual enum loc_api_adapter_err
    225         setExtPowerConfig(int isBatteryCharging)
    226     {
    227         return mLocApi->setExtPowerConfig(isBatteryCharging);
    228     }
    229     inline virtual enum loc_api_adapter_err
    230         setAGLONASSProtocol(unsigned long aGlonassProtocol)
    231     {
    232         return mLocApi->setAGLONASSProtocol(aGlonassProtocol);
    233     }
    234     inline virtual int initDataServiceClient()
    235     {
    236         return mLocApi->initDataServiceClient();
    237     }
    238     inline virtual int openAndStartDataCall()
    239     {
    240         return mLocApi->openAndStartDataCall();
    241     }
    242     inline virtual void stopDataCall()
    243     {
    244         mLocApi->stopDataCall();
    245     }
    246     inline virtual void closeDataCall()
    247     {
    248         mLocApi->closeDataCall();
    249     }
    250     inline enum loc_api_adapter_err
    251         getZpp(GpsLocation &zppLoc, LocPosTechMask &tech_mask)
    252     {
    253         return mLocApi->getBestAvailableZppFix(zppLoc, tech_mask);
    254     }
    255     enum loc_api_adapter_err setTime(GpsUtcTime time,
    256                                      int64_t timeReference,
    257                                      int uncertainty);
    258     enum loc_api_adapter_err setXtraVersionCheck(int check);
    259     inline virtual void installAGpsCert(const DerEncodedCertificate* pData,
    260                                         size_t length,
    261                                         uint32_t slotBitMask)
    262     {
    263         mLocApi->installAGpsCert(pData, length, slotBitMask);
    264     }
    265     virtual void handleEngineDownEvent();
    266     virtual void handleEngineUpEvent();
    267     virtual void reportPosition(UlpLocation &location,
    268                                 GpsLocationExtended &locationExtended,
    269                                 void* locationExt,
    270                                 enum loc_sess_status status,
    271                                 LocPosTechMask loc_technology_mask);
    272     virtual void reportSv(QtiGnssSvStatus &svStatus,
    273                           GpsLocationExtended &locationExtended,
    274                           void* svExt);
    275     virtual void reportStatus(GpsStatusValue status);
    276     virtual void reportNmea(const char* nmea, int length);
    277     virtual bool reportXtraServer(const char* url1, const char* url2,
    278                                   const char* url3, const int maxlength);
    279     virtual bool requestXtraData();
    280     virtual bool requestTime();
    281     virtual bool requestATL(int connHandle, AGpsType agps_type);
    282     virtual bool releaseATL(int connHandle);
    283     virtual bool requestNiNotify(GpsNiNotification &notify, const void* data);
    284     virtual bool requestSuplES(int connHandle);
    285     virtual bool reportDataCallOpened();
    286     virtual bool reportDataCallClosed();
    287     virtual void reportGpsMeasurementData(GpsData &gpsMeasurementData);
    288 
    289     inline const LocPosMode& getPositionMode() const
    290     {return mFixCriteria;}
    291     inline virtual bool isInSession()
    292     { return mNavigating; }
    293     void setInSession(bool inSession);
    294 
    295     // Permit/prohibit power voting
    296     inline void setPowerVoteRight(bool powerVoteRight) {
    297         mPowerVote = powerVoteRight ? (mPowerVote | POWER_VOTE_RIGHT) :
    298                                       (mPowerVote & ~POWER_VOTE_RIGHT);
    299     }
    300     inline bool getPowerVoteRight() const {
    301         return (mPowerVote & POWER_VOTE_RIGHT) != 0 ;
    302     }
    303     // Set the power voting up/down and do actual operation if permitted
    304     inline void setPowerVote(bool powerOn) {
    305         mPowerVote = powerOn ? (mPowerVote | POWER_VOTE_VALUE) :
    306                                (mPowerVote & ~POWER_VOTE_VALUE);
    307         requestPowerVote();
    308         mContext->modemPowerVote(powerOn);
    309     }
    310     inline bool getPowerVote() const {
    311         return (mPowerVote & POWER_VOTE_VALUE) != 0 ;
    312     }
    313     // Do power voting according to last settings if permitted
    314     void requestPowerVote();
    315 
    316     /*Values for lock
    317       1 = Do not lock any position sessions
    318       2 = Lock MI position sessions
    319       3 = Lock MT position sessions
    320       4 = Lock all position sessions
    321     */
    322     inline int setGpsLock(LOC_GPS_LOCK_MASK lock)
    323     {
    324         return mLocApi->setGpsLock(lock);
    325     }
    326 
    327     int setGpsLockMsg(LOC_GPS_LOCK_MASK lock);
    328 
    329     /*
    330       Returns
    331       Current value of GPS lock on success
    332       -1 on failure
    333      */
    334     inline int getGpsLock()
    335     {
    336         return mLocApi->getGpsLock();
    337     }
    338 
    339     /*
    340       Update Registration Mask
    341      */
    342     void updateRegistrationMask(LOC_API_ADAPTER_EVENT_MASK_T event,
    343                                 loc_registration_mask_status isEnabled);
    344 
    345     /*
    346       Set Gnss Constellation Config
    347      */
    348     bool gnssConstellationConfig();
    349 };
    350 
    351 #endif //LOC_API_ENG_ADAPTER_H
    352