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