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