Added gps library code.
diff --git a/gps/Android.mk b/gps/Android.mk
new file mode 100644
index 0000000..3831662
--- /dev/null
+++ b/gps/Android.mk
@@ -0,0 +1,21 @@
+#
+# Copyright (C) 2015 The CyanogenMod Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+ifeq ($(TARGET_DEVICE),gprimeltecan)
+include $(call all-subdir-makefiles,$(LOCAL_PATH))
+endif
diff --git a/gps/core/Android.mk b/gps/core/Android.mk
new file mode 100644
index 0000000..c963894
--- /dev/null
+++ b/gps/core/Android.mk
@@ -0,0 +1,55 @@
+#ifneq ($(BUILD_TINY_ANDROID),true)
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libloc_core
+LOCAL_MODULE_OWNER := qcom
+
+LOCAL_MODULE_TAGS := optional
+
+ifeq ($(TARGET_DEVICE),apq8026_lw)
+LOCAL_CFLAGS += -DPDK_FEATURE_SET
+endif
+
+LOCAL_SHARED_LIBRARIES := \
+    libutils \
+    libcutils \
+    libgps.utils \
+    libdl
+
+LOCAL_SRC_FILES += \
+    MsgTask.cpp \
+    LocApiBase.cpp \
+    LocAdapterBase.cpp \
+    ContextBase.cpp \
+    LocDualContext.cpp \
+    loc_core_log.cpp
+
+LOCAL_CFLAGS += \
+     -fno-short-enums \
+     -D_ANDROID_
+
+LOCAL_C_INCLUDES:= \
+    $(TARGET_OUT_HEADERS)/gps.utils
+
+LOCAL_COPY_HEADERS_TO:= libloc_core/
+LOCAL_COPY_HEADERS:= \
+    MsgTask.h \
+    LocApiBase.h \
+    LocAdapterBase.h \
+    ContextBase.h \
+    LocDualContext.h \
+    LBSProxyBase.h \
+    UlpProxyBase.h \
+    gps_extended_c.h \
+    gps_extended.h \
+    loc_core_log.h \
+    LocAdapterProxyBase.h
+
+LOCAL_PRELINK_MODULE := false
+
+include $(BUILD_SHARED_LIBRARY)
+
+#endif # not BUILD_TINY_ANDROID
diff --git a/gps/core/ContextBase.cpp b/gps/core/ContextBase.cpp
new file mode 100644
index 0000000..9f6c4aa
--- /dev/null
+++ b/gps/core/ContextBase.cpp
@@ -0,0 +1,114 @@
+/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#define LOG_NDDEBUG 0
+#define LOG_TAG "LocSvc_CtxBase"
+
+#include <dlfcn.h>
+#include <cutils/sched_policy.h>
+#include <unistd.h>
+#include <ContextBase.h>
+#include <msg_q.h>
+#include <loc_target.h>
+#include <log_util.h>
+#include <loc_log.h>
+
+namespace loc_core {
+
+LBSProxyBase* ContextBase::getLBSProxy(const char* libName)
+{
+    LBSProxyBase* proxy = NULL;
+    LOC_LOGD("%s:%d]: getLBSProxy libname: %s\n", __func__, __LINE__, libName);
+    void* lib = dlopen(libName, RTLD_NOW);
+
+    if ((void*)NULL != lib) {
+        getLBSProxy_t* getter = (getLBSProxy_t*)dlsym(lib, "getLBSProxy");
+        if (NULL != getter) {
+            proxy = (*getter)();
+        }
+    }
+    if (NULL == proxy) {
+        proxy = new LBSProxyBase();
+    }
+    LOC_LOGD("%s:%d]: Exiting\n", __func__, __LINE__);
+    return proxy;
+}
+
+LocApiBase* ContextBase::createLocApi(LOC_API_ADAPTER_EVENT_MASK_T exMask)
+{
+    LocApiBase* locApi = NULL;
+
+    // first if can not be MPQ
+    if (TARGET_MPQ != loc_get_target()) {
+        if (NULL == (locApi = mLBSProxy->getLocApi(mMsgTask, exMask, this))) {
+            void *handle = NULL;
+            //try to see if LocApiV02 is present
+            if((handle = dlopen("libloc_api_v02.so", RTLD_NOW)) != NULL) {
+                LOC_LOGD("%s:%d]: libloc_api_v02.so is present", __func__, __LINE__);
+                getLocApi_t* getter = (getLocApi_t*)dlsym(handle, "getLocApi");
+                if(getter != NULL) {
+                    LOC_LOGD("%s:%d]: getter is not NULL for LocApiV02", __func__, __LINE__);
+                    locApi = (*getter)(mMsgTask, exMask, this);
+                }
+            }
+            // only RPC is the option now
+            else {
+                LOC_LOGD("%s:%d]: libloc_api_v02.so is NOT present. Trying RPC",
+                         __func__, __LINE__);
+                handle = dlopen("libloc_api-rpc-qc.so", RTLD_NOW);
+                if (NULL != handle) {
+                    getLocApi_t* getter = (getLocApi_t*)dlsym(handle, "getLocApi");
+                    if (NULL != getter) {
+                        LOC_LOGD("%s:%d]: getter is not NULL in RPC", __func__, __LINE__);
+                        locApi = (*getter)(mMsgTask, exMask, this);
+                    }
+                }
+            }
+        }
+    }
+
+    // locApi could still be NULL at this time
+    // we would then create a dummy one
+    if (NULL == locApi) {
+        locApi = new LocApiBase(mMsgTask, exMask, this);
+    }
+
+    return locApi;
+}
+
+ContextBase::ContextBase(const MsgTask* msgTask,
+                         LOC_API_ADAPTER_EVENT_MASK_T exMask,
+                         const char* libName) :
+    mLBSProxy(getLBSProxy(libName)),
+    mMsgTask(msgTask),
+    mLocApi(createLocApi(exMask)),
+    mLocApiProxy(mLocApi->getLocApiProxy())
+{
+}
+
+}
diff --git a/gps/core/ContextBase.h b/gps/core/ContextBase.h
new file mode 100644
index 0000000..2adbedd
--- /dev/null
+++ b/gps/core/ContextBase.h
@@ -0,0 +1,70 @@
+/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef __LOC_CONTEXT_BASE__
+#define __LOC_CONTEXT_BASE__
+
+#include <stdbool.h>
+#include <ctype.h>
+#include <MsgTask.h>
+#include <LocApiBase.h>
+#include <LBSProxyBase.h>
+
+namespace loc_core {
+
+class LocAdapterBase;
+
+class ContextBase {
+    static LBSProxyBase* getLBSProxy(const char* libName);
+    LocApiBase* createLocApi(LOC_API_ADAPTER_EVENT_MASK_T excludedMask);
+protected:
+    const LBSProxyBase* mLBSProxy;
+    const MsgTask* mMsgTask;
+    LocApiBase* mLocApi;
+    LocApiProxyBase *mLocApiProxy;
+public:
+    ContextBase(const MsgTask* msgTask,
+                LOC_API_ADAPTER_EVENT_MASK_T exMask,
+                const char* libName);
+    inline virtual ~ContextBase() { delete mLocApi; delete mLBSProxy; }
+
+    inline const MsgTask* getMsgTask() { return mMsgTask; }
+    inline LocApiBase* getLocApi() { return mLocApi; }
+    inline LocApiProxyBase* getLocApiProxy() { return mLocApiProxy; }
+    inline bool hasAgpsExtendedCapabilities() { return mLBSProxy->hasAgpsExtendedCapabilities(); }
+    inline bool hasCPIExtendedCapabilities() { return mLBSProxy->hasCPIExtendedCapabilities(); }
+    inline void requestUlp(LocAdapterBase* adapter,
+                           unsigned long capabilities) {
+        mLBSProxy->requestUlp(adapter, capabilities);
+    }
+    inline void sendMsg(const LocMsg *msg) { getMsgTask()->sendMsg(msg); }
+};
+
+} // namespace loc_core
+
+#endif //__LOC_CONTEXT_BASE__
diff --git a/gps/core/LBSProxyBase.h b/gps/core/LBSProxyBase.h
new file mode 100644
index 0000000..0b7dbdf
--- /dev/null
+++ b/gps/core/LBSProxyBase.h
@@ -0,0 +1,63 @@
+/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef IZAT_PROXY_BASE_H
+#define IZAT_PROXY_BASE_H
+#include <gps_extended.h>
+#include <MsgTask.h>
+
+namespace loc_core {
+
+class LocApiBase;
+class LocAdapterBase;
+class ContextBase;
+
+class LBSProxyBase {
+    friend class ContextBase;
+    inline virtual LocApiBase*
+        getLocApi(const MsgTask* msgTask,
+                  LOC_API_ADAPTER_EVENT_MASK_T exMask,
+                  ContextBase* context) const {
+        return NULL;
+    }
+protected:
+    inline LBSProxyBase() {}
+public:
+    inline virtual ~LBSProxyBase() {}
+    inline virtual void requestUlp(LocAdapterBase* adapter,
+                                   unsigned long capabilities) const {}
+    inline virtual bool hasAgpsExtendedCapabilities() const { return false; }
+    inline virtual bool hasCPIExtendedCapabilities() const { return false; }
+    virtual void injectFeatureConfig(ContextBase* context) const {}
+};
+
+typedef LBSProxyBase* (getLBSProxy_t)();
+
+} // namespace loc_core
+
+#endif // IZAT_PROXY_BASE_H
diff --git a/gps/core/LocAdapterBase.cpp b/gps/core/LocAdapterBase.cpp
new file mode 100644
index 0000000..b304653
--- /dev/null
+++ b/gps/core/LocAdapterBase.cpp
@@ -0,0 +1,145 @@
+/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#define LOG_NDDEBUG 0
+#define LOG_TAG "LocSvc_LocAdapterBase"
+
+#include <dlfcn.h>
+#include <LocAdapterBase.h>
+#include <loc_target.h>
+#include <log_util.h>
+#include <LocAdapterProxyBase.h>
+
+namespace loc_core {
+
+// This is the top level class, so the constructor will
+// always gets called. Here we prepare for the default.
+// But if getLocApi(targetEnumType target) is overriden,
+// the right locApi should get created.
+LocAdapterBase::LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask,
+                               ContextBase* context, LocAdapterProxyBase *adapterProxyBase) :
+    mEvtMask(mask), mContext(context),
+    mLocApi(context->getLocApi()), mLocAdapterProxyBase(adapterProxyBase),
+    mMsgTask(context->getMsgTask())
+{
+    mLocApi->addAdapter(this);
+}
+
+void LocAdapterBase::handleEngineUpEvent()
+{
+    if (mLocAdapterProxyBase) {
+        mLocAdapterProxyBase->handleEngineUpEvent();
+    }
+}
+
+void LocAdapterBase::handleEngineDownEvent()
+{
+    if (mLocAdapterProxyBase) {
+        mLocAdapterProxyBase->handleEngineDownEvent();
+    }
+}
+
+void LocAdapterBase::
+    reportPosition(UlpLocation &location,
+                   GpsLocationExtended &locationExtended,
+                   void* locationExt,
+                   enum loc_sess_status status,
+                   LocPosTechMask loc_technology_mask) {
+    if (mLocAdapterProxyBase == NULL ||
+        !mLocAdapterProxyBase->reportPosition(location,
+                                              status,
+                                              loc_technology_mask)) {
+        DEFAULT_IMPL()
+    }
+}
+
+void LocAdapterBase::
+    reportSv(GpsSvStatus &svStatus,
+             GpsLocationExtended &locationExtended,
+             void* svExt)
+DEFAULT_IMPL()
+
+
+void LocAdapterBase::
+    reportStatus(GpsStatusValue status)
+DEFAULT_IMPL()
+
+
+void LocAdapterBase::
+    reportNmea(const char* nmea, int length)
+DEFAULT_IMPL()
+
+bool LocAdapterBase::
+    reportXtraServer(const char* url1, const char* url2,
+                     const char* url3, const int maxlength)
+DEFAULT_IMPL(false)
+
+bool LocAdapterBase::
+    requestXtraData()
+DEFAULT_IMPL(false)
+
+bool LocAdapterBase::
+    requestTime()
+DEFAULT_IMPL(false)
+
+bool LocAdapterBase::
+    requestLocation()
+DEFAULT_IMPL(false)
+
+bool LocAdapterBase::
+    requestATL(int connHandle, AGpsType agps_type)
+DEFAULT_IMPL(false)
+
+bool LocAdapterBase::
+    releaseATL(int connHandle)
+DEFAULT_IMPL(false)
+
+bool LocAdapterBase::
+    requestSuplES(int connHandle)
+DEFAULT_IMPL(false)
+
+bool LocAdapterBase::
+    reportDataCallOpened()
+DEFAULT_IMPL(false)
+
+bool LocAdapterBase::
+    reportDataCallClosed()
+DEFAULT_IMPL(false)
+
+bool LocAdapterBase::
+    requestNiNotify(GpsNiNotification &notify, const void* data)
+DEFAULT_IMPL(false)
+
+void LocAdapterBase::
+    shutdown()
+DEFAULT_IMPL()
+
+void LocAdapterBase::
+    reportGpsMeasurementData(GpsData &gpsMeasurementData)
+DEFAULT_IMPL()
+} // namespace loc_core
diff --git a/gps/core/LocAdapterBase.h b/gps/core/LocAdapterBase.h
new file mode 100644
index 0000000..9d5f6a8
--- /dev/null
+++ b/gps/core/LocAdapterBase.h
@@ -0,0 +1,120 @@
+/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef LOC_API_ADAPTER_BASE_H
+#define LOC_API_ADAPTER_BASE_H
+
+#include <gps_extended.h>
+#include <UlpProxyBase.h>
+#include <ContextBase.h>
+
+namespace loc_core {
+
+class LocAdapterProxyBase;
+
+class LocAdapterBase {
+protected:
+    LOC_API_ADAPTER_EVENT_MASK_T mEvtMask;
+    ContextBase* mContext;
+    LocApiBase* mLocApi;
+    LocAdapterProxyBase* mLocAdapterProxyBase;
+    const MsgTask* mMsgTask;
+
+    inline LocAdapterBase(const MsgTask* msgTask) :
+        mEvtMask(0), mContext(NULL), mLocApi(NULL),
+        mLocAdapterProxyBase(NULL), mMsgTask(msgTask) {}
+public:
+    inline virtual ~LocAdapterBase() { mLocApi->removeAdapter(this); }
+    LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask,
+                   ContextBase* context, LocAdapterProxyBase *adapterProxyBase = NULL);
+    inline LOC_API_ADAPTER_EVENT_MASK_T
+        checkMask(LOC_API_ADAPTER_EVENT_MASK_T mask) const {
+        return mEvtMask & mask;
+    }
+
+    inline LOC_API_ADAPTER_EVENT_MASK_T getEvtMask() const {
+        return mEvtMask;
+    }
+
+    inline void sendMsg(const LocMsg* msg) const {
+        mMsgTask->sendMsg(msg);
+    }
+
+    inline void sendMsg(const LocMsg* msg) {
+        mMsgTask->sendMsg(msg);
+    }
+
+    inline void updateEvtMask(LOC_API_ADAPTER_EVENT_MASK_T event,
+                       loc_registration_mask_status isEnabled)
+    {
+        mEvtMask =
+            isEnabled == LOC_REGISTRATION_MASK_ENABLED ? (mEvtMask|event):(mEvtMask&~event);
+
+        mLocApi->updateEvtMask();
+    }
+
+    // This will be overridden by the individual adapters
+    // if necessary.
+    inline virtual void setUlpProxy(UlpProxyBase* ulp) {}
+    virtual void handleEngineUpEvent();
+    virtual void handleEngineDownEvent();
+    inline virtual void setPositionModeInt(LocPosMode& posMode) {}
+    virtual void startFixInt() {}
+    virtual void stopFixInt() {}
+    virtual void getZppInt() {}
+    virtual void reportPosition(UlpLocation &location,
+                                GpsLocationExtended &locationExtended,
+                                void* locationExt,
+                                enum loc_sess_status status,
+                                LocPosTechMask loc_technology_mask);
+    virtual void reportSv(GpsSvStatus &svStatus,
+                          GpsLocationExtended &locationExtended,
+                          void* svExt);
+    virtual void reportStatus(GpsStatusValue status);
+    virtual void reportNmea(const char* nmea, int length);
+    virtual bool reportXtraServer(const char* url1, const char* url2,
+                                  const char* url3, const int maxlength);
+    virtual bool requestXtraData();
+    virtual bool requestTime();
+    virtual bool requestLocation();
+    virtual bool requestATL(int connHandle, AGpsType agps_type);
+    virtual bool releaseATL(int connHandle);
+    virtual bool requestSuplES(int connHandle);
+    virtual bool reportDataCallOpened();
+    virtual bool reportDataCallClosed();
+    virtual bool requestNiNotify(GpsNiNotification &notify,
+                                 const void* data);
+    inline virtual bool isInSession() { return false; }
+    virtual void shutdown();
+    ContextBase* getContext() const { return mContext; }
+    virtual void reportGpsMeasurementData(GpsData &gpsMeasurementData);
+};
+
+} // namespace loc_core
+
+#endif //LOC_API_ADAPTER_BASE_H
diff --git a/gps/core/LocAdapterProxyBase.h b/gps/core/LocAdapterProxyBase.h
new file mode 100644
index 0000000..f6c22af
--- /dev/null
+++ b/gps/core/LocAdapterProxyBase.h
@@ -0,0 +1,69 @@
+/* Copyright (c) 2014 The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef LOC_ADAPTER_PROXY_BASE_H
+#define LOC_ADAPTER_PROXY_BASE_H
+
+#include <ContextBase.h>
+#include <gps_extended.h>
+
+namespace loc_core {
+
+class LocAdapterProxyBase {
+private:
+    LocAdapterBase *mLocAdapterBase;
+protected:
+    inline LocAdapterProxyBase(const LOC_API_ADAPTER_EVENT_MASK_T mask,
+                   ContextBase* context):
+                   mLocAdapterBase(new LocAdapterBase(mask, context, this)) {
+    }
+    inline virtual ~LocAdapterProxyBase() {
+        delete mLocAdapterBase;
+    }
+    ContextBase* getContext() const {
+        return mLocAdapterBase->getContext();
+    }
+    inline void updateEvtMask(LOC_API_ADAPTER_EVENT_MASK_T event,
+                              loc_registration_mask_status isEnabled) {
+        mLocAdapterBase->updateEvtMask(event,isEnabled);
+    }
+
+public:
+    inline virtual void handleEngineUpEvent() {};
+    inline virtual void handleEngineDownEvent() {};
+    inline virtual bool reportPosition(UlpLocation &location,
+                                       enum loc_sess_status status,
+                                       LocPosTechMask loc_technology_mask) {
+        return false;
+    }
+};
+
+} // namespace loc_core
+
+#endif //LOC_ADAPTER_PROXY_BASE_H
diff --git a/gps/core/LocApiBase.cpp b/gps/core/LocApiBase.cpp
new file mode 100644
index 0000000..f56694e
--- /dev/null
+++ b/gps/core/LocApiBase.cpp
@@ -0,0 +1,545 @@
+/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#define LOG_NDDEBUG 0
+#define LOG_TAG "LocSvc_LocApiBase"
+
+#include <dlfcn.h>
+#include <LocApiBase.h>
+#include <LocAdapterBase.h>
+#include <log_util.h>
+#include <LocDualContext.h>
+
+namespace loc_core {
+
+#define TO_ALL_LOCADAPTERS(call) TO_ALL_ADAPTERS(mLocAdapters, (call))
+#define TO_1ST_HANDLING_LOCADAPTERS(call) TO_1ST_HANDLING_ADAPTER(mLocAdapters, (call))
+
+int hexcode(char *hexstring, int string_size,
+            const char *data, int data_size)
+{
+   int i;
+   for (i = 0; i < data_size; i++)
+   {
+      char ch = data[i];
+      if (i*2 + 3 <= string_size)
+      {
+         snprintf(&hexstring[i*2], 3, "%02X", ch);
+      }
+      else {
+         break;
+      }
+   }
+   return i;
+}
+
+int decodeAddress(char *addr_string, int string_size,
+                   const char *data, int data_size)
+{
+    const char addr_prefix = 0x91;
+    int i, idxOutput = 0;
+
+    if (!data || !addr_string) { return 0; }
+
+    if (data[0] != addr_prefix)
+    {
+        LOC_LOGW("decodeAddress: address prefix is not 0x%x but 0x%x", addr_prefix, data[0]);
+        addr_string[0] = '\0';
+        return 0; // prefix not correct
+    }
+
+    for (i = 1; i < data_size; i++)
+    {
+        unsigned char ch = data[i], low = ch & 0x0F, hi = ch >> 4;
+        if (low <= 9 && idxOutput < string_size - 1) { addr_string[idxOutput++] = low + '0'; }
+        if (hi <= 9 && idxOutput < string_size - 1) { addr_string[idxOutput++] = hi + '0'; }
+    }
+
+    addr_string[idxOutput] = '\0'; // Terminates the string
+
+    return idxOutput;
+}
+
+struct LocSsrMsg : public LocMsg {
+    LocApiBase* mLocApi;
+    inline LocSsrMsg(LocApiBase* locApi) :
+        LocMsg(), mLocApi(locApi)
+    {
+        locallog();
+    }
+    inline virtual void proc() const {
+        mLocApi->close();
+        mLocApi->open(mLocApi->getEvtMask());
+    }
+    inline void locallog() {
+        LOC_LOGV("LocSsrMsg");
+    }
+    inline virtual void log() {
+        locallog();
+    }
+};
+
+struct LocOpenMsg : public LocMsg {
+    LocApiBase* mLocApi;
+    LOC_API_ADAPTER_EVENT_MASK_T mMask;
+    inline LocOpenMsg(LocApiBase* locApi,
+                      LOC_API_ADAPTER_EVENT_MASK_T mask) :
+        LocMsg(), mLocApi(locApi), mMask(mask)
+    {
+        locallog();
+    }
+    inline virtual void proc() const {
+        mLocApi->open(mMask);
+    }
+    inline void locallog() {
+        LOC_LOGV("%s:%d]: LocOpen Mask: %x\n",
+                 __func__, __LINE__, mMask);
+    }
+    inline virtual void log() {
+        locallog();
+    }
+};
+
+LocApiBase::LocApiBase(const MsgTask* msgTask,
+                       LOC_API_ADAPTER_EVENT_MASK_T excludedMask,
+                       ContextBase* context) :
+    mExcludedMask(excludedMask), mMsgTask(msgTask),
+    mMask(0), mSupportedMsg(0), mContext(context)
+{
+    memset(mLocAdapters, 0, sizeof(mLocAdapters));
+}
+
+LOC_API_ADAPTER_EVENT_MASK_T LocApiBase::getEvtMask()
+{
+    LOC_API_ADAPTER_EVENT_MASK_T mask = 0;
+
+    TO_ALL_LOCADAPTERS(mask |= mLocAdapters[i]->getEvtMask());
+
+    return mask & ~mExcludedMask;
+}
+
+bool LocApiBase::isInSession()
+{
+    bool inSession = false;
+
+    for (int i = 0;
+         !inSession && i < MAX_ADAPTERS && NULL != mLocAdapters[i];
+         i++) {
+        inSession = mLocAdapters[i]->isInSession();
+    }
+
+    return inSession;
+}
+
+void LocApiBase::addAdapter(LocAdapterBase* adapter)
+{
+    for (int i = 0; i < MAX_ADAPTERS && mLocAdapters[i] != adapter; i++) {
+        if (mLocAdapters[i] == NULL) {
+            mLocAdapters[i] = adapter;
+            mMsgTask->sendMsg(new LocOpenMsg(this,
+                                             (adapter->getEvtMask())));
+            break;
+        }
+    }
+}
+
+void LocApiBase::removeAdapter(LocAdapterBase* adapter)
+{
+    for (int i = 0;
+         i < MAX_ADAPTERS && NULL != mLocAdapters[i];
+         i++) {
+        if (mLocAdapters[i] == adapter) {
+            mLocAdapters[i] = NULL;
+
+            // shift the rest of the adapters up so that the pointers
+            // in the array do not have holes.  This should be more
+            // performant, because the array maintenance is much much
+            // less frequent than event handlings, which need to linear
+            // search all the adapters
+            int j = i;
+            while (++i < MAX_ADAPTERS && mLocAdapters[i] != NULL);
+
+            // i would be MAX_ADAPTERS or point to a NULL
+            i--;
+            // i now should point to a none NULL adapter within valid
+            // range although i could be equal to j, but it won't hurt.
+            // No need to check it, as it gains nothing.
+            mLocAdapters[j] = mLocAdapters[i];
+            // this makes sure that we exit the for loop
+            mLocAdapters[i] = NULL;
+
+            // if we have an empty list of adapters
+            if (0 == i) {
+                close();
+            } else {
+                // else we need to remove the bit
+                mMsgTask->sendMsg(new LocOpenMsg(this, getEvtMask()));
+            }
+        }
+    }
+}
+
+void LocApiBase::updateEvtMask()
+{
+    mMsgTask->sendMsg(new LocOpenMsg(this, getEvtMask()));
+}
+
+void LocApiBase::handleEngineUpEvent()
+{
+    // This will take care of renegotiating the loc handle
+    mMsgTask->sendMsg(new LocSsrMsg(this));
+
+    LocDualContext::injectFeatureConfig(mContext);
+
+    // loop through adapters, and deliver to all adapters.
+    TO_ALL_LOCADAPTERS(mLocAdapters[i]->handleEngineUpEvent());
+}
+
+void LocApiBase::handleEngineDownEvent()
+{
+    // loop through adapters, and deliver to all adapters.
+    TO_ALL_LOCADAPTERS(mLocAdapters[i]->handleEngineDownEvent());
+}
+
+void LocApiBase::reportPosition(UlpLocation &location,
+                                GpsLocationExtended &locationExtended,
+                                void* locationExt,
+                                enum loc_sess_status status,
+                                LocPosTechMask loc_technology_mask)
+{
+    // print the location info before delivering
+    LOC_LOGV("flags: %d\n  source: %d\n  latitude: %f\n  longitude: %f\n  "
+             "altitude: %f\n  speed: %f\n  bearing: %f\n  accuracy: %f\n  "
+             "timestamp: %lld\n  rawDataSize: %d\n  rawData: %p\n  "
+             "Session status: %d\n Technology mask: %u",
+             location.gpsLocation.flags, location.position_source,
+             location.gpsLocation.latitude, location.gpsLocation.longitude,
+             location.gpsLocation.altitude, location.gpsLocation.speed,
+             location.gpsLocation.bearing, location.gpsLocation.accuracy,
+             location.gpsLocation.timestamp, location.rawDataSize,
+             location.rawData, status, loc_technology_mask);
+    // loop through adapters, and deliver to all adapters.
+    TO_ALL_LOCADAPTERS(
+        mLocAdapters[i]->reportPosition(location,
+                                        locationExtended,
+                                        locationExt,
+                                        status,
+                                        loc_technology_mask)
+    );
+}
+
+void LocApiBase::reportSv(GpsSvStatus &svStatus,
+                  GpsLocationExtended &locationExtended,
+                  void* svExt)
+{
+    // print the SV info before delivering
+    LOC_LOGV("num sv: %d\n  ephemeris mask: %dxn  almanac mask: %x\n  used"
+             " in fix mask: %x\n      sv: prn         snr       elevation      azimuth",
+             svStatus.num_svs, svStatus.ephemeris_mask,
+             svStatus.almanac_mask, svStatus.used_in_fix_mask);
+    for (int i = 0; i < svStatus.num_svs && i < GPS_MAX_SVS; i++) {
+        LOC_LOGV("   %d:   %d    %f    %f    %f",
+                 i,
+                 svStatus.sv_list[i].prn,
+                 svStatus.sv_list[i].snr,
+                 svStatus.sv_list[i].elevation,
+                 svStatus.sv_list[i].azimuth);
+    }
+    // loop through adapters, and deliver to all adapters.
+    TO_ALL_LOCADAPTERS(
+        mLocAdapters[i]->reportSv(svStatus,
+                                     locationExtended,
+                                     svExt)
+    );
+}
+
+void LocApiBase::reportStatus(GpsStatusValue status)
+{
+    // loop through adapters, and deliver to all adapters.
+    TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportStatus(status));
+}
+
+void LocApiBase::reportNmea(const char* nmea, int length)
+{
+    // loop through adapters, and deliver to all adapters.
+    TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportNmea(nmea, length));
+}
+
+void LocApiBase::reportXtraServer(const char* url1, const char* url2,
+                                  const char* url3, const int maxlength)
+{
+    // loop through adapters, and deliver to the first handling adapter.
+    TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportXtraServer(url1, url2, url3, maxlength));
+
+}
+
+void LocApiBase::requestXtraData()
+{
+    // loop through adapters, and deliver to the first handling adapter.
+    TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestXtraData());
+}
+
+void LocApiBase::requestTime()
+{
+    // loop through adapters, and deliver to the first handling adapter.
+    TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestTime());
+}
+
+void LocApiBase::requestLocation()
+{
+    // loop through adapters, and deliver to the first handling adapter.
+    TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestLocation());
+}
+
+void LocApiBase::requestATL(int connHandle, AGpsType agps_type)
+{
+    // loop through adapters, and deliver to the first handling adapter.
+    TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestATL(connHandle, agps_type));
+}
+
+void LocApiBase::releaseATL(int connHandle)
+{
+    // loop through adapters, and deliver to the first handling adapter.
+    TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->releaseATL(connHandle));
+}
+
+void LocApiBase::requestSuplES(int connHandle)
+{
+    // loop through adapters, and deliver to the first handling adapter.
+    TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestSuplES(connHandle));
+}
+
+void LocApiBase::reportDataCallOpened()
+{
+    // loop through adapters, and deliver to the first handling adapter.
+    TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportDataCallOpened());
+}
+
+void LocApiBase::reportDataCallClosed()
+{
+    // loop through adapters, and deliver to the first handling adapter.
+    TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportDataCallClosed());
+}
+
+void LocApiBase::requestNiNotify(GpsNiNotification &notify, const void* data)
+{
+    // loop through adapters, and deliver to the first handling adapter.
+    TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestNiNotify(notify, data));
+}
+
+void LocApiBase::saveSupportedMsgList(uint64_t supportedMsgList)
+{
+    mSupportedMsg = supportedMsgList;
+}
+
+void* LocApiBase :: getSibling()
+    DEFAULT_IMPL(NULL)
+
+LocApiProxyBase* LocApiBase :: getLocApiProxy()
+    DEFAULT_IMPL(NULL)
+
+void LocApiBase::reportGpsMeasurementData(GpsData &gpsMeasurementData)
+{
+    // loop through adapters, and deliver to all adapters.
+    TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGpsMeasurementData(gpsMeasurementData));
+}
+
+enum loc_api_adapter_err LocApiBase::
+   open(LOC_API_ADAPTER_EVENT_MASK_T mask)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    close()
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    startFix(const LocPosMode& posMode)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    stopFix()
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    deleteAidingData(GpsAidingData f)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    enableData(int enable)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    setAPN(char* apn, int len)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    injectPosition(double latitude, double longitude, float accuracy)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    setTime(GpsUtcTime time, int64_t timeReference, int uncertainty)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    setXtraData(char* data, int length)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    requestXtraServer()
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+   atlOpenStatus(int handle, int is_succ, char* apn,
+                 AGpsBearerType bear, AGpsType agpsType)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    atlCloseStatus(int handle, int is_succ)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    setPositionMode(const LocPosMode& posMode)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    setServer(const char* url, int len)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    setServer(unsigned int ip, int port,
+              LocServerType type)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    informNiResponse(GpsUserResponseType userResponse,
+                     const void* passThroughData)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    setSUPLVersion(uint32_t version)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    setLPPConfig(uint32_t profile)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    setSensorControlConfig(int sensorUsage,
+                           int sensorProvider)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    setSensorProperties(bool gyroBiasVarianceRandomWalk_valid,
+                        float gyroBiasVarianceRandomWalk,
+                        bool accelBiasVarianceRandomWalk_valid,
+                        float accelBiasVarianceRandomWalk,
+                        bool angleBiasVarianceRandomWalk_valid,
+                        float angleBiasVarianceRandomWalk,
+                        bool rateBiasVarianceRandomWalk_valid,
+                        float rateBiasVarianceRandomWalk,
+                        bool velocityBiasVarianceRandomWalk_valid,
+                        float velocityBiasVarianceRandomWalk)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    setSensorPerfControlConfig(int controlMode,
+                               int accelSamplesPerBatch,
+                               int accelBatchesPerSec,
+                               int gyroSamplesPerBatch,
+                               int gyroBatchesPerSec,
+                               int accelSamplesPerBatchHigh,
+                               int accelBatchesPerSecHigh,
+                               int gyroSamplesPerBatchHigh,
+                               int gyroBatchesPerSecHigh,
+                               int algorithmConfig)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    setExtPowerConfig(int isBatteryCharging)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+    setAGLONASSProtocol(unsigned long aGlonassProtocol)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+   getWwanZppFix(GpsLocation & zppLoc)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+   getBestAvailableZppFix(GpsLocation & zppLoc)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+enum loc_api_adapter_err LocApiBase::
+   getBestAvailableZppFix(GpsLocation & zppLoc, LocPosTechMask & tech_mask)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+int LocApiBase::
+    initDataServiceClient()
+DEFAULT_IMPL(-1)
+
+int LocApiBase::
+    openAndStartDataCall()
+DEFAULT_IMPL(-1)
+
+void LocApiBase::
+    stopDataCall()
+DEFAULT_IMPL()
+
+void LocApiBase::
+    closeDataCall()
+DEFAULT_IMPL()
+
+int LocApiBase::
+    setGpsLock(LOC_GPS_LOCK_MASK lock)
+DEFAULT_IMPL(-1)
+
+void LocApiBase::
+    installAGpsCert(const DerEncodedCertificate* pData,
+                    size_t length,
+                    uint32_t slotBitMask)
+DEFAULT_IMPL()
+
+int LocApiBase::
+    getGpsLock()
+DEFAULT_IMPL(-1)
+
+enum loc_api_adapter_err LocApiBase::
+    setXtraVersionCheck(enum xtra_version_check check)
+DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+
+int LocApiBase::
+    updateRegistrationMask(LOC_API_ADAPTER_EVENT_MASK_T event,
+                           loc_registration_mask_status isEnabled)
+DEFAULT_IMPL(-1)
+
+bool LocApiBase::
+    gnssConstellationConfig()
+DEFAULT_IMPL(false)
+
+} // namespace loc_core
diff --git a/gps/core/LocApiBase.h b/gps/core/LocApiBase.h
new file mode 100644
index 0000000..414769b
--- /dev/null
+++ b/gps/core/LocApiBase.h
@@ -0,0 +1,261 @@
+/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef LOC_API_BASE_H
+#define LOC_API_BASE_H
+
+#include <stddef.h>
+#include <ctype.h>
+#include <gps_extended.h>
+#include <MsgTask.h>
+#include <log_util.h>
+
+namespace loc_core {
+class ContextBase;
+
+int hexcode(char *hexstring, int string_size,
+            const char *data, int data_size);
+int decodeAddress(char *addr_string, int string_size,
+                  const char *data, int data_size);
+
+#define MAX_ADAPTERS          10
+
+#define TO_ALL_ADAPTERS(adapters, call)                                \
+    for (int i = 0; i < MAX_ADAPTERS && NULL != (adapters)[i]; i++) {  \
+        call;                                                          \
+    }
+
+#define TO_1ST_HANDLING_ADAPTER(adapters, call)                              \
+    for (int i = 0; i <MAX_ADAPTERS && NULL != (adapters)[i] && !(call); i++);
+
+enum xtra_version_check {
+    DISABLED,
+    AUTO,
+    XTRA2,
+    XTRA3
+};
+
+class LocAdapterBase;
+struct LocSsrMsg;
+struct LocOpenMsg;
+
+class LocApiProxyBase {
+public:
+    inline LocApiProxyBase() {}
+    inline virtual ~LocApiProxyBase() {}
+    inline virtual void* getSibling2() { return NULL; }
+};
+
+class LocApiBase {
+    friend struct LocSsrMsg;
+    //LocOpenMsg calls open() which makes it necessary to declare
+    //it as a friend
+    friend struct LocOpenMsg;
+    friend class ContextBase;
+    const MsgTask* mMsgTask;
+    ContextBase *mContext;
+    LocAdapterBase* mLocAdapters[MAX_ADAPTERS];
+    uint64_t mSupportedMsg;
+
+protected:
+    virtual enum loc_api_adapter_err
+        open(LOC_API_ADAPTER_EVENT_MASK_T mask);
+    virtual enum loc_api_adapter_err
+        close();
+    LOC_API_ADAPTER_EVENT_MASK_T getEvtMask();
+    LOC_API_ADAPTER_EVENT_MASK_T mMask;
+    LocApiBase(const MsgTask* msgTask,
+               LOC_API_ADAPTER_EVENT_MASK_T excludedMask,
+               ContextBase* context = NULL);
+    inline virtual ~LocApiBase() { close(); }
+    bool isInSession();
+    const LOC_API_ADAPTER_EVENT_MASK_T mExcludedMask;
+
+public:
+    inline void sendMsg(const LocMsg* msg) const {
+        mMsgTask->sendMsg(msg);
+    }
+
+    void addAdapter(LocAdapterBase* adapter);
+    void removeAdapter(LocAdapterBase* adapter);
+
+    // upward calls
+    void handleEngineUpEvent();
+    void handleEngineDownEvent();
+    void reportPosition(UlpLocation &location,
+                        GpsLocationExtended &locationExtended,
+                        void* locationExt,
+                        enum loc_sess_status status,
+                        LocPosTechMask loc_technology_mask =
+                                  LOC_POS_TECH_MASK_DEFAULT);
+    void reportSv(GpsSvStatus &svStatus,
+                  GpsLocationExtended &locationExtended,
+                  void* svExt);
+    void reportStatus(GpsStatusValue status);
+    void reportNmea(const char* nmea, int length);
+    void reportXtraServer(const char* url1, const char* url2,
+                          const char* url3, const int maxlength);
+    void requestXtraData();
+    void requestTime();
+    void requestLocation();
+    void requestATL(int connHandle, AGpsType agps_type);
+    void releaseATL(int connHandle);
+    void requestSuplES(int connHandle);
+    void reportDataCallOpened();
+    void reportDataCallClosed();
+    void requestNiNotify(GpsNiNotification &notify, const void* data);
+    void saveSupportedMsgList(uint64_t supportedMsgList);
+    void reportGpsMeasurementData(GpsData &gpsMeasurementData);
+
+    // downward calls
+    // All below functions are to be defined by adapter specific modules:
+    // RPC, QMI, etc.  The default implementation is empty.
+
+    virtual void* getSibling();
+    virtual LocApiProxyBase* getLocApiProxy();
+    virtual enum loc_api_adapter_err
+        startFix(const LocPosMode& posMode);
+    virtual enum loc_api_adapter_err
+        stopFix();
+    virtual enum loc_api_adapter_err
+        deleteAidingData(GpsAidingData f);
+    virtual enum loc_api_adapter_err
+        enableData(int enable);
+    virtual enum loc_api_adapter_err
+        setAPN(char* apn, int len);
+    virtual enum loc_api_adapter_err
+        injectPosition(double latitude, double longitude, float accuracy);
+    virtual enum loc_api_adapter_err
+        setTime(GpsUtcTime time, int64_t timeReference, int uncertainty);
+    virtual enum loc_api_adapter_err
+        setXtraData(char* data, int length);
+    virtual enum loc_api_adapter_err
+        requestXtraServer();
+    virtual enum loc_api_adapter_err
+        atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bear, AGpsType agpsType);
+    virtual enum loc_api_adapter_err
+        atlCloseStatus(int handle, int is_succ);
+    virtual enum loc_api_adapter_err
+        setPositionMode(const LocPosMode& posMode);
+    virtual enum loc_api_adapter_err
+        setServer(const char* url, int len);
+    virtual enum loc_api_adapter_err
+        setServer(unsigned int ip, int port,
+                  LocServerType type);
+    virtual enum loc_api_adapter_err
+        informNiResponse(GpsUserResponseType userResponse, const void* passThroughData);
+    virtual enum loc_api_adapter_err
+        setSUPLVersion(uint32_t version);
+    virtual enum loc_api_adapter_err
+        setLPPConfig(uint32_t profile);
+    virtual enum loc_api_adapter_err
+        setSensorControlConfig(int sensorUsage, int sensorProvider);
+    virtual enum loc_api_adapter_err
+        setSensorProperties(bool gyroBiasVarianceRandomWalk_valid,
+                            float gyroBiasVarianceRandomWalk,
+                            bool accelBiasVarianceRandomWalk_valid,
+                            float accelBiasVarianceRandomWalk,
+                            bool angleBiasVarianceRandomWalk_valid,
+                            float angleBiasVarianceRandomWalk,
+                            bool rateBiasVarianceRandomWalk_valid,
+                            float rateBiasVarianceRandomWalk,
+                            bool velocityBiasVarianceRandomWalk_valid,
+                            float velocityBiasVarianceRandomWalk);
+    virtual enum loc_api_adapter_err
+        setSensorPerfControlConfig(int controlMode,
+                               int accelSamplesPerBatch,
+                               int accelBatchesPerSec,
+                               int gyroSamplesPerBatch,
+                               int gyroBatchesPerSec,
+                               int accelSamplesPerBatchHigh,
+                               int accelBatchesPerSecHigh,
+                               int gyroSamplesPerBatchHigh,
+                               int gyroBatchesPerSecHigh,
+                               int algorithmConfig);
+    virtual enum loc_api_adapter_err
+        setExtPowerConfig(int isBatteryCharging);
+    virtual enum loc_api_adapter_err
+        setAGLONASSProtocol(unsigned long aGlonassProtocol);
+    virtual enum loc_api_adapter_err
+        getWwanZppFix(GpsLocation & zppLoc);
+    virtual enum loc_api_adapter_err
+        getBestAvailableZppFix(GpsLocation & zppLoc);
+    virtual enum loc_api_adapter_err
+        getBestAvailableZppFix(GpsLocation & zppLoc, LocPosTechMask & tech_mask);
+    virtual int initDataServiceClient();
+    virtual int openAndStartDataCall();
+    virtual void stopDataCall();
+    virtual void closeDataCall();
+    virtual void installAGpsCert(const DerEncodedCertificate* pData,
+                                 size_t length,
+                                 uint32_t slotBitMask);
+    inline virtual void setInSession(bool inSession) {}
+    inline bool isMessageSupported (LocCheckingMessagesID msgID) const {
+        if (msgID > (sizeof(mSupportedMsg) << 3)) {
+            return false;
+        } else {
+            uint32_t messageChecker = 1 << msgID;
+            return (messageChecker & mSupportedMsg) == messageChecker;
+        }
+    }
+    void updateEvtMask();
+
+    /*Values for lock
+      1 = Do not lock any position sessions
+      2 = Lock MI position sessions
+      3 = Lock MT position sessions
+      4 = Lock all position sessions
+     */
+    virtual int setGpsLock(LOC_GPS_LOCK_MASK lock);
+    /*
+      Returns
+      Current value of GPS Lock on success
+      -1 on failure
+     */
+    virtual int getGpsLock(void);
+
+    virtual enum loc_api_adapter_err setXtraVersionCheck(enum xtra_version_check check);
+
+    /*
+      Update gps reporting events
+     */
+    virtual int updateRegistrationMask(LOC_API_ADAPTER_EVENT_MASK_T event,
+                                       loc_registration_mask_status isEnabled);
+    /*
+      Check if the modem support the service
+     */
+    virtual bool gnssConstellationConfig();
+};
+
+typedef LocApiBase* (getLocApi_t)(const MsgTask* msgTask,
+                                  LOC_API_ADAPTER_EVENT_MASK_T exMask,
+                                  ContextBase *context);
+
+} // namespace loc_core
+
+#endif //LOC_API_BASE_H
diff --git a/gps/core/LocDualContext.cpp b/gps/core/LocDualContext.cpp
new file mode 100644
index 0000000..d68cb3b
--- /dev/null
+++ b/gps/core/LocDualContext.cpp
@@ -0,0 +1,183 @@
+/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#define LOG_NDDEBUG 0
+#define LOG_TAG "LocSvc_DualCtx"
+
+#include <cutils/sched_policy.h>
+#include <unistd.h>
+#include <LocDualContext.h>
+#include <msg_q.h>
+#include <log_util.h>
+#include <loc_log.h>
+
+namespace loc_core {
+
+// nothing exclude for foreground
+const LOC_API_ADAPTER_EVENT_MASK_T
+LocDualContext::mFgExclMask = 0;
+// excluded events for background clients
+const LOC_API_ADAPTER_EVENT_MASK_T
+LocDualContext::mBgExclMask =
+    (LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT |
+     LOC_API_ADAPTER_BIT_SATELLITE_REPORT |
+     LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT |
+     LOC_API_ADAPTER_BIT_NMEA_POSITION_REPORT |
+     LOC_API_ADAPTER_BIT_IOCTL_REPORT |
+     LOC_API_ADAPTER_BIT_STATUS_REPORT |
+     LOC_API_ADAPTER_BIT_GEOFENCE_GEN_ALERT |
+     LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT);
+
+const MsgTask* LocDualContext::mMsgTask = NULL;
+ContextBase* LocDualContext::mFgContext = NULL;
+ContextBase* LocDualContext::mBgContext = NULL;
+ContextBase* LocDualContext::mInjectContext = NULL;
+// the name must be shorter than 15 chars
+const char* LocDualContext::mLocationHalName = "Loc_hal_worker";
+const char* LocDualContext::mLBSLibName = "liblbs_core.so";
+
+pthread_mutex_t LocDualContext::mGetLocContextMutex = PTHREAD_MUTEX_INITIALIZER;
+
+const MsgTask* LocDualContext::getMsgTask(MsgTask::tCreate tCreator,
+                                          const char* name)
+{
+    if (NULL == mMsgTask) {
+        mMsgTask = new MsgTask(tCreator, name);
+    }
+    return mMsgTask;
+}
+
+const MsgTask* LocDualContext::getMsgTask(MsgTask::tAssociate tAssociate,
+                                          const char* name)
+{
+    if (NULL == mMsgTask) {
+        mMsgTask = new MsgTask(tAssociate, name);
+    } else if (tAssociate) {
+        mMsgTask->associate(tAssociate);
+    }
+    return mMsgTask;
+}
+
+ContextBase* LocDualContext::getLocFgContext(MsgTask::tCreate tCreator,
+                                             const char* name)
+{
+    pthread_mutex_lock(&LocDualContext::mGetLocContextMutex);
+    LOC_LOGD("%s:%d]: querying ContextBase with tCreator", __func__, __LINE__);
+    if (NULL == mFgContext) {
+        LOC_LOGD("%s:%d]: creating msgTask with tCreator", __func__, __LINE__);
+        const MsgTask* msgTask = getMsgTask(tCreator, name);
+        mFgContext = new LocDualContext(msgTask,
+                                        mFgExclMask);
+    }
+    if(NULL == mInjectContext) {
+        LOC_LOGD("%s:%d]: mInjectContext is FgContext", __func__, __LINE__);
+        mInjectContext = mFgContext;
+        injectFeatureConfig(mInjectContext);
+    }
+    pthread_mutex_unlock(&LocDualContext::mGetLocContextMutex);
+    return mFgContext;
+}
+
+ContextBase* LocDualContext::getLocFgContext(MsgTask::tAssociate tAssociate,
+                                             const char* name)
+{
+    pthread_mutex_lock(&LocDualContext::mGetLocContextMutex);
+    LOC_LOGD("%s:%d]: querying ContextBase with tAssociate", __func__, __LINE__);
+    if (NULL == mFgContext) {
+        LOC_LOGD("%s:%d]: creating msgTask with tAssociate", __func__, __LINE__);
+        const MsgTask* msgTask = getMsgTask(tAssociate, name);
+        mFgContext = new LocDualContext(msgTask,
+                                        mFgExclMask);
+    }
+    if(NULL == mInjectContext) {
+        LOC_LOGD("%s:%d]: mInjectContext is FgContext", __func__, __LINE__);
+        mInjectContext = mFgContext;
+        injectFeatureConfig(mInjectContext);
+    }
+    pthread_mutex_unlock(&LocDualContext::mGetLocContextMutex);
+    return mFgContext;
+}
+
+ContextBase* LocDualContext::getLocBgContext(MsgTask::tCreate tCreator,
+                                             const char* name)
+{
+    pthread_mutex_lock(&LocDualContext::mGetLocContextMutex);
+    LOC_LOGD("%s:%d]: querying ContextBase with tCreator", __func__, __LINE__);
+    if (NULL == mBgContext) {
+        LOC_LOGD("%s:%d]: creating msgTask with tCreator", __func__, __LINE__);
+        const MsgTask* msgTask = getMsgTask(tCreator, name);
+        mBgContext = new LocDualContext(msgTask,
+                                        mBgExclMask);
+    }
+    if(NULL == mInjectContext) {
+        LOC_LOGD("%s:%d]: mInjectContext is BgContext", __func__, __LINE__);
+        mInjectContext = mBgContext;
+        injectFeatureConfig(mInjectContext);
+    }
+    pthread_mutex_unlock(&LocDualContext::mGetLocContextMutex);
+    return mBgContext;
+}
+
+ContextBase* LocDualContext::getLocBgContext(MsgTask::tAssociate tAssociate,
+                                             const char* name)
+{
+    pthread_mutex_lock(&LocDualContext::mGetLocContextMutex);
+    LOC_LOGD("%s:%d]: querying ContextBase with tAssociate", __func__, __LINE__);
+    if (NULL == mBgContext) {
+        LOC_LOGD("%s:%d]: creating msgTask with tAssociate", __func__, __LINE__);
+        const MsgTask* msgTask = getMsgTask(tAssociate, name);
+        mBgContext = new LocDualContext(msgTask,
+                                        mBgExclMask);
+    }
+    if(NULL == mInjectContext) {
+        LOC_LOGD("%s:%d]: mInjectContext is BgContext", __func__, __LINE__);
+        mInjectContext = mBgContext;
+        injectFeatureConfig(mInjectContext);
+    }
+    pthread_mutex_unlock(&LocDualContext::mGetLocContextMutex);
+    return mBgContext;
+}
+
+void LocDualContext :: injectFeatureConfig(ContextBase *curContext)
+{
+    LOC_LOGD("%s:%d]: Enter", __func__, __LINE__);
+    if(curContext == mInjectContext) {
+        LOC_LOGD("%s:%d]: Calling LBSProxy (%p) to inject feature config",
+                 __func__, __LINE__, ((LocDualContext *)mInjectContext)->mLBSProxy);
+        ((LocDualContext *)mInjectContext)->mLBSProxy->injectFeatureConfig(curContext);
+    }
+    LOC_LOGD("%s:%d]: Exit", __func__, __LINE__);
+}
+
+LocDualContext::LocDualContext(const MsgTask* msgTask,
+                               LOC_API_ADAPTER_EVENT_MASK_T exMask) :
+    ContextBase(msgTask, exMask, mLBSLibName)
+{
+}
+
+}
diff --git a/gps/core/LocDualContext.h b/gps/core/LocDualContext.h
new file mode 100644
index 0000000..1e96ea5
--- /dev/null
+++ b/gps/core/LocDualContext.h
@@ -0,0 +1,74 @@
+/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef __LOC_ENG_CONTEXT__
+#define __LOC_ENG_CONTEXT__
+
+#include <stdbool.h>
+#include <ctype.h>
+#include <dlfcn.h>
+#include <ContextBase.h>
+
+namespace loc_core {
+
+class LocDualContext : public ContextBase {
+    static const MsgTask* mMsgTask;
+    static ContextBase* mFgContext;
+    static ContextBase* mBgContext;
+    static ContextBase* mInjectContext;
+    static const MsgTask* getMsgTask(MsgTask::tCreate tCreator,
+                                     const char* name);
+    static const MsgTask* getMsgTask(MsgTask::tAssociate tAssociate,
+                                     const char* name);
+    static pthread_mutex_t mGetLocContextMutex;
+
+protected:
+    LocDualContext(const MsgTask* msgTask,
+                   LOC_API_ADAPTER_EVENT_MASK_T exMask);
+    inline virtual ~LocDualContext() {}
+
+public:
+    static const char* mLBSLibName;
+    static const LOC_API_ADAPTER_EVENT_MASK_T mFgExclMask;
+    static const LOC_API_ADAPTER_EVENT_MASK_T mBgExclMask;
+    static const char* mLocationHalName;
+
+    static ContextBase* getLocFgContext(MsgTask::tCreate tCreator,
+                                        const char* name);
+    static ContextBase* getLocFgContext(MsgTask::tAssociate tAssociate,
+                                        const char* name);
+    static ContextBase* getLocBgContext(MsgTask::tCreate tCreator,
+                                        const char* name);
+    static ContextBase* getLocBgContext(MsgTask::tAssociate tAssociate,
+                                        const char* name);
+    static void injectFeatureConfig(ContextBase *context);
+};
+
+}
+
+#endif //__LOC_ENG_CONTEXT__
diff --git a/gps/core/MsgTask.cpp b/gps/core/MsgTask.cpp
new file mode 100644
index 0000000..5d375aa
--- /dev/null
+++ b/gps/core/MsgTask.cpp
@@ -0,0 +1,147 @@
+/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#define LOG_NDDEBUG 0
+#define LOG_TAG "LocSvc_MsgTask"
+
+#include <cutils/sched_policy.h>
+#include <unistd.h>
+#include <MsgTask.h>
+#include <msg_q.h>
+#include <log_util.h>
+#include <loc_log.h>
+
+namespace loc_core {
+
+#define MAX_TASK_COMM_LEN 15
+
+static void LocMsgDestroy(void* msg) {
+    delete (LocMsg*)msg;
+}
+
+MsgTask::MsgTask(tCreate tCreator, const char* threadName) :
+    mQ(msg_q_init2()), mAssociator(NULL){
+    if (tCreator) {
+        tCreator(threadName, loopMain,
+                 (void*)new MsgTask(mQ, mAssociator));
+    } else {
+        createPThread(threadName);
+    }
+}
+
+MsgTask::MsgTask(tAssociate tAssociator, const char* threadName) :
+    mQ(msg_q_init2()), mAssociator(tAssociator){
+    createPThread(threadName);
+}
+
+inline
+MsgTask::MsgTask(const void* q, tAssociate associator) :
+    mQ(q), mAssociator(associator){
+}
+
+MsgTask::~MsgTask() {
+    msg_q_unblock((void*)mQ);
+}
+
+void MsgTask::associate(tAssociate tAssociator) const {
+    struct LocAssociateMsg : public LocMsg {
+        tAssociate mAssociator;
+        inline LocAssociateMsg(tAssociate associator) :
+            LocMsg(), mAssociator(associator) {}
+        inline virtual void proc() const {
+            if (mAssociator) {
+                LOC_LOGD("MsgTask::associate");
+                mAssociator();
+            }
+        }
+    };
+    sendMsg(new LocAssociateMsg(tAssociator));
+}
+
+void MsgTask::createPThread(const char* threadName) {
+    pthread_attr_t attr;
+    pthread_attr_init(&attr);
+    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+    pthread_t tid;
+    // create the thread here, then if successful
+    // and a name is given, we set the thread name
+    if (!pthread_create(&tid, &attr, loopMain,
+                        (void*)new MsgTask(mQ, mAssociator)) &&
+        NULL != threadName) {
+        char lname[MAX_TASK_COMM_LEN+1];
+        memcpy(lname, threadName, MAX_TASK_COMM_LEN);
+        lname[MAX_TASK_COMM_LEN] = 0;
+        pthread_setname_np(tid, lname);
+    }
+}
+
+void MsgTask::sendMsg(const LocMsg* msg) const {
+    msg_q_snd((void*)mQ, (void*)msg, LocMsgDestroy);
+}
+
+void* MsgTask::loopMain(void* arg) {
+    MsgTask* copy = (MsgTask*)arg;
+
+    // make sure we do not run in background scheduling group
+    set_sched_policy(gettid(), SP_FOREGROUND);
+
+    if (NULL != copy->mAssociator) {
+        copy->mAssociator();
+    }
+
+    LocMsg* msg;
+    int cnt = 0;
+
+    while (1) {
+        LOC_LOGD("MsgTask::loop() %d listening ...\n", cnt++);
+
+        msq_q_err_type result = msg_q_rcv((void*)copy->mQ, (void **)&msg);
+
+        if (eMSG_Q_SUCCESS != result) {
+            LOC_LOGE("%s:%d] fail receiving msg: %s\n", __func__, __LINE__,
+                     loc_get_msg_q_status(result));
+            // destroy the Q and exit
+            msg_q_destroy((void**)&(copy->mQ));
+            delete copy;
+            return NULL;
+        }
+
+        msg->log();
+        // there is where each individual msg handling is invoked
+        msg->proc();
+
+        delete msg;
+    }
+
+    delete copy;
+
+    return NULL;
+}
+
+}
diff --git a/gps/core/MsgTask.h b/gps/core/MsgTask.h
new file mode 100644
index 0000000..d50bb31
--- /dev/null
+++ b/gps/core/MsgTask.h
@@ -0,0 +1,67 @@
+/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef __MSG_TASK__
+#define __MSG_TASK__
+
+#include <stdbool.h>
+#include <ctype.h>
+#include <string.h>
+#include <pthread.h>
+
+namespace loc_core {
+
+struct LocMsg {
+    inline LocMsg() {}
+    inline virtual ~LocMsg() {}
+    virtual void proc() const = 0;
+    inline virtual void log() const {}
+};
+
+class MsgTask {
+public:
+    typedef void* (*tStart)(void*);
+    typedef pthread_t (*tCreate)(const char* name, tStart start, void* arg);
+    typedef int (*tAssociate)();
+    MsgTask(tCreate tCreator, const char* threadName);
+    MsgTask(tAssociate tAssociator, const char* threadName);
+    ~MsgTask();
+    void sendMsg(const LocMsg* msg) const;
+    void associate(tAssociate tAssociator) const;
+
+private:
+    const void* mQ;
+    tAssociate mAssociator;
+    MsgTask(const void* q, tAssociate associator);
+    static void* loopMain(void* copy);
+    void createPThread(const char* name);
+};
+
+} // namespace loc_core
+
+#endif //__MSG_TASK__
diff --git a/gps/core/UlpProxyBase.h b/gps/core/UlpProxyBase.h
new file mode 100644
index 0000000..b9a8224
--- /dev/null
+++ b/gps/core/UlpProxyBase.h
@@ -0,0 +1,85 @@
+/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef ULP_PROXY_BASE_H
+#define ULP_PROXY_BASE_H
+
+#include <gps_extended.h>
+
+namespace loc_core {
+
+class LocAdapterBase;
+
+class UlpProxyBase {
+public:
+    LocPosMode mPosMode;
+    bool mFixSet;
+    inline UlpProxyBase() {
+        mPosMode.mode = LOC_POSITION_MODE_INVALID;
+        mFixSet = false;
+    }
+    inline virtual ~UlpProxyBase() {}
+    inline virtual bool sendStartFix() { mFixSet = true; return false; }
+    inline virtual bool sendStopFix() { mFixSet = false; return false; }
+    inline virtual bool sendFixMode(LocPosMode &params) {
+        mPosMode = params;
+        return false;
+    }
+
+    inline virtual bool reportPosition(UlpLocation &location,
+                                       GpsLocationExtended &locationExtended,
+                                       void* locationExt,
+                                       enum loc_sess_status status,
+                                       LocPosTechMask loc_technology_mask) {
+        return false;
+    }
+    inline virtual bool reportSv(GpsSvStatus &svStatus,
+                                 GpsLocationExtended &locationExtended,
+                                 void* svExt) {
+        return false;
+    }
+    inline virtual bool reportStatus(GpsStatusValue status) {
+        return false;
+    }
+    inline virtual void setAdapter(LocAdapterBase* adapter) {}
+    inline virtual void setCapabilities(unsigned long capabilities) {}
+    inline virtual bool reportBatchingSession(GpsExtBatchOptions &options,
+                                              bool active) {
+        return false;
+    }
+    inline virtual bool reportPositions(GpsExtLocation * locations,
+                                        int32_t number_of_locations,
+                                        enum loc_sess_status status,
+                                        LocPosTechMask techMask) {
+        return false;
+    }
+};
+
+} // namespace loc_core
+
+#endif // ULP_PROXY_BASE_H
diff --git a/gps/core/gps_extended.h b/gps/core/gps_extended.h
new file mode 100644
index 0000000..88b0415
--- /dev/null
+++ b/gps/core/gps_extended.h
@@ -0,0 +1,92 @@
+/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GPS_EXTENDED_H
+#define GPS_EXTENDED_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <gps_extended_c.h>
+
+struct LocPosMode
+{
+    LocPositionMode mode;
+    GpsPositionRecurrence recurrence;
+    uint32_t min_interval;
+    uint32_t preferred_accuracy;
+    uint32_t preferred_time;
+    char credentials[14];
+    char provider[8];
+    LocPosMode(LocPositionMode m, GpsPositionRecurrence recr,
+               uint32_t gap, uint32_t accu, uint32_t time,
+               const char* cred, const char* prov) :
+        mode(m), recurrence(recr),
+        min_interval(gap < MIN_POSSIBLE_FIX_INTERVAL ? MIN_POSSIBLE_FIX_INTERVAL : gap),
+        preferred_accuracy(accu), preferred_time(time) {
+        memset(credentials, 0, sizeof(credentials));
+        memset(provider, 0, sizeof(provider));
+        if (NULL != cred) {
+            memcpy(credentials, cred, sizeof(credentials)-1);
+        }
+        if (NULL != prov) {
+            memcpy(provider, prov, sizeof(provider)-1);
+        }
+    }
+
+    inline LocPosMode() :
+        mode(LOC_POSITION_MODE_MS_BASED),
+        recurrence(GPS_POSITION_RECURRENCE_PERIODIC),
+        min_interval(MIN_POSSIBLE_FIX_INTERVAL),
+        preferred_accuracy(50), preferred_time(120000) {
+        memset(credentials, 0, sizeof(credentials));
+        memset(provider, 0, sizeof(provider));
+    }
+
+    inline bool equals(const LocPosMode &anotherMode) const
+    {
+        return anotherMode.mode == mode &&
+            anotherMode.recurrence == recurrence &&
+            anotherMode.min_interval == min_interval &&
+            anotherMode.preferred_accuracy == preferred_accuracy &&
+            anotherMode.preferred_time == preferred_time &&
+            !strncmp(anotherMode.credentials, credentials, sizeof(credentials)-1) &&
+            !strncmp(anotherMode.provider, provider, sizeof(provider)-1);
+    }
+
+    void logv() const;
+};
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* GPS_EXTENDED_H */
+
diff --git a/gps/core/gps_extended_c.h b/gps/core/gps_extended_c.h
new file mode 100644
index 0000000..ff66ef5
--- /dev/null
+++ b/gps/core/gps_extended_c.h
@@ -0,0 +1,425 @@
+/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GPS_EXTENDED_C_H
+#define GPS_EXTENDED_C_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <ctype.h>
+#include <stdbool.h>
+#include <hardware/gps.h>
+
+/** Location has valid source information. */
+#define LOCATION_HAS_SOURCE_INFO   0x0020
+/** GpsLocation has valid "is indoor?" flag */
+#define GPS_LOCATION_HAS_IS_INDOOR   0x0040
+/** GpsLocation has valid floor number */
+#define GPS_LOCATION_HAS_FLOOR_NUMBER   0x0080
+/** GpsLocation has valid map URL*/
+#define GPS_LOCATION_HAS_MAP_URL   0x0100
+/** GpsLocation has valid map index */
+#define GPS_LOCATION_HAS_MAP_INDEX   0x0200
+
+/** Sizes for indoor fields */
+#define GPS_LOCATION_MAP_URL_SIZE 400
+#define GPS_LOCATION_MAP_INDEX_SIZE 16
+
+/** Position source is ULP */
+#define ULP_LOCATION_IS_FROM_HYBRID   0x0001
+/** Position source is GNSS only */
+#define ULP_LOCATION_IS_FROM_GNSS     0x0002
+/** Position source is ZPP only */
+#define ULP_LOCATION_IS_FROM_ZPP      0x0004
+/** Position is from a Geofence Breach Event */
+#define ULP_LOCATION_IS_FROM_GEOFENCE 0X0008
+/** Positioin is from Hardware FLP */
+#define ULP_LOCATION_IS_FROM_HW_FLP   0x0010
+#define ULP_LOCATION_IS_FROM_NLP   0x0020
+
+#define ULP_MIN_INTERVAL_INVALID 0xffffffff
+
+/*Emergency SUPL*/
+#define GPS_NI_TYPE_EMERGENCY_SUPL    4
+
+#define AGPS_CERTIFICATE_MAX_LENGTH 2000
+#define AGPS_CERTIFICATE_MAX_SLOTS 10
+
+/** Batching default ID for dummy batching session*/
+#define GPS_BATCHING_DEFAULT_ID                 1
+
+/** This cap is used to decide the FLP session cache
+size on AP. If the BATCH_SIZE in flp.conf is less than
+GPS_AP_BATCHING_SIZE_CAP, FLP session cache size will
+be twice the BATCH_SIZE defined in flp.conf. Otherwise,
+FLP session cache size will be equal to the BATCH_SIZE.*/
+#define GPS_AP_BATCHING_SIZE_CAP               40
+
+#define GPS_BATCHING_OPERATION_SUCCEESS         1
+#define GPS_BATCHING_OPERATION_FAILURE          0
+
+/** GPS extended batching flags*/
+#define GPS_EXT_BATCHING_ON_FULL        0x0000001
+#define GPS_EXT_BATCHING_ON_FIX         0x0000002
+
+/** Reasons of GPS reports batched locations*/
+typedef enum loc_batching_reported_type {
+    LOC_BATCHING_ON_FULL_IND_REPORT,
+    LOC_BATCHING_ON_FIX_IND_REPORT,
+    LOC_BATCHING_ON_QUERY_REPORT
+}LocBatchingReportedType;
+
+enum loc_registration_mask_status {
+    LOC_REGISTRATION_MASK_ENABLED,
+    LOC_REGISTRATION_MASK_DISABLED
+};
+
+typedef struct {
+    /** set to sizeof(UlpLocation) */
+    size_t          size;
+    GpsLocation     gpsLocation;
+    /* Provider indicator for HYBRID or GPS */
+    uint16_t        position_source;
+    /*allows HAL to pass additional information related to the location */
+    int             rawDataSize;         /* in # of bytes */
+    void            * rawData;
+    bool            is_indoor;
+    float           floor_number;
+    char            map_url[GPS_LOCATION_MAP_URL_SIZE];
+    unsigned char   map_index[GPS_LOCATION_MAP_INDEX_SIZE];
+} UlpLocation;
+
+/** AGPS type */
+typedef int16_t AGpsExtType;
+#define AGPS_TYPE_INVALID       -1
+#define AGPS_TYPE_ANY           0
+#define AGPS_TYPE_SUPL          1
+#define AGPS_TYPE_C2K           2
+#define AGPS_TYPE_WWAN_ANY      3
+#define AGPS_TYPE_WIFI          4
+#define AGPS_TYPE_SUPL_ES       5
+
+/** SSID length */
+#define SSID_BUF_SIZE (32+1)
+
+typedef int16_t AGpsBearerType;
+#define AGPS_APN_BEARER_INVALID    -1
+#define AGPS_APN_BEARER_IPV4        0
+#define AGPS_APN_BEARER_IPV6        1
+#define AGPS_APN_BEARER_IPV4V6      2
+
+/** GPS extended callback structure. */
+typedef struct {
+    /** set to sizeof(GpsCallbacks) */
+    size_t      size;
+    gps_set_capabilities set_capabilities_cb;
+    gps_acquire_wakelock acquire_wakelock_cb;
+    gps_release_wakelock release_wakelock_cb;
+    gps_create_thread create_thread_cb;
+    gps_request_utc_time request_utc_time_cb;
+} GpsExtCallbacks;
+
+/** GPS extended batch options */
+typedef struct {
+    double max_power_allocation_mW;
+    uint32_t sources_to_use;
+    uint32_t flags;
+    int64_t period_ns;
+} GpsExtBatchOptions;
+
+/** Callback to report the xtra server url to the client.
+ *  The client should use this url when downloading xtra unless overwritten
+ *  in the gps.conf file
+ */
+typedef void (* report_xtra_server)(const char*, const char*, const char*);
+
+/** Callback structure for the XTRA interface. */
+typedef struct {
+    gps_xtra_download_request download_request_cb;
+    gps_create_thread create_thread_cb;
+    report_xtra_server report_xtra_server_cb;
+} GpsXtraExtCallbacks;
+
+/** Represents the status of AGPS. */
+typedef struct {
+    /** set to sizeof(AGpsExtStatus) */
+    size_t          size;
+
+    AGpsExtType type;
+    AGpsStatusValue status;
+    uint32_t        ipv4_addr;
+    char            ipv6_addr[16];
+    char            ssid[SSID_BUF_SIZE];
+    char            password[SSID_BUF_SIZE];
+} AGpsExtStatus;
+
+/** Callback with AGPS status information.
+ *  Can only be called from a thread created by create_thread_cb.
+ */
+typedef void (* agps_status_extended)(AGpsExtStatus* status);
+
+/** Callback structure for the AGPS interface. */
+typedef struct {
+    agps_status_extended status_cb;
+    gps_create_thread create_thread_cb;
+} AGpsExtCallbacks;
+
+
+/** GPS NI callback structure. */
+typedef struct
+{
+    /**
+     * Sends the notification request from HAL to GPSLocationProvider.
+     */
+    gps_ni_notify_callback notify_cb;
+    gps_create_thread create_thread_cb;
+} GpsNiExtCallbacks;
+
+typedef enum loc_server_type {
+    LOC_AGPS_CDMA_PDE_SERVER,
+    LOC_AGPS_CUSTOM_PDE_SERVER,
+    LOC_AGPS_MPC_SERVER,
+    LOC_AGPS_SUPL_SERVER
+} LocServerType;
+
+typedef enum loc_position_mode_type {
+    LOC_POSITION_MODE_INVALID = -1,
+    LOC_POSITION_MODE_STANDALONE = 0,
+    LOC_POSITION_MODE_MS_BASED,
+    LOC_POSITION_MODE_MS_ASSISTED,
+    LOC_POSITION_MODE_RESERVED_1,
+    LOC_POSITION_MODE_RESERVED_2,
+    LOC_POSITION_MODE_RESERVED_3,
+    LOC_POSITION_MODE_RESERVED_4,
+    LOC_POSITION_MODE_RESERVED_5
+
+} LocPositionMode;
+
+#define MIN_POSSIBLE_FIX_INTERVAL 1000 /* msec */
+
+/** GpsLocationExtended has valid latitude and longitude. */
+#define GPS_LOCATION_EXTENDED_HAS_LAT_LONG   (1U<<0)
+/** GpsLocationExtended has valid altitude. */
+#define GPS_LOCATION_EXTENDED_HAS_ALTITUDE   (1U<<1)
+/** GpsLocationExtended has valid speed. */
+#define GPS_LOCATION_EXTENDED_HAS_SPEED      (1U<<2)
+/** GpsLocationExtended has valid bearing. */
+#define GPS_LOCATION_EXTENDED_HAS_BEARING    (1U<<4)
+/** GpsLocationExtended has valid accuracy. */
+#define GPS_LOCATION_EXTENDED_HAS_ACCURACY   (1U<<8)
+
+/** GPS extended supports geofencing */
+#define GPS_EXTENDED_CAPABILITY_GEOFENCE     0x0000001
+/** GPS extended supports batching */
+#define GPS_EXTENDED_CAPABILITY_BATCHING     0x0000002
+
+/** Flags to indicate which values are valid in a GpsLocationExtended. */
+typedef uint16_t GpsLocationExtendedFlags;
+/** GpsLocationExtended has valid pdop, hdop, vdop. */
+#define GPS_LOCATION_EXTENDED_HAS_DOP 0x0001
+/** GpsLocationExtended has valid altitude mean sea level. */
+#define GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL 0x0002
+/** UlpLocation has valid magnetic deviation. */
+#define GPS_LOCATION_EXTENDED_HAS_MAG_DEV 0x0004
+/** UlpLocation has valid mode indicator. */
+#define GPS_LOCATION_EXTENDED_HAS_MODE_IND 0x0008
+/** GpsLocationExtended has valid vertical uncertainty */
+#define GPS_LOCATION_EXTENDED_HAS_VERT_UNC 0x0010
+/** GpsLocationExtended has valid speed uncertainty */
+#define GPS_LOCATION_EXTENDED_HAS_SPEED_UNC 0x0020
+
+/** Represents gps location extended. */
+typedef struct {
+    /** set to sizeof(GpsLocationExtended) */
+    size_t          size;
+    /** Contains GpsLocationExtendedFlags bits. */
+    uint16_t        flags;
+    /** Contains the Altitude wrt mean sea level */
+    float           altitudeMeanSeaLevel;
+    /** Contains Position Dilusion of Precision. */
+    float           pdop;
+    /** Contains Horizontal Dilusion of Precision. */
+    float           hdop;
+    /** Contains Vertical Dilusion of Precision. */
+    float           vdop;
+    /** Contains Magnetic Deviation. */
+    float           magneticDeviation;
+    /** vertical uncertainty in meters */
+    float           vert_unc;
+    /** speed uncertainty in m/s */
+    float           speed_unc;
+} GpsLocationExtended;
+
+typedef struct GpsExtLocation_s {
+    size_t          size;
+    uint16_t        flags;
+    double          latitude;
+    double          longitude;
+    double          altitude;
+    float           speed;
+    float           bearing;
+    float           accuracy;
+    int64_t         timestamp;
+    uint32_t        sources_used;
+} GpsExtLocation;
+
+enum loc_sess_status {
+    LOC_SESS_SUCCESS,
+    LOC_SESS_INTERMEDIATE,
+    LOC_SESS_FAILURE
+};
+
+typedef uint32_t LocPosTechMask;
+#define LOC_POS_TECH_MASK_DEFAULT ((LocPosTechMask)0x00000000)
+#define LOC_POS_TECH_MASK_SATELLITE ((LocPosTechMask)0x00000001)
+#define LOC_POS_TECH_MASK_CELLID ((LocPosTechMask)0x00000002)
+#define LOC_POS_TECH_MASK_WIFI ((LocPosTechMask)0x00000004)
+#define LOC_POS_TECH_MASK_SENSORS ((LocPosTechMask)0x00000008)
+#define LOC_POS_TECH_MASK_REFERENCE_LOCATION ((LocPosTechMask)0x00000010)
+#define LOC_POS_TECH_MASK_INJECTED_COARSE_POSITION ((LocPosTechMask)0x00000020)
+#define LOC_POS_TECH_MASK_AFLT ((LocPosTechMask)0x00000040)
+#define LOC_POS_TECH_MASK_HYBRID ((LocPosTechMask)0x00000080)
+
+typedef enum {
+  LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC = 0,
+  LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM,
+  LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU,
+  LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON,
+  LOC_ENG_IF_REQUEST_SENDER_ID_MODEM,
+  LOC_ENG_IF_REQUEST_SENDER_ID_UNKNOWN
+} loc_if_req_sender_id_e_type;
+
+
+#define smaller_of(a, b) (((a) > (b)) ? (b) : (a))
+#define MAX_APN_LEN 100
+
+// This will be overridden by the individual adapters
+// if necessary.
+#define DEFAULT_IMPL(rtv)                                     \
+{                                                             \
+    LOC_LOGD("%s: default implementation invoked", __func__); \
+    return rtv;                                               \
+}
+
+enum loc_api_adapter_err {
+    LOC_API_ADAPTER_ERR_SUCCESS             = 0,
+    LOC_API_ADAPTER_ERR_GENERAL_FAILURE     = 1,
+    LOC_API_ADAPTER_ERR_UNSUPPORTED         = 2,
+    LOC_API_ADAPTER_ERR_INVALID_HANDLE      = 4,
+    LOC_API_ADAPTER_ERR_INVALID_PARAMETER   = 5,
+    LOC_API_ADAPTER_ERR_ENGINE_BUSY         = 6,
+    LOC_API_ADAPTER_ERR_PHONE_OFFLINE       = 7,
+    LOC_API_ADAPTER_ERR_TIMEOUT             = 8,
+    LOC_API_ADAPTER_ERR_SERVICE_NOT_PRESENT = 9,
+    LOC_API_ADAPTER_ERR_INTERNAL            = 10,
+
+    /* equating engine down to phone offline, as they are the same errror */
+    LOC_API_ADAPTER_ERR_ENGINE_DOWN         = LOC_API_ADAPTER_ERR_PHONE_OFFLINE,
+    LOC_API_ADAPTER_ERR_FAILURE             = 101,
+    LOC_API_ADAPTER_ERR_UNKNOWN
+};
+
+enum loc_api_adapter_event_index {
+    LOC_API_ADAPTER_REPORT_POSITION = 0,               // Position report comes in loc_parsed_position_s_type
+    LOC_API_ADAPTER_REPORT_SATELLITE,                  // Satellite in view report
+    LOC_API_ADAPTER_REPORT_NMEA_1HZ,                   // NMEA report at 1HZ rate
+    LOC_API_ADAPTER_REPORT_NMEA_POSITION,              // NMEA report at position report rate
+    LOC_API_ADAPTER_REQUEST_NI_NOTIFY_VERIFY,          // NI notification/verification request
+    LOC_API_ADAPTER_REQUEST_ASSISTANCE_DATA,           // Assistance data, eg: time, predicted orbits request
+    LOC_API_ADAPTER_REQUEST_LOCATION_SERVER,           // Request for location server
+    LOC_API_ADAPTER_REPORT_IOCTL,                      // Callback report for loc_ioctl
+    LOC_API_ADAPTER_REPORT_STATUS,                     // Misc status report: eg, engine state
+    LOC_API_ADAPTER_REQUEST_WIFI,                      //
+    LOC_API_ADAPTER_SENSOR_STATUS,                     //
+    LOC_API_ADAPTER_REQUEST_TIME_SYNC,                 //
+    LOC_API_ADAPTER_REPORT_SPI,                        //
+    LOC_API_ADAPTER_REPORT_NI_GEOFENCE,                //
+    LOC_API_ADAPTER_GEOFENCE_GEN_ALERT,                //
+    LOC_API_ADAPTER_REPORT_GENFENCE_BREACH,            //
+    LOC_API_ADAPTER_PEDOMETER_CTRL,                    //
+    LOC_API_ADAPTER_MOTION_CTRL,                       //
+    LOC_API_ADAPTER_REQUEST_WIFI_AP_DATA,              // Wifi ap data
+    LOC_API_ADAPTER_BATCH_FULL,                        // Batching on full
+    LOC_API_ADAPTER_BATCHED_POSITION_REPORT,           // Batching on fix
+    LOC_API_ADAPTER_BATCHED_GENFENCE_BREACH_REPORT,    //
+    LOC_API_ADAPTER_GDT_UPLOAD_BEGIN_REQ,              // GDT upload start request
+    LOC_API_ADAPTER_GDT_UPLOAD_END_REQ,                // GDT upload end request
+    LOC_API_ADAPTER_GNSS_MEASUREMENT,                  // GNSS Measurement report
+
+    LOC_API_ADAPTER_EVENT_MAX
+};
+
+#define LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT           (1<<LOC_API_ADAPTER_REPORT_POSITION)
+#define LOC_API_ADAPTER_BIT_SATELLITE_REPORT                 (1<<LOC_API_ADAPTER_REPORT_SATELLITE)
+#define LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT                  (1<<LOC_API_ADAPTER_REPORT_NMEA_1HZ)
+#define LOC_API_ADAPTER_BIT_NMEA_POSITION_REPORT             (1<<LOC_API_ADAPTER_REPORT_NMEA_POSITION)
+#define LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST         (1<<LOC_API_ADAPTER_REQUEST_NI_NOTIFY_VERIFY)
+#define LOC_API_ADAPTER_BIT_ASSISTANCE_DATA_REQUEST          (1<<LOC_API_ADAPTER_REQUEST_ASSISTANCE_DATA)
+#define LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST          (1<<LOC_API_ADAPTER_REQUEST_LOCATION_SERVER)
+#define LOC_API_ADAPTER_BIT_IOCTL_REPORT                     (1<<LOC_API_ADAPTER_REPORT_IOCTL)
+#define LOC_API_ADAPTER_BIT_STATUS_REPORT                    (1<<LOC_API_ADAPTER_REPORT_STATUS)
+#define LOC_API_ADAPTER_BIT_REQUEST_WIFI                     (1<<LOC_API_ADAPTER_REQUEST_WIFI)
+#define LOC_API_ADAPTER_BIT_SENSOR_STATUS                    (1<<LOC_API_ADAPTER_SENSOR_STATUS)
+#define LOC_API_ADAPTER_BIT_REQUEST_TIME_SYNC                (1<<LOC_API_ADAPTER_REQUEST_TIME_SYNC)
+#define LOC_API_ADAPTER_BIT_REPORT_SPI                       (1<<LOC_API_ADAPTER_REPORT_SPI)
+#define LOC_API_ADAPTER_BIT_REPORT_NI_GEOFENCE               (1<<LOC_API_ADAPTER_REPORT_NI_GEOFENCE)
+#define LOC_API_ADAPTER_BIT_GEOFENCE_GEN_ALERT               (1<<LOC_API_ADAPTER_GEOFENCE_GEN_ALERT)
+#define LOC_API_ADAPTER_BIT_REPORT_GENFENCE_BREACH           (1<<LOC_API_ADAPTER_REPORT_GENFENCE_BREACH)
+#define LOC_API_ADAPTER_BIT_BATCHED_GENFENCE_BREACH_REPORT   (1<<LOC_API_ADAPTER_BATCHED_GENFENCE_BREACH_REPORT)
+#define LOC_API_ADAPTER_BIT_PEDOMETER_CTRL                   (1<<LOC_API_ADAPTER_PEDOMETER_CTRL)
+#define LOC_API_ADAPTER_BIT_MOTION_CTRL                      (1<<LOC_API_ADAPTER_MOTION_CTRL)
+#define LOC_API_ADAPTER_BIT_REQUEST_WIFI_AP_DATA             (1<<LOC_API_ADAPTER_REQUEST_WIFI_AP_DATA)
+#define LOC_API_ADAPTER_BIT_BATCH_FULL                       (1<<LOC_API_ADAPTER_BATCH_FULL)
+#define LOC_API_ADAPTER_BIT_BATCHED_POSITION_REPORT          (1<<LOC_API_ADAPTER_BATCHED_POSITION_REPORT)
+#define LOC_API_ADAPTER_BIT_GDT_UPLOAD_BEGIN_REQ             (1<<LOC_API_ADAPTER_GDT_UPLOAD_BEGIN_REQ)
+#define LOC_API_ADAPTER_BIT_GDT_UPLOAD_END_REQ               (1<<LOC_API_ADAPTER_GDT_UPLOAD_END_REQ)
+#define LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT                 (1<<LOC_API_ADAPTER_GNSS_MEASUREMENT)
+
+typedef unsigned int LOC_API_ADAPTER_EVENT_MASK_T;
+
+typedef enum loc_api_adapter_msg_to_check_supported {
+    LOC_API_ADAPTER_MESSAGE_LOCATION_BATCHING,               // Batching
+    LOC_API_ADAPTER_MESSAGE_BATCHED_GENFENCE_BREACH,         // Geofence Batched Breach
+
+    LOC_API_ADAPTER_MESSAGE_MAX
+} LocCheckingMessagesID;
+
+typedef uint32_t LOC_GPS_LOCK_MASK;
+#define isGpsLockNone(lock) ((lock) == 0)
+#define isGpsLockMO(lock) ((lock) & ((LOC_GPS_LOCK_MASK)1))
+#define isGpsLockMT(lock) ((lock) & ((LOC_GPS_LOCK_MASK)2))
+#define isGpsLockAll(lock) (((lock) & ((LOC_GPS_LOCK_MASK)3)) == 3)
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* GPS_EXTENDED_C_H */
+
diff --git a/gps/core/loc_core_log.cpp b/gps/core/loc_core_log.cpp
new file mode 100644
index 0000000..1b22010
--- /dev/null
+++ b/gps/core/loc_core_log.cpp
@@ -0,0 +1,260 @@
+/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#define LOG_NDDEBUG 0
+#define LOG_TAG "LocSvc_core_log"
+
+#include <loc_log.h>
+#include <log_util.h>
+#include <loc_core_log.h>
+
+void LocPosMode::logv() const
+{
+    LOC_LOGV ("Position mode: %s\n  Position recurrence: %s\n  "
+              "min interval: %d\n  preferred accuracy: %d\n  "
+              "preferred time: %d\n  credentials: %s  provider: %s",
+              loc_get_position_mode_name(mode),
+              loc_get_position_recurrence_name(recurrence),
+              min_interval,
+              preferred_accuracy,
+              preferred_time,
+              credentials,
+              provider);
+}
+
+/* GPS status names */
+static loc_name_val_s_type gps_status_name[] =
+{
+    NAME_VAL( GPS_STATUS_NONE ),
+    NAME_VAL( GPS_STATUS_SESSION_BEGIN ),
+    NAME_VAL( GPS_STATUS_SESSION_END ),
+    NAME_VAL( GPS_STATUS_ENGINE_ON ),
+    NAME_VAL( GPS_STATUS_ENGINE_OFF ),
+};
+static int gps_status_num = sizeof(gps_status_name) / sizeof(loc_name_val_s_type);
+
+/* Find Android GPS status name */
+const char* loc_get_gps_status_name(GpsStatusValue gps_status)
+{
+   return loc_get_name_from_val(gps_status_name, gps_status_num,
+         (long) gps_status);
+}
+
+
+
+static loc_name_val_s_type loc_eng_position_modes[] =
+{
+    NAME_VAL( LOC_POSITION_MODE_STANDALONE ),
+    NAME_VAL( LOC_POSITION_MODE_MS_BASED ),
+    NAME_VAL( LOC_POSITION_MODE_MS_ASSISTED ),
+    NAME_VAL( LOC_POSITION_MODE_RESERVED_1 ),
+    NAME_VAL( LOC_POSITION_MODE_RESERVED_2 ),
+    NAME_VAL( LOC_POSITION_MODE_RESERVED_3 ),
+    NAME_VAL( LOC_POSITION_MODE_RESERVED_4 ),
+    NAME_VAL( LOC_POSITION_MODE_RESERVED_5 )
+};
+static int loc_eng_position_mode_num = sizeof(loc_eng_position_modes) / sizeof(loc_name_val_s_type);
+
+const char* loc_get_position_mode_name(GpsPositionMode mode)
+{
+    return loc_get_name_from_val(loc_eng_position_modes, loc_eng_position_mode_num, (long) mode);
+}
+
+
+
+static loc_name_val_s_type loc_eng_position_recurrences[] =
+{
+    NAME_VAL( GPS_POSITION_RECURRENCE_PERIODIC ),
+    NAME_VAL( GPS_POSITION_RECURRENCE_SINGLE )
+};
+static int loc_eng_position_recurrence_num = sizeof(loc_eng_position_recurrences) / sizeof(loc_name_val_s_type);
+
+const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur)
+{
+    return loc_get_name_from_val(loc_eng_position_recurrences, loc_eng_position_recurrence_num, (long) recur);
+}
+
+
+
+static loc_name_val_s_type loc_eng_aiding_data_bits[] =
+{
+    NAME_VAL( GPS_DELETE_EPHEMERIS ),
+    NAME_VAL( GPS_DELETE_ALMANAC ),
+    NAME_VAL( GPS_DELETE_POSITION ),
+    NAME_VAL( GPS_DELETE_TIME ),
+    NAME_VAL( GPS_DELETE_IONO ),
+    NAME_VAL( GPS_DELETE_UTC ),
+    NAME_VAL( GPS_DELETE_HEALTH ),
+    NAME_VAL( GPS_DELETE_SVDIR ),
+    NAME_VAL( GPS_DELETE_SVSTEER ),
+    NAME_VAL( GPS_DELETE_SADATA ),
+    NAME_VAL( GPS_DELETE_RTI ),
+    NAME_VAL( GPS_DELETE_CELLDB_INFO ),
+#ifndef PDK_FEATURE_SET
+    NAME_VAL( GPS_DELETE_ALMANAC_CORR ),
+    NAME_VAL( GPS_DELETE_FREQ_BIAS_EST ),
+    NAME_VAL( GLO_DELETE_EPHEMERIS ),
+    NAME_VAL( GLO_DELETE_ALMANAC ),
+    NAME_VAL( GLO_DELETE_SVDIR ),
+    NAME_VAL( GLO_DELETE_SVSTEER ),
+    NAME_VAL( GLO_DELETE_ALMANAC_CORR ),
+    NAME_VAL( GPS_DELETE_TIME_GPS ),
+    NAME_VAL( GLO_DELETE_TIME ),
+    NAME_VAL( BDS_DELETE_SVDIR ),
+    NAME_VAL( BDS_DELETE_SVSTEER ),
+    NAME_VAL( BDS_DELETE_TIME ),
+    NAME_VAL( BDS_DELETE_ALMANAC_CORR ),
+    NAME_VAL( BDS_DELETE_EPHEMERIS ),
+    NAME_VAL( BDS_DELETE_ALMANAC ),
+#endif
+    NAME_VAL( GPS_DELETE_ALL)
+};
+static int loc_eng_aiding_data_bit_num = sizeof(loc_eng_aiding_data_bits) / sizeof(loc_name_val_s_type);
+
+const char* loc_get_aiding_data_mask_names(GpsAidingData data)
+{
+    return NULL;
+}
+
+
+static loc_name_val_s_type loc_eng_agps_types[] =
+{
+    NAME_VAL( AGPS_TYPE_INVALID ),
+    NAME_VAL( AGPS_TYPE_ANY ),
+    NAME_VAL( AGPS_TYPE_SUPL ),
+    NAME_VAL( AGPS_TYPE_C2K ),
+    NAME_VAL( AGPS_TYPE_WWAN_ANY )
+};
+static int loc_eng_agps_type_num = sizeof(loc_eng_agps_types) / sizeof(loc_name_val_s_type);
+
+const char* loc_get_agps_type_name(AGpsType type)
+{
+    return loc_get_name_from_val(loc_eng_agps_types, loc_eng_agps_type_num, (long) type);
+}
+
+
+static loc_name_val_s_type loc_eng_ni_types[] =
+{
+    NAME_VAL( GPS_NI_TYPE_VOICE ),
+    NAME_VAL( GPS_NI_TYPE_UMTS_SUPL ),
+    NAME_VAL( GPS_NI_TYPE_UMTS_CTRL_PLANE ),
+    NAME_VAL( GPS_NI_TYPE_EMERGENCY_SUPL )
+};
+static int loc_eng_ni_type_num = sizeof(loc_eng_ni_types) / sizeof(loc_name_val_s_type);
+
+const char* loc_get_ni_type_name(GpsNiType type)
+{
+    return loc_get_name_from_val(loc_eng_ni_types, loc_eng_ni_type_num, (long) type);
+}
+
+
+static loc_name_val_s_type loc_eng_ni_responses[] =
+{
+    NAME_VAL( GPS_NI_RESPONSE_ACCEPT ),
+    NAME_VAL( GPS_NI_RESPONSE_DENY ),
+    NAME_VAL( GPS_NI_RESPONSE_DENY )
+};
+static int loc_eng_ni_reponse_num = sizeof(loc_eng_ni_responses) / sizeof(loc_name_val_s_type);
+
+const char* loc_get_ni_response_name(GpsUserResponseType response)
+{
+    return loc_get_name_from_val(loc_eng_ni_responses, loc_eng_ni_reponse_num, (long) response);
+}
+
+
+static loc_name_val_s_type loc_eng_ni_encodings[] =
+{
+    NAME_VAL( GPS_ENC_NONE ),
+    NAME_VAL( GPS_ENC_SUPL_GSM_DEFAULT ),
+    NAME_VAL( GPS_ENC_SUPL_UTF8 ),
+    NAME_VAL( GPS_ENC_SUPL_UCS2 ),
+    NAME_VAL( GPS_ENC_UNKNOWN )
+};
+static int loc_eng_ni_encoding_num = sizeof(loc_eng_ni_encodings) / sizeof(loc_name_val_s_type);
+
+const char* loc_get_ni_encoding_name(GpsNiEncodingType encoding)
+{
+    return loc_get_name_from_val(loc_eng_ni_encodings, loc_eng_ni_encoding_num, (long) encoding);
+}
+
+static loc_name_val_s_type loc_eng_agps_bears[] =
+{
+    NAME_VAL( AGPS_APN_BEARER_INVALID ),
+    NAME_VAL( AGPS_APN_BEARER_IPV4 ),
+    NAME_VAL( AGPS_APN_BEARER_IPV6 ),
+    NAME_VAL( AGPS_APN_BEARER_IPV4V6 )
+};
+static int loc_eng_agps_bears_num = sizeof(loc_eng_agps_bears) / sizeof(loc_name_val_s_type);
+
+const char* loc_get_agps_bear_name(AGpsBearerType bearer)
+{
+    return loc_get_name_from_val(loc_eng_agps_bears, loc_eng_agps_bears_num, (long) bearer);
+}
+
+static loc_name_val_s_type loc_eng_server_types[] =
+{
+    NAME_VAL( LOC_AGPS_CDMA_PDE_SERVER ),
+    NAME_VAL( LOC_AGPS_CUSTOM_PDE_SERVER ),
+    NAME_VAL( LOC_AGPS_MPC_SERVER ),
+    NAME_VAL( LOC_AGPS_SUPL_SERVER )
+};
+static int loc_eng_server_types_num = sizeof(loc_eng_server_types) / sizeof(loc_name_val_s_type);
+
+const char* loc_get_server_type_name(LocServerType type)
+{
+    return loc_get_name_from_val(loc_eng_server_types, loc_eng_server_types_num, (long) type);
+}
+
+static loc_name_val_s_type loc_eng_position_sess_status_types[] =
+{
+    NAME_VAL( LOC_SESS_SUCCESS ),
+    NAME_VAL( LOC_SESS_INTERMEDIATE ),
+    NAME_VAL( LOC_SESS_FAILURE )
+};
+static int loc_eng_position_sess_status_num = sizeof(loc_eng_position_sess_status_types) / sizeof(loc_name_val_s_type);
+
+const char* loc_get_position_sess_status_name(enum loc_sess_status status)
+{
+    return loc_get_name_from_val(loc_eng_position_sess_status_types, loc_eng_position_sess_status_num, (long) status);
+}
+
+static loc_name_val_s_type loc_eng_agps_status_names[] =
+{
+    NAME_VAL( GPS_REQUEST_AGPS_DATA_CONN ),
+    NAME_VAL( GPS_RELEASE_AGPS_DATA_CONN ),
+    NAME_VAL( GPS_AGPS_DATA_CONNECTED ),
+    NAME_VAL( GPS_AGPS_DATA_CONN_DONE ),
+    NAME_VAL( GPS_AGPS_DATA_CONN_FAILED )
+};
+static int loc_eng_agps_status_num = sizeof(loc_eng_agps_status_names) / sizeof(loc_name_val_s_type);
+
+const char* loc_get_agps_status_name(AGpsStatusValue status)
+{
+    return loc_get_name_from_val(loc_eng_agps_status_names, loc_eng_agps_status_num, (long) status);
+}
diff --git a/gps/core/loc_core_log.h b/gps/core/loc_core_log.h
new file mode 100644
index 0000000..8a1825a
--- /dev/null
+++ b/gps/core/loc_core_log.h
@@ -0,0 +1,58 @@
+/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef LOC_CORE_LOG_H
+#define LOC_CORE_LOG_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <ctype.h>
+#include <gps_extended.h>
+
+const char* loc_get_gps_status_name(GpsStatusValue gps_status);
+const char* loc_get_position_mode_name(GpsPositionMode mode);
+const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur);
+const char* loc_get_aiding_data_mask_names(GpsAidingData data);
+const char* loc_get_agps_type_name(AGpsType type);
+const char* loc_get_ni_type_name(GpsNiType type);
+const char* loc_get_ni_response_name(GpsUserResponseType response);
+const char* loc_get_ni_encoding_name(GpsNiEncodingType encoding);
+const char* loc_get_agps_bear_name(AGpsBearerType bear);
+const char* loc_get_server_type_name(LocServerType type);
+const char* loc_get_position_sess_status_name(enum loc_sess_status status);
+const char* loc_get_agps_status_name(AGpsStatusValue status);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LOC_CORE_LOG_H */
diff --git a/gps/gps.conf b/gps/gps.conf
index e967b56..be9755d 100644
--- a/gps/gps.conf
+++ b/gps/gps.conf
@@ -117,10 +117,3 @@
 # 0x2: RRLP UPlane
 # 0x4: LLP Uplane
 A_GLONASS_POS_PROTOCOL_SELECT = 0 #Sensor R&D : This will not be injected to MODEM
-
-##################################################
-# Delete only Ephemeris files
-##################################################
-#0 : off - default
-#1 : on - Erase only eph files when we use 'delete aiding data' function.
-DEL_EPH_ONLY = 0
diff --git a/gps/izat.conf b/gps/izat.conf
index 35f482e..52dd983 100644
--- a/gps/izat.conf
+++ b/gps/izat.conf
@@ -72,11 +72,6 @@
 # BASIC
 GTP_WIFI=BASIC
 
-#GTP_WAA valid modes:
-# DISABLED
-# BASIC
-GTP_WAA=DISABLED
-
 #SAP valid modes:
 # DISABLED
 # BASIC
@@ -99,7 +94,6 @@
 #FEATURE MASKS:
 # GTP-WIFI 0X03
 # GTP-CELL 0X0c
-# GTP-WAA  0X300
 # PIP      0x30
 # SAP      0Xc0
 
@@ -111,17 +105,7 @@
 #1. Any valid values obtained from ro.baseband separated by single space. For example: sglte sglte2
 #2. all -> for all basebands
 
-PROCESS_NAME=/system/bin/garden_app
-PROCESS_ARGUMENT=-u 0 -q 0 -j 0 -g 0 -l 0 -Z 0 -T 1
-PROCESS_STATE=ENABLED
-PROCESS_GROUPS=gps net_raw
-PREMIUM_FEATURE=0
-IZAT_FEATURE_MASK=0
-PLATFORMS=all
-BASEBAND=auto
-
 PROCESS_NAME=/system/bin/gpsone_daemon
-PROCESS_ARGUMENT=
 PROCESS_STATE=DISABLED
 PROCESS_GROUPS=inet net_raw
 PREMIUM_FEATURE=0
@@ -130,7 +114,6 @@
 BASEBAND=svlte2a sglte sglte2
 
 PROCESS_NAME=/system/bin/location-mq
-PROCESS_ARGUMENT=
 PROCESS_STATE=ENABLED
 PROCESS_GROUPS=gps
 PREMIUM_FEATURE=1
@@ -139,7 +122,6 @@
 BASEBAND=all
 
 PROCESS_NAME=/system/bin/lowi-server
-PROCESS_ARGUMENT=
 PROCESS_STATE=ENABLED
 PROCESS_GROUPS=gps net_admin wifi inet qcom_diag net_raw
 PREMIUM_FEATURE=1
@@ -148,7 +130,6 @@
 BASEBAND=all
 
 PROCESS_NAME=/system/bin/quipc_igsn
-PROCESS_ARGUMENT=
 PROCESS_STATE=ENABLED
 PROCESS_GROUPS=inet gps qcom_diag
 PREMIUM_FEATURE=1
@@ -157,7 +138,6 @@
 BASEBAND=all
 
 PROCESS_NAME=/system/bin/quipc_main
-PROCESS_ARGUMENT=
 PROCESS_STATE=ENABLED
 PROCESS_GROUPS=gps net_admin wifi inet qcom_diag
 PREMIUM_FEATURE=1
@@ -166,7 +146,6 @@
 BASEBAND=all
 
 PROCESS_NAME=/system/bin/xtwifi-inet-agent
-PROCESS_ARGUMENT=
 PROCESS_STATE=ENABLED
 PROCESS_GROUPS=inet gps
 PREMIUM_FEATURE=1
@@ -175,16 +154,14 @@
 BASEBAND=all
 
 PROCESS_NAME=/system/bin/xtwifi-client
-PROCESS_ARGUMENT=
 PROCESS_STATE=ENABLED
 PROCESS_GROUPS=net_admin wifi inet gps
 PREMIUM_FEATURE=1
-IZAT_FEATURE_MASK=0x30f
+IZAT_FEATURE_MASK=0x0f
 PLATFORMS=all
 BASEBAND=all
 
-PROCESS_NAME=/system/vendor/bin/slim_ap_daemon
-PROCESS_ARGUMENT=
+PROCESS_NAME=/system/bin/gsiff_daemon
 PROCESS_STATE=ENABLED
 PROCESS_GROUPS=gps net_raw misc qcom_oncrpc
 PREMIUM_FEATURE=1
diff --git a/gps/platform_lib_abstractions/elapsed_millis_since_boot.cpp b/gps/platform_lib_abstractions/elapsed_millis_since_boot.cpp
new file mode 100644
index 0000000..e8cb93a
--- /dev/null
+++ b/gps/platform_lib_abstractions/elapsed_millis_since_boot.cpp
@@ -0,0 +1,46 @@
+/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <sys/time.h>
+#include "platform_lib_time.h"
+
+int64_t systemTime(int clock)
+{
+    struct timeval t;
+    t.tv_sec = t.tv_usec = 0;
+    gettimeofday(&t, NULL);
+    return t.tv_sec*1000000LL + t.tv_usec;
+}
+
+
+int64_t elapsedMillisSinceBoot()
+{
+    int64_t t_us = systemTime(0);
+    return (int64_t) t_us / 1000LL;
+}
diff --git a/gps/platform_lib_abstractions/platform_lib_includes.h b/gps/platform_lib_abstractions/platform_lib_includes.h
new file mode 100644
index 0000000..5858674
--- /dev/null
+++ b/gps/platform_lib_abstractions/platform_lib_includes.h
@@ -0,0 +1,35 @@
+/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _PLATFORM_LIB_INCLUDES_H_
+#define _PLATFORM_LIB_INCLUDES_H_
+
+#include "platform_lib_time.h"
+#include "platform_lib_macros.h"
+
+#endif
diff --git a/gps/platform_lib_abstractions/platform_lib_macros.h b/gps/platform_lib_abstractions/platform_lib_macros.h
new file mode 100644
index 0000000..bc48dd9
--- /dev/null
+++ b/gps/platform_lib_abstractions/platform_lib_macros.h
@@ -0,0 +1,81 @@
+/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __PLATFORM_LIB_MACROS_H__
+#define __PLATFORM_LIB_MACROS_H__
+
+#include <sys/time.h>
+
+#define TS_PRINTF(format, x...)                                \
+{                                                              \
+  struct timeval tv;                                           \
+  struct timezone tz;                                          \
+  int hh, mm, ss;                                              \
+  gettimeofday(&tv, &tz);                                      \
+  hh = tv.tv_sec/3600%24;                                      \
+  mm = (tv.tv_sec%3600)/60;                                    \
+  ss = tv.tv_sec%60;                                           \
+  fprintf(stdout,"%02d:%02d:%02d.%06ld]" format "\n", hh, mm, ss, tv.tv_usec,##x);    \
+}
+
+
+#ifdef USE_GLIB
+
+#define strlcat g_strlcat
+#define strlcpy g_strlcpy
+
+#define ALOGE(format, x...) TS_PRINTF("E/%s (%d): " format , LOG_TAG, getpid(), ##x)
+#define ALOGW(format, x...) TS_PRINTF("W/%s (%d): " format , LOG_TAG, getpid(), ##x)
+#define ALOGI(format, x...) TS_PRINTF("I/%s (%d): " format , LOG_TAG, getpid(), ##x)
+#define ALOGD(format, x...) TS_PRINTF("D/%s (%d): " format , LOG_TAG, getpid(), ##x)
+#define ALOGV(format, x...) TS_PRINTF("V/%s (%d): " format , LOG_TAG, getpid(), ##x)
+
+#define GETTID_PLATFORM_LIB_ABSTRACTION (syscall(SYS_gettid))
+
+#define LOC_EXT_CREATE_THREAD_CB_PLATFORM_LIB_ABSTRACTION createPthread
+#define ELAPSED_MILLIS_SINCE_BOOT_PLATFORM_LIB_ABSTRACTION (elapsedMillisSinceBoot())
+
+
+#else
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+pid_t gettid(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#define GETTID_PLATFORM_LIB_ABSTRACTION (gettid())
+#define LOC_EXT_CREATE_THREAD_CB_PLATFORM_LIB_ABSTRACTION android::AndroidRuntime::createJavaThread
+#define ELAPSED_MILLIS_SINCE_BOOT_PLATFORM_LIB_ABSTRACTION  (android::elapsedRealtime())
+
+#endif
+
+#endif
diff --git a/gps/platform_lib_abstractions/platform_lib_time.h b/gps/platform_lib_abstractions/platform_lib_time.h
new file mode 100644
index 0000000..ce013af
--- /dev/null
+++ b/gps/platform_lib_abstractions/platform_lib_time.h
@@ -0,0 +1,35 @@
+/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _PLATFORM_LIB_TIME_H_
+#define _PLATFORM_LIB_TIME_H_
+
+int64_t systemTime(int clock);
+int64_t elapsedMillisSinceBoot();
+
+#endif
diff --git a/gps/utils/Android.mk b/gps/utils/Android.mk
new file mode 100644
index 0000000..0f99907
--- /dev/null
+++ b/gps/utils/Android.mk
@@ -0,0 +1,59 @@
+ifneq ($(BUILD_TINY_ANDROID),true)
+#Compile this library only for builds with the latest modem image
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+## Libs
+LOCAL_SHARED_LIBRARIES := \
+    libutils \
+    libcutils \
+    liblog
+
+LOCAL_SRC_FILES += \
+    loc_log.cpp \
+    loc_cfg.cpp \
+    msg_q.c \
+    linked_list.c \
+    loc_target.cpp \
+    loc_timer.c \
+    ../platform_lib_abstractions/elapsed_millis_since_boot.cpp \
+    loc_misc_utils.cpp
+
+LOCAL_CFLAGS += \
+     -fno-short-enums \
+     -D_ANDROID_
+
+ifeq ($(TARGET_BUILD_VARIANT),user)
+   LOCAL_CFLAGS += -DTARGET_BUILD_VARIANT_USER
+endif
+
+LOCAL_LDFLAGS += -Wl,--export-dynamic
+
+## Includes
+LOCAL_C_INCLUDES:= \
+    $(LOCAL_PATH)/../platform_lib_abstractions
+
+LOCAL_COPY_HEADERS_TO:= gps.utils/
+LOCAL_COPY_HEADERS:= \
+   loc_log.h \
+   loc_cfg.h \
+   log_util.h \
+   linked_list.h \
+   msg_q.h \
+   loc_target.h \
+   loc_timer.h \
+   ../platform_lib_abstractions/platform_lib_includes.h \
+   ../platform_lib_abstractions/platform_lib_time.h \
+   ../platform_lib_abstractions/platform_lib_macros.h \
+   loc_misc_utils.h
+
+LOCAL_MODULE := libgps.utils
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_PRELINK_MODULE := false
+
+include $(BUILD_SHARED_LIBRARY)
+endif # not BUILD_TINY_ANDROID
diff --git a/gps/utils/Makefile.am b/gps/utils/Makefile.am
new file mode 100644
index 0000000..e5935f0
--- /dev/null
+++ b/gps/utils/Makefile.am
@@ -0,0 +1,44 @@
+AM_CFLAGS = -Wundef \
+         -MD \
+         -Wno-trigraphs \
+         -g -O0 \
+         -fno-inline \
+         -fno-short-enums \
+         -fpic \
+         -I../platform_lib_abstractions
+
+libgps_utils_so_la_h_sources = log_util.h \
+            msg_q.h \
+            linked_list.h \
+            loc_cfg.h \
+            loc_log.h \
+            ../platform_lib_abstractions/platform_lib_includes.h \
+            ../platform_lib_abstractions/platform_lib_time.h \
+            ../platform_lib_abstractions/platform_lib_macros.h
+
+libgps_utils_so_la_c_sources = linked_list.c \
+            msg_q.c \
+            loc_cfg.cpp \
+            loc_log.cpp \
+            ../platform_lib_abstractions/elapsed_millis_since_boot.cpp
+
+library_includedir = $(pkgincludedir)/utils
+
+library_include_HEADERS = $(libgps_utils_so_la_h_sources)
+
+libgps_utils_so_la_SOURCES = $(libgps_utils_so_la_c_sources)
+
+if USE_GLIB
+libgps_utils_so_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@
+libgps_utils_so_la_LDFLAGS = -lstdc++ -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0
+libgps_utils_so_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@
+else
+libgps_utils_so_la_CFLAGS = $(AM_CFLAGS)
+libgps_utils_so_la_LDFLAGS = -lpthread -shared -version-info 1:0:0
+libgps_utils_so_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS)
+endif
+
+libgps_utils_so_la_LIBADD = -lstdc++ -lcutils
+
+#Create and Install libraries
+lib_LTLIBRARIES = libgps_utils_so.la
diff --git a/gps/utils/linked_list.c b/gps/utils/linked_list.c
new file mode 100644
index 0000000..92617fe
--- /dev/null
+++ b/gps/utils/linked_list.c
@@ -0,0 +1,328 @@
+/* Copyright (c) 2011, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "linked_list.h"
+#include <stdio.h>
+#include <string.h>
+
+#define LOG_TAG "LocSvc_utils_ll"
+#include "log_util.h"
+#include "platform_lib_includes.h"
+#include <stdlib.h>
+#include <stdint.h>
+
+typedef struct list_element {
+   struct list_element* next;
+   struct list_element* prev;
+   void* data_ptr;
+   void (*dealloc_func)(void*);
+}list_element;
+
+typedef struct list_state {
+   list_element* p_head;
+   list_element* p_tail;
+} list_state;
+
+/* ----------------------- END INTERNAL FUNCTIONS ---------------------------------------- */
+
+/*===========================================================================
+
+  FUNCTION:   linked_list_init
+
+  ===========================================================================*/
+linked_list_err_type linked_list_init(void** list_data)
+{
+   if( list_data == NULL )
+   {
+      LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__);
+      return eLINKED_LIST_INVALID_PARAMETER;
+   }
+
+   list_state* tmp_list;
+   tmp_list = (list_state*)calloc(1, sizeof(list_state));
+   if( tmp_list == NULL )
+   {
+      LOC_LOGE("%s: Unable to allocate space for list!\n", __FUNCTION__);
+      return eLINKED_LIST_FAILURE_GENERAL;
+   }
+
+   tmp_list->p_head = NULL;
+   tmp_list->p_tail = NULL;
+
+   *list_data = tmp_list;
+
+   return eLINKED_LIST_SUCCESS;
+}
+
+/*===========================================================================
+
+  FUNCTION:   linked_list_destroy
+
+  ===========================================================================*/
+linked_list_err_type linked_list_destroy(void** list_data)
+{
+   if( list_data == NULL )
+   {
+      LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__);
+      return eLINKED_LIST_INVALID_HANDLE;
+   }
+
+   list_state* p_list = (list_state*)*list_data;
+
+   linked_list_flush(p_list);
+
+   free(*list_data);
+   *list_data = NULL;
+
+   return eLINKED_LIST_SUCCESS;
+}
+
+/*===========================================================================
+
+  FUNCTION:   linked_list_add
+
+  ===========================================================================*/
+linked_list_err_type linked_list_add(void* list_data, void *data_obj, void (*dealloc)(void*))
+{
+   LOC_LOGD("%s: Adding to list data_obj = 0x%08X\n", __FUNCTION__, data_obj);
+   if( list_data == NULL )
+   {
+      LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__);
+      return eLINKED_LIST_INVALID_HANDLE;
+   }
+
+   if( data_obj == NULL )
+   {
+      LOC_LOGE("%s: Invalid input parameter!\n", __FUNCTION__);
+      return eLINKED_LIST_INVALID_PARAMETER;
+   }
+
+   list_state* p_list = (list_state*)list_data;
+   list_element* elem = (list_element*)malloc(sizeof(list_element));
+   if( elem == NULL )
+   {
+      LOC_LOGE("%s: Memory allocation failed\n", __FUNCTION__);
+      return eLINKED_LIST_FAILURE_GENERAL;
+   }
+
+   /* Copy data to newly created element */
+   elem->data_ptr = data_obj;
+   elem->next = NULL;
+   elem->prev = NULL;
+   elem->dealloc_func = dealloc;
+
+   /* Replace head element */
+   list_element* tmp = p_list->p_head;
+   p_list->p_head = elem;
+   /* Point next to the previous head element */
+   p_list->p_head->next = tmp;
+
+   if( tmp != NULL )
+   {
+      tmp->prev = p_list->p_head;
+   }
+   else
+   {
+      p_list->p_tail = p_list->p_head;
+   }
+
+   return eLINKED_LIST_SUCCESS;
+}
+
+/*===========================================================================
+
+  FUNCTION:   linked_list_remove
+
+  ===========================================================================*/
+linked_list_err_type linked_list_remove(void* list_data, void **data_obj)
+{
+   LOC_LOGD("%s: Removing from list\n", __FUNCTION__);
+   if( list_data == NULL )
+   {
+      LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__);
+      return eLINKED_LIST_INVALID_HANDLE;
+   }
+
+   if( data_obj == NULL )
+   {
+      LOC_LOGE("%s: Invalid input parameter!\n", __FUNCTION__);
+      return eLINKED_LIST_INVALID_PARAMETER;
+   }
+
+   list_state* p_list = (list_state*)list_data;
+   if( p_list->p_tail == NULL )
+   {
+      return eLINKED_LIST_UNAVAILABLE_RESOURCE;
+   }
+
+   list_element* tmp = p_list->p_tail;
+
+   /* Replace tail element */
+   p_list->p_tail = tmp->prev;
+
+   if( p_list->p_tail != NULL )
+   {
+      p_list->p_tail->next = NULL;
+   }
+   else
+   {
+      p_list->p_head = p_list->p_tail;
+   }
+
+   /* Copy data to output param */
+   *data_obj = tmp->data_ptr;
+
+   /* Free allocated list element */
+   free(tmp);
+
+   return eLINKED_LIST_SUCCESS;
+}
+
+/*===========================================================================
+
+  FUNCTION:   linked_list_empty
+
+  ===========================================================================*/
+int linked_list_empty(void* list_data)
+{
+   if( list_data == NULL )
+   {
+      LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__);
+      return (int)eLINKED_LIST_INVALID_HANDLE;
+   }
+   else
+   {
+      list_state* p_list = (list_state*)list_data;
+      return p_list->p_head == NULL ? 1 : 0;
+   }
+}
+
+/*===========================================================================
+
+  FUNCTION:   linked_list_flush
+
+  ===========================================================================*/
+linked_list_err_type linked_list_flush(void* list_data)
+{
+   if( list_data == NULL )
+   {
+      LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__);
+      return eLINKED_LIST_INVALID_HANDLE;
+   }
+
+   list_state* p_list = (list_state*)list_data;
+
+   /* Remove all dynamically allocated elements */
+   while( p_list->p_head != NULL )
+   {
+      list_element* tmp = p_list->p_head->next;
+
+      /* Free data pointer if told to do so. */
+      if( p_list->p_head->dealloc_func != NULL )
+      {
+         p_list->p_head->dealloc_func(p_list->p_head->data_ptr);
+      }
+
+      /* Free list element */
+      free(p_list->p_head);
+
+      p_list->p_head = tmp;
+   }
+
+   p_list->p_tail = NULL;
+
+   return eLINKED_LIST_SUCCESS;
+}
+
+/*===========================================================================
+
+  FUNCTION:   linked_list_search
+
+  ===========================================================================*/
+linked_list_err_type linked_list_search(void* list_data, void **data_p,
+                                        bool (*equal)(void* data_0, void* data),
+                                        void* data_0, bool rm_if_found)
+{
+   LOC_LOGD("%s: Search the list\n", __FUNCTION__);
+   if( list_data == NULL || NULL == equal )
+   {
+      LOC_LOGE("%s: Invalid list parameter! list_data %p equal %p\n",
+               __FUNCTION__, list_data, equal);
+      return eLINKED_LIST_INVALID_HANDLE;
+   }
+
+   list_state* p_list = (list_state*)list_data;
+   if( p_list->p_tail == NULL )
+   {
+      return eLINKED_LIST_UNAVAILABLE_RESOURCE;
+   }
+
+   list_element* tmp = p_list->p_head;
+
+   if (NULL != data_p) {
+     *data_p = NULL;
+   }
+
+   while (NULL != tmp) {
+     if ((*equal)(data_0, tmp->data_ptr)) {
+       if (NULL != data_p) {
+         *data_p = tmp->data_ptr;
+       }
+
+       if (rm_if_found) {
+         if (NULL == tmp->prev) {
+           p_list->p_head = tmp->next;
+         } else {
+           tmp->prev->next = tmp->next;
+         }
+
+         if (NULL == tmp->next) {
+           p_list->p_tail = tmp->prev;
+         } else {
+           tmp->next->prev = tmp->prev;
+         }
+
+         tmp->prev = tmp->next = NULL;
+
+         // dealloc data if it is not copied out && caller
+         // has given us a dealloc function pointer.
+         if (NULL == data_p && NULL != tmp->dealloc_func) {
+             tmp->dealloc_func(tmp->data_ptr);
+         }
+         free(tmp);
+       }
+
+       tmp = NULL;
+     } else {
+       tmp = tmp->next;
+     }
+   }
+
+   return eLINKED_LIST_SUCCESS;
+}
+
diff --git a/gps/utils/linked_list.h b/gps/utils/linked_list.h
new file mode 100644
index 0000000..a85f09a
--- /dev/null
+++ b/gps/utils/linked_list.h
@@ -0,0 +1,217 @@
+/* Copyright (c) 2011, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef __LINKED_LIST_H__
+#define __LINKED_LIST_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <stdbool.h>
+#include <stdlib.h>
+
+/** Linked List Return Codes */
+typedef enum
+{
+  eLINKED_LIST_SUCCESS                             = 0,
+     /**< Request was successful. */
+  eLINKED_LIST_FAILURE_GENERAL                     = -1,
+     /**< Failed because of a general failure. */
+  eLINKED_LIST_INVALID_PARAMETER                   = -2,
+     /**< Failed because the request contained invalid parameters. */
+  eLINKED_LIST_INVALID_HANDLE                      = -3,
+     /**< Failed because an invalid handle was specified. */
+  eLINKED_LIST_UNAVAILABLE_RESOURCE                = -4,
+     /**< Failed because an there were not enough resources. */
+  eLINKED_LIST_INSUFFICIENT_BUFFER                 = -5,
+     /**< Failed because an the supplied buffer was too small. */
+}linked_list_err_type;
+
+/*===========================================================================
+FUNCTION    linked_list_init
+
+DESCRIPTION
+   Initializes internal structures for linked list.
+
+   list_data: State of list to be initialized.
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Look at error codes above.
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+linked_list_err_type linked_list_init(void** list_data);
+
+/*===========================================================================
+FUNCTION    linked_list_destroy
+
+DESCRIPTION
+   Destroys internal structures for linked list.
+
+   p_list_data: State of list to be destroyed.
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Look at error codes above.
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+linked_list_err_type linked_list_destroy(void** list_data);
+
+/*===========================================================================
+FUNCTION    linked_list_add
+
+DESCRIPTION
+   Adds an element to the head of the linked list. The passed in data pointer
+   is not modified or freed. Passed in data_obj is expected to live throughout
+   the use of the linked_list (i.e. data is not allocated internally)
+
+   p_list_data:  List to add data to the head of.
+   data_obj:     Pointer to data to add into list
+   dealloc:      Function used to deallocate memory for this element. Pass NULL
+                 if you do not want data deallocated during a flush operation
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Look at error codes above.
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+linked_list_err_type linked_list_add(void* list_data, void *data_obj, void (*dealloc)(void*));
+
+/*===========================================================================
+FUNCTION    linked_list_remove
+
+DESCRIPTION
+   Retrieves data from the list tail. data_obj is the tail element from the list
+   passed in by linked_list_add.
+
+   p_list_data:  List to remove the tail from.
+   data_obj:     Pointer to data removed from list
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Look at error codes above.
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+linked_list_err_type linked_list_remove(void* list_data, void **data_obj);
+
+/*===========================================================================
+FUNCTION    linked_list_empty
+
+DESCRIPTION
+   Tells whether the list currently contains any elements
+
+   p_list_data:  List to check if empty.
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   0/FALSE : List contains elements
+   1/TRUE  : List is Empty
+   Otherwise look at error codes above.
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+int linked_list_empty(void* list_data);
+
+/*===========================================================================
+FUNCTION    linked_list_flush
+
+DESCRIPTION
+   Removes all elements from the list and deallocates them using the provided
+   dealloc function while adding elements.
+
+   p_list_data:  List to remove all elements from.
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Look at error codes above.
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+linked_list_err_type linked_list_flush(void* list_data);
+
+/*===========================================================================
+FUNCTION    linked_list_search
+
+DESCRIPTION
+   Searches for an element in the linked list.
+
+   p_list_data:  List handle.
+   data_p:       to be stored with the data found; NUll if no match.
+                 if data_p passed in as NULL, then no write to it.
+   equal:        Function ptr takes in a list element, and returns
+                 indication if this the one looking for.
+   data_0:       The data being compared against.
+   rm_if_found:  Should data be removed if found?
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Look at error codes above.
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+linked_list_err_type linked_list_search(void* list_data, void **data_p,
+                                        bool (*equal)(void* data_0, void* data),
+                                        void* data_0, bool rm_if_found);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __LINKED_LIST_H__ */
diff --git a/gps/utils/loc_cfg.cpp b/gps/utils/loc_cfg.cpp
new file mode 100644
index 0000000..7ffe6a4
--- /dev/null
+++ b/gps/utils/loc_cfg.cpp
@@ -0,0 +1,399 @@
+/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#define LOG_NDDEBUG 0
+#define LOG_TAG "LocSvc_utils_cfg"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <time.h>
+#include <loc_cfg.h>
+#include <log_util.h>
+#include <loc_misc_utils.h>
+#ifdef USE_GLIB
+#include <glib.h>
+#endif
+#include "platform_lib_includes.h"
+
+/*=============================================================================
+ *
+ *                          GLOBAL DATA DECLARATION
+ *
+ *============================================================================*/
+
+/* Parameter data */
+static uint8_t DEBUG_LEVEL = 0xff;
+static uint8_t TIMESTAMP = 0;
+
+/* Parameter spec table */
+static loc_param_s_type loc_param_table[] =
+{
+    {"DEBUG_LEVEL",    &DEBUG_LEVEL, NULL,    'n'},
+    {"TIMESTAMP",      &TIMESTAMP,   NULL,    'n'},
+};
+int loc_param_num = sizeof(loc_param_table) / sizeof(loc_param_s_type);
+
+typedef struct loc_param_v_type
+{
+    char* param_name;
+    char* param_str_value;
+    int param_int_value;
+    double param_double_value;
+}loc_param_v_type;
+
+/*===========================================================================
+FUNCTION loc_set_config_entry
+
+DESCRIPTION
+   Potentially sets a given configuration table entry based on the passed in
+   configuration value. This is done by using a string comparison of the
+   parameter names and those found in the configuration file.
+
+PARAMETERS:
+   config_entry: configuration entry in the table to possibly set
+   config_value: value to store in the entry if the parameter names match
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   None
+
+SIDE EFFECTS
+   N/A
+===========================================================================*/
+int loc_set_config_entry(loc_param_s_type* config_entry, loc_param_v_type* config_value)
+{
+    int ret=-1;
+    if(NULL == config_entry || NULL == config_value)
+    {
+        LOC_LOGE("%s: INVALID config entry or parameter", __FUNCTION__);
+        return ret;
+    }
+
+    if (strcmp(config_entry->param_name, config_value->param_name) == 0 &&
+        config_entry->param_ptr)
+    {
+        switch (config_entry->param_type)
+        {
+        case 's':
+            if (strcmp(config_value->param_str_value, "NULL") == 0)
+            {
+                *((char*)config_entry->param_ptr) = '\0';
+            }
+            else {
+                strlcpy((char*) config_entry->param_ptr,
+                        config_value->param_str_value,
+                        LOC_MAX_PARAM_STRING + 1);
+            }
+            /* Log INI values */
+            LOC_LOGD("%s: PARAM %s = %s", __FUNCTION__,
+                     config_entry->param_name, (char*)config_entry->param_ptr);
+
+            if(NULL != config_entry->param_set)
+            {
+                *(config_entry->param_set) = 1;
+            }
+            ret = 0;
+            break;
+        case 'n':
+            *((int *)config_entry->param_ptr) = config_value->param_int_value;
+            /* Log INI values */
+            LOC_LOGD("%s: PARAM %s = %d", __FUNCTION__,
+                     config_entry->param_name, config_value->param_int_value);
+
+            if(NULL != config_entry->param_set)
+            {
+                *(config_entry->param_set) = 1;
+            }
+            ret = 0;
+            break;
+        case 'f':
+            *((double *)config_entry->param_ptr) = config_value->param_double_value;
+            /* Log INI values */
+            LOC_LOGD("%s: PARAM %s = %f", __FUNCTION__,
+                     config_entry->param_name, config_value->param_double_value);
+
+            if(NULL != config_entry->param_set)
+            {
+                *(config_entry->param_set) = 1;
+            }
+            ret = 0;
+            break;
+        default:
+            LOC_LOGE("%s: PARAM %s parameter type must be n, f, or s",
+                     __FUNCTION__, config_entry->param_name);
+        }
+    }
+    return ret;
+}
+
+/*===========================================================================
+FUNCTION loc_fill_conf_item
+
+DESCRIPTION
+   Takes a line of configuration item and sets defined values based on
+   the passed in configuration table. This table maps strings to values to
+   set along with the type of each of these values.
+
+PARAMETERS:
+   input_buf : buffer contanis config item
+   config_table: table definition of strings to places to store information
+   table_length: length of the configuration table
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   0: Number of records in the config_table filled with input_buf
+
+SIDE EFFECTS
+   N/A
+===========================================================================*/
+int loc_fill_conf_item(char* input_buf,
+                       loc_param_s_type* config_table, uint32_t table_length)
+{
+    int ret = 0;
+
+    if (input_buf && config_table) {
+        char *lasts;
+        loc_param_v_type config_value;
+        memset(&config_value, 0, sizeof(config_value));
+
+        /* Separate variable and value */
+        config_value.param_name = strtok_r(input_buf, "=", &lasts);
+        /* skip lines that do not contain "=" */
+        if (config_value.param_name) {
+            config_value.param_str_value = strtok_r(NULL, "=", &lasts);
+
+            /* skip lines that do not contain two operands */
+            if (config_value.param_str_value) {
+                /* Trim leading and trailing spaces */
+                loc_util_trim_space(config_value.param_name);
+                loc_util_trim_space(config_value.param_str_value);
+
+                /* Parse numerical value */
+                if ((strlen(config_value.param_str_value) >=3) &&
+                    (config_value.param_str_value[0] == '0') &&
+                    (tolower(config_value.param_str_value[1]) == 'x'))
+                {
+                    /* hex */
+                    config_value.param_int_value = (int) strtol(&config_value.param_str_value[2],
+                                                                (char**) NULL, 16);
+                }
+                else {
+                    config_value.param_double_value = (double) atof(config_value.param_str_value); /* float */
+                    config_value.param_int_value = atoi(config_value.param_str_value); /* dec */
+                }
+
+                for(uint32_t i = 0; NULL != config_table && i < table_length; i++)
+                {
+                    if(!loc_set_config_entry(&config_table[i], &config_value)) {
+                        ret += 1;
+                    }
+                }
+            }
+        }
+    }
+
+    return ret;
+}
+
+/*===========================================================================
+FUNCTION loc_read_conf_r (repetitive)
+
+DESCRIPTION
+   Reads the specified configuration file and sets defined values based on
+   the passed in configuration table. This table maps strings to values to
+   set along with the type of each of these values.
+   The difference between this and loc_read_conf is that this function returns
+   the file pointer position at the end of filling a config table. Also, it
+   reads a fixed number of parameters at a time which is equal to the length
+   of the configuration table. This functionality enables the caller to
+   repeatedly call the function to read data from the same file.
+
+PARAMETERS:
+   conf_fp : file pointer
+   config_table: table definition of strings to places to store information
+   table_length: length of the configuration table
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   0: Table filled successfully
+   1: No more parameters to read
+  -1: Error filling table
+
+SIDE EFFECTS
+   N/A
+===========================================================================*/
+int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table, uint32_t table_length)
+{
+    int ret=0;
+
+    unsigned int num_params=table_length;
+    if(conf_fp == NULL) {
+        LOC_LOGE("%s:%d]: ERROR: File pointer is NULL\n", __func__, __LINE__);
+        ret = -1;
+        goto err;
+    }
+
+    /* Clear all validity bits */
+    for(uint32_t i = 0; NULL != config_table && i < table_length; i++)
+    {
+        if(NULL != config_table[i].param_set)
+        {
+            *(config_table[i].param_set) = 0;
+        }
+    }
+
+    char input_buf[LOC_MAX_PARAM_LINE];  /* declare a char array */
+
+    LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params);
+    while(num_params)
+    {
+        if(!fgets(input_buf, LOC_MAX_PARAM_LINE, conf_fp)) {
+            LOC_LOGD("%s:%d]: fgets returned NULL\n", __func__, __LINE__);
+            break;
+        }
+
+        num_params -= loc_fill_conf_item(input_buf, config_table, table_length);
+    }
+
+err:
+    return ret;
+}
+
+/*===========================================================================
+FUNCTION loc_udpate_conf
+
+DESCRIPTION
+   Parses the passed in buffer for configuration items, and update the table
+   that is also passed in.
+
+Reads the specified configuration file and sets defined values based on
+   the passed in configuration table. This table maps strings to values to
+   set along with the type of each of these values.
+
+PARAMETERS:
+   conf_data: configuration items in bufferas a string
+   length: strlen(conf_data)
+   config_table: table definition of strings to places to store information
+   table_length: length of the configuration table
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   number of the records in the table that is updated at time of return.
+
+SIDE EFFECTS
+   N/A
+===========================================================================*/
+int loc_update_conf(const char* conf_data, int32_t length,
+                    loc_param_s_type* config_table, uint32_t table_length)
+{
+    int ret = -1;
+
+    if (conf_data && length && config_table && table_length) {
+        // make a copy, so we do not tokenize the original data
+        char* conf_copy = (char*)malloc(length+1);
+
+        if(conf_copy !=NULL)
+        {
+          memcpy(conf_copy, conf_data, length);
+          // we hard NULL the end of string to be safe
+          conf_copy[length] = 0;
+        }
+
+        // start with one record off
+        uint32_t num_params = table_length - 1;
+        char* saveptr = NULL;
+        char* input_buf = strtok_r(conf_copy, "\n", &saveptr);
+        ret = 0;
+
+        LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params);
+        while(num_params && input_buf) {
+            ret++;
+            num_params -= loc_fill_conf_item(input_buf, config_table, table_length);
+            input_buf = strtok_r(NULL, "\n", &saveptr);
+        }
+    }
+
+    return ret;
+}
+
+/*===========================================================================
+FUNCTION loc_read_conf
+
+DESCRIPTION
+   Reads the specified configuration file and sets defined values based on
+   the passed in configuration table. This table maps strings to values to
+   set along with the type of each of these values.
+
+PARAMETERS:
+   conf_file_name: configuration file to read
+   config_table: table definition of strings to places to store information
+   table_length: length of the configuration table
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   None
+
+SIDE EFFECTS
+   N/A
+===========================================================================*/
+void loc_read_conf(const char* conf_file_name, loc_param_s_type* config_table,
+                   uint32_t table_length)
+{
+    FILE *conf_fp = NULL;
+    char *lasts;
+    loc_param_v_type config_value;
+    uint32_t i;
+
+    if((conf_fp = fopen(conf_file_name, "r")) != NULL)
+    {
+        LOC_LOGD("%s: using %s", __FUNCTION__, conf_file_name);
+        if(table_length && config_table) {
+            loc_read_conf_r(conf_fp, config_table, table_length);
+            rewind(conf_fp);
+        }
+        loc_read_conf_r(conf_fp, loc_param_table, loc_param_num);
+        fclose(conf_fp);
+    }
+    /* Initialize logging mechanism with parsed data */
+    loc_logger_init(DEBUG_LEVEL, TIMESTAMP);
+}
diff --git a/gps/utils/loc_cfg.h b/gps/utils/loc_cfg.h
new file mode 100644
index 0000000..ea4865b
--- /dev/null
+++ b/gps/utils/loc_cfg.h
@@ -0,0 +1,91 @@
+/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef LOC_CFG_H
+#define LOC_CFG_H
+
+#include <stdio.h>
+#include <stdint.h>
+
+#define LOC_MAX_PARAM_NAME                 80
+#define LOC_MAX_PARAM_STRING               80
+#define LOC_MAX_PARAM_LINE    (LOC_MAX_PARAM_NAME + LOC_MAX_PARAM_STRING)
+
+#define UTIL_UPDATE_CONF(conf_data, len, config_table) \
+    loc_update_conf((conf_data), (len), (config_table), \
+                    sizeof(config_table) / sizeof(config_table[0]))
+
+#define UTIL_READ_CONF_DEFAULT(filename) \
+    loc_read_conf((filename), NULL, 0);
+
+#define UTIL_READ_CONF(filename, config_table) \
+    loc_read_conf((filename), (config_table), sizeof(config_table) / sizeof(config_table[0]))
+
+/*=============================================================================
+ *
+ *                        MODULE TYPE DECLARATION
+ *
+ *============================================================================*/
+typedef struct
+{
+  char                           param_name[LOC_MAX_PARAM_NAME];
+  void                          *param_ptr;
+  uint8_t                       *param_set;   /* was this value set by config file? */
+  char                           param_type;  /* 'n' for number,
+                                                 's' for string,
+                                                 'f' for float */
+} loc_param_s_type;
+
+/*=============================================================================
+ *
+ *                          MODULE EXTERNAL DATA
+ *
+ *============================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*=============================================================================
+ *
+ *                       MODULE EXPORTED FUNCTIONS
+ *
+ *============================================================================*/
+void loc_read_conf(const char* conf_file_name,
+                   loc_param_s_type* config_table,
+                   uint32_t table_length);
+int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table,
+                    uint32_t table_length);
+int loc_update_conf(const char* conf_data, int32_t length,
+                    loc_param_s_type* config_table, uint32_t table_length);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LOC_CFG_H */
diff --git a/gps/utils/loc_log.cpp b/gps/utils/loc_log.cpp
new file mode 100644
index 0000000..18182b7
--- /dev/null
+++ b/gps/utils/loc_log.cpp
@@ -0,0 +1,241 @@
+/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#define LOG_NDDEBUG 0
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include "loc_log.h"
+#include "msg_q.h"
+#ifdef USE_GLIB
+#include <time.h>
+#endif /* USE_GLIB  */
+#include "log_util.h"
+#include "platform_lib_includes.h"
+
+#define  BUFFER_SIZE  120
+
+// Logging Improvements
+const char *loc_logger_boolStr[]={"False","True"};
+const char VOID_RET[]   = "None";
+const char FROM_AFW[]   = "===>";
+const char TO_MODEM[]   = "--->";
+const char FROM_MODEM[] = "<---";
+const char TO_AFW[]     = "<===";
+const char EXIT_TAG[]   = "Exiting";
+const char ENTRY_TAG[]  = "Entering";
+
+/* Logging Mechanism */
+loc_logger_s_type loc_logger;
+
+/* Get names from value */
+const char* loc_get_name_from_mask(loc_name_val_s_type table[], int table_size, long mask)
+{
+   int i;
+   for (i = 0; i < table_size; i++)
+   {
+      if (table[i].val & (long) mask)
+      {
+         return table[i].name;
+      }
+   }
+   return UNKNOWN_STR;
+}
+
+/* Get names from value */
+const char* loc_get_name_from_val(loc_name_val_s_type table[], int table_size, long value)
+{
+   int i;
+   for (i = 0; i < table_size; i++)
+   {
+      if (table[i].val == (long) value)
+      {
+         return table[i].name;
+      }
+   }
+   return UNKNOWN_STR;
+}
+
+static loc_name_val_s_type loc_msg_q_status[] =
+{
+    NAME_VAL( eMSG_Q_SUCCESS ),
+    NAME_VAL( eMSG_Q_FAILURE_GENERAL ),
+    NAME_VAL( eMSG_Q_INVALID_PARAMETER ),
+    NAME_VAL( eMSG_Q_INVALID_HANDLE ),
+    NAME_VAL( eMSG_Q_UNAVAILABLE_RESOURCE ),
+    NAME_VAL( eMSG_Q_INSUFFICIENT_BUFFER )
+};
+static int loc_msg_q_status_num = sizeof(loc_msg_q_status) / sizeof(loc_name_val_s_type);
+
+/* Find msg_q status name */
+const char* loc_get_msg_q_status(int status)
+{
+   return loc_get_name_from_val(loc_msg_q_status, loc_msg_q_status_num, (long) status);
+}
+
+const char* log_succ_fail_string(int is_succ)
+{
+   return is_succ? "successful" : "failed";
+}
+
+//Target names
+loc_name_val_s_type target_name[] =
+{
+    NAME_VAL(GNSS_NONE),
+    NAME_VAL(GNSS_MSM),
+    NAME_VAL(GNSS_GSS),
+    NAME_VAL(GNSS_MDM),
+    NAME_VAL(GNSS_QCA1530),
+    NAME_VAL(GNSS_AUTO),
+    NAME_VAL(GNSS_UNKNOWN)
+};
+
+static int target_name_num = sizeof(target_name)/sizeof(loc_name_val_s_type);
+
+/*===========================================================================
+
+FUNCTION loc_get_target_name
+
+DESCRIPTION
+   Returns pointer to a string that contains name of the target
+
+   XX:XX:XX.000\0
+
+RETURN VALUE
+   The target name string
+
+===========================================================================*/
+const char *loc_get_target_name(unsigned int target)
+{
+    int index = 0;
+    static char ret[BUFFER_SIZE];
+
+    index =  getTargetGnssType(target);
+    if( index >= target_name_num || index < 0)
+        index = target_name_num - 1;
+
+    if( (target & HAS_SSC) == HAS_SSC ) {
+        snprintf(ret, sizeof(ret), " %s with SSC",
+           loc_get_name_from_val(target_name, target_name_num, (long)index) );
+    }
+    else {
+       snprintf(ret, sizeof(ret), " %s  without SSC",
+           loc_get_name_from_val(target_name, target_name_num, (long)index) );
+    }
+    return ret;
+}
+
+
+/*===========================================================================
+
+FUNCTION loc_get_time
+
+DESCRIPTION
+   Logs a callback event header.
+   The pointer time_string should point to a buffer of at least 13 bytes:
+
+   XX:XX:XX.000\0
+
+RETURN VALUE
+   The time string
+
+===========================================================================*/
+char *loc_get_time(char *time_string, unsigned long buf_size)
+{
+   struct timeval now;     /* sec and usec     */
+   struct tm now_tm;       /* broken-down time */
+   char hms_string[80];    /* HH:MM:SS         */
+
+   gettimeofday(&now, NULL);
+   localtime_r(&now.tv_sec, &now_tm);
+
+   strftime(hms_string, sizeof hms_string, "%H:%M:%S", &now_tm);
+   snprintf(time_string, buf_size, "%s.%03d", hms_string, (int) (now.tv_usec / 1000));
+
+   return time_string;
+}
+
+
+/*===========================================================================
+FUNCTION loc_logger_init
+
+DESCRIPTION
+   Initializes the state of DEBUG_LEVEL and TIMESTAMP
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   None
+
+SIDE EFFECTS
+   N/A
+===========================================================================*/
+void loc_logger_init(unsigned long debug, unsigned long timestamp)
+{
+   loc_logger.DEBUG_LEVEL = debug;
+#ifdef TARGET_BUILD_VARIANT_USER
+   // force user builds to 2 or less
+   if (loc_logger.DEBUG_LEVEL > 2) {
+       loc_logger.DEBUG_LEVEL = 2;
+   }
+#endif
+   loc_logger.TIMESTAMP   = timestamp;
+}
+
+
+/*===========================================================================
+FUNCTION get_timestamp
+
+DESCRIPTION
+   Generates a timestamp using the current system time
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Char pointer to the parameter str
+
+SIDE EFFECTS
+   N/A
+===========================================================================*/
+char * get_timestamp(char *str, unsigned long buf_size)
+{
+  struct timeval tv;
+  struct timezone tz;
+  int hh, mm, ss;
+  gettimeofday(&tv, &tz);
+  hh = tv.tv_sec/3600%24;
+  mm = (tv.tv_sec%3600)/60;
+  ss = tv.tv_sec%60;
+  snprintf(str, buf_size, "%02d:%02d:%02d.%06ld", hh, mm, ss, tv.tv_usec);
+  return str;
+}
+
diff --git a/gps/utils/loc_log.h b/gps/utils/loc_log.h
new file mode 100644
index 0000000..82dc636
--- /dev/null
+++ b/gps/utils/loc_log.h
@@ -0,0 +1,68 @@
+/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef LOC_LOG_H
+#define LOC_LOG_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <ctype.h>
+#include "loc_target.h"
+
+typedef struct
+{
+   char                 name[128];
+   long                 val;
+} loc_name_val_s_type;
+
+#define NAME_VAL(x) {"" #x "", x }
+
+#define UNKNOWN_STR "UNKNOWN"
+
+#define CHECK_MASK(type, value, mask_var, mask) \
+   ((mask_var & mask) ? (type) value : (type) (-1))
+
+/* Get names from value */
+const char* loc_get_name_from_mask(loc_name_val_s_type table[], int table_size, long mask);
+const char* loc_get_name_from_val(loc_name_val_s_type table[], int table_size, long value);
+const char* loc_get_msg_q_status(int status);
+const char* loc_get_target_name(unsigned int target);
+
+extern const char* log_succ_fail_string(int is_succ);
+
+extern char *loc_get_time(char *time_string, unsigned long buf_size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LOC_LOG_H */
diff --git a/gps/utils/loc_misc_utils.cpp b/gps/utils/loc_misc_utils.cpp
new file mode 100644
index 0000000..7e96313
--- /dev/null
+++ b/gps/utils/loc_misc_utils.cpp
@@ -0,0 +1,114 @@
+/* Copyright (c) 2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include <stdio.h>
+#include <string.h>
+#include <log_util.h>
+#include <loc_misc_utils.h>
+#include <ctype.h>
+
+#define LOG_NDDEBUG 0
+#define LOG_TAG "LocSvc_misc_utils"
+
+int loc_util_split_string(char *raw_string, char **split_strings_ptr,
+                          int max_num_substrings, char delimiter)
+{
+    int raw_string_index=0;
+    int num_split_strings=0;
+    unsigned char end_string=0;
+    int raw_string_length=0;
+
+    if(!raw_string || !split_strings_ptr) {
+        LOC_LOGE("%s:%d]: NULL parameters", __func__, __LINE__);
+        num_split_strings = -1;
+        goto err;
+    }
+    LOC_LOGD("%s:%d]: raw string: %s\n", __func__, __LINE__, raw_string);
+    raw_string_length = strlen(raw_string) + 1;
+    split_strings_ptr[num_split_strings] = &raw_string[raw_string_index];
+    for(raw_string_index=0; raw_string_index < raw_string_length; raw_string_index++) {
+        if(raw_string[raw_string_index] == '\0')
+            end_string=1;
+        if((raw_string[raw_string_index] == delimiter) || end_string) {
+            raw_string[raw_string_index] = '\0';
+            LOC_LOGD("%s:%d]: split string: %s\n",
+                     __func__, __LINE__, split_strings_ptr[num_split_strings]);
+            num_split_strings++;
+            if(((raw_string_index + 1) < raw_string_length) &&
+               (num_split_strings < max_num_substrings)) {
+                split_strings_ptr[num_split_strings] = &raw_string[raw_string_index+1];
+            }
+            else {
+                break;
+            }
+        }
+        if(end_string)
+            break;
+    }
+err:
+    LOC_LOGD("%s:%d]: num_split_strings: %d\n", __func__, __LINE__, num_split_strings);
+    return num_split_strings;
+}
+
+void loc_util_trim_space(char *org_string)
+{
+    char *scan_ptr, *write_ptr;
+    char *first_nonspace = NULL, *last_nonspace = NULL;
+
+    if(org_string == NULL) {
+        LOC_LOGE("%s:%d]: NULL parameter", __func__, __LINE__);
+        goto err;
+    }
+
+    scan_ptr = write_ptr = org_string;
+
+    while (*scan_ptr) {
+        //Find the first non-space character
+        if ( !isspace(*scan_ptr) && first_nonspace == NULL) {
+            first_nonspace = scan_ptr;
+        }
+        //Once the first non-space character is found in the
+        //above check, keep shifting the characters to the left
+        //to replace the spaces
+        if (first_nonspace != NULL) {
+            *(write_ptr++) = *scan_ptr;
+            //Keep track of which was the last non-space character
+            //encountered
+            //last_nonspace will not be updated in the case where
+            //the string ends with spaces
+            if ( !isspace(*scan_ptr)) {
+                last_nonspace = write_ptr;
+            }
+        }
+        scan_ptr++;
+    }
+    //Add NULL terminator after the last non-space character
+    if (last_nonspace) { *last_nonspace = '\0'; }
+err:
+    return;
+}
diff --git a/gps/utils/loc_misc_utils.h b/gps/utils/loc_misc_utils.h
new file mode 100644
index 0000000..7d66d84
--- /dev/null
+++ b/gps/utils/loc_misc_utils.h
@@ -0,0 +1,99 @@
+/* Copyright (c) 2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef _LOC_MISC_UTILS_H_
+#define _LOC_MISC_UTILS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*===========================================================================
+FUNCTION loc_split_string
+
+DESCRIPTION:
+    This function is used to split a delimiter separated string into
+    sub-strings. This function does not allocate new memory to store the split
+    strings. Instead, it places '\0' in places of delimiters and assings the
+    starting address of the substring within the raw string as the string address
+    The input raw_string no longer remains to be a collection of sub-strings
+    after this function is executed.
+    Please make a copy of the input string before calling this function if
+    necessary
+
+PARAMETERS:
+    char *raw_string: is the original string with delimiter separated substrings
+    char **split_strings_ptr: is the arraw of pointers which will hold the addresses
+                              of individual substrings
+    int max_num_substrings: is the maximum number of substrings that are expected
+                            by the caller. The array of pointers in the above parameter
+                            is usually this long
+    char delimiter: is the delimiter that separates the substrings. Examples: ' ', ';'
+
+DEPENDENCIES
+    N/A
+
+RETURN VALUE
+    int Number of split strings
+
+SIDE EFFECTS
+    The input raw_string no longer remains a delimiter separated single string.
+
+EXAMPLE
+    delimiter = ' ' //space
+    raw_string = "hello new user" //delimiter is space ' '
+    addresses  =  0123456789abcd
+    split_strings_ptr[0] = &raw_string[0]; //split_strings_ptr[0] contains "hello"
+    split_strings_ptr[1] = &raw_string[6]; //split_strings_ptr[1] contains "new"
+    split_strings_ptr[2] = &raw_string[a]; //split_strings_ptr[2] contains "user"
+
+===========================================================================*/
+int loc_util_split_string(char *raw_string, char **split_strings_ptr, int max_num_substrings,
+                     char delimiter);
+
+/*===========================================================================
+FUNCTION trim_space
+
+DESCRIPTION
+   Removes leading and trailing spaces of the string
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   None
+
+SIDE EFFECTS
+   N/A
+===========================================================================*/
+void loc_util_trim_space(char *org_string);
+#ifdef __cplusplus
+}
+#endif
+
+#endif //_LOC_MISC_UTILS_H_
diff --git a/gps/utils/loc_target.cpp b/gps/utils/loc_target.cpp
new file mode 100644
index 0000000..08f5584
--- /dev/null
+++ b/gps/utils/loc_target.cpp
@@ -0,0 +1,260 @@
+/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <hardware/gps.h>
+#include <cutils/properties.h>
+#include "loc_target.h"
+#include "loc_log.h"
+#include "log_util.h"
+
+#define APQ8064_ID_1 "109"
+#define APQ8064_ID_2 "153"
+#define MPQ8064_ID_1 "130"
+#define MSM8930_ID_1 "142"
+#define MSM8930_ID_2 "116"
+#define APQ8030_ID_1 "157"
+#define APQ8074_ID_1 "184"
+
+#define LINE_LEN 100
+#define STR_LIQUID    "Liquid"
+#define STR_SURF      "Surf"
+#define STR_MTP       "MTP"
+#define STR_APQ       "apq"
+#define STR_AUTO      "auto"
+#define IS_STR_END(c) ((c) == '\0' || (c) == '\n' || (c) == '\r')
+#define LENGTH(s) (sizeof(s) - 1)
+#define GPS_CHECK_NO_ERROR 0
+#define GPS_CHECK_NO_GPS_HW 1
+/* When system server is started, it uses 20 seconds as ActivityManager
+ * timeout. After that it sends SIGSTOP signal to process.
+ */
+#define QCA1530_DETECT_TIMEOUT 15
+#define QCA1530_DETECT_PRESENT "yes"
+#define QCA1530_DETECT_PROGRESS "detect"
+
+static unsigned int gTarget = (unsigned int)-1;
+
+static int read_a_line(const char * file_path, char * line, int line_size)
+{
+    FILE *fp;
+    int result = 0;
+
+    * line = '\0';
+    fp = fopen(file_path, "r" );
+    if( fp == NULL ) {
+        LOC_LOGE("open failed: %s: %s\n", file_path, strerror(errno));
+        result = -1;
+    } else {
+        int len;
+        fgets(line, line_size, fp);
+        len = strlen(line);
+        len = len < line_size - 1? len : line_size - 1;
+        line[len] = '\0';
+        LOC_LOGD("cat %s: %s", file_path, line);
+        fclose(fp);
+    }
+    return result;
+}
+
+/*!
+ * \brief Checks if QCA1530 is avalable.
+ *
+ * Function verifies if qca1530 SoC is configured on the device. The test is
+ * based on property value. For 1530 scenario, the value shall be one of the
+ * following: "yes", "no", "detect". All other values are treated equally to
+ * "no". When the value is "detect" the system waits for SoC detection to
+ * finish before returning result.
+ *
+ * \retval true - QCA1530 is available.
+ * \retval false - QCA1530 is not available.
+ */
+static bool is_qca1530(void)
+{
+    static const char qca1530_property_name[] = "sys.qca1530";
+    bool res = false;
+    int ret, i;
+    char buf[PROPERTY_VALUE_MAX];
+
+    memset(buf, 0, sizeof(buf));
+
+    for (i = 0; i < QCA1530_DETECT_TIMEOUT; ++i)
+    {
+        ret = property_get(qca1530_property_name, buf, NULL);
+        if (ret < 0)
+        {
+            LOC_LOGV( "qca1530: property %s is not accessible, ret=%d",
+                  qca1530_property_name,
+                  ret);
+
+            break;
+        }
+
+        LOC_LOGV( "qca1530: property %s is set to %s",
+                  qca1530_property_name,
+                  buf);
+
+        if (!memcmp(buf, QCA1530_DETECT_PRESENT,
+                    sizeof(QCA1530_DETECT_PRESENT)))
+        {
+            res = true;
+            break;
+        }
+        if (!memcmp(buf, QCA1530_DETECT_PROGRESS,
+                    sizeof(QCA1530_DETECT_PROGRESS)))
+        {
+            LOC_LOGV("qca1530: SoC detection is in progress.");
+            sleep(1);
+            continue;
+        }
+        break;
+    }
+
+    LOC_LOGD("qca1530: detected=%s", res ? "true" : "false");
+    return res;
+}
+
+/*The character array passed to this function should have length
+  of atleast PROPERTY_VALUE_MAX*/
+void loc_get_target_baseband(char *baseband, int array_length)
+{
+    if(baseband && (array_length >= PROPERTY_VALUE_MAX)) {
+        property_get("ro.baseband", baseband, "");
+        LOC_LOGD("%s:%d]: Baseband: %s\n", __func__, __LINE__, baseband);
+    }
+    else {
+        LOC_LOGE("%s:%d]: NULL parameter or array length less than PROPERTY_VALUE_MAX\n",
+                 __func__, __LINE__);
+    }
+}
+
+/*The character array passed to this function should have length
+  of atleast PROPERTY_VALUE_MAX*/
+void loc_get_platform_name(char *platform_name, int array_length)
+{
+    if(platform_name && (array_length >= PROPERTY_VALUE_MAX)) {
+        property_get("ro.board.platform", platform_name, "");
+        LOC_LOGD("%s:%d]: Target name: %s\n", __func__, __LINE__, platform_name);
+    }
+    else {
+        LOC_LOGE("%s:%d]: Null parameter or array length less than PROPERTY_VALUE_MAX\n",
+                 __func__, __LINE__);
+    }
+}
+
+unsigned int loc_get_target(void)
+{
+    if (gTarget != (unsigned int)-1)
+        return gTarget;
+
+    static const char hw_platform[]      = "/sys/devices/soc0/hw_platform";
+    static const char id[]               = "/sys/devices/soc0/soc_id";
+    static const char hw_platform_dep[]  =
+        "/sys/devices/system/soc/soc0/hw_platform";
+    static const char id_dep[]           = "/sys/devices/system/soc/soc0/id";
+    static const char mdm[]              = "/dev/mdm"; // No such file or directory
+
+    char rd_hw_platform[LINE_LEN];
+    char rd_id[LINE_LEN];
+    char rd_mdm[LINE_LEN];
+    char baseband[LINE_LEN];
+
+    if (is_qca1530()) {
+        gTarget = TARGET_QCA1530;
+        goto detected;
+    }
+
+    loc_get_target_baseband(baseband, sizeof(baseband));
+
+    if (!access(hw_platform, F_OK)) {
+        read_a_line(hw_platform, rd_hw_platform, LINE_LEN);
+    } else {
+        read_a_line(hw_platform_dep, rd_hw_platform, LINE_LEN);
+    }
+    if (!access(id, F_OK)) {
+        read_a_line(id, rd_id, LINE_LEN);
+    } else {
+        read_a_line(id_dep, rd_id, LINE_LEN);
+    }
+    if( !memcmp(baseband, STR_AUTO, LENGTH(STR_AUTO)) )
+    {
+          gTarget = TARGET_AUTO;
+          goto detected;
+    }
+    if( !memcmp(baseband, STR_APQ, LENGTH(STR_APQ)) ){
+
+        if( !memcmp(rd_id, MPQ8064_ID_1, LENGTH(MPQ8064_ID_1))
+            && IS_STR_END(rd_id[LENGTH(MPQ8064_ID_1)]) )
+            gTarget = TARGET_MPQ;
+        else
+            gTarget = TARGET_APQ_SA;
+    }
+    else {
+        if( (!memcmp(rd_hw_platform, STR_LIQUID, LENGTH(STR_LIQUID))
+             && IS_STR_END(rd_hw_platform[LENGTH(STR_LIQUID)])) ||
+            (!memcmp(rd_hw_platform, STR_SURF,   LENGTH(STR_SURF))
+             && IS_STR_END(rd_hw_platform[LENGTH(STR_SURF)])) ||
+            (!memcmp(rd_hw_platform, STR_MTP,   LENGTH(STR_MTP))
+             && IS_STR_END(rd_hw_platform[LENGTH(STR_MTP)]))) {
+
+            if (!read_a_line( mdm, rd_mdm, LINE_LEN))
+                gTarget = TARGET_MDM;
+        }
+        else if( (!memcmp(rd_id, MSM8930_ID_1, LENGTH(MSM8930_ID_1))
+                   && IS_STR_END(rd_id[LENGTH(MSM8930_ID_1)])) ||
+                  (!memcmp(rd_id, MSM8930_ID_2, LENGTH(MSM8930_ID_2))
+                   && IS_STR_END(rd_id[LENGTH(MSM8930_ID_2)])) )
+             gTarget = TARGET_MSM_NO_SSC;
+        else
+             gTarget = TARGET_UNKNOWN;
+    }
+
+detected:
+    LOC_LOGD("HAL: %s returned %d", __FUNCTION__, gTarget);
+    return gTarget;
+}
+
+/*Reads the property ro.lean to identify if this is a lean target
+  Returns:
+  0 if not a lean and mean target
+  1 if this is a lean and mean target
+*/
+int loc_identify_lean_target()
+{
+    int ret = 0;
+    char lean_target[PROPERTY_VALUE_MAX];
+    property_get("ro.lean", lean_target, "");
+    LOC_LOGD("%s:%d]: lean target: %s\n", __func__, __LINE__, lean_target);
+    return !(strncmp(lean_target, "true", PROPERTY_VALUE_MAX));
+}
diff --git a/gps/utils/loc_target.h b/gps/utils/loc_target.h
new file mode 100644
index 0000000..3bb3b5e
--- /dev/null
+++ b/gps/utils/loc_target.h
@@ -0,0 +1,82 @@
+/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef LOC_TARGET_H
+#define LOC_TARGET_H
+#define TARGET_SET(gnss,ssc) ( (gnss<<1)|ssc )
+#define TARGET_DEFAULT       TARGET_SET(GNSS_MSM, HAS_SSC)
+#define TARGET_MDM           TARGET_SET(GNSS_MDM, HAS_SSC)
+#define TARGET_APQ_SA        TARGET_SET(GNSS_GSS, NO_SSC)
+#define TARGET_MPQ           TARGET_SET(GNSS_NONE,NO_SSC)
+#define TARGET_MSM_NO_SSC    TARGET_SET(GNSS_MSM, NO_SSC)
+#define TARGET_QCA1530       TARGET_SET(GNSS_QCA1530, NO_SSC)
+#define TARGET_AUTO          TARGET_SET(GNSS_AUTO, NO_SSC)
+#define TARGET_UNKNOWN       TARGET_SET(GNSS_UNKNOWN, NO_SSC)
+#define getTargetGnssType(target)  (target>>1)
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+unsigned int loc_get_target(void);
+
+/*The character array passed to this function should have length
+  of atleast PROPERTY_VALUE_MAX*/
+void loc_get_target_baseband(char *baseband, int array_length);
+/*The character array passed to this function should have length
+  of atleast PROPERTY_VALUE_MAX*/
+void loc_get_platform_name(char *platform_name, int array_length);
+/*Reads the property ro.lean to identify if this is a lean target
+  Returns:
+  0 if not a lean and mean target
+  1 if this is a lean and mean target*/
+int loc_identify_lean_target();
+
+/* Please remember to update 'target_name' in loc_log.cpp,
+   if do any changes to this enum. */
+typedef enum {
+    GNSS_NONE = 0,
+    GNSS_MSM,
+    GNSS_GSS,
+    GNSS_MDM,
+    GNSS_QCA1530,
+    GNSS_AUTO,
+    GNSS_UNKNOWN
+}GNSS_TARGET;
+
+typedef enum {
+    NO_SSC = 0,
+    HAS_SSC
+}SSC_TYPE;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*LOC_TARGET_H*/
diff --git a/gps/utils/loc_timer.c b/gps/utils/loc_timer.c
new file mode 100644
index 0000000..2beca5f
--- /dev/null
+++ b/gps/utils/loc_timer.c
@@ -0,0 +1,202 @@
+/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include<stdio.h>
+#include<stdlib.h>
+#include<sys/time.h>
+#include "loc_timer.h"
+#include<time.h>
+#include<errno.h>
+
+enum timer_state {
+    READY = 100,
+    WAITING,
+    DONE,
+    ABORT
+};
+
+typedef struct {
+    loc_timer_callback callback_func;
+    void *user_data;
+    unsigned int time_msec;
+    pthread_cond_t timer_cond;
+    pthread_mutex_t timer_mutex;
+    enum timer_state state;
+}timer_data;
+
+static void *timer_thread(void *thread_data)
+{
+    int ret = -ETIMEDOUT;
+    struct timespec ts;
+    struct timeval tv;
+    timer_data* t = (timer_data*)thread_data;
+
+    LOC_LOGD("%s:%d]: Enter. Delay = %d\n", __func__, __LINE__, t->time_msec);
+
+    gettimeofday(&tv, NULL);
+    clock_gettime(CLOCK_REALTIME, &ts);
+    if(t->time_msec >= 1000) {
+        ts.tv_sec += t->time_msec/1000;
+        t->time_msec = t->time_msec % 1000;
+    }
+    if(t->time_msec)
+        ts.tv_nsec += t->time_msec * 1000000;
+    if(ts.tv_nsec > 999999999) {
+        LOC_LOGD("%s:%d]: Large nanosecs\n", __func__, __LINE__);
+        ts.tv_sec += 1;
+        ts.tv_nsec -= 1000000000;
+    }
+    LOC_LOGD("%s:%d]: ts.tv_sec:%d; ts.tv_nsec:%d\n"
+             "\t Current time: %d sec; %d nsec",
+             __func__, __LINE__, (int)ts.tv_sec, (int)ts.tv_nsec,
+             (int)tv.tv_sec, (int)tv.tv_usec*1000);
+
+    pthread_mutex_lock(&(t->timer_mutex));
+    if (READY == t->state) {
+        t->state = WAITING;
+        ret = pthread_cond_timedwait(&t->timer_cond, &t->timer_mutex, &ts);
+        t->state = DONE;
+    }
+    pthread_mutex_unlock(&(t->timer_mutex));
+
+    switch (ret) {
+    case ETIMEDOUT:
+        LOC_LOGV("%s:%d]: loc_timer timed out",  __func__, __LINE__);
+        break;
+    case 0:
+        LOC_LOGV("%s:%d]: loc_timer stopped",  __func__, __LINE__);
+        break;
+    case -ETIMEDOUT:
+        LOC_LOGV("%s:%d]: loc_timer cancelled",  __func__, __LINE__);
+        break;
+    default:
+        LOC_LOGE("%s:%d]: Call to pthread timedwait failed; ret=%d\n",
+                 __func__, __LINE__, ret);
+        break;
+    }
+
+    if(ETIMEDOUT == ret)
+        t->callback_func(t->user_data, ret);
+
+    // A (should be rare) race condition is that, when the loc_time_stop is called
+    // and acquired mutex, we reach here.  pthread_mutex_destroy will fail with
+    // error code EBUSY.  We give it 6 tries in 5 seconds.  Should be eanough time
+    // for loc_timer_stop to complete.  With the 7th try, we also perform unlock
+    // prior to destroy.
+    {
+        int i;
+        for (i = 0; EBUSY == pthread_mutex_destroy(&t->timer_mutex) && i <= 5; i++) {
+            if (i < 5) {
+                sleep(1);
+            } else {
+                // nah, forget it, something is seriously wrong.  Mutex has been
+                // held too long.  Unlock the mutext here.
+                pthread_mutex_unlock(&t->timer_mutex);
+            }
+        }
+    }
+    pthread_cond_destroy(&t->timer_cond);
+
+    free(t);
+    LOC_LOGD("%s:%d]: Exit\n", __func__, __LINE__);
+    return NULL;
+}
+
+void* loc_timer_start(unsigned int msec, loc_timer_callback cb_func,
+                      void* caller_data)
+{
+    timer_data *t=NULL;
+    pthread_attr_t tattr;
+    pthread_t id;
+    LOC_LOGD("%s:%d]: Enter\n", __func__, __LINE__);
+    if(cb_func == NULL || msec == 0) {
+        LOC_LOGE("%s:%d]: Error: Wrong parameters\n", __func__, __LINE__);
+        goto _err;
+    }
+    t = (timer_data *)calloc(1, sizeof(timer_data));
+    if(t == NULL) {
+        LOC_LOGE("%s:%d]: Could not allocate memory. Failing.\n",
+                 __func__, __LINE__);
+        goto _err;
+    }
+
+    if(pthread_cond_init(&(t->timer_cond), NULL)) {
+        LOC_LOGE("%s:%d]: Pthread cond init failed\n", __func__, __LINE__);
+        goto t_err;
+    }
+    if(pthread_mutex_init(&(t->timer_mutex), NULL)) {
+        LOC_LOGE("%s:%d]: Pthread mutex init failed\n", __func__, __LINE__);
+        goto cond_err;
+    }
+
+    t->callback_func = cb_func;
+    t->user_data = caller_data;
+    t->time_msec = msec;
+    t->state = READY;
+
+    if (pthread_attr_init(&tattr)) {
+        LOC_LOGE("%s:%d]: Pthread mutex init failed\n", __func__, __LINE__);
+        goto mutex_err;
+    }
+    pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
+
+    if(pthread_create(&(id), &tattr, timer_thread, (void *)t)) {
+        LOC_LOGE("%s:%d]: Could not create thread\n", __func__, __LINE__);
+        goto attr_err;
+    }
+
+    LOC_LOGD("%s:%d]: Created thread with id: %d\n",
+             __func__, __LINE__, (int)id);
+    goto _err;
+
+attr_err:
+    pthread_attr_destroy(&tattr);
+mutex_err:
+    pthread_mutex_destroy(&t->timer_mutex);
+cond_err:
+    pthread_cond_destroy(&t->timer_cond);
+t_err:
+    free(t);
+_err:
+    LOC_LOGD("%s:%d]: Exit\n", __func__, __LINE__);
+    return t;
+}
+
+void loc_timer_stop(void* handle) {
+    timer_data* t = (timer_data*)handle;
+
+    if (NULL != t && (READY == t->state || WAITING == t->state) &&
+        pthread_mutex_lock(&(t->timer_mutex)) == 0) {
+        if (READY == t->state || WAITING == t->state) {
+            pthread_cond_signal(&t->timer_cond);
+            t->state = ABORT;
+        }
+        pthread_mutex_unlock(&(t->timer_mutex));
+    }
+}
diff --git a/gps/utils/loc_timer.h b/gps/utils/loc_timer.h
new file mode 100644
index 0000000..0034d27
--- /dev/null
+++ b/gps/utils/loc_timer.h
@@ -0,0 +1,63 @@
+/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef __LOC_DELAY_H__
+#define __LOC_DELAY_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#include<pthread.h>
+#include "log_util.h"
+
+/*
+  Return values:
+  Success = 0
+  Failure = Non zero
+*/
+typedef void(*loc_timer_callback)(void *user_data, int result);
+
+
+/*
+  Returns the handle, which can be used to stop the timer
+*/
+void* loc_timer_start(unsigned int delay_msec,
+                      loc_timer_callback,
+                      void* user_data);
+
+/*
+  handle becomes invalid upon the return of the callback
+*/
+void loc_timer_stop(void* handle);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif //__LOC_DELAY_H__
diff --git a/gps/utils/log_util.h b/gps/utils/log_util.h
new file mode 100644
index 0000000..8ff6b5a
--- /dev/null
+++ b/gps/utils/log_util.h
@@ -0,0 +1,181 @@
+/* Copyright (c) 2011-2014 The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef __LOG_UTIL_H__
+#define __LOG_UTIL_H__
+
+#ifndef USE_GLIB
+#include <utils/Log.h>
+#endif /* USE_GLIB */
+
+#ifdef USE_GLIB
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#ifndef LOG_TAG
+#define LOG_TAG "GPS_UTILS"
+
+#endif  // LOG_TAG
+
+#endif /* USE_GLIB */
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/*=============================================================================
+ *
+ *                         LOC LOGGER TYPE DECLARATION
+ *
+ *============================================================================*/
+/* LOC LOGGER */
+typedef struct loc_logger_s
+{
+  unsigned long  DEBUG_LEVEL;
+  unsigned long  TIMESTAMP;
+} loc_logger_s_type;
+
+/*=============================================================================
+ *
+ *                               EXTERNAL DATA
+ *
+ *============================================================================*/
+extern loc_logger_s_type loc_logger;
+
+// Logging Improvements
+extern const char *loc_logger_boolStr[];
+
+extern const char *boolStr[];
+extern const char VOID_RET[];
+extern const char FROM_AFW[];
+extern const char TO_MODEM[];
+extern const char FROM_MODEM[];
+extern const char TO_AFW[];
+extern const char EXIT_TAG[];
+extern const char ENTRY_TAG[];
+/*=============================================================================
+ *
+ *                        MODULE EXPORTED FUNCTIONS
+ *
+ *============================================================================*/
+extern void loc_logger_init(unsigned long debug, unsigned long timestamp);
+extern char* get_timestamp(char* str, unsigned long buf_size);
+
+#ifndef DEBUG_DMN_LOC_API
+
+/* LOGGING MACROS */
+/*loc_logger.DEBUG_LEVEL is initialized to 0xff in loc_cfg.cpp
+  if that value remains unchanged, it means gps.conf did not
+  provide a value and we default to the initial value to use
+  Android's logging levels*/
+#define IF_LOC_LOGE if((loc_logger.DEBUG_LEVEL >= 1) && (loc_logger.DEBUG_LEVEL <= 5))
+
+#define IF_LOC_LOGW if((loc_logger.DEBUG_LEVEL >= 2) && (loc_logger.DEBUG_LEVEL <= 5))
+
+#define IF_LOC_LOGI if((loc_logger.DEBUG_LEVEL >= 3) && (loc_logger.DEBUG_LEVEL <= 5))
+
+#define IF_LOC_LOGD if((loc_logger.DEBUG_LEVEL >= 4) && (loc_logger.DEBUG_LEVEL <= 5))
+
+#define IF_LOC_LOGV if((loc_logger.DEBUG_LEVEL >= 5) && (loc_logger.DEBUG_LEVEL <= 5))
+
+#define LOC_LOGE(...) \
+IF_LOC_LOGE { ALOGE("E/" __VA_ARGS__); } \
+else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGE("E/" __VA_ARGS__); }
+
+#define LOC_LOGW(...) \
+IF_LOC_LOGW { ALOGE("W/" __VA_ARGS__); }  \
+else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGW("W/" __VA_ARGS__); }
+
+#define LOC_LOGI(...) \
+IF_LOC_LOGI { ALOGE("I/" __VA_ARGS__); }   \
+else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGI("I/" __VA_ARGS__); }
+
+#define LOC_LOGD(...) \
+IF_LOC_LOGD { ALOGE("D/" __VA_ARGS__); }   \
+else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGD("D/" __VA_ARGS__); }
+
+#define LOC_LOGV(...) \
+IF_LOC_LOGV { ALOGE("V/" __VA_ARGS__); }   \
+else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGV("V/" __VA_ARGS__); }
+
+#else /* DEBUG_DMN_LOC_API */
+
+#define LOC_LOGE(...) ALOGE("E/" __VA_ARGS__)
+
+#define LOC_LOGW(...) ALOGW("W/" __VA_ARGS__)
+
+#define LOC_LOGI(...) ALOGI("I/" __VA_ARGS__)
+
+#define LOC_LOGD(...) ALOGD("D/" __VA_ARGS__)
+
+#define LOC_LOGV(...) ALOGV("V/" __VA_ARGS__)
+
+#endif /* DEBUG_DMN_LOC_API */
+
+/*=============================================================================
+ *
+ *                          LOGGING IMPROVEMENT MACROS
+ *
+ *============================================================================*/
+#define LOG_(LOC_LOG, ID, WHAT, SPEC, VAL)                                    \
+    do {                                                                      \
+        if (loc_logger.TIMESTAMP) {                                           \
+            char ts[32];                                                      \
+            LOC_LOG("[%s] %s %s line %d " #SPEC,                              \
+                     get_timestamp(ts, sizeof(ts)), ID, WHAT, __LINE__, VAL); \
+        } else {                                                              \
+            LOC_LOG("%s %s line %d " #SPEC,                                   \
+                     ID, WHAT, __LINE__, VAL);                                \
+        }                                                                     \
+    } while(0)
+
+
+#define LOG_I(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGI, ID, WHAT, SPEC, VAL)
+#define LOG_V(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGV, ID, WHAT, SPEC, VAL)
+
+#define ENTRY_LOG() LOG_V(ENTRY_TAG, __func__, %s, "")
+#define EXIT_LOG(SPEC, VAL) LOG_V(EXIT_TAG, __func__, SPEC, VAL)
+
+
+// Used for logging callflow from Android Framework
+#define ENTRY_LOG_CALLFLOW() LOG_I(FROM_AFW, __func__, %s, "")
+// Used for logging callflow to Modem
+#define EXIT_LOG_CALLFLOW(SPEC, VAL) LOG_I(TO_MODEM, __func__, SPEC, VAL)
+// Used for logging callflow from Modem(TO_MODEM, __func__, %s, "")
+#define MODEM_LOG_CALLFLOW(SPEC, VAL) LOG_I(FROM_MODEM, __func__, SPEC, VAL)
+// Used for logging callflow to Android Framework
+#define CALLBACK_LOG_CALLFLOW(CB, SPEC, VAL) LOG_I(TO_AFW, CB, SPEC, VAL)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __LOG_UTIL_H__
diff --git a/gps/utils/msg_q.c b/gps/utils/msg_q.c
new file mode 100644
index 0000000..f82d4c0
--- /dev/null
+++ b/gps/utils/msg_q.c
@@ -0,0 +1,336 @@
+/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation, nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "msg_q.h"
+
+#define LOG_TAG "LocSvc_utils_q"
+#include "log_util.h"
+#include "platform_lib_includes.h"
+#include "linked_list.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+
+typedef struct msg_q {
+   void* msg_list;                  /* Linked list to store information */
+   pthread_cond_t  list_cond;       /* Condition variable for waiting on msg queue */
+   pthread_mutex_t list_mutex;      /* Mutex for exclusive access to message queue */
+   int unblocked;                   /* Has this message queue been unblocked? */
+} msg_q;
+
+/*===========================================================================
+FUNCTION    convert_linked_list_err_type
+
+DESCRIPTION
+   Converts from one set of enum values to another.
+
+   linked_list_val: Value to convert to msg_q_enum_type
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Corresponding linked_list_enum_type in msg_q_enum_type
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+static msq_q_err_type convert_linked_list_err_type(linked_list_err_type linked_list_val)
+{
+   switch( linked_list_val )
+   {
+   case eLINKED_LIST_SUCCESS:
+      return eMSG_Q_SUCCESS;
+   case eLINKED_LIST_INVALID_PARAMETER:
+      return eMSG_Q_INVALID_PARAMETER;
+   case eLINKED_LIST_INVALID_HANDLE:
+      return eMSG_Q_INVALID_HANDLE;
+   case eLINKED_LIST_UNAVAILABLE_RESOURCE:
+      return eMSG_Q_UNAVAILABLE_RESOURCE;
+   case eLINKED_LIST_INSUFFICIENT_BUFFER:
+      return eMSG_Q_INSUFFICIENT_BUFFER;
+
+   case eLINKED_LIST_FAILURE_GENERAL:
+   default:
+      return eMSG_Q_FAILURE_GENERAL;
+   }
+}
+
+/* ----------------------- END INTERNAL FUNCTIONS ---------------------------------------- */
+
+/*===========================================================================
+
+  FUNCTION:   msg_q_init
+
+  ===========================================================================*/
+msq_q_err_type msg_q_init(void** msg_q_data)
+{
+   if( msg_q_data == NULL )
+   {
+      LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__);
+      return eMSG_Q_INVALID_PARAMETER;
+   }
+
+   msg_q* tmp_msg_q;
+   tmp_msg_q = (msg_q*)calloc(1, sizeof(msg_q));
+   if( tmp_msg_q == NULL )
+   {
+      LOC_LOGE("%s: Unable to allocate space for message queue!\n", __FUNCTION__);
+      return eMSG_Q_FAILURE_GENERAL;
+   }
+
+   if( linked_list_init(&tmp_msg_q->msg_list) != 0 )
+   {
+      LOC_LOGE("%s: Unable to initialize storage list!\n", __FUNCTION__);
+      free(tmp_msg_q);
+      return eMSG_Q_FAILURE_GENERAL;
+   }
+
+   if( pthread_mutex_init(&tmp_msg_q->list_mutex, NULL) != 0 )
+   {
+      LOC_LOGE("%s: Unable to initialize list mutex!\n", __FUNCTION__);
+      linked_list_destroy(&tmp_msg_q->msg_list);
+      free(tmp_msg_q);
+      return eMSG_Q_FAILURE_GENERAL;
+   }
+
+   if( pthread_cond_init(&tmp_msg_q->list_cond, NULL) != 0 )
+   {
+      LOC_LOGE("%s: Unable to initialize msg q cond var!\n", __FUNCTION__);
+      linked_list_destroy(&tmp_msg_q->msg_list);
+      pthread_mutex_destroy(&tmp_msg_q->list_mutex);
+      free(tmp_msg_q);
+      return eMSG_Q_FAILURE_GENERAL;
+   }
+
+   tmp_msg_q->unblocked = 0;
+
+   *msg_q_data = tmp_msg_q;
+
+   return eMSG_Q_SUCCESS;
+}
+
+/*===========================================================================
+
+  FUNCTION:   msg_q_init2
+
+  ===========================================================================*/
+const void* msg_q_init2()
+{
+  void* q = NULL;
+  if (eMSG_Q_SUCCESS != msg_q_init(&q)) {
+    q = NULL;
+  }
+  return q;
+}
+
+/*===========================================================================
+
+  FUNCTION:   msg_q_destroy
+
+  ===========================================================================*/
+msq_q_err_type msg_q_destroy(void** msg_q_data)
+{
+   if( msg_q_data == NULL )
+   {
+      LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__);
+      return eMSG_Q_INVALID_HANDLE;
+   }
+
+   msg_q* p_msg_q = (msg_q*)*msg_q_data;
+
+   linked_list_destroy(&p_msg_q->msg_list);
+   pthread_mutex_destroy(&p_msg_q->list_mutex);
+   pthread_cond_destroy(&p_msg_q->list_cond);
+
+   p_msg_q->unblocked = 0;
+
+   free(*msg_q_data);
+   *msg_q_data = NULL;
+
+   return eMSG_Q_SUCCESS;
+}
+
+/*===========================================================================
+
+  FUNCTION:   msg_q_snd
+
+  ===========================================================================*/
+msq_q_err_type msg_q_snd(void* msg_q_data, void* msg_obj, void (*dealloc)(void*))
+{
+   msq_q_err_type rv;
+   if( msg_q_data == NULL )
+   {
+      LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__);
+      return eMSG_Q_INVALID_HANDLE;
+   }
+   if( msg_obj == NULL )
+   {
+      LOC_LOGE("%s: Invalid msg_obj parameter!\n", __FUNCTION__);
+      return eMSG_Q_INVALID_PARAMETER;
+   }
+
+   msg_q* p_msg_q = (msg_q*)msg_q_data;
+
+   pthread_mutex_lock(&p_msg_q->list_mutex);
+   LOC_LOGD("%s: Sending message with handle = 0x%08X\n", __FUNCTION__, msg_obj);
+
+   if( p_msg_q->unblocked )
+   {
+      LOC_LOGE("%s: Message queue has been unblocked.\n", __FUNCTION__);
+      pthread_mutex_unlock(&p_msg_q->list_mutex);
+      return eMSG_Q_UNAVAILABLE_RESOURCE;
+   }
+
+   rv = convert_linked_list_err_type(linked_list_add(p_msg_q->msg_list, msg_obj, dealloc));
+
+   /* Show data is in the message queue. */
+   pthread_cond_signal(&p_msg_q->list_cond);
+
+   pthread_mutex_unlock(&p_msg_q->list_mutex);
+
+   LOC_LOGD("%s: Finished Sending message with handle = 0x%08X\n", __FUNCTION__, msg_obj);
+
+   return rv;
+}
+
+/*===========================================================================
+
+  FUNCTION:   msg_q_rcv
+
+  ===========================================================================*/
+msq_q_err_type msg_q_rcv(void* msg_q_data, void** msg_obj)
+{
+   msq_q_err_type rv;
+   if( msg_q_data == NULL )
+   {
+      LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__);
+      return eMSG_Q_INVALID_HANDLE;
+   }
+
+   if( msg_obj == NULL )
+   {
+      LOC_LOGE("%s: Invalid msg_obj parameter!\n", __FUNCTION__);
+      return eMSG_Q_INVALID_PARAMETER;
+   }
+
+   msg_q* p_msg_q = (msg_q*)msg_q_data;
+
+   LOC_LOGD("%s: Waiting on message\n", __FUNCTION__);
+
+   pthread_mutex_lock(&p_msg_q->list_mutex);
+
+   if( p_msg_q->unblocked )
+   {
+      LOC_LOGE("%s: Message queue has been unblocked.\n", __FUNCTION__);
+      pthread_mutex_unlock(&p_msg_q->list_mutex);
+      return eMSG_Q_UNAVAILABLE_RESOURCE;
+   }
+
+   /* Wait for data in the message queue */
+   while( linked_list_empty(p_msg_q->msg_list) && !p_msg_q->unblocked )
+   {
+      pthread_cond_wait(&p_msg_q->list_cond, &p_msg_q->list_mutex);
+   }
+
+   rv = convert_linked_list_err_type(linked_list_remove(p_msg_q->msg_list, msg_obj));
+
+   pthread_mutex_unlock(&p_msg_q->list_mutex);
+
+   LOC_LOGD("%s: Received message 0x%08X rv = %d\n", __FUNCTION__, *msg_obj, rv);
+
+   return rv;
+}
+
+/*===========================================================================
+
+  FUNCTION:   msg_q_flush
+
+  ===========================================================================*/
+msq_q_err_type msg_q_flush(void* msg_q_data)
+{
+   msq_q_err_type rv;
+   if ( msg_q_data == NULL )
+   {
+      LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__);
+      return eMSG_Q_INVALID_HANDLE;
+   }
+
+   msg_q* p_msg_q = (msg_q*)msg_q_data;
+
+   LOC_LOGD("%s: Flushing Message Queue\n", __FUNCTION__);
+
+   pthread_mutex_lock(&p_msg_q->list_mutex);
+
+   /* Remove all elements from the list */
+   rv = convert_linked_list_err_type(linked_list_flush(p_msg_q->msg_list));
+
+   pthread_mutex_unlock(&p_msg_q->list_mutex);
+
+   LOC_LOGD("%s: Message Queue flushed\n", __FUNCTION__);
+
+   return rv;
+}
+
+/*===========================================================================
+
+  FUNCTION:   msg_q_unblock
+
+  ===========================================================================*/
+msq_q_err_type msg_q_unblock(void* msg_q_data)
+{
+   if ( msg_q_data == NULL )
+   {
+      LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__);
+      return eMSG_Q_INVALID_HANDLE;
+   }
+
+   msg_q* p_msg_q = (msg_q*)msg_q_data;
+   pthread_mutex_lock(&p_msg_q->list_mutex);
+
+   if( p_msg_q->unblocked )
+   {
+      LOC_LOGE("%s: Message queue has been unblocked.\n", __FUNCTION__);
+      pthread_mutex_unlock(&p_msg_q->list_mutex);
+      return eMSG_Q_UNAVAILABLE_RESOURCE;
+   }
+
+   LOC_LOGD("%s: Unblocking Message Queue\n", __FUNCTION__);
+   /* Unblocking message queue */
+   p_msg_q->unblocked = 1;
+
+   /* Allow all the waiters to wake up */
+   pthread_cond_broadcast(&p_msg_q->list_cond);
+
+   pthread_mutex_unlock(&p_msg_q->list_mutex);
+
+   LOC_LOGD("%s: Message Queue unblocked\n", __FUNCTION__);
+
+   return eMSG_Q_SUCCESS;
+}
diff --git a/gps/utils/msg_q.h b/gps/utils/msg_q.h
new file mode 100644
index 0000000..453b8ce
--- /dev/null
+++ b/gps/utils/msg_q.h
@@ -0,0 +1,207 @@
+/* Copyright (c) 2011, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __MSG_Q_H__
+#define __MSG_Q_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <stdlib.h>
+
+/** Linked List Return Codes */
+typedef enum
+{
+  eMSG_Q_SUCCESS                             = 0,
+     /**< Request was successful. */
+  eMSG_Q_FAILURE_GENERAL                     = -1,
+     /**< Failed because of a general failure. */
+  eMSG_Q_INVALID_PARAMETER                   = -2,
+     /**< Failed because the request contained invalid parameters. */
+  eMSG_Q_INVALID_HANDLE                      = -3,
+     /**< Failed because an invalid handle was specified. */
+  eMSG_Q_UNAVAILABLE_RESOURCE                = -4,
+     /**< Failed because an there were not enough resources. */
+  eMSG_Q_INSUFFICIENT_BUFFER                 = -5,
+     /**< Failed because an the supplied buffer was too small. */
+}msq_q_err_type;
+
+/*===========================================================================
+FUNCTION    msg_q_init
+
+DESCRIPTION
+   Initializes internal structures for message queue.
+
+   msg_q_data: pointer to an opaque Q handle to be returned; NULL if fails
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Look at error codes above.
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+msq_q_err_type msg_q_init(void** msg_q_data);
+
+/*===========================================================================
+FUNCTION    msg_q_init2
+
+DESCRIPTION
+   Initializes internal structures for message queue.
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   opaque handle to the Q created; NULL if create fails
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+const void* msg_q_init2();
+
+/*===========================================================================
+FUNCTION    msg_q_destroy
+
+DESCRIPTION
+   Releases internal structures for message queue.
+
+   msg_q_data: State of message queue to be released.
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Look at error codes above.
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+msq_q_err_type msg_q_destroy(void** msg_q_data);
+
+/*===========================================================================
+FUNCTION    msg_q_snd
+
+DESCRIPTION
+   Sends data to the message queue. The passed in data pointer
+   is not modified or freed. Passed in msg_obj is expected to live throughout
+   the use of the msg_q (i.e. data is not allocated internally)
+
+   msg_q_data: Message Queue to add the element to.
+   msgp:       Pointer to data to add into message queue.
+   dealloc:    Function used to deallocate memory for this element. Pass NULL
+               if you do not want data deallocated during a flush operation
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Look at error codes above.
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+msq_q_err_type msg_q_snd(void* msg_q_data, void* msg_obj, void (*dealloc)(void*));
+
+/*===========================================================================
+FUNCTION    msg_q_rcv
+
+DESCRIPTION
+   Retrieves data from the message queue. msg_obj is the oldest message received
+   and pointer is simply removed from message queue.
+
+   msg_q_data: Message Queue to copy data from into msgp.
+   msg_obj:    Pointer to space to copy msg_q contents to.
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Look at error codes above.
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+msq_q_err_type msg_q_rcv(void* msg_q_data, void** msg_obj);
+
+/*===========================================================================
+FUNCTION    msg_q_flush
+
+DESCRIPTION
+   Function removes all elements from the message queue.
+
+   msg_q_data: Message Queue to remove elements from.
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Look at error codes above.
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+msq_q_err_type msg_q_flush(void* msg_q_data);
+
+/*===========================================================================
+FUNCTION    msg_q_unblock
+
+DESCRIPTION
+   This function will stop use of the message queue. All waiters will wake up
+   and likely receive nothing from the queue resulting in a negative return
+   value. The message queue can no longer be used until it is destroyed
+   and initialized again after calling this function.
+
+   msg_q_data: Message queue to unblock.
+
+DEPENDENCIES
+   N/A
+
+RETURN VALUE
+   Look at error codes above.
+
+SIDE EFFECTS
+   N/A
+
+===========================================================================*/
+msq_q_err_type msg_q_unblock(void* msg_q_data);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __MSG_Q_H__ */