msm8998: Update to 07.00.00.279.027

.: from hardware/qcom/gps
  fb6ada7 LOC logging macro changes
  a41371d Adding ATL call flow to new Loc API interface
  1f0f30d hidl gnss hal 1.0 implementation
  dcaa2b1 LocationAPI implementation
  17227a4 Add explicit liblog dependency
  10f961e fixing a race condition on MsgTask::destroy() am: 4eda8e1eab am: 4797bfa900 am: acd98bcaab
  dabb110 fixing a race condition on MsgTask::destroy() am: 4eda8e1eab am: 6a27094a7b am: ecb76928eb
  acd98bc fixing a race condition on MsgTask::destroy() am: 4eda8e1eab am: 4797bfa900
  ecb7692 fixing a race condition on MsgTask::destroy() am: 4eda8e1eab am: 6a27094a7b
  4797bfa fixing a race condition on MsgTask::destroy() am: 4eda8e1eab
  6a27094 fixing a race condition on MsgTask::destroy() am: 4eda8e1eab
  4eda8e1 fixing a race condition on MsgTask::destroy()
  96349ca msm8998: Update to 07.00.00.253.056
  f7bbba4 Merge "Depend on libandroid_runtime" am: 82dd9367cf am: 1a94090191 am: 634a10c780 am: 2a7e5e066f
  2a7e5e0 Merge "Depend on libandroid_runtime" am: 82dd9367cf am: 1a94090191 am: 634a10c780
  634a10c Merge "Depend on libandroid_runtime" am: 82dd9367cf am: 1a94090191
  1a94090 Merge "Depend on libandroid_runtime" am: 82dd9367cf
  82dd936 Merge "Depend on libandroid_runtime"
  edc762c Depend on libandroid_runtime
  ada6527 Depend on libandroid_runtime
  435b813 msm8998: rename msmcobalt to msm8998 am: 02f13da8e1 am: 6e9861804c
  6e98618 msm8998: rename msmcobalt to msm8998 am: 02f13da8e1
  02f13da msm8998: rename msmcobalt to msm8998
  99a2828 Merge "Added XTRA CA path to gps.conf am: 47b626358a am: da0886d286" into nyc-mr2-dev-plus-aosp am: bd59daa7b2
  0be00e4 Added XTRA CA path to gps.conf am: 47b626358a am: da0886d286 am: 558ea5a345
  3626f27 Added XTRA CA path to gps.conf am: 47b626358a am: 07377b1319 am: cc1c500b57
  bd59daa Merge "Added XTRA CA path to gps.conf am: 47b626358a am: da0886d286" into nyc-mr2-dev-plus-aosp
  558ea5a Added XTRA CA path to gps.conf am: 47b626358a am: da0886d286
  cc1c500 Added XTRA CA path to gps.conf am: 47b626358a am: 07377b1319
  07377b1 Added XTRA CA path to gps.conf am: 47b626358a
  da0886d Added XTRA CA path to gps.conf am: 47b626358a
  47b6263 Added XTRA CA path to gps.conf
  73da450 msmcobalt: Update to LA.UM.5.7_RB1.07.00.00.251.006 am: c2fbb41f69 am: 2fc9d83718
  2fc9d83 msmcobalt: Update to LA.UM.5.7_RB1.07.00.00.251.006 am: c2fbb41f69
  c2fbb41 msmcobalt: Update to LA.UM.5.7_RB1.07.00.00.251.006
  088623b gps: enable SAP am: c5b4bd3794 am: e646f881b5
  e646f88 gps: enable SAP am: c5b4bd3794
  c5b4bd3 gps: enable SAP
  b0f6b2c msmcobalt: Update to 07.00.00.253.039 am: bc2807add2 am: 93f2dceb14 am: f1c1d98026 am: 9e55f15c05
  faf90fa fixed a copy paste error am: 90ff845856 am: 16f3d1e963 am: b0d47c984c
  9e55f15 msmcobalt: Update to 07.00.00.253.039 am: bc2807add2 am: 93f2dceb14 am: f1c1d98026
  b0d47c9 fixed a copy paste error am: 90ff845856 am: 16f3d1e963
  f1c1d98 msmcobalt: Update to 07.00.00.253.039 am: bc2807add2 am: 93f2dceb14
  16f3d1e fixed a copy paste error am: 90ff845856
  5446d0f Prevent gps.conf from being included twice on swordfish.
  0bedfd7 Changes to have swordfish build.
  c992f49 msmcobalt: Update to 07.00.00.253.042 am: 63f8eb733a am: a88d1331b7
  a88d133 msmcobalt: Update to 07.00.00.253.042 am: 63f8eb733a
  63f8eb7 msmcobalt: Update to 07.00.00.253.042
  2e35081 Merge "fix warning: Use of memory after it is freed" am: 05ef6c51f6 am: 314acc48fb am: 75034fd5a1 am: c5484e5147
  c5484e5 Merge "fix warning: Use of memory after it is freed" am: 05ef6c51f6 am: 314acc48fb am: 75034fd5a1
  75034fd Merge "fix warning: Use of memory after it is freed" am: 05ef6c51f6 am: 314acc48fb
  314acc4 Merge "fix warning: Use of memory after it is freed" am: 05ef6c51f6
  05ef6c5 Merge "fix warning: Use of memory after it is freed"
  9853496 fix warning: Use of memory after it is freed
  cf7e221 msmcobalt: Update to 07.00.00.253.039 am: bc2807add2 am: 93f2dceb14 am: 829ed002cb am: 21c8fa6dc8
  21c8fa6 msmcobalt: Update to 07.00.00.253.039 am: bc2807add2 am: 93f2dceb14 am: 829ed002cb
  829ed00 msmcobalt: Update to 07.00.00.253.039 am: bc2807add2 am: 93f2dceb14
  93f2dce msmcobalt: Update to 07.00.00.253.039 am: bc2807add2
  bc2807a msmcobalt: Update to 07.00.00.253.039
  539077a fixed a copy paste error am: 90ff845856 am: 30f9d208cb am: 39fe507fdb
  39fe507 fixed a copy paste error am: 90ff845856 am: 30f9d208cb
  30f9d20 fixed a copy paste error am: 90ff845856
  90ff845 fixed a copy paste error
  1566b37 msmcobalt: update to 07.00.00.253.035 am: 1c56f4feb3 am: dfc9c9ed55 am: c31584c53c
  c31584c msmcobalt: update to 07.00.00.253.035 am: 1c56f4feb3 am: dfc9c9ed55
  dfc9c9e msmcobalt: update to 07.00.00.253.035 am: 1c56f4feb3
  1c56f4f msmcobalt: update to 07.00.00.253.035
  06ef7a3 msmcobalt: Update to 07.00.00.253.032 am: 5bea9589b6 am: 2f928597e7 am: 0ebc797f0b
  518ba35 msmcobalt: Update to 07.00.00.253.024 am: 6f2a63d31d am: 5c07def4f2 am: 0061f41bb8
  0ebc797 msmcobalt: Update to 07.00.00.253.032 am: 5bea9589b6 am: 2f928597e7
  0061f41 msmcobalt: Update to 07.00.00.253.024 am: 6f2a63d31d am: 5c07def4f2
  2f92859 msmcobalt: Update to 07.00.00.253.032 am: 5bea9589b6
  5c07def msmcobalt: Update to 07.00.00.253.024 am: 6f2a63d31d
  5bea958 msmcobalt: Update to 07.00.00.253.032
  6f2a63d msmcobalt: Update to 07.00.00.253.024
  018788d deprecate legacy NTP time download am: 685517e30a am: 2191154ca6
  2191154 deprecate legacy NTP time download am: 685517e30a
  685517e deprecate legacy NTP time download
  2f5fecd Add missing liblog dependency
  8f129a6 Add missing liblog dependency am: 3241b11d40
  3241b11 Add missing liblog dependency
  6a7bcbc Merge "Add missing liblog dependency" am: ac7c3e2801 am: 319408f97b am: 7eaa57e398 am: a09f183289
  a09f183 Merge "Add missing liblog dependency" am: ac7c3e2801 am: 319408f97b am: 7eaa57e398
  7eaa57e Merge "Add missing liblog dependency" am: ac7c3e2801 am: 319408f97b
  319408f Merge "Add missing liblog dependency" am: ac7c3e2801
  ac7c3e2 Merge "Add missing liblog dependency"
  b452837 Add missing liblog dependency
  1fa137f Merge "Add missing liblog dependency"
  6c3c4bb multiple XTRA downloaders could be triggered on boot up am: 351d6980ab am: 9cb11ad806
  9bc19df XTRA Client 2.0 am: d304a98437 am: 769e19e20b
  9cb11ad multiple XTRA downloaders could be triggered on boot up am: 351d6980ab
  769e19e XTRA Client 2.0 am: d304a98437
  351d698 multiple XTRA downloaders could be triggered on boot up
  d304a98 XTRA Client 2.0
  532f337 Add missing liblog dependency
  bd2b55a Merge "Add missing liblog dependency" am: 0cb64f83b7 am: d750da0bb5 am: 37639b35f8 am: 34ecd7320a
  34ecd73 Merge "Add missing liblog dependency" am: 0cb64f83b7 am: d750da0bb5 am: 37639b35f8
  37639b3 Merge "Add missing liblog dependency" am: 0cb64f83b7 am: d750da0bb5
  d750da0 Merge "Add missing liblog dependency" am: 0cb64f83b7
  0cb64f8 Merge "Add missing liblog dependency"
  c784d5e Add missing liblog dependency
  9c86882 fix Converting NULL to non-pointer type warning
  2d6a48f msmcobalt: fix wrong absolute path am: cb4d2fd2f8 am: 95bae3332a am: 9d5dee88dc
  9d5dee8 msmcobalt: fix wrong absolute path am: cb4d2fd2f8 am: 95bae3332a
  f94f1f8 Merge changes I1561518c,Ic7ad172a into cw-f-dev am: 146bb3bc6e am: 54c926623a
  d258a81 Adding TARGET_NO_GNSS check while creating LocApi am: d4fd1e91f6 am: 24fdf8a95c
  95d59eb Fix gps compilation for 8x26 am: f89bb9b1af am: 004a0335cf
  95bae33 msmcobalt: fix wrong absolute path am: cb4d2fd2f8
  54c9266 Merge changes I1561518c,Ic7ad172a into cw-f-dev am: 146bb3bc6e
  24fdf8a Adding TARGET_NO_GNSS check while creating LocApi am: d4fd1e91f6
  004a033 Fix gps compilation for 8x26 am: f89bb9b1af
  146bb3b Merge changes I1561518c,Ic7ad172a into cw-f-dev
  cb4d2fd msmcobalt: fix wrong absolute path
  d4fd1e9 Adding TARGET_NO_GNSS check while creating LocApi
  f89bb9b Fix gps compilation for 8x26
  e9d0c8b msmcobalt: import from LA.UM.5.7.R1.06.00.01.253.019 am: 129edaf7d0 am: ef384b99bc am: 9ea942d749
  9ea942d msmcobalt: import from LA.UM.5.7.R1.06.00.01.253.019 am: 129edaf7d0 am: ef384b99bc
  ef384b9 msmcobalt: import from LA.UM.5.7.R1.06.00.01.253.019 am: 129edaf7d0
  129edaf msmcobalt: import from LA.UM.5.7.R1.06.00.01.253.019
  47d02ce DO NOT MERGE ANYWHERE: (nyc-dr1-dev) Move local gps/sap configuration to Context am: 950f058081  -s ours am: bece38a9ef  -s ours am: 7a2809aec4  -s ours am: 4ceccaca1d  -s ours
  4ceccac DO NOT MERGE ANYWHERE: (nyc-dr1-dev) Move local gps/sap configuration to Context am: 950f058081  -s ours am: bece38a9ef  -s ours am: 7a2809aec4  -s ours
  7a2809a DO NOT MERGE ANYWHERE: (nyc-dr1-dev) Move local gps/sap configuration to Context am: 950f058081  -s ours am: bece38a9ef  -s ours
  bece38a DO NOT MERGE ANYWHERE: (nyc-dr1-dev) Move local gps/sap configuration to Context am: 950f058081  -s ours
  950f058 DO NOT MERGE ANYWHERE: (nyc-dr1-dev) Move local gps/sap configuration to Context
  4ac084d Move local gps/sap configuration to Context am: 8cf3e0e4dd am: 10144bef7a am: ecb4275f4f
  ecb4275 Move local gps/sap configuration to Context am: 8cf3e0e4dd am: 10144bef7a
  10144be Move local gps/sap configuration to Context am: 8cf3e0e4dd
  8cf3e0e Move local gps/sap configuration to Context
  b3a031e Support GnssMeasurement am: 64efbd901d am: 2bffa26206
  2bffa26 Support GnssMeasurement am: 64efbd901d
  64efbd9 Support GnssMeasurement
  48f3b8f Fix logging level and remove nmea log am: fecc8ce536 am: 155a71c33b
  b963bde multiple XTRA downloaders could be triggered on boot up am: e0bc79ad55 am: fb1c904613
  1b4677e Return the correct length of nmea sentence. am: 76733cd8ab am: 0af33eddac
  3c4612e XTRA Client 2.0 am: 16ac9aa2c1 am: b20fb31405
  155a71c Fix logging level and remove nmea log am: fecc8ce536
  fb1c904 multiple XTRA downloaders could be triggered on boot up am: e0bc79ad55
  0af33ed Return the correct length of nmea sentence. am: 76733cd8ab
  b20fb31 XTRA Client 2.0 am: 16ac9aa2c1
  fecc8ce Fix logging level and remove nmea log
  e0bc79a multiple XTRA downloaders could be triggered on boot up
  76733cd Return the correct length of nmea sentence.
  16ac9aa XTRA Client 2.0
  15e9cf7 Resolved CLANG reported errors. am: 9e34f5b67a am: cdc5bbcfc8
  cdc5bbc Resolved CLANG reported errors. am: 9e34f5b67a
  9e34f5b Resolved CLANG reported errors.
  6bf3f62 Don\\'t include default gps.conf if device-specific overlay exists am: 83280d12ce am: c4343c4375
  c4343c4 Don\'t include default gps.conf if device-specific overlay exists am: 83280d12ce
  83280d1 Don't include default gps.conf if device-specific overlay exists
  2ad9cb9 Merge "Merge "Default apn ip type to ipv4" into nyc-dev am: e98a418560 am: 2129a41fce" into nyc-mr1-dev-plus-aosp am: c35b347362
  c6b14d2 Merge "Default apn ip type to ipv4" into nyc-dev am: e98a418560 am: 107456fbba am: d731d2f3ca
  c35b347 Merge "Merge "Default apn ip type to ipv4" into nyc-dev am: e98a418560 am: 2129a41fce" into nyc-mr1-dev-plus-aosp
  475bd7a Merge "Default apn ip type to ipv4" into nyc-dev am: e98a418560 am: 2129a41fce
  d731d2f Merge "Default apn ip type to ipv4" into nyc-dev am: e98a418560 am: 107456fbba
  107456f Merge "Default apn ip type to ipv4" into nyc-dev am: e98a418560
  2129a41 Merge "Default apn ip type to ipv4" into nyc-dev am: e98a418560
  e98a418 Merge "Default apn ip type to ipv4" into nyc-dev
  d7b1204 Default apn ip type to ipv4
  86a36d3 Remove problematic dependency am: de7700cdd7 am: f7cb5caf08
  5729eb7 makefile change to enable CLANG am: 7fd74c908e am: 6b6a10c860
  f7cb5ca Remove problematic dependency am: de7700cdd7
  6b6a10c makefile change to enable CLANG am: 7fd74c908e
  de7700c Remove problematic dependency
  7fd74c9 makefile change to enable CLANG
  1c21715 Merge "msm8974: remove from top level makefile am: 53bf15aab7 am: c5e73a33f3" into nyc-mr1-dev-plus-aosp am: f1ea4b1864
  9486084 msm8974: remove from top level makefile am: 53bf15aab7 am: 5e4de8a60e am: 2fdf772c2d
  f1ea4b1 Merge "msm8974: remove from top level makefile am: 53bf15aab7 am: c5e73a33f3" into nyc-mr1-dev-plus-aosp
  1686b6b msm8974: remove from top level makefile am: 53bf15aab7 am: c5e73a33f3
  2fdf772 msm8974: remove from top level makefile am: 53bf15aab7 am: 5e4de8a60e
  c5e73a3 msm8974: remove from top level makefile am: 53bf15aab7
  5e4de8a msm8974: remove from top level makefile am: 53bf15aab7
  53bf15a msm8974: remove from top level makefile
  c3d974a msm8974: deprecate msm8974 am: 486ab75159 am: 7f3057afa8 am: a489465053
  a7663b4 resolve merge conflicts of 486ab75 to nyc-dev-plus-aosp am: dbb62f01af am: f18370c8a6
  a489465 msm8974: deprecate msm8974 am: 486ab75159 am: 7f3057afa8
  f18370c resolve merge conflicts of 486ab75 to nyc-dev-plus-aosp am: dbb62f01af
  dbb62f0 resolve merge conflicts of 486ab75 to nyc-dev-plus-aosp
  7f3057a msm8974: deprecate msm8974 am: 486ab75159
  486ab75 msm8974: deprecate msm8974
  0a581f9 Support GnssMeasurement am: 78bdcaf6f9 am: a56327631f
  a563276 Support GnssMeasurement am: 78bdcaf6f9
  78bdcaf Support GnssMeasurement
  35d8351 Disable GPS only for adp8064 and fox
  04783a7 gps: fix msm8994 typo am: 728d6c7523 am: f3f2274403 am: db4a9d6d6c
  df040e1 gps: fix msm8994 typo am: 728d6c7523 am: 1df22d3173 am: 5a003101ce
  db4a9d6 gps: fix msm8994 typo am: 728d6c7523 am: f3f2274403
  5a00310 gps: fix msm8994 typo am: 728d6c7523 am: 1df22d3173
  1df22d3 gps: fix msm8994 typo am: 728d6c7523
  f3f2274 gps: fix msm8994 typo am: 728d6c7523
  728d6c7 gps: fix msm8994 typo
  0226df7 Fix memory leak in loc_update_conf(). am: a31fdb9 am: e848997
  e848997 Fix memory leak in loc_update_conf(). am: a31fdb9
  a31fdb9 Fix memory leak in loc_update_conf().
  3bed97f Modify makefile to point to new GPS HAL path am: f6d4513 am: e6b49f2 am: 8a06ba7 am: ae527de
  ae527de Modify makefile to point to new GPS HAL path am: f6d4513 am: e6b49f2 am: 8a06ba7
  8a06ba7 Modify makefile to point to new GPS HAL path am: f6d4513 am: e6b49f2
  e6b49f2 Modify makefile to point to new GPS HAL path am: f6d4513
  f6d4513 Modify makefile to point to new GPS HAL path
  df55d81 Add the support for geofence dwell am: 293643d am: 970ce96 am: 1d40ddf
  1d40ddf Add the support for geofence dwell am: 293643d am: 970ce96
  970ce96 Add the support for geofence dwell am: 293643d
  293643d Add the support for geofence dwell
  b5a649c make LocSharedLock::mRef ops atomic am: 37d684c am: a2a181b am: 6639c61
  ee92bb7 Add support for dynamic TBF updating am: 0fde446 am: 85f8ea7 am: eba9942
  3df5842 encode field separator characters am: d0d586a am: 06e3b77 am: c6c6ed5
  de6cdff Xtra client always reports carrier as \'unknown\' am: 25c1936 am: c421d38 am: 360951d
  6639c61 make LocSharedLock::mRef ops atomic am: 37d684c am: a2a181b
  eba9942 Add support for dynamic TBF updating am: 0fde446 am: 85f8ea7
  c6c6ed5 encode field separator characters am: d0d586a am: 06e3b77
  360951d Xtra client always reports carrier as \'unknown\' am: 25c1936 am: c421d38
  a2a181b make LocSharedLock::mRef ops atomic am: 37d684c
  85f8ea7 Add support for dynamic TBF updating am: 0fde446
  06e3b77 encode field separator characters am: d0d586a
  c421d38 Xtra client always reports carrier as \'unknown\' am: 25c1936
  2ed9a9d Add the support for geofence dwell am: b12c98c20a am: 621d69f7eb
  621d69f Add the support for geofence dwell am: b12c98c20a
  b12c98c Add the support for geofence dwell
  37d684c make LocSharedLock::mRef ops atomic
  0fde446 Add support for dynamic TBF updating
  d0d586a encode field separator characters
  25c1936 Xtra client always reports carrier as 'unknown'
  82a0698 Rename QcomGnssSvStatus to QtiGnssSvStatus am: 2e0c5f2f0d am: 0ededfbfac
  ef75e07 Create msm8994 target for GPS HAL am: 8c2d3d5afc am: 76b3527c06
  0ededfb Rename QcomGnssSvStatus to QtiGnssSvStatus am: 2e0c5f2f0d
  76b3527 Create msm8994 target for GPS HAL am: 8c2d3d5afc
  2e0c5f2 Rename QcomGnssSvStatus to QtiGnssSvStatus
  8c2d3d5 Create msm8994 target for GPS HAL
  1b898fc Merge "Suppress unused-parameter warnings in hardware/qcom/gps/" into nyc-dev am: 20160f64d5 am: 274f4455bc
  274f445 Merge "Suppress unused-parameter warnings in hardware/qcom/gps/" into nyc-dev am: 20160f64d5
  20160f6 Merge "Suppress unused-parameter warnings in hardware/qcom/gps/" into nyc-dev
  ddb6532 Merge "Fix duplicate gps.conf for Flo/Deb" am: d5810f1a3a am: 0999be14ee am: b585f64c87
  b585f64 Merge "Fix duplicate gps.conf for Flo/Deb" am: d5810f1a3a am: 0999be14ee
  0999be1 Merge "Fix duplicate gps.conf for Flo/Deb" am: d5810f1a3a
  d5810f1 Merge "Fix duplicate gps.conf for Flo/Deb"
  4b35907 Fix duplicate gps.conf for Flo/Deb
  155639f Merge "Fix duplicate gps.conf for Shamu/Hammerhead" am: a3d4e93d67 am: 6fccfd8f5f am: 34350a3a3b
  34350a3 Merge "Fix duplicate gps.conf for Shamu/Hammerhead" am: a3d4e93d67 am: 6fccfd8f5f
  6fccfd8 Merge "Fix duplicate gps.conf for Shamu/Hammerhead" am: a3d4e93d67
  a3d4e93 Merge "Fix duplicate gps.conf for Shamu/Hammerhead"
  8c406e3 resolve merge conflicts of 12a7f538f6 to nyc-dev am: 38487b179c am: 6a27c23732
  6a27c23 resolve merge conflicts of 12a7f538f6 to nyc-dev am: 38487b179c
  38487b1 resolve merge conflicts of 12a7f538f6 to nyc-dev
  12a7f53 msm8909: Fix compilation issues with HAL GPS
  38785f2 Suppress unused-parameter warnings in hardware/qcom/gps/
  6cf5d45 Fix duplicate gps.conf for Shamu/Hammerhead
  1571b12 Merge "gps: Avoid duplicate gps.conf" am: 437931edd2 am: 03937b8a1b am: 244e0ac48d
  244e0ac Merge "gps: Avoid duplicate gps.conf" am: 437931edd2 am: 03937b8a1b
  03937b8 Merge "gps: Avoid duplicate gps.conf" am: 437931edd2
  437931e Merge "gps: Avoid duplicate gps.conf"
  558f1da gps: Avoid duplicate gps.conf
  f0b6bd8 Merge commit \'e7c98642e1e156ea6cde1238cd0006f669cfb696\' into HEAD am: 2819314769 am: a1df2abd8e
  a1df2ab Merge commit \'e7c98642e1e156ea6cde1238cd0006f669cfb696\' into HEAD am: 2819314769
  2819314 Merge commit 'e7c98642e1e156ea6cde1238cd0006f669cfb696' into HEAD
  d63e720 Merge "Add missing liblog dependency" am: c5a4eb13dc am: 73d77abd43
  73d77ab Merge "Add missing liblog dependency" am: c5a4eb13dc
  c5a4eb1 Merge "Add missing liblog dependency"
  53f040d Add missing liblog dependency
  70db819 Merge "Fixed the build break" into nyc-dev am: 976ed0484f
  976ed04 Merge "Fixed the build break" into nyc-dev
  2ec254f Fixed the build break
  c9a6ef1 gps: Avoid duplicate gps.conf am: 420b042f38
  420b042 gps: Avoid duplicate gps.conf
  96d10a1 [DO NOT MERGE] gps: Update to proprietary drop AU_LINUX_ANDROID_LA.HB.1.3.9.06.00.01.213.002 am: f53ac3ae2f  -s ours
  f53ac3a [DO NOT MERGE] gps: Update to proprietary drop AU_LINUX_ANDROID_LA.HB.1.3.9.06.00.01.213.002
  3511668 Merge "gps: Update to proprietary drop AU_LINUX_ANDROID_LA.HB.1.3.9.06.00.01.213.002"
  4fb2620 gps: Update to proprietary drop AU_LINUX_ANDROID_LA.HB.1.3.9.06.00.01.213.002
  123cac6 gps: Avoid duplicate gps.conf
  f764372 msm8996: add GPS HAL to top level makefile
  ff62c84 msm8996: add top level makefile to msm8996 GPS HAL directory
  86009d7 msm8996: fix makefile to point to chip specific directory
  4035be2 msm8996: Add initial GPS HAL drop
  cffbb9e resolve merge conflicts of e7c98642e1 to master.
  e7c9864 gps: msm8909w caf release LW.BR.1.0-00410-8x09w.0
  02685cb Workaround for adp8064
  7d84e9e Merge "Fix ASan global-buffer-overflow in loc_set_config_entry."
  eca401b am 0c7fdf01: qcom/gps: update gps hal
  0c7fdf0 qcom/gps: update gps hal
  9198ff2 Properly convert GpsXtraCallbacks to GpsXtraExtCallbacks.
  aa6e5af Fix ASan global-buffer-overflow in loc_set_config_entry.
  98cb761 msm8960: Fix build errors
  5c7552e Do not build GPS HAL for msm8916
  45b9829 Fix some compilation issues with legacy targets
  bfff634 gps: upgrade GPS HAL to latest
  51025d5 Do not build GPS HAL for msm8916
  0e4f469 am 5191b0fe: am 2f930f38: Merge "Fix "error: \'strerror\' was not declared in this scope"."
  5191b0f am 2f930f38: Merge "Fix "error: \'strerror\' was not declared in this scope"."
  2f930f3 Merge "Fix "error: 'strerror' was not declared in this scope"."
  9e09232 Fix "error: 'strerror' was not declared in this scope".
  42e8b5d am c534e7f3: am 05e3dc51: Merge "Add missing includes."
  c534e7f am 05e3dc51: Merge "Add missing includes."
  05e3dc5 Merge "Add missing includes."
  7757808 Add missing includes.
  68dd2c8 am c3e0eb7c: am 1ba57de8: Merge "Add missing <string.h> include."
  c3e0eb7 am 1ba57de8: Merge "Add missing <string.h> include."
  1ba57de Merge "Add missing <string.h> include."
  ccfd464 Add missing <string.h> include.
  0b31322 am 5d1b68b5: am 66b3250c: carrier configured GPS_LOCK value missed out
  5d1b68b am 66b3250c: carrier configured GPS_LOCK value missed out
  66b3250 carrier configured GPS_LOCK value missed out
  9c557a8 am bdaef3e5: am 3ce5de3a: Merge "Cleanup Obsolete LOCAL_PRELINK_MODULE."
  bdaef3e am 3ce5de3a: Merge "Cleanup Obsolete LOCAL_PRELINK_MODULE."
  3ce5de3 Merge "Cleanup Obsolete LOCAL_PRELINK_MODULE."
  38bc21f Cleanup Obsolete LOCAL_PRELINK_MODULE.
  a0de11c am 67a679de: am e5949fd1: Merge "C++11 compatibility fixes."
  67a679d am e5949fd1: Merge "C++11 compatibility fixes."
  e5949fd Merge "C++11 compatibility fixes."
  6076fa7 am 0afd2944: am f01db6fc: Merge "Add missing include."
  0afd294 am f01db6fc: Merge "Add missing include."
  f01db6f Merge "Add missing include."
  35ad85c C++11 compatibility fixes.
  93cad3f Add missing include.
  53c2cf1 Add missing include.
  534f4aa am 4750276b: Merge "Add a missing include."
  4750276 Merge "Add a missing include."
  3074723 Add a missing include.
  8aac9d3 Revert "Revert "GNSS measurement""
  a8f9a02 Revert "GNSS measurement"
  af0c0cc GNSS measurement
  2344717 support reinjecting supl url for sim hot swap
  b2c66a0 GPS lock is stuck as disabled after post powerup enablement
  1300ae6 GPS LOCK did not work when NMEA_PROVIDER follows it
  8aa503a GPS_LOCK configuration support
  dd587e5 allow reconfiguration update happen before HAL init
  fe66007 adding update config post power up
  9aba726 correct AGpsStatus size in call to reportAgpsStatus
  74b1898 GPS HAL: actually remove build dependency on libmdmdetect
  2c4f9ae GPS HAL: decouple 8x84 targets from vendor/
  0d00b9e Add support for IPV6 in AGPS Interface
  1d49400 Agps Cert Install Api Implementation
  33627a4 Fix regression issues with msm8960 hal split
  baa459d flounder: remove filter out check of TARGET_ARCH for arm64
  87543bf Add conditional compilation for libmdmdetect
  8369d5b Revert "Remove masks for Glonass"
  5cf20a0 Changes for GPS HAL compilation
  47ad5e4 Merge branch 'KK.04.04.02.010.399' into l-pdk
  ec6e5d3 Split GPS HAL for older targets
  fd8c2c3 Fix build.
  07c3401 Revert "Revert "Remove masks for Glonass""
  0ed9ab1 Revert "Merge branch 'KK.04.04.02.010.399' into l-pdk"
  544e9a1 Merge "Revert "Add conditional compilation for libmdmdetect""
  408e216 Revert "Add conditional compilation for libmdmdetect"
  d500f4f Add conditional compilation for libmdmdetect
  8a20422 Revert "Remove masks for Glonass"
  6270087 Changes for GPS HAL compilation
  8c61f8c Merge branch 'KK.04.04.02.010.399' into l-pdk
  4fe12bb Split GPS HAL for older targets
  f2d8258 Merge "Revert "Split GPS HAL for older targets""
  2a0deb9 Revert "Split GPS HAL for older targets"
  a4a8ee2 Merge "Revert "Changes for GPS HAL compilation""
  915c96c Revert "Changes for GPS HAL compilation"
  c02d4b1 Add IPv6 support to GPS HAL.
  5527c15 Add option to fallback to LocApiV02
  07bee4d am a41314bd: Resolved On-Demand XTRA time injection issue
  a41314b Resolved On-Demand XTRA time injection issue
  1fdba83 Resolved On-Demand XTRA time injection issue
  8f6bca4 Revert "Fix inject NTP time fail"
  0acd743 Fix LocSvc log spam issue
  04bfb8f Fix inject NTP time fail
  4c50617 Bug fixed in AGPS checks
  9ca398a Include this Android.mk only if BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE is defined
  e14a6c8 Merge latest gps hal
  baa4c49 am 2a9f38e7: Merge "gps: geofence hal integration" into jb-mr2-dev
  af615e3 am ce5efcc5: Add liblog
  5899c82 am c65fed03: gps: Runtime detection between apq v/s mdm gps support
  fa96e0d am ade0338d: moved most of the GPS HAL back to aosp
  c7e36f3 am 52f4c8ca: add LOCAL_MODULE_OWNER := qcom to gps modules
  2610479 am 34ee0955: Revert "remove loc_api from hardware/qcom/gps"
  8229399 am 63e3dc43: (-s ours) am 3dac3016: am 65102c39: am 47210994: (-s ours) am c2f34af0: (-s ours) Reconcile with jb-mr1-release - do not merge

Change-Id: I9016a28c2c84fe39d3d3e7fe4183c3ce6df99d51
Signed-off-by: Thierry Strudel <tstrudel@google.com>
(cherry picked from commit b4dcb0e3da7f3f737289d237b53b6b5e904b5284)
diff --git a/msm8998/android/AGnss.cpp b/msm8998/android/AGnss.cpp
new file mode 100644
index 0000000..c497ed4
--- /dev/null
+++ b/msm8998/android/AGnss.cpp
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#define LOG_TAG "LocSvc_AGnssInterface"
+
+#include <log_util.h>
+#include "Gnss.h"
+#include "AGnss.h"
+#include <gps_extended_c.h>
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+sp<IAGnssCallback> AGnss::sAGnssCbIface = nullptr;
+
+AGnss::AGnss(Gnss* gnss) : mGnss(gnss) {
+}
+
+void AGnss::agnssStatusIpV4Cb(IAGnssCallback::AGnssStatusIpV4 status){
+
+    sAGnssCbIface->agnssStatusIpV4Cb(status);
+}
+
+Return<void> AGnss::setCallback(const sp<IAGnssCallback>& callback) {
+
+    if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
+        LOC_LOGE("Null GNSS interface");
+        return Void();
+    }
+
+    // Save the interface
+    sAGnssCbIface = callback;
+
+    mGnss->getGnssInterface()->agpsInit((void*)agnssStatusIpV4Cb);
+    return Void();
+}
+
+Return<bool> AGnss::dataConnClosed() {
+
+    if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
+        LOC_LOGE("Null GNSS interface");
+        return false;
+    }
+
+    mGnss->getGnssInterface()->agpsDataConnClosed(LOC_AGPS_TYPE_SUPL);
+    return true;
+}
+
+Return<bool> AGnss::dataConnFailed() {
+
+    if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
+        LOC_LOGE("Null GNSS interface");
+        return false;
+    }
+
+    mGnss->getGnssInterface()->agpsDataConnFailed(LOC_AGPS_TYPE_SUPL);
+    return true;
+}
+
+Return<bool> AGnss::dataConnOpen(const hidl_string& apn,
+        IAGnss::ApnIpType apnIpType) {
+
+    if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
+        LOC_LOGE("Null GNSS interface");
+        return false;
+    }
+
+    /* Validate */
+    if(apn.empty()){
+        LOC_LOGE("Invalid APN");
+        return false;
+    }
+
+    LOC_LOGD("dataConnOpen APN name = [%s]", apn.c_str());
+
+    mGnss->getGnssInterface()->agpsDataConnOpen(
+            LOC_AGPS_TYPE_SUPL, apn.c_str(), apn.size(), (int)apnIpType);
+    return true;
+}
+
+Return<bool> AGnss::setServer(IAGnssCallback::AGnssType type,
+                              const hidl_string& hostname,
+                              int32_t port) {
+    if (mGnss == nullptr) {
+        LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
+        return false;
+    }
+
+    GnssConfig config;
+    memset(&config, 0, sizeof(GnssConfig));
+    config.size = sizeof(GnssConfig);
+    config.flags = GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT;
+    config.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer);
+    if (type == IAGnssCallback::AGnssType::TYPE_SUPL) {
+        config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL;
+    } else if (type == IAGnssCallback::AGnssType::TYPE_C2K) {
+        config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_C2K;
+    } else {
+        LOC_LOGE("%s]: invalid AGnssType: %d", __FUNCTION__, static_cast<int>(type));
+        return false;
+    }
+    config.assistanceServer.hostName = strdup(hostname.c_str());
+    config.assistanceServer.port = port;
+    return mGnss->updateConfiguration(config);
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
diff --git a/msm8998/android/AGnss.h b/msm8998/android/AGnss.h
new file mode 100644
index 0000000..f4216b0
--- /dev/null
+++ b/msm8998/android/AGnss.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#ifndef ANDROID_HARDWARE_GNSS_V1_1_AGNSS_H
+#define ANDROID_HARDWARE_GNSS_V1_1_AGNSS_H
+
+#include <android/hardware/gnss/1.0/IAGnss.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::gnss::V1_0::IAGnss;
+using ::android::hardware::gnss::V1_0::IAGnssCallback;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+struct Gnss;
+struct AGnss : public IAGnss {
+
+    AGnss(Gnss* gnss);
+    ~AGnss() = default;
+    /*
+     * Methods from ::android::hardware::gnss::V1_0::IAGnss interface follow.
+     * These declarations were generated from IAGnss.hal.
+     */
+    Return<void> setCallback(const sp<IAGnssCallback>& callback) override;
+
+    Return<bool> dataConnClosed() override;
+
+    Return<bool> dataConnFailed() override;
+
+    Return<bool> dataConnOpen(const hidl_string& apn,
+            IAGnss::ApnIpType apnIpType) override;
+
+    Return<bool> setServer(IAGnssCallback::AGnssType type,
+                         const hidl_string& hostname, int32_t port) override;
+
+    /* Data call setup callback passed down to GNSS HAL implementation */
+    static void agnssStatusIpV4Cb(IAGnssCallback::AGnssStatusIpV4 status);
+
+ private:
+    Gnss* mGnss = nullptr;
+    static sp<IAGnssCallback> sAGnssCbIface;
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_GNSS_V1_1_AGNSS_H
diff --git a/msm8998/android/Android.mk b/msm8998/android/Android.mk
new file mode 100644
index 0000000..e359e88
--- /dev/null
+++ b/msm8998/android/Android.mk
@@ -0,0 +1,76 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android.hardware.gnss@1.0-impl-qti
+LOCAL_MODULE_OWNER := qti
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_SRC_FILES := \
+    AGnss.cpp \
+    Gnss.cpp \
+    GnssBatching.cpp \
+    GnssGeofencing.cpp \
+    GnssMeasurement.cpp \
+    GnssNi.cpp \
+    GnssConfiguration.cpp \
+
+LOCAL_SRC_FILES += \
+    location_api/LocationUtil.cpp \
+    location_api/GnssAPIClient.cpp \
+    location_api/GeofenceAPIClient.cpp \
+    location_api/FlpAPIClient.cpp \
+    location_api/GnssMeasurementAPIClient.cpp \
+
+LOCAL_C_INCLUDES:= \
+    $(LOCAL_PATH)/location_api \
+    $(TARGET_OUT_HEADERS)/gps.utils \
+    $(TARGET_OUT_HEADERS)/libloc_core \
+    $(TARGET_OUT_HEADERS)/libloc_pla \
+    $(TARGET_OUT_HEADERS)/liblocation_api \
+
+LOCAL_SHARED_LIBRARIES := \
+    liblog \
+    libhidlbase \
+    libhidltransport \
+    libhwbinder \
+    libutils \
+    android.hardware.gnss@1.0 \
+
+LOCAL_SHARED_LIBRARIES += \
+    libloc_core \
+    libgps.utils \
+    libdl \
+    libloc_pla \
+    liblocation_api \
+
+include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android.hardware.gnss@1.0-service-qti
+LOCAL_MODULE_OWNER := qti
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_INIT_RC := android.hardware.gnss@1.0-service-qti.rc
+LOCAL_SRC_FILES := \
+    service.cpp \
+
+LOCAL_C_INCLUDES:= \
+    $(LOCAL_PATH)/location_api \
+    $(TARGET_OUT_HEADERS)/gps.utils \
+    $(TARGET_OUT_HEADERS)/libloc_core \
+    $(TARGET_OUT_HEADERS)/libloc_pla \
+    $(TARGET_OUT_HEADERS)/liblocation_api \
+
+
+LOCAL_SHARED_LIBRARIES := \
+    liblog \
+    libcutils \
+    libdl \
+    libbase \
+    libutils \
+
+LOCAL_SHARED_LIBRARIES += \
+    libhwbinder \
+    libhidlbase \
+    libhidltransport \
+    android.hardware.gnss@1.0 \
+
+include $(BUILD_EXECUTABLE)
diff --git a/msm8998/android/Gnss.cpp b/msm8998/android/Gnss.cpp
new file mode 100644
index 0000000..1412883
--- /dev/null
+++ b/msm8998/android/Gnss.cpp
@@ -0,0 +1,326 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#define LOG_TAG "LocSvc_GnssInterface"
+
+#include <log_util.h>
+#include <dlfcn.h>
+#include "Gnss.h"
+typedef void* (getLocationInterface)();
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+void Gnss::GnssDeathRecipient::serviceDied(uint64_t cookie, const wp<IBase>& who) {
+    LOC_LOGE("%s] service died. cookie: %llu, who: %p",
+            __FUNCTION__, static_cast<unsigned long long>(cookie), &who);
+    if (mGnss != nullptr) {
+        mGnss->stop();
+        mGnss->cleanup();
+    }
+}
+
+Gnss::Gnss() {
+    ENTRY_LOG_CALLFLOW();
+    // clear pending GnssConfig
+    memset(&mPendingConfig, 0, sizeof(GnssConfig));
+
+    mGnssDeathRecipient = new GnssDeathRecipient(this);
+}
+
+Gnss::~Gnss() {
+    ENTRY_LOG_CALLFLOW();
+    if (mApi != nullptr) {
+        delete mApi;
+        mApi = nullptr;
+    }
+}
+
+GnssAPIClient* Gnss::getApi() {
+    if (mApi == nullptr && (mGnssCbIface != nullptr || mGnssNiCbIface != nullptr)) {
+        mApi = new GnssAPIClient(mGnssCbIface, mGnssNiCbIface);
+        if (mApi == nullptr) {
+            LOC_LOGE("%s] faild to create GnssAPIClient", __FUNCTION__);
+            return mApi;
+        }
+
+        if (mPendingConfig.size == sizeof(GnssConfig)) {
+            // we have pending GnssConfig
+            mApi->gnssConfigurationUpdate(mPendingConfig);
+            // clear size to invalid mPendingConfig
+            mPendingConfig.size = 0;
+            if (mPendingConfig.assistanceServer.hostName != nullptr) {
+                free((void*)mPendingConfig.assistanceServer.hostName);
+            }
+        }
+    }
+    if (mApi == nullptr) {
+        LOC_LOGW("%s] GnssAPIClient is not ready", __FUNCTION__);
+    }
+    return mApi;
+}
+
+GnssInterface* Gnss::getGnssInterface() {
+    static bool getGnssInterfaceFailed = false;
+    if (nullptr == mGnssInterface && !getGnssInterfaceFailed) {
+        LOC_LOGD("%s]: loading libgnss.so::getGnssInterface ...", __func__);
+        getLocationInterface* getter = NULL;
+        const char *error;
+        dlerror();
+        void *handle = dlopen("libgnss.so", RTLD_NOW);
+        if (NULL == handle || (error = dlerror()) != NULL)  {
+            LOC_LOGW("dlopen for libgnss.so failed, error = %s", error);
+        } else {
+            getter = (getLocationInterface*)dlsym(handle, "getGnssInterface");
+            if ((error = dlerror()) != NULL)  {
+                LOC_LOGW("dlsym for libgnss.so::getGnssInterface failed, error = %s", error);
+                getter = NULL;
+            }
+        }
+
+        if (NULL == getter) {
+            getGnssInterfaceFailed = true;
+        } else {
+            mGnssInterface = (GnssInterface*)(*getter)();
+        }
+    }
+    return mGnssInterface;
+}
+
+Return<bool> Gnss::setCallback(const sp<IGnssCallback>& callback)  {
+    ENTRY_LOG_CALLFLOW();
+    if (mGnssCbIface != nullptr) {
+        mGnssCbIface->unlinkToDeath(mGnssDeathRecipient);
+    }
+    mGnssCbIface = callback;
+    if (mGnssCbIface != nullptr) {
+        mGnssCbIface->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/);
+    }
+
+    GnssAPIClient* api = getApi();
+    if (api != nullptr) {
+        api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface);
+        api->locAPIEnable(LOCATION_TECHNOLOGY_TYPE_GNSS);
+    }
+    return true;
+}
+
+Return<bool> Gnss::setGnssNiCb(const sp<IGnssNiCallback>& callback) {
+    ENTRY_LOG_CALLFLOW();
+    mGnssNiCbIface = callback;
+    GnssAPIClient* api = getApi();
+    if (api != nullptr) {
+        api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface);
+    }
+    return true;
+}
+
+Return<bool> Gnss::updateConfiguration(GnssConfig& gnssConfig) {
+    ENTRY_LOG_CALLFLOW();
+    GnssAPIClient* api = getApi();
+    if (api) {
+        api->locAPIGnssUpdateConfig(gnssConfig);
+    } else if (gnssConfig.flags != 0) {
+        // api is not ready yet, update mPendingConfig with gnssConfig
+        mPendingConfig.size = sizeof(GnssConfig);
+
+        if (gnssConfig.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) {
+            mPendingConfig.flags |= GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT;
+            mPendingConfig.gpsLock = gnssConfig.gpsLock;
+        }
+        if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) {
+            mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT;
+            mPendingConfig.suplVersion = gnssConfig.suplVersion;
+        }
+        if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) {
+            mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT;
+            mPendingConfig.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer);
+            mPendingConfig.assistanceServer.type = gnssConfig.assistanceServer.type;
+            if (mPendingConfig.assistanceServer.hostName != nullptr) {
+                free((void*)mPendingConfig.assistanceServer.hostName);
+                mPendingConfig.assistanceServer.hostName =
+                    strdup(gnssConfig.assistanceServer.hostName);
+            }
+            mPendingConfig.assistanceServer.port = gnssConfig.assistanceServer.port;
+        }
+        if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) {
+            mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT;
+            mPendingConfig.lppProfile = gnssConfig.lppProfile;
+        }
+        if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) {
+            mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT;
+            mPendingConfig.lppeControlPlaneMask = gnssConfig.lppeControlPlaneMask;
+        }
+        if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) {
+            mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT;
+            mPendingConfig.lppeUserPlaneMask = gnssConfig.lppeUserPlaneMask;
+        }
+        if (gnssConfig.flags & GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) {
+            mPendingConfig.flags |= GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT;
+            mPendingConfig.aGlonassPositionProtocolMask = gnssConfig.aGlonassPositionProtocolMask;
+        }
+        if (gnssConfig.flags & GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT) {
+            mPendingConfig.flags |= GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT;
+            mPendingConfig.emergencyPdnForEmergencySupl = gnssConfig.emergencyPdnForEmergencySupl;
+        }
+        if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT) {
+            mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT;
+            mPendingConfig.suplEmergencyServices = gnssConfig.suplEmergencyServices;
+        }
+        if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_MODE_BIT) {
+            mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_MODE_BIT;
+            mPendingConfig.suplModeMask = gnssConfig.suplModeMask;
+        }
+    }
+    return true;
+}
+
+Return<bool> Gnss::start()  {
+    ENTRY_LOG_CALLFLOW();
+    bool retVal = false;
+    GnssAPIClient* api = getApi();
+    if (api) {
+        retVal = api->gnssStart();
+    }
+    return retVal;
+}
+
+Return<bool> Gnss::stop()  {
+    ENTRY_LOG_CALLFLOW();
+    bool retVal = false;
+    GnssAPIClient* api = getApi();
+    if (api) {
+        retVal = api->gnssStop();
+    }
+    return retVal;
+}
+
+Return<void> Gnss::cleanup()  {
+    ENTRY_LOG_CALLFLOW();
+
+    if (mApi != nullptr) {
+        mApi->locAPIDisable();
+    }
+
+    return Void();
+}
+
+Return<bool> Gnss::injectLocation(double latitudeDegrees,
+                                  double longitudeDegrees,
+                                  float accuracyMeters)  {
+    ENTRY_LOG_CALLFLOW();
+    GnssInterface* gnssInterface = getGnssInterface();
+    if (nullptr != gnssInterface) {
+        gnssInterface->injectLocation(latitudeDegrees, longitudeDegrees, accuracyMeters);
+        return true;
+    } else {
+        return false;
+    }
+}
+
+Return<bool> Gnss::injectTime(int64_t timeMs, int64_t timeReferenceMs,
+                              int32_t uncertaintyMs) {
+    ENTRY_LOG_CALLFLOW();
+    GnssInterface* gnssInterface = getGnssInterface();
+    if (nullptr != gnssInterface) {
+        gnssInterface->injectTime(timeMs, timeReferenceMs, uncertaintyMs);
+        return true;
+    } else {
+        return false;
+    }
+}
+
+Return<void> Gnss::deleteAidingData(IGnss::GnssAidingData aidingDataFlags)  {
+    ENTRY_LOG_CALLFLOW();
+    GnssAPIClient* api = getApi();
+    if (api) {
+        api->gnssDeleteAidingData(aidingDataFlags);
+    }
+    return Void();
+}
+
+Return<bool> Gnss::setPositionMode(IGnss::GnssPositionMode mode,
+                                   IGnss::GnssPositionRecurrence recurrence,
+                                   uint32_t minIntervalMs,
+                                   uint32_t preferredAccuracyMeters,
+                                   uint32_t preferredTimeMs)  {
+    ENTRY_LOG_CALLFLOW();
+    bool retVal = false;
+    GnssAPIClient* api = getApi();
+    if (api) {
+        retVal = api->gnssSetPositionMode(mode, recurrence, minIntervalMs,
+                preferredAccuracyMeters, preferredTimeMs);
+    }
+    return retVal;
+}
+
+Return<sp<IAGnss>> Gnss::getExtensionAGnss()  {
+    ENTRY_LOG_CALLFLOW();
+    mAGnssIface = new AGnss(this);
+    return mAGnssIface;
+}
+
+Return<sp<IGnssNi>> Gnss::getExtensionGnssNi()  {
+    ENTRY_LOG_CALLFLOW();
+    mGnssNi = new GnssNi(this);
+    return mGnssNi;
+}
+
+Return<sp<IGnssMeasurement>> Gnss::getExtensionGnssMeasurement() {
+    ENTRY_LOG_CALLFLOW();
+    mGnssMeasurement = new GnssMeasurement();
+    return mGnssMeasurement;
+}
+
+Return<sp<IGnssConfiguration>> Gnss::getExtensionGnssConfiguration()  {
+    ENTRY_LOG_CALLFLOW();
+    mGnssConfig = new GnssConfiguration(this);
+    return mGnssConfig;
+}
+
+Return<sp<IGnssGeofencing>> Gnss::getExtensionGnssGeofencing()  {
+    ENTRY_LOG_CALLFLOW();
+    mGnssGeofencingIface = new GnssGeofencing();
+    return mGnssGeofencingIface;
+}
+
+Return<sp<IGnssBatching>> Gnss::getExtensionGnssBatching()  {
+    mGnssBatching = new GnssBatching();
+    return mGnssBatching;
+}
+
+IGnss* HIDL_FETCH_IGnss(const char* hal) {
+    ENTRY_LOG_CALLFLOW();
+    IGnss* iface = nullptr;
+    iface = new Gnss();
+    if (iface == nullptr) {
+        LOC_LOGE("%s]: failed to get %s", __FUNCTION__, hal);
+    }
+    return iface;
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
diff --git a/msm8998/android/Gnss.h b/msm8998/android/Gnss.h
new file mode 100644
index 0000000..b338b08
--- /dev/null
+++ b/msm8998/android/Gnss.h
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSS_H
+#define ANDROID_HARDWARE_GNSS_V1_1_GNSS_H
+
+#include <AGnss.h>
+#include <GnssBatching.h>
+#include <GnssConfiguration.h>
+#include <GnssGeofencing.h>
+#include <GnssMeasurement.h>
+#include <GnssNi.h>
+
+#include <android/hardware/gnss/1.0/IGnss.h>
+#include <hidl/Status.h>
+
+#include <GnssAPIClient.h>
+#include <location_interface.h>
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+struct Gnss : public IGnss {
+    Gnss();
+    ~Gnss();
+
+    // registerAsService will call interfaceChain to determine the version of service
+    /* comment this out until we know really how to manipulate hidl version
+    using interfaceChain_cb = std::function<
+        void(const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& descriptors)>;
+    virtual ::android::hardware::Return<void> interfaceChain(interfaceChain_cb _hidl_cb) override {
+        _hidl_cb({
+                "android.hardware.gnss@1.1::IGnss",
+                ::android::hidl::base::V1_0::IBase::descriptor,
+                });
+        return ::android::hardware::Void();
+    }
+    */
+
+    /*
+     * Methods from ::android::hardware::gnss::V1_0::IGnss follow.
+     * These declarations were generated from Gnss.hal.
+     */
+    Return<bool> setCallback(const sp<IGnssCallback>& callback)  override;
+    Return<bool> start()  override;
+    Return<bool> stop()  override;
+    Return<void> cleanup()  override;
+    Return<bool> injectLocation(double latitudeDegrees,
+                                double longitudeDegrees,
+                                float accuracyMeters)  override;
+    Return<bool> injectTime(int64_t timeMs,
+                            int64_t timeReferenceMs,
+                            int32_t uncertaintyMs) override;
+    Return<void> deleteAidingData(IGnss::GnssAidingData aidingDataFlags)  override;
+    Return<bool> setPositionMode(IGnss::GnssPositionMode mode,
+                                 IGnss::GnssPositionRecurrence recurrence,
+                                 uint32_t minIntervalMs,
+                                 uint32_t preferredAccuracyMeters,
+                                 uint32_t preferredTimeMs)  override;
+    Return<sp<IAGnss>> getExtensionAGnss() override;
+    Return<sp<IGnssNi>> getExtensionGnssNi() override;
+    Return<sp<IGnssMeasurement>> getExtensionGnssMeasurement() override;
+    Return<sp<IGnssConfiguration>> getExtensionGnssConfiguration() override;
+    Return<sp<IGnssGeofencing>> getExtensionGnssGeofencing() override;
+    Return<sp<IGnssBatching>> getExtensionGnssBatching() override;
+
+    inline Return<sp<IAGnssRil>> getExtensionAGnssRil() override {
+        return nullptr;
+    }
+
+    inline Return<sp<IGnssNavigationMessage>> getExtensionGnssNavigationMessage() override {
+        return nullptr;
+    }
+
+    inline Return<sp<IGnssXtra>> getExtensionXtra() override {
+        return nullptr;
+    }
+
+    inline Return<sp<IGnssDebug>> getExtensionGnssDebug() override {
+        return nullptr;
+    }
+
+    // These methods are not part of the IGnss base class.
+    GnssAPIClient* getApi();
+    Return<bool> setGnssNiCb(const sp<IGnssNiCallback>& niCb);
+    Return<bool> updateConfiguration(GnssConfig& gnssConfig);
+    GnssInterface* getGnssInterface();
+
+ private:
+    struct GnssDeathRecipient : hidl_death_recipient {
+        GnssDeathRecipient(sp<Gnss> gnss) : mGnss(gnss) {
+        }
+        ~GnssDeathRecipient() = default;
+        virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) override;
+        sp<Gnss> mGnss;
+    };
+
+ private:
+    sp<GnssDeathRecipient> mGnssDeathRecipient = nullptr;
+
+    sp<AGnss> mAGnssIface = nullptr;
+    sp<GnssNi> mGnssNi = nullptr;
+    sp<GnssMeasurement> mGnssMeasurement = nullptr;
+    sp<GnssConfiguration> mGnssConfig = nullptr;
+    sp<GnssGeofencing> mGnssGeofencingIface = nullptr;
+    sp<GnssBatching> mGnssBatching = nullptr;
+
+    GnssAPIClient* mApi = nullptr;
+    sp<IGnssCallback> mGnssCbIface = nullptr;
+    sp<IGnssNiCallback> mGnssNiCbIface = nullptr;
+    GnssConfig mPendingConfig;
+    GnssInterface* mGnssInterface = nullptr;
+};
+
+extern "C" IGnss* HIDL_FETCH_IGnss(const char* name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_GNSS_V1_1_GNSS_H
diff --git a/msm8998/android/GnssBatching.cpp b/msm8998/android/GnssBatching.cpp
new file mode 100644
index 0000000..5eff819
--- /dev/null
+++ b/msm8998/android/GnssBatching.cpp
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#define LOG_TAG "LocSvc_GnssBatchingInterface"
+
+#include <log_util.h>
+#include <FlpAPIClient.h>
+#include "GnssBatching.h"
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+void GnssBatching::GnssBatchingDeathRecipient::serviceDied(
+        uint64_t cookie, const wp<IBase>& who) {
+    LOC_LOGE("%s] service died. cookie: %llu, who: %p",
+            __FUNCTION__, static_cast<unsigned long long>(cookie), &who);
+    if (mGnssBatching != nullptr) {
+        mGnssBatching->stop();
+        mGnssBatching->cleanup();
+    }
+}
+
+GnssBatching::GnssBatching() : mApi(nullptr) {
+    mGnssBatchingDeathRecipient = new GnssBatchingDeathRecipient(this);
+}
+
+GnssBatching::~GnssBatching() {
+    if (mApi != nullptr) {
+        delete mApi;
+        mApi = nullptr;
+    }
+}
+
+
+// Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow.
+Return<bool> GnssBatching::init(const sp<IGnssBatchingCallback>& callback) {
+    if (mApi != nullptr) {
+        LOC_LOGE("%s]: mApi is NOT nullptr", __FUNCTION__);
+        return false;
+    }
+
+    mApi = new FlpAPIClient(callback);
+    if (mApi == nullptr) {
+        LOC_LOGE("%s]: failed to create mApi", __FUNCTION__);
+        return false;
+    }
+
+    if (mGnssBatchingCbIface != nullptr) {
+        mGnssBatchingCbIface->unlinkToDeath(mGnssBatchingDeathRecipient);
+    }
+    mGnssBatchingCbIface = callback;
+    if (mGnssBatchingCbIface != nullptr) {
+        mGnssBatchingCbIface->linkToDeath(mGnssBatchingDeathRecipient, 0 /*cookie*/);
+    }
+
+    return true;
+}
+
+Return<uint16_t> GnssBatching::getBatchSize() {
+    uint16_t ret = 0;
+    if (mApi == nullptr) {
+        LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
+    } else {
+        ret = mApi->flpGetBatchSize();
+    }
+    return ret;
+}
+
+Return<bool> GnssBatching::start(const IGnssBatching::Options& options) {
+    bool ret = false;
+    if (mApi == nullptr) {
+        LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
+    } else {
+        ret = mApi->flpStartSession(options);
+    }
+    return ret;
+}
+
+Return<void> GnssBatching::flush() {
+    if (mApi == nullptr) {
+        LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
+    } else {
+        mApi->flpFlushBatchedLocations();
+    }
+    return Void();
+}
+
+Return<bool> GnssBatching::stop() {
+    bool ret = false;
+    if (mApi == nullptr) {
+        LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
+    } else {
+        ret = mApi->flpStopSession();
+    }
+    return ret;
+}
+
+Return<void> GnssBatching::cleanup() {
+    if (mGnssBatchingCbIface != nullptr) {
+        mGnssBatchingCbIface->unlinkToDeath(mGnssBatchingDeathRecipient);
+    }
+    return Void();
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
diff --git a/msm8998/android/GnssBatching.h b/msm8998/android/GnssBatching.h
new file mode 100644
index 0000000..b46fae8
--- /dev/null
+++ b/msm8998/android/GnssBatching.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSBATCHING_H
+#define ANDROID_HARDWARE_GNSS_V1_1_GNSSBATCHING_H
+
+#include <android/hardware/gnss/1.0/IGnssBatching.h>
+#include <hidl/Status.h>
+
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::gnss::V1_0::IGnssBatching;
+using ::android::hardware::gnss::V1_0::IGnssBatchingCallback;
+using ::android::hidl::base::V1_0::IBase;
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+class FlpAPIClient;
+struct GnssBatching : public IGnssBatching {
+    GnssBatching();
+    ~GnssBatching();
+
+    // Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow.
+    Return<bool> init(const sp<IGnssBatchingCallback>& callback) override;
+    Return<uint16_t> getBatchSize() override;
+    Return<bool> start(const IGnssBatching::Options& options ) override;
+    Return<void> flush() override;
+    Return<bool> stop() override;
+    Return<void> cleanup() override;
+
+ private:
+    struct GnssBatchingDeathRecipient : hidl_death_recipient {
+        GnssBatchingDeathRecipient(sp<GnssBatching> gnssBatching) :
+            mGnssBatching(gnssBatching) {
+        }
+        ~GnssBatchingDeathRecipient() = default;
+        virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) override;
+        sp<GnssBatching> mGnssBatching;
+    };
+
+ private:
+    sp<GnssBatchingDeathRecipient> mGnssBatchingDeathRecipient = nullptr;
+    sp<IGnssBatchingCallback> mGnssBatchingCbIface = nullptr;
+    FlpAPIClient* mApi = nullptr;
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_GNSS_V1_1_GNSSBATCHING_H
diff --git a/msm8998/android/GnssConfiguration.cpp b/msm8998/android/GnssConfiguration.cpp
new file mode 100644
index 0000000..591a01a
--- /dev/null
+++ b/msm8998/android/GnssConfiguration.cpp
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#define LOG_TAG "LocSvc_GnssConfigurationInterface"
+
+#include <log_util.h>
+#include "Gnss.h"
+#include "GnssConfiguration.h"
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+GnssConfiguration::GnssConfiguration(Gnss* gnss) : mGnss(gnss) {
+}
+
+// Methods from ::android::hardware::gps::V1_0::IGnssConfiguration follow.
+Return<bool> GnssConfiguration::setSuplEs(bool enabled)  {
+    if (mGnss == nullptr) {
+        LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
+        return false;
+    }
+
+    GnssConfig config;
+    memset(&config, 0, sizeof(GnssConfig));
+    config.size = sizeof(GnssConfig);
+    config.flags = GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT;
+    config.suplEmergencyServices = static_cast<GnssConfigSuplEmergencyServices>(enabled);
+
+    return mGnss->updateConfiguration(config);
+}
+
+Return<bool> GnssConfiguration::setSuplVersion(uint32_t version)  {
+    if (mGnss == nullptr) {
+        LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
+        return false;
+    }
+
+    GnssConfig config;
+    memset(&config, 0, sizeof(GnssConfig));
+    config.size = sizeof(GnssConfig);
+    config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT;
+    config.suplVersion = static_cast<GnssConfigSuplVersion>(version);
+
+    return mGnss->updateConfiguration(config);
+}
+
+Return<bool> GnssConfiguration::setSuplMode(uint8_t mode)  {
+    if (mGnss == nullptr) {
+        LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
+        return false;
+    }
+
+    GnssConfig config;
+    memset(&config, 0, sizeof(GnssConfig));
+    config.size = sizeof(GnssConfig);
+    config.flags = GNSS_CONFIG_FLAGS_SUPL_MODE_BIT;
+    config.suplModeMask = static_cast<GnssConfigSuplModeMask>(mode);
+
+    return mGnss->updateConfiguration(config);
+}
+
+Return<bool> GnssConfiguration::setLppProfile(uint8_t lppProfile) {
+    if (mGnss == nullptr) {
+        LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
+        return false;
+    }
+
+    GnssConfig config;
+    memset(&config, 0, sizeof(GnssConfig));
+    config.size = sizeof(GnssConfig);
+    config.flags = GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT;
+    config.lppProfile = static_cast<GnssConfigLppProfile>(lppProfile);
+
+    return mGnss->updateConfiguration(config);
+}
+
+Return<bool> GnssConfiguration::setGlonassPositioningProtocol(uint8_t protocol) {
+    if (mGnss == nullptr) {
+        LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
+        return false;
+    }
+
+    GnssConfig config;
+    memset(&config, 0, sizeof(GnssConfig));
+    config.size = sizeof(GnssConfig);
+    config.flags = GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT;
+    config.aGlonassPositionProtocolMask =
+        static_cast<GnssConfigAGlonassPositionProtocolMask>(protocol);
+
+    return mGnss->updateConfiguration(config);
+}
+
+Return<bool> GnssConfiguration::setGpsLock(uint8_t lock) {
+    if (mGnss == nullptr) {
+        LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
+        return false;
+    }
+
+    GnssConfig config;
+    memset(&config, 0, sizeof(GnssConfig));
+    config.size = sizeof(GnssConfig);
+    config.flags = GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT;
+    config.gpsLock = static_cast<GnssConfigGpsLock>(lock);
+
+    return mGnss->updateConfiguration(config);
+}
+
+Return<bool> GnssConfiguration::setEmergencySuplPdn(bool enabled) {
+    if (mGnss == nullptr) {
+        LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
+        return false;
+    }
+
+    GnssConfig config;
+    memset(&config, 0, sizeof(GnssConfig));
+    config.size = sizeof(GnssConfig);
+    config.flags = GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT;
+    config.emergencyPdnForEmergencySupl =
+        static_cast<GnssConfigEmergencyPdnForEmergencySupl>(enabled);
+
+    return mGnss->updateConfiguration(config);
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
diff --git a/msm8998/android/GnssConfiguration.h b/msm8998/android/GnssConfiguration.h
new file mode 100644
index 0000000..f9ea423
--- /dev/null
+++ b/msm8998/android/GnssConfiguration.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+
+ /* Copyright (C) 2016 The Android Open Source 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.
+ */
+
+
+#ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H
+#define ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H
+
+#include <android/hardware/gnss/1.0/IGnssConfiguration.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::gnss::V1_0::IGnssConfiguration;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+/*
+ * Interface for passing GNSS configuration info from platform to HAL.
+ */
+struct Gnss;
+struct GnssConfiguration : public IGnssConfiguration {
+    GnssConfiguration(Gnss* gnss);
+    ~GnssConfiguration() = default;
+
+    /*
+     * Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow.
+     * These declarations were generated from IGnssConfiguration.hal.
+     */
+    Return<bool> setSuplVersion(uint32_t version) override;
+    Return<bool> setSuplMode(uint8_t mode) override;
+    Return<bool> setSuplEs(bool enabled) override;
+    Return<bool> setLppProfile(uint8_t lppProfile) override;
+    Return<bool> setGlonassPositioningProtocol(uint8_t protocol) override;
+    Return<bool> setEmergencySuplPdn(bool enable) override;
+    Return<bool> setGpsLock(uint8_t lock) override;
+
+ private:
+    Gnss* mGnss = nullptr;
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H
diff --git a/msm8998/android/GnssGeofencing.cpp b/msm8998/android/GnssGeofencing.cpp
new file mode 100644
index 0000000..035a092
--- /dev/null
+++ b/msm8998/android/GnssGeofencing.cpp
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#define LOG_TAG "GnssHal_GnssGeofencing"
+
+#include <log_util.h>
+#include <GeofenceAPIClient.h>
+#include "GnssGeofencing.h"
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+void GnssGeofencing::GnssGeofencingDeathRecipient::serviceDied(
+        uint64_t cookie, const wp<IBase>& who) {
+    LOC_LOGE("%s] service died. cookie: %llu, who: %p",
+            __FUNCTION__, static_cast<unsigned long long>(cookie), &who);
+    if (mGnssGeofencing != nullptr) {
+        mGnssGeofencing->removeAllGeofences();
+    }
+}
+
+GnssGeofencing::GnssGeofencing() : mApi(nullptr) {
+    mGnssGeofencingDeathRecipient = new GnssGeofencingDeathRecipient(this);
+}
+
+GnssGeofencing::~GnssGeofencing() {
+    if (mApi != nullptr) {
+        delete mApi;
+        mApi = nullptr;
+    }
+}
+
+// Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow.
+Return<void> GnssGeofencing::setCallback(const sp<IGnssGeofenceCallback>& callback)  {
+    if (mApi != nullptr) {
+        LOC_LOGE("%s]: mApi is NOT nullptr", __FUNCTION__);
+        return Void();
+    }
+
+    mApi = new GeofenceAPIClient(callback);
+    if (mApi == nullptr) {
+        LOC_LOGE("%s]: failed to create mApi", __FUNCTION__);
+    }
+
+    if (mGnssGeofencingCbIface != nullptr) {
+        mGnssGeofencingCbIface->unlinkToDeath(mGnssGeofencingDeathRecipient);
+    }
+    mGnssGeofencingCbIface = callback;
+    if (mGnssGeofencingCbIface != nullptr) {
+        mGnssGeofencingCbIface->linkToDeath(mGnssGeofencingDeathRecipient, 0 /*cookie*/);
+    }
+
+    return Void();
+}
+
+Return<void> GnssGeofencing::addGeofence(
+        int32_t geofenceId,
+        double latitudeDegrees,
+        double longitudeDegrees,
+        double radiusMeters,
+        IGnssGeofenceCallback::GeofenceTransition lastTransition,
+        int32_t monitorTransitions,
+        uint32_t notificationResponsivenessMs,
+        uint32_t unknownTimerMs)  {
+    if (mApi == nullptr) {
+        LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
+    } else {
+        mApi->geofenceAdd(
+                geofenceId,
+                latitudeDegrees,
+                longitudeDegrees,
+                radiusMeters,
+                static_cast<int32_t>(lastTransition),
+                monitorTransitions,
+                notificationResponsivenessMs,
+                unknownTimerMs);
+    }
+    return Void();
+}
+
+Return<void> GnssGeofencing::pauseGeofence(int32_t geofenceId)  {
+    if (mApi == nullptr) {
+        LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
+    } else {
+        mApi->geofencePause(geofenceId);
+    }
+    return Void();
+}
+
+Return<void> GnssGeofencing::resumeGeofence(int32_t geofenceId, int32_t monitorTransitions)  {
+    if (mApi == nullptr) {
+        LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
+    } else {
+        mApi->geofenceResume(geofenceId, monitorTransitions);
+    }
+    return Void();
+}
+
+Return<void> GnssGeofencing::removeGeofence(int32_t geofenceId)  {
+    if (mApi == nullptr) {
+        LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
+    } else {
+        mApi->geofenceRemove(geofenceId);
+    }
+    return Void();
+}
+
+Return<void> GnssGeofencing::removeAllGeofences()  {
+    if (mApi == nullptr) {
+        LOC_LOGD("%s]: mApi is nullptr, do nothing", __FUNCTION__);
+    } else {
+        mApi->geofenceRemoveAll();
+    }
+    return Void();
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
diff --git a/msm8998/android/GnssGeofencing.h b/msm8998/android/GnssGeofencing.h
new file mode 100644
index 0000000..7af5f91
--- /dev/null
+++ b/msm8998/android/GnssGeofencing.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSGEOFENCING_H
+#define ANDROID_HARDWARE_GNSS_V1_1_GNSSGEOFENCING_H
+
+#include <android/hardware/gnss/1.0/IGnssGeofencing.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::gnss::V1_0::IGnssGeofenceCallback;
+using ::android::hardware::gnss::V1_0::IGnssGeofencing;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+class GeofenceAPIClient;
+struct GnssGeofencing : public IGnssGeofencing {
+    GnssGeofencing();
+    ~GnssGeofencing();
+
+    /*
+     * Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow.
+     * These declarations were generated from IGnssGeofencing.hal.
+     */
+    Return<void> setCallback(const sp<IGnssGeofenceCallback>& callback)  override;
+    Return<void> addGeofence(int32_t geofenceId,
+                             double latitudeDegrees,
+                             double longitudeDegrees,
+                             double radiusMeters,
+                             IGnssGeofenceCallback::GeofenceTransition lastTransition,
+                             int32_t monitorTransitions,
+                             uint32_t notificationResponsivenessMs,
+                             uint32_t unknownTimerMs)  override;
+
+    Return<void> pauseGeofence(int32_t geofenceId)  override;
+    Return<void> resumeGeofence(int32_t geofenceId, int32_t monitorTransitions)  override;
+    Return<void> removeGeofence(int32_t geofenceId)  override;
+
+ private:
+    // This method is not part of the IGnss base class.
+    // It is called by GnssGeofencingDeathRecipient to remove all geofences added so far.
+    Return<void> removeAllGeofences();
+
+ private:
+    struct GnssGeofencingDeathRecipient : hidl_death_recipient {
+        GnssGeofencingDeathRecipient(sp<GnssGeofencing> gnssGeofencing) :
+            mGnssGeofencing(gnssGeofencing) {
+        }
+        ~GnssGeofencingDeathRecipient() = default;
+        virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) override;
+        sp<GnssGeofencing> mGnssGeofencing;
+    };
+
+ private:
+    sp<GnssGeofencingDeathRecipient> mGnssGeofencingDeathRecipient = nullptr;
+    sp<IGnssGeofenceCallback> mGnssGeofencingCbIface = nullptr;
+    GeofenceAPIClient* mApi = nullptr;
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_GNSS_V1_1_GNSSGEOFENCING_H
diff --git a/msm8998/android/GnssMeasurement.cpp b/msm8998/android/GnssMeasurement.cpp
new file mode 100644
index 0000000..bc07265
--- /dev/null
+++ b/msm8998/android/GnssMeasurement.cpp
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#define LOG_TAG "LocSvc_GnssMeasurementInterface"
+
+#include <log_util.h>
+#include <GnssMeasurementAPIClient.h>
+#include "GnssMeasurement.h"
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+void GnssMeasurement::GnssMeasurementDeathRecipient::serviceDied(
+        uint64_t cookie, const wp<IBase>& who) {
+    LOC_LOGE("%s] service died. cookie: %llu, who: %p",
+            __FUNCTION__, static_cast<unsigned long long>(cookie), &who);
+    if (mGnssMeasurement != nullptr) {
+        mGnssMeasurement->close();
+    }
+}
+
+GnssMeasurement::GnssMeasurement() {
+    mGnssMeasurementDeathRecipient = new GnssMeasurementDeathRecipient(this);
+    mApi = new GnssMeasurementAPIClient();
+}
+
+GnssMeasurement::~GnssMeasurement() {
+    if (mApi) {
+        delete mApi;
+        mApi = nullptr;
+    }
+}
+
+// Methods from ::android::hardware::gnss::V1_0::IGnssMeasurement follow.
+Return<IGnssMeasurement::GnssMeasurementStatus> GnssMeasurement::setCallback(
+        const sp<IGnssMeasurementCallback>& callback)  {
+
+    Return<IGnssMeasurement::GnssMeasurementStatus> ret =
+        IGnssMeasurement::GnssMeasurementStatus::ERROR_GENERIC;
+    if (mGnssMeasurementCbIface != nullptr) {
+        LOC_LOGE("%s]: GnssMeasurementCallback is already set", __FUNCTION__);
+        return IGnssMeasurement::GnssMeasurementStatus::ERROR_ALREADY_INIT;
+    }
+
+    if (callback == nullptr) {
+        LOC_LOGE("%s]: callback is nullptr", __FUNCTION__);
+        return ret;
+    }
+    if (mApi == nullptr) {
+        LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
+        return ret;
+    }
+
+    mGnssMeasurementCbIface = callback;
+    mGnssMeasurementCbIface->linkToDeath(mGnssMeasurementDeathRecipient, 0 /*cookie*/);
+
+    return mApi->gnssMeasurementSetCallback(callback);
+}
+
+Return<void> GnssMeasurement::close()  {
+    if (mApi == nullptr) {
+        LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
+        return Void();
+    }
+
+    if (mGnssMeasurementCbIface != nullptr) {
+        mGnssMeasurementCbIface->unlinkToDeath(mGnssMeasurementDeathRecipient);
+        mGnssMeasurementCbIface = nullptr;
+    }
+    mApi->gnssMeasurementClose();
+
+    return Void();
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
diff --git a/msm8998/android/GnssMeasurement.h b/msm8998/android/GnssMeasurement.h
new file mode 100644
index 0000000..cd364c3
--- /dev/null
+++ b/msm8998/android/GnssMeasurement.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSMEASUREMENT_H
+#define ANDROID_HARDWARE_GNSS_V1_1_GNSSMEASUREMENT_H
+
+#include <android/hardware/gnss/1.0/IGnssMeasurement.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::gnss::V1_0::IGnssMeasurement;
+using ::android::hardware::gnss::V1_0::IGnssMeasurementCallback;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+class GnssMeasurementAPIClient;
+struct GnssMeasurement : public IGnssMeasurement {
+    GnssMeasurement();
+    ~GnssMeasurement();
+
+    /*
+     * Methods from ::android::hardware::gnss::V1_0::IGnssMeasurement follow.
+     * These declarations were generated from IGnssMeasurement.hal.
+     */
+    Return<GnssMeasurementStatus> setCallback(
+        const sp<IGnssMeasurementCallback>& callback) override;
+    Return<void> close() override;
+
+ private:
+    struct GnssMeasurementDeathRecipient : hidl_death_recipient {
+        GnssMeasurementDeathRecipient(sp<GnssMeasurement> gnssMeasurement) :
+            mGnssMeasurement(gnssMeasurement) {
+        }
+        ~GnssMeasurementDeathRecipient() = default;
+        virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) override;
+        sp<GnssMeasurement> mGnssMeasurement;
+    };
+
+ private:
+    sp<GnssMeasurementDeathRecipient> mGnssMeasurementDeathRecipient = nullptr;
+    sp<IGnssMeasurementCallback> mGnssMeasurementCbIface = nullptr;
+    GnssMeasurementAPIClient* mApi;
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_GNSS_V1_1_GNSSMEASUREMENT_H
diff --git a/msm8998/android/GnssNi.cpp b/msm8998/android/GnssNi.cpp
new file mode 100644
index 0000000..4437932
--- /dev/null
+++ b/msm8998/android/GnssNi.cpp
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#define LOG_TAG "LocSvc_GnssNiInterface"
+
+#include <log_util.h>
+#include "Gnss.h"
+#include "GnssNi.h"
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+void GnssNi::GnssNiDeathRecipient::serviceDied(uint64_t cookie, const wp<IBase>& who) {
+    LOC_LOGE("%s] service died. cookie: %llu, who: %p",
+            __FUNCTION__, static_cast<unsigned long long>(cookie), &who);
+    // we do nothing here
+    // Gnss::GnssDeathRecipient will stop the session
+}
+
+GnssNi::GnssNi(Gnss* gnss) : mGnss(gnss) {
+    mGnssNiDeathRecipient = new GnssNiDeathRecipient(this);
+}
+
+// Methods from ::android::hardware::gnss::V1_0::IGnssNi follow.
+Return<void> GnssNi::setCallback(const sp<IGnssNiCallback>& callback)  {
+    if (mGnss == nullptr) {
+        LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
+        return Void();
+    }
+
+    mGnss->setGnssNiCb(callback);
+
+    if (mGnssNiCbIface != nullptr) {
+        mGnssNiCbIface->unlinkToDeath(mGnssNiDeathRecipient);
+    }
+    mGnssNiCbIface = callback;
+    if (mGnssNiCbIface != nullptr) {
+        mGnssNiCbIface->linkToDeath(mGnssNiDeathRecipient, 0 /*cookie*/);
+    }
+
+    return Void();
+}
+
+Return<void> GnssNi::respond(int32_t notifId, IGnssNiCallback::GnssUserResponseType userResponse)  {
+    if (mGnss == nullptr) {
+        LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
+        return Void();
+    }
+
+    GnssAPIClient* api = mGnss->getApi();
+    if (api == nullptr) {
+        LOC_LOGE("%s]: api is nullptr", __FUNCTION__);
+        return Void();
+    }
+
+    api->gnssNiRespond(notifId, userResponse);
+
+    return Void();
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
diff --git a/msm8998/android/GnssNi.h b/msm8998/android/GnssNi.h
new file mode 100644
index 0000000..f6fe0bb
--- /dev/null
+++ b/msm8998/android/GnssNi.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSNI_H
+#define ANDROID_HARDWARE_GNSS_V1_1_GNSSNI_H
+
+#include <android/hardware/gnss/1.0/IGnssNi.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::gnss::V1_0::IGnssNi;
+using ::android::hardware::gnss::V1_0::IGnssNiCallback;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+struct Gnss;
+struct GnssNi : public IGnssNi {
+    GnssNi(Gnss* gnss);
+    ~GnssNi() = default;
+
+    /*
+     * Methods from ::android::hardware::gnss::V1_0::IGnssNi follow.
+     * These declarations were generated from IGnssNi.hal.
+     */
+    Return<void> setCallback(const sp<IGnssNiCallback>& callback) override;
+    Return<void> respond(int32_t notifId,
+                         IGnssNiCallback::GnssUserResponseType userResponse) override;
+
+ private:
+    struct GnssNiDeathRecipient : hidl_death_recipient {
+        GnssNiDeathRecipient(sp<GnssNi> gnssNi) : mGnssNi(gnssNi) {
+        }
+        ~GnssNiDeathRecipient() = default;
+        virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) override;
+        sp<GnssNi> mGnssNi;
+    };
+
+ private:
+    sp<GnssNiDeathRecipient> mGnssNiDeathRecipient = nullptr;
+    sp<IGnssNiCallback> mGnssNiCbIface = nullptr;
+    Gnss* mGnss = nullptr;
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_GNSS_V1_1_GNSSNI_H
diff --git a/msm8998/android/android.hardware.gnss@1.0-service-qti.rc b/msm8998/android/android.hardware.gnss@1.0-service-qti.rc
new file mode 100644
index 0000000..7ba6460
--- /dev/null
+++ b/msm8998/android/android.hardware.gnss@1.0-service-qti.rc
@@ -0,0 +1,4 @@
+service gnss_service /system/bin/hw/android.hardware.gnss@1.0-service-qti
+    class main
+    user system
+    group system
diff --git a/msm8998/android/location_api/FlpAPIClient.cpp b/msm8998/android/location_api/FlpAPIClient.cpp
new file mode 100644
index 0000000..2fb8caa
--- /dev/null
+++ b/msm8998/android/location_api/FlpAPIClient.cpp
@@ -0,0 +1,182 @@
+/* Copyright (c) 2017, 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_FlpAPIClient"
+
+#include <log_util.h>
+#include <loc_cfg.h>
+
+#include "LocationUtil.h"
+#include "FlpAPIClient.h"
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+static void convertBatchOption(const IGnssBatching::Options& in, LocationOptions& out,
+        LocationCapabilitiesMask mask);
+
+FlpAPIClient::FlpAPIClient(const sp<IGnssBatchingCallback>& callback) :
+    LocationAPIClientBase(),
+    mGnssBatchingCbIface(callback),
+    mDefaultId(42),
+    mLocationCapabilitiesMask(0)
+{
+    LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback);
+
+    LocationCallbacks locationCallbacks;
+    locationCallbacks.size = sizeof(LocationCallbacks);
+
+    locationCallbacks.trackingCb = nullptr;
+    locationCallbacks.batchingCb = nullptr;
+    if (mGnssBatchingCbIface != nullptr) {
+        locationCallbacks.batchingCb = [this](size_t count, Location* location) {
+            onBatchingCb(count, location);
+        };
+    }
+    locationCallbacks.geofenceBreachCb = nullptr;
+    locationCallbacks.geofenceStatusCb = nullptr;
+    locationCallbacks.gnssLocationInfoCb = nullptr;
+    locationCallbacks.gnssNiCb = nullptr;
+    locationCallbacks.gnssSvCb = nullptr;
+    locationCallbacks.gnssNmeaCb = nullptr;
+    locationCallbacks.gnssMeasurementsCb = nullptr;
+
+    locAPISetCallbacks(locationCallbacks);
+}
+
+FlpAPIClient::~FlpAPIClient()
+{
+    LOC_LOGD("%s]: ()", __FUNCTION__);
+}
+
+int FlpAPIClient::flpGetBatchSize()
+{
+    LOC_LOGD("%s]: ()", __FUNCTION__);
+    return locAPIGetBatchSize();
+}
+
+int FlpAPIClient::flpStartSession(const IGnssBatching::Options& opts)
+{
+    LOC_LOGD("%s]: (%lld %d)", __FUNCTION__,
+            static_cast<long long>(opts.periodNanos), static_cast<uint8_t>(opts.flags));
+    int retVal = -1;
+    LocationOptions options;
+    convertBatchOption(opts, options, mLocationCapabilitiesMask);
+    uint32_t mode = 0;
+    if (opts.flags == static_cast<uint8_t>(IGnssBatching::Flag::WAKEUP_ON_FIFO_FULL)) {
+        mode = SESSION_MODE_ON_FULL;
+    }
+    if (locAPIStartSession(mDefaultId, mode, options) == LOCATION_ERROR_SUCCESS) {
+        retVal = 1;
+    }
+    return retVal;
+}
+
+int FlpAPIClient::flpUpdateSessionOptions(const IGnssBatching::Options& opts)
+{
+    LOC_LOGD("%s]: (%lld %d)", __FUNCTION__,
+            static_cast<long long>(opts.periodNanos), static_cast<uint8_t>(opts.flags));
+    int retVal = -1;
+    LocationOptions options;
+    convertBatchOption(opts, options, mLocationCapabilitiesMask);
+
+    uint32_t mode = 0;
+    if (opts.flags == static_cast<uint8_t>(IGnssBatching::Flag::WAKEUP_ON_FIFO_FULL)) {
+        mode = SESSION_MODE_ON_FULL;
+    }
+    if (locAPIUpdateSessionOptions(mDefaultId, mode, options) == LOCATION_ERROR_SUCCESS) {
+        retVal = 1;
+    }
+    return retVal;
+}
+
+int FlpAPIClient::flpStopSession()
+{
+    LOC_LOGD("%s]: ", __FUNCTION__);
+    int retVal = -1;
+    if (locAPIStopSession(mDefaultId) == LOCATION_ERROR_SUCCESS) {
+        retVal = 1;
+    }
+    return retVal;
+}
+
+void FlpAPIClient::flpGetBatchedLocation(int last_n_locations)
+{
+    LOC_LOGD("%s]: (%d)", __FUNCTION__, last_n_locations);
+    locAPIGetBatchedLocations(last_n_locations);
+}
+
+void FlpAPIClient::flpFlushBatchedLocations()
+{
+    LOC_LOGD("%s]: ()", __FUNCTION__);
+    locAPIGetBatchedLocations(SIZE_MAX);
+}
+
+void FlpAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask)
+{
+    LOC_LOGD("%s]: (%02x)", __FUNCTION__, capabilitiesMask);
+    mLocationCapabilitiesMask = capabilitiesMask;
+}
+
+void FlpAPIClient::onBatchingCb(size_t count, Location* location)
+{
+    LOC_LOGD("%s]: (count: %zu)", __FUNCTION__, count);
+    if (mGnssBatchingCbIface != nullptr && count > 0) {
+        hidl_vec<GnssLocation> locationVec;
+        locationVec.resize(count);
+        for (size_t i = 0; i < count; i++) {
+            convertGnssLocation(location[i], locationVec[i]);
+        }
+        mGnssBatchingCbIface->gnssLocationBatchCb(locationVec);
+    }
+}
+
+static void convertBatchOption(const IGnssBatching::Options& in, LocationOptions& out,
+        LocationCapabilitiesMask mask)
+{
+    memset(&out, 0, sizeof(LocationOptions));
+    out.size = sizeof(LocationOptions);
+    out.minInterval = (uint32_t)(in.periodNanos / 1000000L);
+    out.minDistance = 0;
+    out.mode = GNSS_SUPL_MODE_STANDALONE;
+    if (mask & LOCATION_CAPABILITIES_GNSS_MSA_BIT)
+        out.mode = GNSS_SUPL_MODE_MSA;
+    if (mask & LOCATION_CAPABILITIES_GNSS_MSB_BIT)
+        out.mode = GNSS_SUPL_MODE_MSB;
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
diff --git a/msm8998/android/location_api/FlpAPIClient.h b/msm8998/android/location_api/FlpAPIClient.h
new file mode 100644
index 0000000..9f9be1e
--- /dev/null
+++ b/msm8998/android/location_api/FlpAPIClient.h
@@ -0,0 +1,77 @@
+/* Copyright (c) 2017, 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 FLP_API_CLINET_H
+#define FLP_API_CLINET_H
+
+#include <android/hardware/gnss/1.0/IGnssBatching.h>
+#include <android/hardware/gnss/1.0/IGnssBatchingCallback.h>
+#include <pthread.h>
+
+#include <LocationAPIClientBase.h>
+
+#define FLP_CONF_FILE "/etc/flp.conf"
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+class FlpAPIClient : public LocationAPIClientBase
+{
+public:
+    FlpAPIClient(const sp<IGnssBatchingCallback>& callback);
+    ~FlpAPIClient();
+    int flpGetBatchSize();
+    int flpStartSession(const IGnssBatching::Options& options);
+    int flpUpdateSessionOptions(const IGnssBatching::Options& options);
+    int flpStopSession();
+    void flpGetBatchedLocation(int last_n_locations);
+    void flpFlushBatchedLocations();
+
+    inline LocationCapabilitiesMask flpGetCapabilities() { return mLocationCapabilitiesMask; }
+
+    // callbacks
+    void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final;
+    void onBatchingCb(size_t count, Location* location) final;
+
+private:
+    sp<IGnssBatchingCallback> mGnssBatchingCbIface;
+    uint32_t mDefaultId;
+    int mBatchSize;
+    LocationCapabilitiesMask mLocationCapabilitiesMask;
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
+#endif // FLP_API_CLINET_H
diff --git a/msm8998/android/location_api/GeofenceAPIClient.cpp b/msm8998/android/location_api/GeofenceAPIClient.cpp
new file mode 100644
index 0000000..5be1cff
--- /dev/null
+++ b/msm8998/android/location_api/GeofenceAPIClient.cpp
@@ -0,0 +1,245 @@
+/* Copyright (c) 2017, 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_GeofenceApiClient"
+
+#include <log_util.h>
+#include <loc_cfg.h>
+
+#include "LocationUtil.h"
+#include "GeofenceAPIClient.h"
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+
+GeofenceAPIClient::GeofenceAPIClient(const sp<IGnssGeofenceCallback>& callback) :
+    LocationAPIClientBase(),
+    mGnssGeofencingCbIface(callback)
+{
+    LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback);
+
+    LocationCallbacks locationCallbacks;
+    locationCallbacks.size = sizeof(LocationCallbacks);
+
+    locationCallbacks.trackingCb = nullptr;
+    locationCallbacks.batchingCb = nullptr;
+
+    locationCallbacks.geofenceBreachCb = nullptr;
+    if (mGnssGeofencingCbIface != nullptr) {
+        locationCallbacks.geofenceBreachCb =
+            [this](GeofenceBreachNotification geofenceBreachNotification) {
+                onGeofenceBreachCb(geofenceBreachNotification);
+            };
+
+        locationCallbacks.geofenceStatusCb =
+            [this](GeofenceStatusNotification geofenceStatusNotification) {
+                onGeofenceStatusCb(geofenceStatusNotification);
+            };
+    }
+
+    locationCallbacks.gnssLocationInfoCb = nullptr;
+    locationCallbacks.gnssNiCb = nullptr;
+    locationCallbacks.gnssSvCb = nullptr;
+    locationCallbacks.gnssNmeaCb = nullptr;
+    locationCallbacks.gnssMeasurementsCb = nullptr;
+
+    locAPISetCallbacks(locationCallbacks);
+}
+
+void GeofenceAPIClient::geofenceAdd(uint32_t geofence_id, double latitude, double longitude,
+        double radius_meters, int32_t last_transition, int32_t monitor_transitions,
+        uint32_t notification_responsiveness_ms, uint32_t unknown_timer_ms)
+{
+    LOC_LOGD("%s]: (%d %f %f %f %d %d %d %d)", __FUNCTION__,
+            geofence_id, latitude, longitude, radius_meters,
+            last_transition, monitor_transitions, notification_responsiveness_ms, unknown_timer_ms);
+
+    GeofenceOption options;
+    memset(&options, 0, sizeof(GeofenceOption));
+    options.size = sizeof(GeofenceOption);
+    if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::ENTERED)
+        options.breachTypeMask |= GEOFENCE_BREACH_ENTER_BIT;
+    if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::EXITED)
+        options.breachTypeMask |=  GEOFENCE_BREACH_EXIT_BIT;
+    options.responsiveness = notification_responsiveness_ms;
+
+    GeofenceInfo data;
+    data.size = sizeof(GeofenceInfo);
+    data.latitude = latitude;
+    data.longitude = longitude;
+    data.radius = radius_meters;
+
+    locAPIAddGeofences(1, &geofence_id, &options, &data);
+}
+
+void GeofenceAPIClient::geofencePause(uint32_t geofence_id)
+{
+    LOC_LOGD("%s]: (%d)", __FUNCTION__, geofence_id);
+    locAPIPauseGeofences(1, &geofence_id);
+}
+
+void GeofenceAPIClient::geofenceResume(uint32_t geofence_id, int32_t monitor_transitions)
+{
+    LOC_LOGD("%s]: (%d %d)", __FUNCTION__, geofence_id, monitor_transitions);
+    GeofenceBreachTypeMask mask = 0;
+    if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::ENTERED)
+        mask |= GEOFENCE_BREACH_ENTER_BIT;
+    if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::EXITED)
+        mask |=  GEOFENCE_BREACH_EXIT_BIT;
+    locAPIResumeGeofences(1, &geofence_id, &mask);
+}
+
+void GeofenceAPIClient::geofenceRemove(uint32_t geofence_id)
+{
+    LOC_LOGD("%s]: (%d)", __FUNCTION__, geofence_id);
+    locAPIRemoveGeofences(1, &geofence_id);
+}
+
+void GeofenceAPIClient::geofenceRemoveAll()
+{
+    LOC_LOGD("%s]", __FUNCTION__);
+    // TODO locAPIRemoveAllGeofences();
+}
+
+// callbacks
+void GeofenceAPIClient::onGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification)
+{
+    LOC_LOGD("%s]: (%zu)", __FUNCTION__, geofenceBreachNotification.count);
+    if (mGnssGeofencingCbIface != nullptr) {
+        for (size_t i = 0; i < geofenceBreachNotification.count; i++) {
+            GnssLocation gnssLocation;
+            convertGnssLocation(geofenceBreachNotification.location, gnssLocation);
+
+            IGnssGeofenceCallback::GeofenceTransition transition;
+            if (geofenceBreachNotification.type == GEOFENCE_BREACH_ENTER)
+                transition = IGnssGeofenceCallback::GeofenceTransition::ENTERED;
+            else if (geofenceBreachNotification.type == GEOFENCE_BREACH_EXIT)
+                transition = IGnssGeofenceCallback::GeofenceTransition::EXITED;
+            else {
+                // continue with other breach if transition is
+                // nether GPS_GEOFENCE_ENTERED nor GPS_GEOFENCE_EXITED
+                continue;
+            }
+
+            mGnssGeofencingCbIface->gnssGeofenceTransitionCb(
+                    geofenceBreachNotification.ids[i], gnssLocation, transition,
+                    static_cast<GnssUtcTime>(geofenceBreachNotification.timestamp));
+        }
+    }
+}
+
+void GeofenceAPIClient::onGeofenceStatusCb(GeofenceStatusNotification geofenceStatusNotification)
+{
+    LOC_LOGD("%s]: (%d)", __FUNCTION__, geofenceStatusNotification.available);
+    if (mGnssGeofencingCbIface != nullptr) {
+        IGnssGeofenceCallback::GeofenceAvailability status =
+            IGnssGeofenceCallback::GeofenceAvailability::UNAVAILABLE;
+        if (geofenceStatusNotification.available == GEOFENCE_STATUS_AVAILABILE_YES) {
+            status = IGnssGeofenceCallback::GeofenceAvailability::AVAILABLE;
+        }
+        GnssLocation gnssLocation;
+        memset(&gnssLocation, 0, sizeof(GnssLocation));
+        mGnssGeofencingCbIface->gnssGeofenceStatusCb(status, gnssLocation);
+    }
+}
+
+void GeofenceAPIClient::onAddGeofencesCb(size_t count, LocationError* errors, uint32_t* ids)
+{
+    LOC_LOGD("%s]: (%zu)", __FUNCTION__, count);
+    if (mGnssGeofencingCbIface != nullptr) {
+        for (size_t i = 0; i < count; i++) {
+            IGnssGeofenceCallback::GeofenceStatus status =
+                IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC;
+            if (errors[i] == LOCATION_ERROR_SUCCESS)
+                status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS;
+            else if (errors[i] == LOCATION_ERROR_ID_EXISTS)
+                status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_EXISTS;
+            mGnssGeofencingCbIface->gnssGeofenceAddCb(ids[i], status);
+        }
+    }
+}
+
+void GeofenceAPIClient::onRemoveGeofencesCb(size_t count, LocationError* errors, uint32_t* ids)
+{
+    LOC_LOGD("%s]: (%zu)", __FUNCTION__, count);
+    if (mGnssGeofencingCbIface != nullptr) {
+        for (size_t i = 0; i < count; i++) {
+            IGnssGeofenceCallback::GeofenceStatus status =
+                IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC;
+            if (errors[i] == LOCATION_ERROR_SUCCESS)
+                status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS;
+            else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN)
+                status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN;
+            mGnssGeofencingCbIface->gnssGeofenceRemoveCb(ids[i], status);
+        }
+    }
+}
+
+void GeofenceAPIClient::onPauseGeofencesCb(size_t count, LocationError* errors, uint32_t* ids)
+{
+    LOC_LOGD("%s]: (%zu)", __FUNCTION__, count);
+    if (mGnssGeofencingCbIface != nullptr) {
+        for (size_t i = 0; i < count; i++) {
+            IGnssGeofenceCallback::GeofenceStatus status =
+                IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC;
+            if (errors[i] == LOCATION_ERROR_SUCCESS)
+                status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS;
+            else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN)
+                status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN;
+            mGnssGeofencingCbIface->gnssGeofencePauseCb(ids[i], status);
+        }
+    }
+}
+
+void GeofenceAPIClient::onResumeGeofencesCb(size_t count, LocationError* errors, uint32_t* ids)
+{
+    LOC_LOGD("%s]: (%zu)", __FUNCTION__, count);
+    if (mGnssGeofencingCbIface != nullptr) {
+        for (size_t i = 0; i < count; i++) {
+            IGnssGeofenceCallback::GeofenceStatus status =
+                IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC;
+            if (errors[i] == LOCATION_ERROR_SUCCESS)
+                status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS;
+            else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN)
+                status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN;
+            mGnssGeofencingCbIface->gnssGeofenceResumeCb(ids[i], status);
+        }
+    }
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
diff --git a/msm8998/android/location_api/GeofenceAPIClient.h b/msm8998/android/location_api/GeofenceAPIClient.h
new file mode 100644
index 0000000..f779bcb
--- /dev/null
+++ b/msm8998/android/location_api/GeofenceAPIClient.h
@@ -0,0 +1,76 @@
+/* Copyright (c) 2017, 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 GEOFENCE_API_CLINET_H
+#define GEOFENCE_API_CLINET_H
+
+
+#include <android/hardware/gnss/1.0/IGnssGeofenceCallback.h>
+#include <LocationAPIClientBase.h>
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::sp;
+
+class GeofenceAPIClient : public LocationAPIClientBase
+{
+public:
+    GeofenceAPIClient(const sp<IGnssGeofenceCallback>& callback);
+    virtual ~GeofenceAPIClient() = default;
+
+    void geofenceAdd(uint32_t geofence_id, double latitude, double longitude,
+            double radius_meters, int32_t last_transition, int32_t monitor_transitions,
+            uint32_t notification_responsiveness_ms, uint32_t unknown_timer_ms);
+    void geofencePause(uint32_t geofence_id);
+    void geofenceResume(uint32_t geofence_id, int32_t monitor_transitions);
+    void geofenceRemove(uint32_t geofence_id);
+    void geofenceRemoveAll();
+
+    // callbacks
+    void onGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification) final;
+    void onGeofenceStatusCb(GeofenceStatusNotification geofenceStatusNotification) final;
+    void onAddGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final;
+    void onRemoveGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final;
+    void onPauseGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final;
+    void onResumeGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final;
+
+private:
+    sp<IGnssGeofenceCallback> mGnssGeofencingCbIface;
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
+#endif // GEOFENCE_API_CLINET_H
diff --git a/msm8998/android/location_api/GnssAPIClient.cpp b/msm8998/android/location_api/GnssAPIClient.cpp
new file mode 100644
index 0000000..b4f0406
--- /dev/null
+++ b/msm8998/android/location_api/GnssAPIClient.cpp
@@ -0,0 +1,406 @@
+/* Copyright (c) 2017, 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_GnssAPIClient"
+
+#include <log_util.h>
+#include <loc_cfg.h>
+
+#include "LocationUtil.h"
+#include "GnssAPIClient.h"
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+static void convertGnssSvStatus(GnssSvNotification& in, IGnssCallback::GnssSvStatus& out);
+
+GnssAPIClient::GnssAPIClient(const sp<IGnssCallback>& gpsCb,
+    const sp<IGnssNiCallback>& niCb) :
+    LocationAPIClientBase(),
+    mGnssCbIface(nullptr),
+    mGnssNiCbIface(nullptr),
+    mLocationCapabilitiesMask(0)
+{
+    LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb);
+
+    // set default LocationOptions.
+    memset(&mLocationOptions, 0, sizeof(LocationOptions));
+    mLocationOptions.size = sizeof(LocationOptions);
+    mLocationOptions.minInterval = 1000;
+    mLocationOptions.minDistance = 0;
+    mLocationOptions.mode = GNSS_SUPL_MODE_STANDALONE;
+
+    gnssUpdateCallbacks(gpsCb, niCb);
+}
+
+GnssAPIClient::~GnssAPIClient()
+{
+    LOC_LOGD("%s]: ()", __FUNCTION__);
+}
+
+// for GpsInterface
+void GnssAPIClient::gnssUpdateCallbacks(const sp<IGnssCallback>& gpsCb,
+    const sp<IGnssNiCallback>& niCb)
+{
+    LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb);
+
+    mGnssCbIface = gpsCb;
+    mGnssNiCbIface = niCb;
+
+    LocationCallbacks locationCallbacks;
+    locationCallbacks.size = sizeof(LocationCallbacks);
+
+    locationCallbacks.trackingCb = nullptr;
+    if (mGnssCbIface != nullptr) {
+        locationCallbacks.trackingCb = [this](Location location) {
+            onTrackingCb(location);
+        };
+    }
+
+    locationCallbacks.batchingCb = nullptr;
+    locationCallbacks.geofenceBreachCb = nullptr;
+    locationCallbacks.geofenceStatusCb = nullptr;
+    locationCallbacks.gnssLocationInfoCb = nullptr;
+
+    locationCallbacks.gnssNiCb = nullptr;
+    if (mGnssNiCbIface != nullptr) {
+        locationCallbacks.gnssNiCb = [this](uint32_t id, GnssNiNotification gnssNiNotification) {
+            onGnssNiCb(id, gnssNiNotification);
+        };
+    }
+
+    locationCallbacks.gnssSvCb = nullptr;
+    if (mGnssCbIface != nullptr) {
+        locationCallbacks.gnssSvCb = [this](GnssSvNotification gnssSvNotification) {
+            onGnssSvCb(gnssSvNotification);
+        };
+    }
+
+    locationCallbacks.gnssNmeaCb = nullptr;
+    if (mGnssCbIface != nullptr) {
+        locationCallbacks.gnssNmeaCb = [this](GnssNmeaNotification gnssNmeaNotification) {
+            onGnssNmeaCb(gnssNmeaNotification);
+        };
+    }
+
+    locationCallbacks.gnssMeasurementsCb = nullptr;
+
+    locAPISetCallbacks(locationCallbacks);
+}
+
+bool GnssAPIClient::gnssStart()
+{
+    LOC_LOGD("%s]: ()", __FUNCTION__);
+    bool retVal = true;
+    locAPIStartTracking(mLocationOptions);
+    return retVal;
+}
+
+bool GnssAPIClient::gnssStop()
+{
+    LOC_LOGD("%s]: ()", __FUNCTION__);
+    bool retVal = true;
+    locAPIStopTracking();
+    return retVal;
+}
+
+void GnssAPIClient::gnssDeleteAidingData(IGnss::GnssAidingData aidingDataFlags)
+{
+    LOC_LOGD("%s]: (%02hx)", __FUNCTION__, aidingDataFlags);
+    GnssAidingData data;
+    memset(&data, 0, sizeof (GnssAidingData));
+    data.sv.svTypeMask = GNSS_AIDING_DATA_SV_TYPE_GPS |
+        GNSS_AIDING_DATA_SV_TYPE_GLONASS |
+        GNSS_AIDING_DATA_SV_TYPE_QZSS |
+        GNSS_AIDING_DATA_SV_TYPE_BEIDOU |
+        GNSS_AIDING_DATA_SV_TYPE_GALILEO;
+
+    if (aidingDataFlags == IGnss::GnssAidingData::DELETE_ALL)
+        data.deleteAll = true;
+    else {
+        if (aidingDataFlags & IGnss::GnssAidingData::DELETE_EPHEMERIS)
+            data.sv.svMask |= GNSS_AIDING_DATA_SV_EPHEMERIS;
+        if (aidingDataFlags & IGnss::GnssAidingData::DELETE_ALMANAC)
+            data.sv.svMask |= GNSS_AIDING_DATA_SV_ALMANAC;
+        if (aidingDataFlags & IGnss::GnssAidingData::DELETE_POSITION)
+            data.common.mask |= GNSS_AIDING_DATA_COMMON_POSITION;
+        if (aidingDataFlags & IGnss::GnssAidingData::DELETE_TIME)
+            data.common.mask |= GNSS_AIDING_DATA_COMMON_TIME;
+        if (aidingDataFlags & IGnss::GnssAidingData::DELETE_IONO)
+            data.sv.svMask |= GNSS_AIDING_DATA_SV_IONOSPHERE;
+        if (aidingDataFlags & IGnss::GnssAidingData::DELETE_UTC)
+            data.common.mask |= GNSS_AIDING_DATA_COMMON_UTC;
+        if (aidingDataFlags & IGnss::GnssAidingData::DELETE_HEALTH)
+            data.sv.svMask |= GNSS_AIDING_DATA_SV_HEALTH;
+        if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SVDIR)
+            data.sv.svMask |= GNSS_AIDING_DATA_SV_DIRECTION;
+        if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SVSTEER)
+            data.sv.svMask |= GNSS_AIDING_DATA_SV_STEER;
+        if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SADATA)
+            data.sv.svMask |= GNSS_AIDING_DATA_SV_SA_DATA;
+        if (aidingDataFlags & IGnss::GnssAidingData::DELETE_RTI)
+            data.common.mask |= GNSS_AIDING_DATA_COMMON_RTI;
+        if (aidingDataFlags & IGnss::GnssAidingData::DELETE_CELLDB_INFO)
+            data.common.mask |= GNSS_AIDING_DATA_COMMON_CELLDB;
+    }
+    locAPIGnssDeleteAidingData(data);
+}
+
+bool GnssAPIClient::gnssSetPositionMode(IGnss::GnssPositionMode mode,
+        IGnss::GnssPositionRecurrence recurrence, uint32_t minIntervalMs,
+        uint32_t preferredAccuracyMeters, uint32_t preferredTimeMs)
+{
+    LOC_LOGD("%s]: (%d %d %d %d %d)", __FUNCTION__,
+            (int)mode, recurrence, minIntervalMs, preferredAccuracyMeters, preferredTimeMs);
+    bool retVal = true;
+    memset(&mLocationOptions, 0, sizeof(LocationOptions));
+    mLocationOptions.size = sizeof(LocationOptions);
+    mLocationOptions.minInterval = minIntervalMs;
+    mLocationOptions.minDistance = preferredAccuracyMeters;
+    if (mode == IGnss::GnssPositionMode::STANDALONE)
+        mLocationOptions.mode = GNSS_SUPL_MODE_STANDALONE;
+    else if (mode == IGnss::GnssPositionMode::MS_BASED)
+        mLocationOptions.mode = GNSS_SUPL_MODE_MSB;
+    else if (mode ==  IGnss::GnssPositionMode::MS_ASSISTED)
+        mLocationOptions.mode = GNSS_SUPL_MODE_MSA;
+    return retVal;
+}
+
+// for GpsNiInterface
+void GnssAPIClient::gnssNiRespond(int32_t notifId,
+        IGnssNiCallback::GnssUserResponseType userResponse)
+{
+    LOC_LOGD("%s]: (%d %d)", __FUNCTION__, notifId, static_cast<int>(userResponse));
+    GnssNiResponse data = GNSS_NI_RESPONSE_IGNORE;
+    if (userResponse == IGnssNiCallback::GnssUserResponseType::RESPONSE_ACCEPT)
+        data = GNSS_NI_RESPONSE_ACCEPT;
+    else if (userResponse == IGnssNiCallback::GnssUserResponseType::RESPONSE_DENY)
+        data = GNSS_NI_RESPONSE_DENY;
+    else if (userResponse == IGnssNiCallback::GnssUserResponseType::RESPONSE_NORESP)
+        data = GNSS_NI_RESPONSE_NO_RESPONSE;
+    locAPIGnssNiResponse(notifId, data);
+}
+
+// for GnssConfigurationInterface
+void GnssAPIClient::gnssConfigurationUpdate(const GnssConfig& gnssConfig)
+{
+    LOC_LOGD("%s]: (%02x)", __FUNCTION__, gnssConfig.flags);
+    locAPIGnssUpdateConfig(gnssConfig);
+}
+
+// callbacks
+void GnssAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask)
+{
+    LOC_LOGD("%s]: (%02x)", __FUNCTION__, capabilitiesMask);
+    mLocationCapabilitiesMask = capabilitiesMask;
+    if (mGnssCbIface != nullptr) {
+        uint32_t data = 0;
+        if ((capabilitiesMask & LOCATION_CAPABILITIES_TIME_BASED_TRACKING_BIT) ||
+                (capabilitiesMask & LOCATION_CAPABILITIES_TIME_BASED_BATCHING_BIT) ||
+                (capabilitiesMask & LOCATION_CAPABILITIES_DISTANCE_BASED_TRACKING_BIT) ||
+                (capabilitiesMask & LOCATION_CAPABILITIES_DISTANCE_BASED_BATCHING_BIT))
+            data |= IGnssCallback::Capabilities::SCHEDULING;
+        if (capabilitiesMask & LOCATION_CAPABILITIES_GEOFENCE_BIT)
+            data |= IGnssCallback::Capabilities::GEOFENCING;
+        if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT)
+            data |= IGnssCallback::Capabilities::MEASUREMENTS;
+        if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSB_BIT)
+            data |= IGnssCallback::Capabilities::MSB;
+        if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSA_BIT)
+            data |= IGnssCallback::Capabilities::MSA;
+        mGnssCbIface->gnssSetCapabilitesCb(data);
+    }
+    if (mGnssCbIface != nullptr) {
+        IGnssCallback::GnssSystemInfo gnssInfo;
+        gnssInfo.yearOfHw = 2015;
+        if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT) {
+            gnssInfo.yearOfHw = 2017;
+        }
+        LOC_LOGV("%s:%d] set_system_info_cb (%d)", __FUNCTION__, __LINE__, gnssInfo.yearOfHw);
+        mGnssCbIface->gnssSetSystemInfoCb(gnssInfo);
+    }
+}
+
+void GnssAPIClient::onTrackingCb(Location location)
+{
+    LOC_LOGD("%s]: (flags: %02x)", __FUNCTION__, location.flags);
+    if (mGnssCbIface != nullptr) {
+        GnssLocation gnssLocation;
+        convertGnssLocation(location, gnssLocation);
+        mGnssCbIface->gnssLocationCb(gnssLocation);
+    }
+}
+
+void GnssAPIClient::onGnssNiCb(uint32_t id, GnssNiNotification gnssNiNotification)
+{
+    LOC_LOGD("%s]: (id: %d)", __FUNCTION__, id);
+
+    if (mGnssNiCbIface == nullptr) {
+        LOC_LOGE("%s]: mGnssNiCbIface is nullptr", __FUNCTION__);
+        return;
+    }
+
+    IGnssNiCallback::GnssNiNotification notificationGnss;
+
+    notificationGnss.notificationId = id;
+
+    if (gnssNiNotification.type == GNSS_NI_TYPE_VOICE)
+        notificationGnss.niType = IGnssNiCallback::GnssNiType::VOICE;
+    else if (gnssNiNotification.type == GNSS_NI_TYPE_SUPL)
+        notificationGnss.niType = IGnssNiCallback::GnssNiType::UMTS_SUPL;
+    else if (gnssNiNotification.type == GNSS_NI_TYPE_CONTROL_PLANE)
+        notificationGnss.niType = IGnssNiCallback::GnssNiType::UMTS_CTRL_PLANE;
+    // GNSS_NI_TYPE_EMERGENCY_SUPL not supported
+
+    if (gnssNiNotification.options == GNSS_NI_OPTIONS_NOTIFICATION)
+        notificationGnss.notifyFlags =
+            static_cast<uint32_t>(IGnssNiCallback::GnssNiNotifyFlags::NEED_NOTIFY);
+    else if (gnssNiNotification.options == GNSS_NI_OPTIONS_VERIFICATION)
+        notificationGnss.notifyFlags =
+            static_cast<uint32_t>(IGnssNiCallback::GnssNiNotifyFlags::NEED_VERIFY);
+    else if (gnssNiNotification.options == GNSS_NI_OPTIONS_PRIVACY_OVERRIDE)
+        notificationGnss.notifyFlags =
+            static_cast<uint32_t>(IGnssNiCallback::GnssNiNotifyFlags::PRIVACY_OVERRIDE);
+
+    notificationGnss.timeoutSec = gnssNiNotification.timeout;
+
+    if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_ACCEPT)
+        notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_ACCEPT;
+    else if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_DENY)
+        notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_DENY;
+    else if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_NO_RESPONSE ||
+            gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_IGNORE)
+        notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_NORESP;
+
+    notificationGnss.requestorId = gnssNiNotification.requestor;
+
+    notificationGnss.notificationMessage = gnssNiNotification.message;
+
+    if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_NONE)
+        notificationGnss.requestorIdEncoding =
+            IGnssNiCallback::GnssNiEncodingType::ENC_NONE;
+    else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_GSM_DEFAULT)
+        notificationGnss.requestorIdEncoding =
+            IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_GSM_DEFAULT;
+    else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_UTF8)
+        notificationGnss.requestorIdEncoding =
+            IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UTF8;
+    else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_UCS2)
+        notificationGnss.requestorIdEncoding =
+            IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UCS2;
+
+    if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_NONE)
+        notificationGnss.notificationIdEncoding =
+            IGnssNiCallback::GnssNiEncodingType::ENC_NONE;
+    else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_GSM_DEFAULT)
+        notificationGnss.notificationIdEncoding =
+            IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_GSM_DEFAULT;
+    else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_UTF8)
+        notificationGnss.notificationIdEncoding =
+            IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UTF8;
+    else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_UCS2)
+        notificationGnss.notificationIdEncoding =
+            IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UCS2;
+
+    mGnssNiCbIface->niNotifyCb(notificationGnss);
+}
+
+void GnssAPIClient::onGnssSvCb(GnssSvNotification gnssSvNotification)
+{
+    LOC_LOGD("%s]: (count: %zu)", __FUNCTION__, gnssSvNotification.count);
+    if (mGnssCbIface != nullptr) {
+        IGnssCallback::GnssSvStatus svStatus;
+        convertGnssSvStatus(gnssSvNotification, svStatus);
+        mGnssCbIface->gnssSvStatusCb(svStatus);
+    }
+}
+
+void GnssAPIClient::onGnssNmeaCb(GnssNmeaNotification gnssNmeaNotification)
+{
+    if (mGnssCbIface != nullptr) {
+        android::hardware::hidl_string nmeaString;
+        nmeaString.setToExternal(gnssNmeaNotification.nmea, gnssNmeaNotification.length);
+        mGnssCbIface->gnssNmeaCb(static_cast<GnssUtcTime>(gnssNmeaNotification.timestamp),
+                nmeaString);
+    }
+}
+
+void GnssAPIClient::onStartTrackingCb(LocationError error)
+{
+    LOC_LOGD("%s]: (%d)", __FUNCTION__, error);
+    if (error == LOCATION_ERROR_SUCCESS && mGnssCbIface != nullptr) {
+        mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_ON);
+        mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_BEGIN);
+    }
+}
+
+void GnssAPIClient::onStopTrackingCb(LocationError error)
+{
+    LOC_LOGD("%s]: (%d)", __FUNCTION__, error);
+    if (error == LOCATION_ERROR_SUCCESS && mGnssCbIface != nullptr) {
+        mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_END);
+        mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_ON);
+    }
+}
+
+static void convertGnssSvStatus(GnssSvNotification& in, IGnssCallback::GnssSvStatus& out)
+{
+    memset(&out, 0, sizeof(IGnssCallback::GnssSvStatus));
+    out.numSvs = in.count;
+    if (out.numSvs > static_cast<uint32_t>(GnssMax::SVS_COUNT)) {
+        LOC_LOGW("%s]: Too many satellites %zd. Clamps to %d.",
+                __FUNCTION__,  out.numSvs, GnssMax::SVS_COUNT);
+        out.numSvs = static_cast<uint32_t>(GnssMax::SVS_COUNT);
+    }
+    for (size_t i = 0; i < out.numSvs; i++) {
+        IGnssCallback::GnssSvInfo& info = out.gnssSvList[i];
+        info.svid = in.gnssSvs[i].svId;
+        convertGnssConstellationType(in.gnssSvs[i].type, info.constellation);
+        info.cN0Dbhz = in.gnssSvs[i].cN0Dbhz;
+        info.elevationDegrees = in.gnssSvs[i].elevation;
+        info.azimuthDegrees = in.gnssSvs[i].azimuth;
+        info.svFlag = static_cast<uint8_t>(IGnssCallback::GnssSvFlags::NONE);
+        if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_EPHEMER_BIT)
+            info.svFlag |= IGnssCallback::GnssSvFlags::HAS_EPHEMERIS_DATA;
+        if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_ALMANAC_BIT)
+            info.svFlag |= IGnssCallback::GnssSvFlags::HAS_ALMANAC_DATA;
+        if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_USED_IN_FIX_BIT)
+            info.svFlag |= IGnssCallback::GnssSvFlags::USED_IN_FIX;
+    }
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
diff --git a/msm8998/android/location_api/GnssAPIClient.h b/msm8998/android/location_api/GnssAPIClient.h
new file mode 100644
index 0000000..1809c09
--- /dev/null
+++ b/msm8998/android/location_api/GnssAPIClient.h
@@ -0,0 +1,102 @@
+/* Copyright (c) 2017, 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 GNSS_API_CLINET_H
+#define GNSS_API_CLINET_H
+
+
+#include <android/hardware/gnss/1.0/IGnss.h>
+#include <android/hardware/gnss/1.0/IGnssCallback.h>
+#include <android/hardware/gnss/1.0/IGnssNiCallback.h>
+#include <LocationAPIClientBase.h>
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::sp;
+
+class GnssAPIClient : public LocationAPIClientBase
+{
+public:
+    GnssAPIClient(const sp<IGnssCallback>& gpsCb,
+            const sp<IGnssNiCallback>& niCb);
+    virtual ~GnssAPIClient();
+    GnssAPIClient(const GnssAPIClient&) = delete;
+    GnssAPIClient& operator=(const GnssAPIClient&) = delete;
+
+    // for GpsInterface
+    void gnssUpdateCallbacks(const sp<IGnssCallback>& gpsCb,
+            const sp<IGnssNiCallback>& niCb);
+    bool gnssStart();
+    bool gnssStop();
+    void gnssDeleteAidingData(IGnss::GnssAidingData aidingDataFlags);
+    bool gnssSetPositionMode(IGnss::GnssPositionMode mode,
+            IGnss::GnssPositionRecurrence recurrence,
+            uint32_t minIntervalMs,
+            uint32_t preferredAccuracyMeters,
+            uint32_t preferredTimeMs);
+
+    // for GpsNiInterface
+    void gnssNiRespond(int32_t notifId, IGnssNiCallback::GnssUserResponseType userResponse);
+
+    // for GnssConfigurationInterface
+    void gnssConfigurationUpdate(const GnssConfig& gnssConfig);
+
+    inline LocationCapabilitiesMask gnssGetCapabilities() const {
+        return mLocationCapabilitiesMask;
+    }
+
+    // callbacks we are interested in
+    void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final;
+    void onTrackingCb(Location location) final;
+    void onGnssNiCb(uint32_t id, GnssNiNotification gnssNiNotification) final;
+    void onGnssSvCb(GnssSvNotification gnssSvNotification) final;
+    void onGnssNmeaCb(GnssNmeaNotification gnssNmeaNotification) final;
+
+    void onStartTrackingCb(LocationError error) final;
+    void onStopTrackingCb(LocationError error) final;
+
+private:
+    sp<IGnssCallback> mGnssCbIface;
+    sp<IGnssNiCallback> mGnssNiCbIface;
+
+    LocationCapabilitiesMask mLocationCapabilitiesMask;
+
+    LocationOptions mLocationOptions;
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
+#endif // GNSS_API_CLINET_H
diff --git a/msm8998/android/location_api/GnssMeasurementAPIClient.cpp b/msm8998/android/location_api/GnssMeasurementAPIClient.cpp
new file mode 100644
index 0000000..3201625
--- /dev/null
+++ b/msm8998/android/location_api/GnssMeasurementAPIClient.cpp
@@ -0,0 +1,278 @@
+/* Copyright (c) 2017, 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_GnssMeasurementAPIClient"
+
+#include <log_util.h>
+#include <loc_cfg.h>
+
+#include "LocationUtil.h"
+#include "GnssMeasurementAPIClient.h"
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+static void convertGnssData(GnssMeasurementsNotification& in,
+        IGnssMeasurementCallback::GnssData& out);
+static void convertGnssMeasurement(GnssMeasurementsData& in,
+        IGnssMeasurementCallback::GnssMeasurement& out);
+static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out);
+
+GnssMeasurementAPIClient::GnssMeasurementAPIClient() :
+    mGnssMeasurementCbIface(nullptr),
+    mLocationCapabilitiesMask(0)
+{
+    LOC_LOGD("%s]: ()", __FUNCTION__);
+    pthread_mutex_init(&mLock, nullptr);
+    pthread_cond_init (&mCond, nullptr);
+
+    // set default LocationOptions.
+    memset(&mLocationOptions, 0, sizeof(LocationOptions));
+    mLocationOptions.size = sizeof(LocationOptions);
+    mLocationOptions.minInterval = 1000;
+    mLocationOptions.minDistance = 0;
+    mLocationOptions.mode = GNSS_SUPL_MODE_STANDALONE;
+}
+
+GnssMeasurementAPIClient::~GnssMeasurementAPIClient()
+{
+    LOC_LOGD("%s]: ()", __FUNCTION__);
+    pthread_cond_destroy(&mCond);
+    pthread_mutex_destroy(&mLock);
+}
+
+// for GpsInterface
+Return<IGnssMeasurement::GnssMeasurementStatus>
+GnssMeasurementAPIClient::gnssMeasurementSetCallback(const sp<IGnssMeasurementCallback>& callback)
+{
+    LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback);
+
+    mGnssMeasurementCbIface = callback;
+
+    LocationCallbacks locationCallbacks;
+    locationCallbacks.size = sizeof(LocationCallbacks);
+
+    locationCallbacks.trackingCb = nullptr;
+    locationCallbacks.batchingCb = nullptr;
+    locationCallbacks.geofenceBreachCb = nullptr;
+    locationCallbacks.geofenceStatusCb = nullptr;
+    locationCallbacks.gnssLocationInfoCb = nullptr;
+    locationCallbacks.gnssNiCb = nullptr;
+    locationCallbacks.gnssSvCb = nullptr;
+    locationCallbacks.gnssNmeaCb = nullptr;
+
+    locationCallbacks.gnssMeasurementsCb = nullptr;
+    if (mGnssMeasurementCbIface != nullptr) {
+        locationCallbacks.gnssMeasurementsCb =
+            [this](GnssMeasurementsNotification gnssMeasurementsNotification) {
+                onGnssMeasurementsCb(gnssMeasurementsNotification);
+            };
+    }
+
+    locAPISetCallbacks(locationCallbacks);
+
+    while (!mLocationCapabilitiesMask) {
+        LOC_LOGD("%s]: wait for capabilities...", __FUNCTION__);
+        pthread_mutex_lock(&mLock);
+        pthread_cond_wait(&mCond, &mLock);
+        pthread_mutex_unlock(&mLock);
+    }
+    if (mLocationCapabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSB_BIT)
+        mLocationOptions.mode = GNSS_SUPL_MODE_MSB;
+    else if (mLocationCapabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSA_BIT)
+        mLocationOptions.mode = GNSS_SUPL_MODE_MSA;
+    LOC_LOGD("%s]: start tracking session", __FUNCTION__);
+    locAPIStartTracking(mLocationOptions);
+
+    return IGnssMeasurement::GnssMeasurementStatus::SUCCESS;
+}
+
+// for GpsMeasurementInterface
+void GnssMeasurementAPIClient::gnssMeasurementClose() {
+    LOC_LOGD("%s]: ()", __FUNCTION__);
+    pthread_mutex_lock(&mLock);
+    mGnssMeasurementCbIface = nullptr;
+    pthread_mutex_unlock(&mLock);
+}
+
+// callbacks
+void GnssMeasurementAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask)
+{
+    LOC_LOGD("%s]: (%02x)", __FUNCTION__, capabilitiesMask);
+    mLocationCapabilitiesMask = capabilitiesMask;
+    pthread_mutex_lock(&mLock);
+    pthread_cond_signal(&mCond);
+    pthread_mutex_unlock(&mLock);
+}
+
+void GnssMeasurementAPIClient::onGnssMeasurementsCb(
+        GnssMeasurementsNotification gnssMeasurementsNotification)
+{
+    LOC_LOGD("%s]: (count: %zu)", __FUNCTION__, gnssMeasurementsNotification.count);
+    // we don't need to lock the mutext
+    // if mGnssMeasurementCbIface is set to nullptr
+    if (mGnssMeasurementCbIface != nullptr) {
+        pthread_mutex_lock(&mLock);
+        if (mGnssMeasurementCbIface != nullptr) {
+            IGnssMeasurementCallback::GnssData gnssData;
+            convertGnssData(gnssMeasurementsNotification, gnssData);
+            mGnssMeasurementCbIface->GnssMeasurementCb(gnssData);
+        }
+        pthread_mutex_unlock(&mLock);
+    }
+}
+
+static void convertGnssMeasurement(GnssMeasurementsData& in,
+        IGnssMeasurementCallback::GnssMeasurement& out)
+{
+    memset(&out, 0, sizeof(IGnssMeasurementCallback::GnssMeasurement));
+    if (in.flags & GNSS_MEASUREMENTS_DATA_SIGNAL_TO_NOISE_RATIO_BIT)
+        out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_SNR;
+    if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_FREQUENCY_BIT)
+        out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_FREQUENCY;
+    if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_CYCLES_BIT)
+        out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_CYCLES;
+    if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_BIT)
+        out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE;
+    if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_UNCERTAINTY_BIT)
+        out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE_UNCERTAINTY;
+    out.svid = in.svId;
+    convertGnssConstellationType(in.svType, out.constellation);
+    out.timeOffsetNs = in.timeOffsetNs;
+    if (in.stateMask & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_CODE_LOCK;
+    if (in.stateMask & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BIT_SYNC;
+    if (in.stateMask & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SUBFRAME_SYNC;
+    if (in.stateMask & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_DECODED;
+    if (in.stateMask & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_MSEC_AMBIGUOUS;
+    if (in.stateMask & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SYMBOL_SYNC;
+    if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_STRING_SYNC;
+    if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_DECODED;
+    if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_BIT_SYNC;
+    if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_SUBFRAME_SYNC;
+    if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1BC_CODE_LOCK;
+    if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1C_2ND_CODE_LOCK;
+    if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1B_PAGE_SYNC;
+    if (in.stateMask &  GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT)
+        out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SBAS_SYNC;
+    out.receivedSvTimeInNs = in.receivedSvTimeNs;
+    out.receivedSvTimeUncertaintyInNs = in.receivedSvTimeUncertaintyNs;
+    out.cN0DbHz = in.carrierToNoiseDbHz;
+    out.pseudorangeRateMps = in.pseudorangeRateMps;
+    out.pseudorangeRateUncertaintyMps = in.pseudorangeRateUncertaintyMps;
+    if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT)
+        out.accumulatedDeltaRangeState |=
+            IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID;
+    if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT)
+        out.accumulatedDeltaRangeState |=
+            IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET;
+    if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT)
+        out.accumulatedDeltaRangeState |=
+            IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP;
+    out.accumulatedDeltaRangeM = in.adrMeters;
+    out.accumulatedDeltaRangeUncertaintyM = in.adrUncertaintyMeters;
+    out.carrierFrequencyHz = in.carrierFrequencyHz;
+    out.carrierCycles = in.carrierCycles;
+    out.carrierPhase = in.carrierPhase;
+    out.carrierPhaseUncertainty = in.carrierPhaseUncertainty;
+    uint8_t indicator =
+        static_cast<uint8_t>(IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_UNKNOWN);
+    if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_PRESENT)
+        indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_PRESENT;
+    if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_NOT_PRESENT)
+        indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATIOR_NOT_PRESENT;
+    out.multipathIndicator =
+        static_cast<IGnssMeasurementCallback::GnssMultipathIndicator>(indicator);
+    out.snrDb = in.signalToNoiseRatioDb;
+}
+
+static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out)
+{
+    memset(&out, 0, sizeof(IGnssMeasurementCallback::GnssClock));
+    if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_LEAP_SECOND_BIT)
+        out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_LEAP_SECOND;
+    if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_TIME_UNCERTAINTY_BIT)
+        out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_TIME_UNCERTAINTY;
+    if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_FULL_BIAS_BIT)
+        out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_FULL_BIAS;
+    if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_BIT)
+        out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS;
+    if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_UNCERTAINTY_BIT)
+        out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS_UNCERTAINTY;
+    if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_BIT)
+        out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT;
+    if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_UNCERTAINTY_BIT)
+        out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT_UNCERTAINTY;
+    out.leapSecond = in.leapSecond;
+    out.timeNs = in.timeNs;
+    out.timeUncertaintyNs = in.timeUncertaintyNs;
+    out.fullBiasNs = in.fullBiasNs;
+    out.biasNs = in.biasNs;
+    out.biasUncertaintyNs = in.biasUncertaintyNs;
+    out.driftNsps = in.driftNsps;
+    out.driftUncertaintyNsps = in.driftUncertaintyNsps;
+    out.hwClockDiscontinuityCount = in.hwClockDiscontinuityCount;
+}
+
+static void convertGnssData(GnssMeasurementsNotification& in,
+        IGnssMeasurementCallback::GnssData& out)
+{
+    out.measurementCount = in.count;
+    if (out.measurementCount > static_cast<uint32_t>(GnssMax::SVS_COUNT)) {
+        LOC_LOGW("%s]: Too many measurement %zd. Clamps to %d.",
+                __FUNCTION__,  out.measurementCount, GnssMax::SVS_COUNT);
+        out.measurementCount = static_cast<uint32_t>(GnssMax::SVS_COUNT);
+    }
+    for (size_t i = 0; i < out.measurementCount; i++) {
+        convertGnssMeasurement(in.measurements[i], out.measurements[i]);
+    }
+    convertGnssClock(in.clock, out.clock);
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
diff --git a/msm8998/android/location_api/GnssMeasurementAPIClient.h b/msm8998/android/location_api/GnssMeasurementAPIClient.h
new file mode 100644
index 0000000..02fe89a
--- /dev/null
+++ b/msm8998/android/location_api/GnssMeasurementAPIClient.h
@@ -0,0 +1,81 @@
+/* Copyright (c) 2017, 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 GNSS_MEASUREMENT_API_CLINET_H
+#define GNSS_MEASUREMENT_API_CLINET_H
+
+
+#include <android/hardware/gnss/1.0/IGnssMeasurement.h>
+#include <android/hardware/gnss/1.0/IGnssMeasurementCallback.h>
+#include <LocationAPIClientBase.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::gnss::V1_0::IGnssMeasurement;
+using ::android::sp;
+
+class GnssMeasurementAPIClient : public LocationAPIClientBase
+{
+public:
+    GnssMeasurementAPIClient();
+    virtual ~GnssMeasurementAPIClient();
+    GnssMeasurementAPIClient(const GnssMeasurementAPIClient&) = delete;
+    GnssMeasurementAPIClient& operator=(const GnssMeasurementAPIClient&) = delete;
+
+    // for GpsMeasurementInterface
+    Return<IGnssMeasurement::GnssMeasurementStatus> gnssMeasurementSetCallback(
+            const sp<IGnssMeasurementCallback>& callback);
+    void gnssMeasurementClose();
+
+    // callbacks we are interested in
+    void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final;
+    void onGnssMeasurementsCb(GnssMeasurementsNotification gnssMeasurementsNotification) final;
+
+private:
+    pthread_mutex_t mLock;
+    pthread_cond_t mCond;
+
+    sp<IGnssMeasurementCallback> mGnssMeasurementCbIface;
+
+    LocationCapabilitiesMask mLocationCapabilitiesMask;
+
+    LocationOptions mLocationOptions;
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
+#endif // GNSS_MEASUREMENT_API_CLINET_H
diff --git a/msm8998/android/location_api/LocationUtil.cpp b/msm8998/android/location_api/LocationUtil.cpp
new file mode 100644
index 0000000..dbafe5d
--- /dev/null
+++ b/msm8998/android/location_api/LocationUtil.cpp
@@ -0,0 +1,98 @@
+/* Copyright (c) 2017, 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 <LocationUtil.h>
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+void convertGnssLocation(Location& in, GnssLocation& out)
+{
+    memset(&out, 0, sizeof(GnssLocation));
+    if (in.flags & LOCATION_HAS_LAT_LONG_BIT)
+        out.gnssLocationFlags |= GnssLocationFlags::HAS_LAT_LONG;
+    if (in.flags & LOCATION_HAS_ALTITUDE_BIT)
+        out.gnssLocationFlags |= GnssLocationFlags::HAS_ALTITUDE;
+    if (in.flags & LOCATION_HAS_SPEED_BIT)
+        out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED;
+    if (in.flags & LOCATION_HAS_BEARING_BIT)
+        out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING;
+    if (in.flags & LOCATION_HAS_ACCURACY_BIT) {
+        out.gnssLocationFlags |= GnssLocationFlags::HAS_HORIZONTAL_ACCURACY;
+        //out.gnssLocationFlags |= GnssLocationFlags::HAS_VERTICAL_ACCURACY;
+        //out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED_ACCURACY;
+        //out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING_ACCURACY;
+    }
+    out.latitudeDegrees = in.latitude;
+    out.longitudeDegrees = in.longitude;
+    out.altitudeMeters = in.altitude;
+    out.speedMetersPerSec = in.speed;
+    out.bearingDegrees = in.bearing;
+    out.horizontalAccuracyMeters = in.accuracy;
+    //out.verticalAccuracyMeters = in.accuracy;
+    //out.speedAccuracyMetersPerSecond = in.accuracy;
+    //out.bearingAccuracyDegrees = in.accuracy;
+    out.timestamp = static_cast<GnssUtcTime>(in.timestamp);
+}
+
+void convertGnssConstellationType(GnssSvType& in, GnssConstellationType& out)
+{
+    switch(in) {
+        case GNSS_SV_TYPE_GPS:
+            out = GnssConstellationType::UNKNOWN;
+            break;
+        case GNSS_SV_TYPE_SBAS:
+            out = GnssConstellationType::SBAS;
+            break;
+        case GNSS_SV_TYPE_GLONASS:
+            out = GnssConstellationType::GLONASS;
+            break;
+        case GNSS_SV_TYPE_QZSS:
+            out = GnssConstellationType::QZSS;
+            break;
+        case GNSS_SV_TYPE_BEIDOU:
+            out = GnssConstellationType::BEIDOU;
+            break;
+        case GNSS_SV_TYPE_GALILEO:
+            out = GnssConstellationType::GALILEO;
+            break;
+        default:
+            out = GnssConstellationType::UNKNOWN;
+            break;
+    }
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
diff --git a/msm8998/loc_api/libloc_api_50001/loc_eng_log.h b/msm8998/android/location_api/LocationUtil.h
similarity index 72%
rename from msm8998/loc_api/libloc_api_50001/loc_eng_log.h
rename to msm8998/android/location_api/LocationUtil.h
index a68bd84..de098b1 100644
--- a/msm8998/loc_api/libloc_api_50001/loc_eng_log.h
+++ b/msm8998/android/location_api/LocationUtil.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2017, 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
@@ -27,18 +27,24 @@
  *
  */
 
-#ifndef LOC_ENG_LOG_H
-#define LOC_ENG_LOG_H
+#ifndef LOCATION_UTIL_H
+#define LOCATION_UTIL_H
 
-#ifdef __cplusplus
-extern "C"
-{
-#endif
+#include <android/hardware/gnss/1.0/types.h>
+#include <LocationAPI.h>
 
-#include <ctype.h>
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
 
-#ifdef __cplusplus
-}
-#endif
+void convertGnssLocation(Location& in, GnssLocation& out);
+void convertGnssConstellationType(GnssSvType& in, GnssConstellationType& out);
 
-#endif /* LOC_ENG_LOG_H */
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
+#endif // LOCATION_UTIL_H
diff --git a/msm8998/android/service.cpp b/msm8998/android/service.cpp
new file mode 100644
index 0000000..bfa0d88
--- /dev/null
+++ b/msm8998/android/service.cpp
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Not a Contribution
+ */
+/*
+ * Copyright (C) 2016 The Android Open Source 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.
+ */
+
+#define LOG_TAG "android.hardware.gnss@1.0-service-qti"
+
+#include <android/hardware/gnss/1.0/IGnss.h>
+#include <hidl/LegacySupport.h>
+
+using android::hardware::gnss::V1_0::IGnss;
+using android::hardware::defaultPassthroughServiceImplementation;
+
+int main() {
+    return defaultPassthroughServiceImplementation<IGnss>("gnss");
+}
diff --git a/msm8998/core/Android.mk b/msm8998/core/Android.mk
index 7fe2534..02056e3 100644
--- a/msm8998/core/Android.mk
+++ b/msm8998/core/Android.mk
@@ -6,7 +6,7 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := libloc_core
-LOCAL_MODULE_OWNER := qcom
+LOCAL_MODULE_OWNER := qti
 
 LOCAL_MODULE_TAGS := optional
 
@@ -17,6 +17,7 @@
 endif
 
 LOCAL_SHARED_LIBRARIES := \
+    liblog \
     libutils \
     liblog \
     libcutils \
@@ -37,8 +38,8 @@
 
 LOCAL_C_INCLUDES:= \
     $(TARGET_OUT_HEADERS)/gps.utils \
-    $(TARGET_OUT_HEADERS)/libflp \
-    $(TARGET_OUT_HEADERS)/libloc_pla
+    $(TARGET_OUT_HEADERS)/libloc_pla \
+    $(TARGET_OUT_HEADERS)/liblocation_api
 
 LOCAL_COPY_HEADERS_TO:= libloc_core/
 LOCAL_COPY_HEADERS:= \
diff --git a/msm8998/core/ContextBase.cpp b/msm8998/core/ContextBase.cpp
index 1ae8482..a9858e2 100644
--- a/msm8998/core/ContextBase.cpp
+++ b/msm8998/core/ContextBase.cpp
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2011-2014,2016-2017 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
@@ -40,8 +40,116 @@
 
 namespace loc_core {
 
-loc_gps_cfg_s_type ContextBase::mGps_conf {0};
-loc_sap_cfg_s_type ContextBase::mSap_conf {0};
+loc_gps_cfg_s_type ContextBase::mGps_conf {};
+loc_sap_cfg_s_type ContextBase::mSap_conf {};
+
+const loc_param_s_type ContextBase::mGps_conf_table[] =
+{
+  {"GPS_LOCK",                       &mGps_conf.GPS_LOCK,                       NULL, 'n'},
+  {"SUPL_VER",                       &mGps_conf.SUPL_VER,                       NULL, 'n'},
+  {"LPP_PROFILE",                    &mGps_conf.LPP_PROFILE,                    NULL, 'n'},
+  {"A_GLONASS_POS_PROTOCOL_SELECT",  &mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT,  NULL, 'n'},
+  {"LPPE_CP_TECHNOLOGY",             &mGps_conf.LPPE_CP_TECHNOLOGY,             NULL, 'n'},
+  {"LPPE_UP_TECHNOLOGY",             &mGps_conf.LPPE_UP_TECHNOLOGY,             NULL, 'n'},
+  {"AGPS_CERT_WRITABLE_MASK",        &mGps_conf.AGPS_CERT_WRITABLE_MASK,        NULL, 'n'},
+  {"SUPL_MODE",                      &mGps_conf.SUPL_MODE,                      NULL, 'n'},
+  {"SUPL_ES",                        &mGps_conf.SUPL_ES,                        NULL, 'n'},
+  {"INTERMEDIATE_POS",               &mGps_conf.INTERMEDIATE_POS,               NULL, 'n'},
+  {"ACCURACY_THRES",                 &mGps_conf.ACCURACY_THRES,                 NULL, 'n'},
+  {"NMEA_PROVIDER",                  &mGps_conf.NMEA_PROVIDER,                  NULL, 'n'},
+  {"CAPABILITIES",                   &mGps_conf.CAPABILITIES,                   NULL, 'n'},
+  {"XTRA_VERSION_CHECK",             &mGps_conf.XTRA_VERSION_CHECK,             NULL, 'n'},
+  {"XTRA_SERVER_1",                  &mGps_conf.XTRA_SERVER_1,                  NULL, 's'},
+  {"XTRA_SERVER_2",                  &mGps_conf.XTRA_SERVER_2,                  NULL, 's'},
+  {"XTRA_SERVER_3",                  &mGps_conf.XTRA_SERVER_3,                  NULL, 's'},
+  {"USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL",  &mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL,          NULL, 'n'},
+  {"AGPS_CONFIG_INJECT",             &mGps_conf.AGPS_CONFIG_INJECT,             NULL, 'n'},
+  {"EXTERNAL_DR_ENABLED",            &mGps_conf.EXTERNAL_DR_ENABLED,                  NULL, 'n'},
+};
+
+const loc_param_s_type ContextBase::mSap_conf_table[] =
+{
+  {"GYRO_BIAS_RANDOM_WALK",          &mSap_conf.GYRO_BIAS_RANDOM_WALK,          &mSap_conf.GYRO_BIAS_RANDOM_WALK_VALID, 'f'},
+  {"ACCEL_RANDOM_WALK_SPECTRAL_DENSITY",     &mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY,    &mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'},
+  {"ANGLE_RANDOM_WALK_SPECTRAL_DENSITY",     &mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY,    &mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'},
+  {"RATE_RANDOM_WALK_SPECTRAL_DENSITY",      &mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY,     &mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'},
+  {"VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY",  &mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY, &mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'},
+  {"SENSOR_ACCEL_BATCHES_PER_SEC",   &mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC,   NULL, 'n'},
+  {"SENSOR_ACCEL_SAMPLES_PER_BATCH", &mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH, NULL, 'n'},
+  {"SENSOR_GYRO_BATCHES_PER_SEC",    &mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC,    NULL, 'n'},
+  {"SENSOR_GYRO_SAMPLES_PER_BATCH",  &mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH,  NULL, 'n'},
+  {"SENSOR_ACCEL_BATCHES_PER_SEC_HIGH",   &mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH,   NULL, 'n'},
+  {"SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH", &mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH, NULL, 'n'},
+  {"SENSOR_GYRO_BATCHES_PER_SEC_HIGH",    &mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH,    NULL, 'n'},
+  {"SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH",  &mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH,  NULL, 'n'},
+  {"SENSOR_CONTROL_MODE",            &mSap_conf.SENSOR_CONTROL_MODE,            NULL, 'n'},
+  {"SENSOR_USAGE",                   &mSap_conf.SENSOR_USAGE,                   NULL, 'n'},
+  {"SENSOR_ALGORITHM_CONFIG_MASK",   &mSap_conf.SENSOR_ALGORITHM_CONFIG_MASK,   NULL, 'n'},
+  {"SENSOR_PROVIDER",                &mSap_conf.SENSOR_PROVIDER,                NULL, 'n'}
+};
+
+void ContextBase::readConfig()
+{
+   /*Defaults for gps.conf*/
+   mGps_conf.INTERMEDIATE_POS = 0;
+   mGps_conf.ACCURACY_THRES = 0;
+   mGps_conf.NMEA_PROVIDER = 0;
+   mGps_conf.GPS_LOCK = 0;
+   mGps_conf.SUPL_VER = 0x10000;
+   mGps_conf.SUPL_MODE = 0x3;
+   mGps_conf.SUPL_ES = 0;
+   mGps_conf.CAPABILITIES = 0x7;
+   /* LTE Positioning Profile configuration is disable by default*/
+   mGps_conf.LPP_PROFILE = 0;
+   /*By default no positioning protocol is selected on A-GLONASS system*/
+   mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT = 0;
+   /*XTRA version check is disabled by default*/
+   mGps_conf.XTRA_VERSION_CHECK=0;
+   /*Use emergency PDN by default*/
+   mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL = 1;
+   /* By default no LPPe CP technology is enabled*/
+   mGps_conf.LPPE_CP_TECHNOLOGY = 0;
+   /* By default no LPPe UP technology is enabled*/
+   mGps_conf.LPPE_UP_TECHNOLOGY = 0;
+
+   /*Defaults for sap.conf*/
+   mSap_conf.GYRO_BIAS_RANDOM_WALK = 0;
+   mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC = 2;
+   mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH = 5;
+   mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC = 2;
+   mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH = 5;
+   mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH = 4;
+   mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH = 25;
+   mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH = 4;
+   mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH = 25;
+   mSap_conf.SENSOR_CONTROL_MODE = 0; /* AUTO */
+   mSap_conf.SENSOR_USAGE = 0; /* Enabled */
+   mSap_conf.SENSOR_ALGORITHM_CONFIG_MASK = 0; /* INS Disabled = FALSE*/
+   /* Values MUST be set by OEMs in configuration for sensor-assisted
+      navigation to work. There are NO default values */
+   mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY = 0;
+   mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY = 0;
+   mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY = 0;
+   mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY = 0;
+   mSap_conf.GYRO_BIAS_RANDOM_WALK_VALID = 0;
+   mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0;
+   mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0;
+   mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0;
+   mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0;
+   /* default provider is SSC */
+   mSap_conf.SENSOR_PROVIDER = 1;
+
+   /* None of the 10 slots for agps certificates are writable by default */
+   mGps_conf.AGPS_CERT_WRITABLE_MASK = 0;
+
+   /* inject supl config to modem with config values from config.xml or gps.conf, default 1 */
+   mGps_conf.AGPS_CONFIG_INJECT = 1;
+
+   const char* GPS_CONF_FILE = "/etc/gps.conf";
+   const char* SAP_CONF_FILE = "/etc/sap.conf";
+   UTIL_READ_CONF(GPS_CONF_FILE, mGps_conf_table);
+   UTIL_READ_CONF(SAP_CONF_FILE, mSap_conf_table);
+}
 
 uint32_t ContextBase::getCarrierCapabilities() {
     #define carrierMSA (uint32_t)0x2
diff --git a/msm8998/core/ContextBase.h b/msm8998/core/ContextBase.h
index 87d2acf..83de999 100644
--- a/msm8998/core/ContextBase.h
+++ b/msm8998/core/ContextBase.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2011-2017, 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
@@ -34,6 +34,7 @@
 #include <MsgTask.h>
 #include <LocApiBase.h>
 #include <LBSProxyBase.h>
+#include <loc_cfg.h>
 
 #define MAX_XTRA_SERVER_URL_LENGTH 256
 
@@ -105,6 +106,8 @@
 class ContextBase {
     static LBSProxyBase* getLBSProxy(const char* libName);
     LocApiBase* createLocApi(LOC_API_ADAPTER_EVENT_MASK_T excludedMask);
+    static const loc_param_s_type mGps_conf_table[];
+    static const loc_param_s_type mSap_conf_table[];
 protected:
     const LBSProxyBase* mLBSProxy;
     const MsgTask* mMsgTask;
@@ -135,6 +138,7 @@
     static loc_gps_cfg_s_type mGps_conf;
     static loc_sap_cfg_s_type mSap_conf;
 
+    void readConfig();
     static uint32_t getCarrierCapabilities();
 
 };
diff --git a/msm8998/core/LocAdapterBase.cpp b/msm8998/core/LocAdapterBase.cpp
index 166fd91..27132b7 100644
--- a/msm8998/core/LocAdapterBase.cpp
+++ b/msm8998/core/LocAdapterBase.cpp
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2011-2014, 2016-2017The 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
@@ -50,6 +50,16 @@
     mLocApi->addAdapter(this);
 }
 
+uint32_t LocAdapterBase::mSessionIdCounter(1);
+
+uint32_t LocAdapterBase::generateSessionId()
+{
+    if (++mSessionIdCounter == 0xFFFFFFFF)
+        mSessionIdCounter = 1;
+
+     return mSessionIdCounter;
+}
+
 void LocAdapterBase::handleEngineUpEvent()
 {
     if (mLocAdapterProxyBase) {
@@ -65,32 +75,31 @@
 }
 
 void LocAdapterBase::
-    reportPosition(UlpLocation &location,
-                   GpsLocationExtended &locationExtended,
-                   void* locationExt,
-                   enum loc_sess_status status,
-                   LocPosTechMask loc_technology_mask) {
-    if (mLocAdapterProxyBase == NULL ||
-        !mLocAdapterProxyBase->reportPosition(location,
-                                              locationExtended,
-                                              status,
-                                              loc_technology_mask)) {
+    reportPositionEvent(const UlpLocation& location,
+                        const GpsLocationExtended& locationExtended,
+                        enum loc_sess_status status,
+                        LocPosTechMask loc_technology_mask,
+                        bool fromUlp) {
+    if (mLocAdapterProxyBase != NULL) {
+        mLocAdapterProxyBase->reportPositionEvent((UlpLocation&)location,
+                                                   (GpsLocationExtended&)locationExtended,
+                                                   status,
+                                                   loc_technology_mask);
+    } else {
         DEFAULT_IMPL()
     }
 }
 
 void LocAdapterBase::
-    reportSv(LocGnssSvStatus &svStatus,
-             GpsLocationExtended &locationExtended,
-             void* svExt)
+    reportSvEvent(const GnssSvNotification& svNotify, bool fromUlp)
 DEFAULT_IMPL()
 
 void LocAdapterBase::
-    reportSvMeasurement(GnssSvMeasurementSet &svMeasurementSet)
+    reportSvMeasurementEvent(GnssSvMeasurementSet &svMeasurementSet)
 DEFAULT_IMPL()
 
 void LocAdapterBase::
-    reportSvPolynomial(GnssSvPolynomial &svPolynomial)
+    reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial)
 DEFAULT_IMPL()
 
 void LocAdapterBase::
@@ -99,7 +108,7 @@
 
 
 void LocAdapterBase::
-    reportNmea(const char* nmea, int length)
+    reportNmeaEvent(const char* nmea, size_t length, bool fromUlp)
 DEFAULT_IMPL()
 
 bool LocAdapterBase::
@@ -140,11 +149,11 @@
 DEFAULT_IMPL(false)
 
 bool LocAdapterBase::
-    requestNiNotify(LocGpsNiNotification &notify, const void* data)
+    requestNiNotifyEvent(GnssNiNotification &notify, const void* data)
 DEFAULT_IMPL(false)
 
 void LocAdapterBase::
-    reportGnssMeasurementData(LocGnssData &gnssMeasurementData)
+    reportGnssMeasurementDataEvent(const GnssMeasurementsNotification& measurementsNotify)
 DEFAULT_IMPL()
 
 bool LocAdapterBase::
diff --git a/msm8998/core/LocAdapterBase.h b/msm8998/core/LocAdapterBase.h
index f3ec489..824a340 100644
--- a/msm8998/core/LocAdapterBase.h
+++ b/msm8998/core/LocAdapterBase.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2014,2016 The Linux Foundation. All rights reserved.
+/* Copyright (c) 2011-2014, 2016-2017 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
@@ -32,19 +32,39 @@
 #include <gps_extended.h>
 #include <UlpProxyBase.h>
 #include <ContextBase.h>
+#include <LocationAPI.h>
+#include <map>
+
+typedef struct LocationSessionKey {
+    LocationAPI* client;
+    uint32_t id;
+    inline LocationSessionKey(LocationAPI* _client, uint32_t _id) :
+        client(_client), id(_id) {}
+} LocationSessionKey;
+inline bool operator <(LocationSessionKey const& left, LocationSessionKey const& right) {
+    return left.id < right.id || (left.id == right.id && left.client < right.client);
+}
+inline bool operator ==(LocationSessionKey const& left, LocationSessionKey const& right) {
+    return left.id == right.id && left.client == right.client;
+}
+inline bool operator !=(LocationSessionKey const& left, LocationSessionKey const& right) {
+    return left.id != right.id || left.client != right.client;
+}
+typedef std::map<LocationSessionKey, LocationOptions> LocationSessionMap;
 
 namespace loc_core {
 
 class LocAdapterProxyBase;
 
 class LocAdapterBase {
+private:
+    static uint32_t mSessionIdCounter;
 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) {}
@@ -70,11 +90,19 @@
     }
 
     inline void updateEvtMask(LOC_API_ADAPTER_EVENT_MASK_T event,
-                       loc_registration_mask_status isEnabled)
+                              loc_registration_mask_status status)
     {
-        mEvtMask =
-            isEnabled == LOC_REGISTRATION_MASK_ENABLED ? (mEvtMask|event):(mEvtMask&~event);
-
+        switch(status) {
+            case (LOC_REGISTRATION_MASK_ENABLED):
+                mEvtMask = mEvtMask | event;
+                break;
+            case (LOC_REGISTRATION_MASK_DISABLED):
+                mEvtMask = mEvtMask &~ event;
+                break;
+            case (LOC_REGISTRATION_MASK_SET):
+                mEvtMask = event;
+                break;
+        }
         mLocApi->updateEvtMask();
     }
 
@@ -82,33 +110,33 @@
         return mLocApi->isFeatureSupported(featureVal);
     }
 
+    uint32_t generateSessionId();
+
     // This will be overridden by the individual adapters
     // if necessary.
-    inline virtual void setUlpProxy(UlpProxyBase* ulp) {
+    inline virtual void setUlpProxyCommand(UlpProxyBase* ulp) {
 
         (void)ulp;
     }
     virtual void handleEngineUpEvent();
     virtual void handleEngineDownEvent();
-    inline virtual void setPositionModeInt(LocPosMode& posMode) {
+    inline virtual void setPositionModeCommand(LocPosMode& posMode) {
 
         (void)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(LocGnssSvStatus &svStatus,
-                          GpsLocationExtended &locationExtended,
-                          void* svExt);
-    virtual void reportSvMeasurement(GnssSvMeasurementSet &svMeasurementSet);
-    virtual void reportSvPolynomial(GnssSvPolynomial &svPolynomial);
+    virtual void startTrackingCommand() {}
+    virtual void stopTrackingCommand() {}
+    virtual void getZppCommand() {}
+    virtual void reportPositionEvent(const UlpLocation& location,
+                                     const GpsLocationExtended& locationExtended,
+                                     enum loc_sess_status status,
+                                     LocPosTechMask loc_technology_mask,
+                                     bool fromUlp=false);
+    virtual void reportSvEvent(const GnssSvNotification& svNotify, bool fromUlp=false);
+    virtual void reportNmeaEvent(const char* nmea, size_t length, bool fromUlp=false);
+    virtual void reportSvMeasurementEvent(GnssSvMeasurementSet &svMeasurementSet);
+    virtual void reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial);
     virtual void reportStatus(LocGpsStatusValue 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();
@@ -119,11 +147,10 @@
     virtual bool requestSuplES(int connHandle);
     virtual bool reportDataCallOpened();
     virtual bool reportDataCallClosed();
-    virtual bool requestNiNotify(LocGpsNiNotification &notify,
-                                 const void* data);
+    virtual bool requestNiNotifyEvent(GnssNiNotification &notify, const void* data);
     inline virtual bool isInSession() { return false; }
     ContextBase* getContext() const { return mContext; }
-    virtual void reportGnssMeasurementData(LocGnssData &gnssMeasurementData);
+    virtual void reportGnssMeasurementDataEvent(const GnssMeasurementsNotification& measurementsNotify);
     virtual bool reportWwanZppFix(LocGpsLocation &zppLoc);
 };
 
diff --git a/msm8998/core/LocAdapterProxyBase.h b/msm8998/core/LocAdapterProxyBase.h
index 82cba6b..044f59b 100644
--- a/msm8998/core/LocAdapterProxyBase.h
+++ b/msm8998/core/LocAdapterProxyBase.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2014 The Linux Foundation. All rights reserved.
+/* Copyright (c) 2014, 2016-2017 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
@@ -51,22 +51,25 @@
         mLocAdapterBase->updateEvtMask(event,isEnabled);
     }
 
+    inline uint32_t generateSessionId() {
+        return mLocAdapterBase->generateSessionId();
+    }
 public:
     inline ContextBase* getContext() const {
         return mLocAdapterBase->getContext();
     }
+
     inline virtual void handleEngineUpEvent() {};
     inline virtual void handleEngineDownEvent() {};
-    inline virtual bool reportPosition(UlpLocation &location,
-                                       GpsLocationExtended &locationExtended,
-                                       enum loc_sess_status status,
-                                       LocPosTechMask loc_technology_mask) {
+    inline virtual void reportPositionEvent(UlpLocation &location,
+                                            GpsLocationExtended &locationExtended,
+                                            enum loc_sess_status status,
+                                            LocPosTechMask loc_technology_mask) {
 
         (void)location;
         (void)locationExtended;
         (void)status;
         (void)loc_technology_mask;
-        return false;
     }
 };
 
diff --git a/msm8998/core/LocApiBase.cpp b/msm8998/core/LocApiBase.cpp
index 4cc8cb8..3bbbf8f 100644
--- a/msm8998/core/LocApiBase.cpp
+++ b/msm8998/core/LocApiBase.cpp
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2014,2016 The Linux Foundation. All rights reserved.
+/* Copyright (c) 2011-2014, 2016-2017 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
@@ -227,14 +227,13 @@
     TO_ALL_LOCADAPTERS(mLocAdapters[i]->handleEngineDownEvent());
 }
 
-void LocApiBase::reportPosition(UlpLocation &location,
-                                GpsLocationExtended &locationExtended,
-                                void* locationExt,
+void LocApiBase::reportPosition(UlpLocation& location,
+                                GpsLocationExtended& locationExtended,
                                 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  "
+    LOC_LOGD("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\n "
@@ -251,11 +250,8 @@
              locationExtended.gnss_sv_used_ids.gal_sv_used_ids_mask);
     // loop through adapters, and deliver to all adapters.
     TO_ALL_LOCADAPTERS(
-        mLocAdapters[i]->reportPosition(location,
-                                        locationExtended,
-                                        locationExt,
-                                        status,
-                                        loc_technology_mask)
+        mLocAdapters[i]->reportPositionEvent(location, locationExtended,
+                                             status, loc_technology_mask)
     );
 }
 
@@ -265,9 +261,7 @@
     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportWwanZppFix(zppLoc));
 }
 
-void LocApiBase::reportSv(LocGnssSvStatus &svStatus,
-                  GpsLocationExtended &locationExtended,
-                  void* svExt)
+void LocApiBase::reportSv(GnssSvNotification& svNotify)
 {
     const char* constellationString[] = { "Unknown", "GPS", "SBAS", "GLONASS",
         "QZSS", "BEIDOU", "GALILEO" };
@@ -276,27 +270,25 @@
     LOC_LOGV("num sv: %d\n"
         "      sv: constellation svid         cN0"
         "    elevation    azimuth    flags",
-        svStatus.num_svs);
-    for (int i = 0; i < svStatus.num_svs && i < LOC_GNSS_MAX_SVS; i++) {
-        if (svStatus.gnss_sv_list[i].constellation >
+        svNotify.count);
+    for (int i = 0; i < svNotify.count && i < LOC_GNSS_MAX_SVS; i++) {
+        if (svNotify.gnssSvs[i].type >
             sizeof(constellationString) / sizeof(constellationString[0]) - 1) {
-            svStatus.gnss_sv_list[i].constellation = 0;
+            svNotify.gnssSvs[i].type = GNSS_SV_TYPE_UNKNOWN;
         }
         LOC_LOGV("   %03d: %*s  %02d    %f    %f    %f   0x%02X",
             i,
             13,
-            constellationString[svStatus.gnss_sv_list[i].constellation],
-            svStatus.gnss_sv_list[i].svid,
-            svStatus.gnss_sv_list[i].c_n0_dbhz,
-            svStatus.gnss_sv_list[i].elevation,
-            svStatus.gnss_sv_list[i].azimuth,
-            svStatus.gnss_sv_list[i].flags);
+            constellationString[svNotify.gnssSvs[i].type],
+            svNotify.gnssSvs[i].svId,
+            svNotify.gnssSvs[i].cN0Dbhz,
+            svNotify.gnssSvs[i].elevation,
+            svNotify.gnssSvs[i].azimuth,
+            svNotify.gnssSvs[i].gnssSvOptionsMask);
     }
     // loop through adapters, and deliver to all adapters.
     TO_ALL_LOCADAPTERS(
-        mLocAdapters[i]->reportSv(svStatus,
-            locationExtended,
-            svExt)
+        mLocAdapters[i]->reportSvEvent(svNotify)
         );
 }
 
@@ -304,7 +296,7 @@
 {
     // loop through adapters, and deliver to all adapters.
     TO_ALL_LOCADAPTERS(
-        mLocAdapters[i]->reportSvMeasurement(svMeasurementSet)
+        mLocAdapters[i]->reportSvMeasurementEvent(svMeasurementSet)
     );
 }
 
@@ -312,7 +304,7 @@
 {
     // loop through adapters, and deliver to all adapters.
     TO_ALL_LOCADAPTERS(
-        mLocAdapters[i]->reportSvPolynomial(svPolynomial)
+        mLocAdapters[i]->reportSvPolynomialEvent(svPolynomial)
     );
 }
 
@@ -325,7 +317,7 @@
 void LocApiBase::reportNmea(const char* nmea, int length)
 {
     // loop through adapters, and deliver to all adapters.
-    TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportNmea(nmea, length));
+    TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportNmeaEvent(nmea, length));
 }
 
 void LocApiBase::reportXtraServer(const char* url1, const char* url2,
@@ -384,10 +376,10 @@
     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportDataCallClosed());
 }
 
-void LocApiBase::requestNiNotify(LocGpsNiNotification &notify, const void* data)
+void LocApiBase::requestNiNotify(GnssNiNotification &notify, const void* data)
 {
     // loop through adapters, and deliver to the first handling adapter.
-    TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestNiNotify(notify, data));
+    TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestNiNotifyEvent(notify, data));
 }
 
 void LocApiBase::saveSupportedMsgList(uint64_t supportedMsgList)
@@ -406,10 +398,10 @@
 LocApiProxyBase* LocApiBase :: getLocApiProxy()
     DEFAULT_IMPL(NULL)
 
-void LocApiBase::reportGnssMeasurementData(LocGnssData &gnssMeasurementData)
+void LocApiBase::reportGnssMeasurementData(GnssMeasurementsNotification& measurementsNotify)
 {
     // loop through adapters, and deliver to all adapters.
-    TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGnssMeasurementData(gnssMeasurementData));
+    TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGnssMeasurementDataEvent(measurementsNotify));
 }
 
 enum loc_api_adapter_err LocApiBase::
@@ -428,9 +420,9 @@
     stopFix()
 DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
 
-enum loc_api_adapter_err LocApiBase::
-    deleteAidingData(LocGpsAidingData f)
-DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+LocationError LocApiBase::
+    deleteAidingData(const GnssAidingData& data)
+DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
 
 enum loc_api_adapter_err LocApiBase::
     enableData(int enable)
@@ -469,31 +461,29 @@
     setPositionMode(const LocPosMode& posMode)
 DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
 
-enum loc_api_adapter_err LocApiBase::
+LocationError LocApiBase::
     setServer(const char* url, int len)
-DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
 
-enum loc_api_adapter_err LocApiBase::
-    setServer(unsigned int ip, int port,
-              LocServerType type)
-DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+LocationError LocApiBase::
+    setServer(unsigned int ip, int port, LocServerType type)
+DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
 
-enum loc_api_adapter_err LocApiBase::
-    informNiResponse(LocGpsUserResponseType userResponse,
-                     const void* passThroughData)
-DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+LocationError LocApiBase::
+    informNiResponse(GnssNiResponse userResponse, const void* passThroughData)
+DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
 
-enum loc_api_adapter_err LocApiBase::
-    setSUPLVersion(uint32_t version)
-DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+LocationError LocApiBase::
+    setSUPLVersion(GnssConfigSuplVersion version)
+DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
 
 enum loc_api_adapter_err LocApiBase::
     setNMEATypes (uint32_t typesMask)
 DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
 
-enum loc_api_adapter_err LocApiBase::
-    setLPPConfig(uint32_t profile)
-DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+LocationError LocApiBase::
+    setLPPConfig(GnssConfigLppProfile profile)
+DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
 
 enum loc_api_adapter_err LocApiBase::
     setSensorControlConfig(int sensorUsage,
@@ -526,13 +516,17 @@
                                int algorithmConfig)
 DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
 
-enum loc_api_adapter_err LocApiBase::
-    setAGLONASSProtocol(unsigned long aGlonassProtocol)
-DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+LocationError LocApiBase::
+    setAGLONASSProtocol(GnssConfigAGlonassPositionProtocolMask aGlonassProtocol)
+DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
 
-enum loc_api_adapter_err LocApiBase::
-        setLPPeProtocol(unsigned long lppeCP, unsigned long lppeUP)
-    DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+LocationError LocApiBase::
+    setLPPeProtocolCp(GnssConfigLppeControlPlaneMask lppeCP)
+DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
+
+LocationError LocApiBase::
+    setLPPeProtocolUp(GnssConfigLppeUserPlaneMask lppeUP)
+DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
 
 enum loc_api_adapter_err LocApiBase::
    getWwanZppFix()
@@ -573,9 +567,9 @@
     releaseDataServiceClient()
 DEFAULT_IMPL()
 
-int LocApiBase::
-    setGpsLock(LOC_GPS_LOCK_MASK lock)
-DEFAULT_IMPL(-1)
+LocationError LocApiBase::
+    setGpsLock(GnssConfigGpsLock lock)
+DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
 
 void LocApiBase::
     installAGpsCert(const LocDerEncodedCertificate* pData,
@@ -587,9 +581,9 @@
     getGpsLock()
 DEFAULT_IMPL(-1)
 
-enum loc_api_adapter_err LocApiBase::
-    setXtraVersionCheck(enum xtra_version_check check)
-DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
+LocationError LocApiBase::
+    setXtraVersionCheck(uint32_t check)
+DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
 
 bool LocApiBase::
     gnssConstellationConfig()
diff --git a/msm8998/core/LocApiBase.h b/msm8998/core/LocApiBase.h
index 9127a2e..86610e7 100644
--- a/msm8998/core/LocApiBase.h
+++ b/msm8998/core/LocApiBase.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2014, 2016 The Linux Foundation. All rights reserved.
+/* Copyright (c) 2011-2014, 2016-2017 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
@@ -32,6 +32,7 @@
 #include <stddef.h>
 #include <ctype.h>
 #include <gps_extended.h>
+#include <LocationAPI.h>
 #include <MsgTask.h>
 #include <platform_lib_log_util.h>
 
@@ -102,22 +103,18 @@
     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,
+    void reportPosition(UlpLocation& location,
+                        GpsLocationExtended& locationExtended,
                         enum loc_sess_status status,
                         LocPosTechMask loc_technology_mask =
                                   LOC_POS_TECH_MASK_DEFAULT);
-    void reportSv(LocGnssSvStatus &svStatus,
-                  GpsLocationExtended &locationExtended,
-                  void* svExt);
+    void reportSv(GnssSvNotification& svNotify);
     void reportSvMeasurement(GnssSvMeasurementSet &svMeasurementSet);
     void reportSvPolynomial(GnssSvPolynomial &svPolynomial);
     void reportStatus(LocGpsStatusValue status);
@@ -132,9 +129,9 @@
     void requestSuplES(int connHandle);
     void reportDataCallOpened();
     void reportDataCallClosed();
-    void requestNiNotify(LocGpsNiNotification &notify, const void* data);
+    void requestNiNotify(GnssNiNotification &notify, const void* data);
     void saveSupportedMsgList(uint64_t supportedMsgList);
-    void reportGnssMeasurementData(LocGnssData &gnssMeasurementData);
+    void reportGnssMeasurementData(GnssMeasurementsNotification& measurementsNotify);
     void saveSupportedFeatureList(uint8_t *featureList);
     void reportWwanZppFix(LocGpsLocation &zppLoc);
 
@@ -148,8 +145,8 @@
         startFix(const LocPosMode& posMode);
     virtual enum loc_api_adapter_err
         stopFix();
-    virtual enum loc_api_adapter_err
-        deleteAidingData(LocGpsAidingData f);
+    virtual LocationError
+        deleteAidingData(const GnssAidingData& data);
     virtual enum loc_api_adapter_err
         enableData(int enable);
     virtual enum loc_api_adapter_err
@@ -168,19 +165,17 @@
         atlCloseStatus(int handle, int is_succ);
     virtual enum loc_api_adapter_err
         setPositionMode(const LocPosMode& posMode);
-    virtual enum loc_api_adapter_err
+    virtual LocationError
         setServer(const char* url, int len);
-    virtual enum loc_api_adapter_err
+    virtual LocationError
         setServer(unsigned int ip, int port,
                   LocServerType type);
-    virtual enum loc_api_adapter_err
-        informNiResponse(LocGpsUserResponseType userResponse, const void* passThroughData);
-    virtual enum loc_api_adapter_err
-        setSUPLVersion(uint32_t version);
+    virtual LocationError
+        informNiResponse(GnssNiResponse userResponse, const void* passThroughData);
+    virtual LocationError setSUPLVersion(GnssConfigSuplVersion version);
     virtual enum loc_api_adapter_err
         setNMEATypes (uint32_t typesMask);
-    virtual enum loc_api_adapter_err
-        setLPPConfig(uint32_t profile);
+    virtual LocationError setLPPConfig(GnssConfigLppProfile profile);
     virtual enum loc_api_adapter_err
         setSensorControlConfig(int sensorUsage, int sensorProvider);
     virtual enum loc_api_adapter_err
@@ -205,10 +200,10 @@
                                int gyroSamplesPerBatchHigh,
                                int gyroBatchesPerSecHigh,
                                int algorithmConfig);
-    virtual enum loc_api_adapter_err
-        setAGLONASSProtocol(unsigned long aGlonassProtocol);
-    virtual enum loc_api_adapter_err
-        setLPPeProtocol(unsigned long lppeCP, unsigned long lppeUP);
+    virtual LocationError
+        setAGLONASSProtocol(GnssConfigAGlonassPositionProtocolMask aGlonassProtocol);
+    virtual LocationError setLPPeProtocolCp(GnssConfigLppeControlPlaneMask lppeCP);
+    virtual LocationError setLPPeProtocolUp(GnssConfigLppeUserPlaneMask lppeUP);
     virtual enum loc_api_adapter_err
         getWwanZppFix();
     virtual enum loc_api_adapter_err
@@ -238,15 +233,10 @@
             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);
+    virtual LocationError setGpsLock(GnssConfigGpsLock lock);
     /*
       Returns
       Current value of GPS Lock on success
@@ -254,8 +244,7 @@
      */
     virtual int getGpsLock(void);
 
-    virtual enum loc_api_adapter_err setXtraVersionCheck(enum xtra_version_check check);
-
+    virtual LocationError setXtraVersionCheck(uint32_t check);
     /*
       Check if the modem support the service
      */
diff --git a/msm8998/core/LocDualContext.cpp b/msm8998/core/LocDualContext.cpp
index 74b2903..fd465e9 100644
--- a/msm8998/core/LocDualContext.cpp
+++ b/msm8998/core/LocDualContext.cpp
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2011-2014, 2016-2017 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
@@ -44,8 +44,7 @@
 // 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_SATELLITE_REPORT |
      LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT |
      LOC_API_ADAPTER_BIT_NMEA_POSITION_REPORT |
      LOC_API_ADAPTER_BIT_IOCTL_REPORT |
diff --git a/msm8998/core/LocDualContext.h b/msm8998/core/LocDualContext.h
index ce77a1a..2b1b4bb 100644
--- a/msm8998/core/LocDualContext.h
+++ b/msm8998/core/LocDualContext.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2011-2014, 2016-2017 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
diff --git a/msm8998/core/Makefile.am b/msm8998/core/Makefile.am
index 0a9d3e2..b3d833f 100644
--- a/msm8998/core/Makefile.am
+++ b/msm8998/core/Makefile.am
@@ -33,11 +33,11 @@
 
 if USE_GLIB
 libloc_core_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@
-libloc_core_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0
+libloc_core_la_LDFLAGS = -lstdc++ -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0
 libloc_core_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@
 else
 libloc_core_la_CFLAGS = $(AM_CFLAGS)
-libloc_core_la_LDFLAGS = -Wl,-z,defs -lpthread -shared -version-info 1:0:0
+libloc_core_la_LDFLAGS = -lpthread -shared -version-info 1:0:0
 libloc_core_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS)
 endif
 
diff --git a/msm8998/core/UlpProxyBase.h b/msm8998/core/UlpProxyBase.h
index d30e9cc..8863b66 100644
--- a/msm8998/core/UlpProxyBase.h
+++ b/msm8998/core/UlpProxyBase.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2013-2017, 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
@@ -30,7 +30,8 @@
 #define ULP_PROXY_BASE_H
 
 #include <gps_extended.h>
-#include "fused_location_extended.h"
+#include <LocationAPI.h>
+
 namespace loc_core {
 
 class LocAdapterBase;
@@ -51,24 +52,18 @@
         return false;
     }
 
-    inline virtual bool reportPosition(UlpLocation &location,
-                                       GpsLocationExtended &locationExtended,
-                                       void* locationExt,
+    inline virtual bool reportPosition(const UlpLocation &location,
+                                       const GpsLocationExtended &locationExtended,
                                        enum loc_sess_status status,
                                        LocPosTechMask loc_technology_mask) {
         (void)location;
         (void)locationExtended;
-        (void)locationExt;
         (void)status;
         (void)loc_technology_mask;
         return false;
     }
-    inline virtual bool reportSv(LocGnssSvStatus &svStatus,
-                                 GpsLocationExtended &locationExtended,
-                                 void* svExt) {
-        (void)svStatus;
-        (void)locationExtended;
-        (void)svExt;
+    inline virtual bool reportSv(const GnssSvNotification& svNotify) {
+        (void)svNotify;
         return false;
     }
     inline virtual bool reportSvMeasurement(GnssSvMeasurementSet &svMeasurementSet) {
@@ -94,17 +89,21 @@
 
         (void)capabilities;
     }
-    inline virtual bool reportBatchingSession(FlpExtBatchOptions &options,
-                                              bool active) {
-
-        (void)options;
-        (void)active;
-        return false;
+    inline virtual bool reportBatchingSession(const LocationOptions& options, bool active)
+    {
+         (void)options;
+         (void)active;
+         return false;
     }
-    inline virtual bool reportPositions(const FlpExtLocation* locations,
-                                        int32_t number_of_locations) {
-        (void)locations;
-        (void)number_of_locations;
+    inline virtual bool reportPositions(const UlpLocation* ulpLocations,
+                                        const GpsLocationExtended* extendedLocations,
+                                        const uint32_t* techMasks,
+                                        const size_t count)
+    {
+        (void)ulpLocations;
+        (void)extendedLocations;
+        (void)techMasks;
+        (void)count;
         return false;
     }
     inline virtual bool reportDeleteAidingData(LocGpsAidingData aidingData)
diff --git a/msm8998/core/gps_extended.h b/msm8998/core/gps_extended.h
index 5255da1..dc6ad1e 100644
--- a/msm8998/core/gps_extended.h
+++ b/msm8998/core/gps_extended.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2013-2017 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
@@ -29,19 +29,21 @@
 #ifndef GPS_EXTENDED_H
 #define GPS_EXTENDED_H
 
-#include <gps_extended_c.h>
 /**
  * @file
  * @brief C++ declarations for GPS types
  */
 
+#include <gps_extended_c.h>
+#if defined(USE_GLIB) || defined(OFF_TARGET)
+#include <string.h>
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
 
-#if defined(USE_GLIB) || defined(OFF_TARGET)
-#include <string.h>
-#endif
+
 
 struct LocPosMode
 {
diff --git a/msm8998/core/gps_extended_c.h b/msm8998/core/gps_extended_c.h
index c67e835..55fd03e 100644
--- a/msm8998/core/gps_extended_c.h
+++ b/msm8998/core/gps_extended_c.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2015, 2016 The Linux Foundation. All rights reserved.
+/* Copyright (c) 2013-2017 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
@@ -34,6 +34,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <loc_gps.h>
+#include <LocationAPI.h>
 #include <time.h>
 
 /**
@@ -86,20 +87,10 @@
 #define LOC_AGPS_CERTIFICATE_MAX_LENGTH 2000
 #define LOC_AGPS_CERTIFICATE_MAX_SLOTS 10
 
-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)
-
 enum loc_registration_mask_status {
     LOC_REGISTRATION_MASK_ENABLED,
-    LOC_REGISTRATION_MASK_DISABLED
+    LOC_REGISTRATION_MASK_DISABLED,
+    LOC_REGISTRATION_MASK_SET
 };
 
 typedef enum {
@@ -113,7 +104,6 @@
     LocGpsLocation     gpsLocation;
     /* Provider indicator for HYBRID or GPS */
     uint16_t        position_source;
-    LocPosTechMask  tech_mask;
     /*allows HAL to pass additional information related to the location */
     int             rawDataSize;         /* in # of bytes */
     void            * rawData;
@@ -276,18 +266,6 @@
 #define GPS_LOCATION_EXTENDED_HAS_HOR_ELIP_UNC_AZIMUTH 0x0800
 /** GpsLocationExtended has valid gnss sv used in position data */
 #define GPS_LOCATION_EXTENDED_HAS_GNSS_SV_USED_DATA 0x1000
-/** GpsLocationExtended has valid navSolutionMask */
-#define GPS_LOCATION_EXTENDED_HAS_NAV_SOLUTION_MASK 0x2000
-
-typedef uint32_t LocNavSolutionMask;
-/* Bitmask to specify whether SBAS ionospheric correction is used  */
-#define LOC_NAV_MASK_SBAS_CORRECTION_IONO ((LocNavSolutionMask)0x0001)
-/* Bitmask to specify whether SBAS fast correction is used  */
-#define LOC_NAV_MASK_SBAS_CORRECTION_FAST ((LocNavSolutionMask)0x0002)
-/**<  Bitmask to specify whether SBAS long-tem correction is used  */
-#define LOC_NAV_MASK_SBAS_CORRECTION_LONG ((LocNavSolutionMask)0x0004)
-/**<  Bitmask to specify whether SBAS integrity information is used  */
-#define LOC_NAV_MASK_SBAS_INTEGRITY ((LocNavSolutionMask)0x0008)
 
 /** GPS PRN Range */
 #define GPS_SV_PRN_MIN      1
@@ -357,10 +335,6 @@
     Gnss_ApTimeStampStructType               timeStamp;
     /** Gnss sv used in position data */
     GnssSvUsedInPosition gnss_sv_used_ids;
-    /** Nav solution mask to indicate sbas corrections */
-    LocNavSolutionMask  navSolutionMask;
-    /** Position technology used in computing this fix */
-    LocPosTechMask tech_mask;
 } GpsLocationExtended;
 
 enum loc_sess_status {
@@ -369,6 +343,17 @@
     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)
+
 // Nmea sentence types mask
 typedef uint32_t NmeaSentenceTypesMask;
 #define LOC_NMEA_MASK_GGA_V02   ((NmeaSentenceTypesMask)0x00000001) /**<  Enable GGA type  */
@@ -891,10 +876,8 @@
     */
     uint64_t                        measurementStatus;
     /**< Bitmask indicating SV measurement status.
-        Valid bitmasks: \n
-        If any MSB bit in 0xFFC0000000000000 DONT_USE is set, the measurement
-        must not be used by the client.
-        @MASK()
+         Valid bitmasks: \n
+         @MASK()
     */
     uint16_t                        CNo;
     /**< Carrier to Noise ratio  \n
diff --git a/msm8998/core/loc_core_log.cpp b/msm8998/core/loc_core_log.cpp
index 620d1b0..b8addec 100644
--- a/msm8998/core/loc_core_log.cpp
+++ b/msm8998/core/loc_core_log.cpp
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2011-2017 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
diff --git a/msm8998/core/loc_core_log.h b/msm8998/core/loc_core_log.h
index 4fe8d3f..2beb687 100644
--- a/msm8998/core/loc_core_log.h
+++ b/msm8998/core/loc_core_log.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2011-2013, 2016-2017 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
@@ -30,14 +30,14 @@
 #ifndef LOC_CORE_LOG_H
 #define LOC_CORE_LOG_H
 
+#include <ctype.h>
+#include <gps_extended.h>
+
 #ifdef __cplusplus
 extern "C"
 {
 #endif
 
-#include <ctype.h>
-#include <gps_extended.h>
-
 const char* loc_get_gps_status_name(LocGpsStatusValue gps_status);
 const char* loc_get_position_mode_name(LocGpsPositionMode mode);
 const char* loc_get_position_recurrence_name(LocGpsPositionRecurrence recur);
diff --git a/msm8998/core/loc_gps.h b/msm8998/core/loc_gps.h
index 2e495b8..cdb1af6 100644
--- a/msm8998/core/loc_gps.h
+++ b/msm8998/core/loc_gps.h
@@ -2187,7 +2187,7 @@
      * Deliver GNSS configuration contents to HAL.
      * Parameters:
      *     config_data - a pointer to a char array which holds what usually is expected from
-                         file(/vendor/etc/gps.conf), i.e., a sequence of UTF8 strings separated by '\n'.
+                         file(/etc/gps.conf), i.e., a sequence of UTF8 strings separated by '\n'.
      *     length - total number of UTF8 characters in configuraiton data.
      *
      * IMPORTANT:
diff --git a/msm8998/etc/Android.mk b/msm8998/etc/Android.mk
index d9eb0e1..025d3f7 100644
--- a/msm8998/etc/Android.mk
+++ b/msm8998/etc/Android.mk
@@ -5,7 +5,7 @@
 LOCAL_MODULE := gps.conf
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := ETC
-LOCAL_MODULE_PATH  := $(TARGET_OUT_VENDOR)/etc/
+LOCAL_MODULE_PATH  := $(TARGET_OUT_ETC)/
 LOCAL_SRC_FILES := gps.conf
 
 include $(BUILD_PREBUILT)
diff --git a/msm8998/etc/gps.conf b/msm8998/etc/gps.conf
index 828cf68..895ebb5 100644
--- a/msm8998/etc/gps.conf
+++ b/msm8998/etc/gps.conf
@@ -127,77 +127,43 @@
 # 0x2: WLAN AP Measurements for LPPe UP
 LPPE_UP_TECHNOLOGY = 0
 
-##################################################
-# AGPS_CONFIG_INJECT
-##################################################
-# enable/disable injection of AGPS configurations:
-#     SUPL_VER
-#     SUPL_HOST
-#     SUPL_PORT
-#     C2K_HOST
-#     C2K_PORT
-#     LPP_PROFILE
-#     A_GLONASS_POS_PROTOCOL_SELECT
-# 0: disable
-# 1: enable
-AGPS_CONFIG_INJECT = 1
-
-##################################################
-# GNSS settings for automotive use cases
-# Configurations in following section are
-# specific to automotive use cases, others
-# please do not change, keep the default values
-##################################################
-
 # AP Coarse Timestamp Uncertainty
 ##################################################
 # default : 10
-# AP time stamp uncertainty, until GNSS receiver
-# is able to acquire better timing information
+# or as per clock uncertainty of product
 AP_TIMESTAMP_UNCERTAINTY = 10
 
-##################################################
-# QDR engine availability status
-##################################################
-# 0 : NO QDR (default)
-# 1 : QDR enabled
-# This settings enables QDR Configuration for
-# automotive use case, if enabled then
-# DR_AP_Service needs to be enabled in izat.conf
+#####################################
+# GNSS PPS settings
+#####################################
+#AP DR engine availability status
+# 0 : NO AP DR (default)
+# 1 : AP DR enabled
 #EXTERNAL_DR_ENABLED = 0
 
 #####################################
-# DR_SYNC Pulse Availability
+#DR_SYNC Pulse Availability
 #####################################
 # 0 : DR_SYNC pulse not available (default)
 # 1 : DR_SYNC pulse available
-# This configuration enables the driver to make use
-# of PPS events generated by DR_SYNC pulse
-# Standard Linux PPS driver needs to be enabled
 DR_SYNC_ENABLED = 0
 
 #####################################
-# PPS Device name
+#PPS Device name
 #####################################
 PPS_DEVICENAME = /dev/pps0
 
 #####################################
-# AP Clock Accuracy
+#AP Clock Accuracy
 #####################################
-# Quality of APPS processor clock (in PPM).
-# Value specified is used for calculation of
-# APPS time stamp uncertainty
 AP_CLOCK_PPM = 100
 
 #####################################
-# MAX ms difference to detect missing pulse
+#MAX ms difference to detect missing pulse
 #####################################
-# Specifies time threshold in ms to validate any missing PPS pulses
 MISSING_PULSE_TIME_DELTA = 900
 
 #####################################
-# Propagation time uncertainty
+#Propagation time uncertainty
 #####################################
-# This settings enables time uncertainty propagation
-# logic incase of missing PPS pulse
 PROPAGATION_TIME_UNCERTAINTY = 1
diff --git a/msm8998/gnss/Agps.cpp b/msm8998/gnss/Agps.cpp
new file mode 100644
index 0000000..aacd9da
--- /dev/null
+++ b/msm8998/gnss/Agps.cpp
@@ -0,0 +1,963 @@
+/* Copyright (c) 2012-2017, 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_TAG "LocSvc_Agps"
+
+#include <Agps.h>
+#include <platform_lib_includes.h>
+#include <ContextBase.h>
+#include <loc_timer.h>
+
+/* --------------------------------------------------------------------
+ *   AGPS State Machine Methods
+ * -------------------------------------------------------------------*/
+void AgpsStateMachine::processAgpsEvent(AgpsEvent event){
+
+    LOC_LOGD("processAgpsEvent(): SM %p, Event %d, State %d",
+               this, event, mState);
+
+    switch (event){
+
+        case AGPS_EVENT_SUBSCRIBE:
+            processAgpsEventSubscribe();
+            break;
+
+        case AGPS_EVENT_UNSUBSCRIBE:
+            processAgpsEventUnsubscribe();
+            break;
+
+        case AGPS_EVENT_GRANTED:
+            processAgpsEventGranted();
+            break;
+
+        case AGPS_EVENT_RELEASED:
+            processAgpsEventReleased();
+            break;
+
+        case AGPS_EVENT_DENIED:
+            processAgpsEventDenied();
+            break;
+
+        default:
+            LOC_LOGE("Invalid Loc Agps Event");
+    }
+}
+
+void AgpsStateMachine::processAgpsEventSubscribe(){
+
+    switch (mState){
+
+        case AGPS_STATE_RELEASED:
+            /* Add subscriber to list
+             * No notifications until we get RSRC_GRANTED */
+            addSubscriber(mCurrentSubscriber);
+
+            /* Send data request
+             * The if condition below is added so that if the data call setup
+             * fails for DS State Machine, we want to retry in released state.
+             * for Agps State Machine, sendRsrcRequest() will always return
+             * success. */
+            if(requestOrReleaseDataConn(true) == 0){
+                // If data request successful, move to pending state
+                transitionState(AGPS_STATE_PENDING);
+            }
+            break;
+
+        case AGPS_STATE_PENDING:
+            /* Already requested for data connection,
+             * do nothing until we get RSRC_GRANTED event;
+             * Just add this subscriber to the list, for notifications */
+            addSubscriber(mCurrentSubscriber);
+            break;
+
+        case AGPS_STATE_ACQUIRED:
+            /* We already have the data connection setup,
+             * Notify current subscriber with GRANTED event,
+             * And add it to the subscriber list for further notifications. */
+            notifyEventToSubscriber(AGPS_EVENT_GRANTED, mCurrentSubscriber, false);
+            addSubscriber(mCurrentSubscriber);
+            break;
+
+        case AGPS_STATE_RELEASING:
+            addSubscriber(mCurrentSubscriber);
+            break;
+
+        default:
+            LOC_LOGE("Invalid state: %d", mState);
+    }
+}
+
+void AgpsStateMachine::processAgpsEventUnsubscribe(){
+
+    switch (mState){
+
+        case AGPS_STATE_RELEASED:
+            notifyEventToSubscriber(
+                    AGPS_EVENT_UNSUBSCRIBE, mCurrentSubscriber, false);
+            break;
+
+        case AGPS_STATE_PENDING:
+        case AGPS_STATE_ACQUIRED:
+            /* If the subscriber wishes to wait for connection close,
+             * before being removed from list, move to inactive state
+             * and notify */
+            if(mCurrentSubscriber->mWaitForCloseComplete){
+                mCurrentSubscriber->mIsInactive = true;
+                notifyEventToSubscriber(
+                        AGPS_EVENT_UNSUBSCRIBE, mCurrentSubscriber, false);
+            }
+            else{
+                /* Notify only current subscriber and then delete it from
+                 * subscriberList */
+                notifyEventToSubscriber(
+                        AGPS_EVENT_UNSUBSCRIBE, mCurrentSubscriber, true);
+            }
+
+            /* If no subscribers in list, release data connection */
+            if(mSubscriberList.empty()){
+                transitionState(AGPS_STATE_RELEASED);
+                requestOrReleaseDataConn(false);
+            }
+            /* Some subscribers in list, but all inactive;
+             * Release data connection */
+            else if(!anyActiveSubscribers()){
+                transitionState(AGPS_STATE_RELEASING);
+                requestOrReleaseDataConn(false);
+            }
+            break;
+
+        case AGPS_STATE_RELEASING:
+            /* If the subscriber wishes to wait for connection close,
+             * before being removed from list, move to inactive state
+             * and notify */
+            if(mCurrentSubscriber->mWaitForCloseComplete){
+                mCurrentSubscriber->mIsInactive = true;
+                notifyEventToSubscriber(
+                        AGPS_EVENT_UNSUBSCRIBE, mCurrentSubscriber, false);
+            }
+            else{
+                /* Notify only current subscriber and then delete it from
+                 * subscriberList */
+                notifyEventToSubscriber(
+                        AGPS_EVENT_UNSUBSCRIBE, mCurrentSubscriber, true);
+            }
+
+            /* If no subscribers in list, just move the state.
+             * Request for releasing data connection should already have been
+             * sent */
+            if(mSubscriberList.empty()){
+                transitionState(AGPS_STATE_RELEASED);
+            }
+            break;
+
+        default:
+            LOC_LOGE("Invalid state: %d", mState);
+    }
+}
+
+void AgpsStateMachine::processAgpsEventGranted(){
+
+    switch (mState){
+
+        case AGPS_STATE_RELEASED:
+        case AGPS_STATE_ACQUIRED:
+        case AGPS_STATE_RELEASING:
+            LOC_LOGE("Unexpected event GRANTED in state %d", mState);
+            break;
+
+        case AGPS_STATE_PENDING:
+            // Move to acquired state
+            transitionState(AGPS_STATE_ACQUIRED);
+            notifyAllSubscribers(
+                    AGPS_EVENT_GRANTED, false,
+                    AGPS_NOTIFICATION_TYPE_FOR_ACTIVE_SUBSCRIBERS);
+            break;
+
+        default:
+            LOC_LOGE("Invalid state: %d", mState);
+    }
+}
+
+void AgpsStateMachine::processAgpsEventReleased(){
+
+    switch (mState){
+
+        case AGPS_STATE_RELEASED:
+            LOC_LOGE("Unexpected event RELEASED in state %d", mState);
+            break;
+
+        case AGPS_STATE_ACQUIRED:
+            /* Force release received */
+            LOC_LOGW("Force RELEASED event in ACQUIRED state");
+            transitionState(AGPS_STATE_RELEASED);
+            notifyAllSubscribers(
+                    AGPS_EVENT_RELEASED, true,
+                    AGPS_NOTIFICATION_TYPE_FOR_ALL_SUBSCRIBERS);
+            break;
+
+        case AGPS_STATE_RELEASING:
+            /* Notify all inactive subscribers about the event */
+            notifyAllSubscribers(
+                    AGPS_EVENT_RELEASED, true,
+                    AGPS_NOTIFICATION_TYPE_FOR_INACTIVE_SUBSCRIBERS);
+
+            /* If we have active subscribers now, they must be waiting for
+             * data conn setup */
+            if(anyActiveSubscribers()){
+                transitionState(AGPS_STATE_PENDING);
+                requestOrReleaseDataConn(true);
+            }
+            /* No active subscribers, move to released state */
+            else{
+                transitionState(AGPS_STATE_RELEASED);
+            }
+            break;
+
+        case AGPS_STATE_PENDING:
+            /* NOOP */
+            break;
+
+        default:
+            LOC_LOGE("Invalid state: %d", mState);
+    }
+}
+
+void AgpsStateMachine::processAgpsEventDenied(){
+
+    switch (mState){
+
+        case AGPS_STATE_RELEASED:
+            LOC_LOGE("Unexpected event DENIED in state %d", mState);
+            break;
+
+        case AGPS_STATE_ACQUIRED:
+            /* NOOP */
+            break;
+
+        case AGPS_STATE_RELEASING:
+            /* Notify all inactive subscribers about the event */
+            notifyAllSubscribers(
+                    AGPS_EVENT_RELEASED, true,
+                    AGPS_NOTIFICATION_TYPE_FOR_INACTIVE_SUBSCRIBERS);
+
+            /* If we have active subscribers now, they must be waiting for
+             * data conn setup */
+            if(anyActiveSubscribers()){
+                transitionState(AGPS_STATE_PENDING);
+                requestOrReleaseDataConn(true);
+            }
+            /* No active subscribers, move to released state */
+            else{
+                transitionState(AGPS_STATE_RELEASED);
+            }
+            break;
+
+        case AGPS_STATE_PENDING:
+            transitionState(AGPS_STATE_RELEASED);
+            notifyAllSubscribers(
+                    AGPS_EVENT_DENIED, true,
+                    AGPS_NOTIFICATION_TYPE_FOR_ALL_SUBSCRIBERS);
+            break;
+
+        default:
+            LOC_LOGE("Invalid state: %d", mState);
+    }
+}
+
+/* Request or Release data connection
+ * bool request :
+ *      true  = Request data connection
+ *      false = Release data connection */
+int AgpsStateMachine::requestOrReleaseDataConn(bool request){
+
+    AgpsFrameworkInterface::AGnssStatusIpV4 nifRequest;
+    memset(&nifRequest, 0, sizeof(nifRequest));
+
+    nifRequest.type = (AgpsFrameworkInterface::AGnssType)mAgpsType;
+
+    if(request){
+        LOC_LOGD("AGPS Data Conn Request");
+        nifRequest.status = (AgpsFrameworkInterface::AGnssStatusValue)
+                                LOC_GPS_REQUEST_AGPS_DATA_CONN;
+    }
+    else{
+        LOC_LOGD("AGPS Data Conn Release");
+        nifRequest.status = (AgpsFrameworkInterface::AGnssStatusValue)
+                                LOC_GPS_RELEASE_AGPS_DATA_CONN;
+    }
+
+    mAgpsManager->mFrameworkStatusV4Cb(nifRequest);
+    return 0;
+}
+
+void AgpsStateMachine::notifyAllSubscribers(
+        AgpsEvent event, bool deleteSubscriberPostNotify,
+        AgpsNotificationType notificationType){
+
+    LOC_LOGD("notifyAllSubscribers(): "
+            "SM %p, Event %d Delete %d Notification Type %d",
+            this, event, deleteSubscriberPostNotify, notificationType);
+
+    std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
+    while ( it != mSubscriberList.end() ){
+
+        AgpsSubscriber* subscriber = *it;
+
+        if(notificationType == AGPS_NOTIFICATION_TYPE_FOR_ALL_SUBSCRIBERS ||
+                (notificationType == AGPS_NOTIFICATION_TYPE_FOR_INACTIVE_SUBSCRIBERS &&
+                        subscriber->mIsInactive) ||
+                (notificationType == AGPS_NOTIFICATION_TYPE_FOR_ACTIVE_SUBSCRIBERS &&
+                        !subscriber->mIsInactive)) {
+
+            /* Deleting via this call would require another traversal
+             * through subscriber list, inefficient; hence pass in false*/
+            notifyEventToSubscriber(event, subscriber, false);
+
+            if(deleteSubscriberPostNotify){
+                it = mSubscriberList.erase(it);
+                delete subscriber;
+            } else{
+                it++;
+            }
+        } else{
+            it++;
+        }
+    }
+}
+
+void AgpsStateMachine::notifyEventToSubscriber(
+        AgpsEvent event, AgpsSubscriber* subscriberToNotify,
+        bool deleteSubscriberPostNotify) {
+
+    LOC_LOGD("notifyEventToSubscriber(): "
+            "SM %p, Event %d Subscriber %p Delete %d",
+            this, event, subscriberToNotify, deleteSubscriberPostNotify);
+
+    switch (event){
+
+        case AGPS_EVENT_GRANTED:
+            mAgpsManager->mAtlOpenStatusCb(
+                    subscriberToNotify->mConnHandle, 1, getAPN(),
+                    getBearer(), mAgpsType);
+            break;
+
+        case AGPS_EVENT_DENIED:
+            mAgpsManager->mAtlOpenStatusCb(
+                    subscriberToNotify->mConnHandle, 0, getAPN(),
+                    getBearer(), mAgpsType);
+            break;
+
+        case AGPS_EVENT_UNSUBSCRIBE:
+        case AGPS_EVENT_RELEASED:
+            mAgpsManager->mAtlCloseStatusCb(subscriberToNotify->mConnHandle, 1);
+            break;
+
+        default:
+            LOC_LOGE("Invalid event %d", event);
+    }
+
+    /* Search this subscriber in list and delete */
+    if (deleteSubscriberPostNotify) {
+        deleteSubscriber(subscriberToNotify);
+    }
+}
+
+void AgpsStateMachine::transitionState(AgpsState newState){
+
+    LOC_LOGD("transitionState(): SM %p, old %d, new %d",
+               this, mState, newState);
+
+    mState = newState;
+
+    // notify state transitions to all subscribers ?
+}
+
+void AgpsStateMachine::addSubscriber(AgpsSubscriber* subscriberToAdd){
+
+    LOC_LOGD("addSubscriber(): SM %p, Subscriber %p",
+               this, subscriberToAdd);
+
+    // Check if subscriber is already present in the current list
+    // If not, then add
+    std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
+    for(; it != mSubscriberList.end(); it++){
+        AgpsSubscriber* subscriber = *it;
+        if(subscriber->equals(subscriberToAdd)){
+            LOC_LOGE("Subscriber already in list");
+            return;
+        }
+    }
+
+    AgpsSubscriber* cloned = subscriberToAdd->clone();
+    LOC_LOGD("addSubscriber(): cloned subscriber: %p", cloned);
+    mSubscriberList.push_back(cloned);
+}
+
+void AgpsStateMachine::deleteSubscriber(AgpsSubscriber* subscriberToDelete){
+
+    LOC_LOGD("deleteSubscriber(): SM %p, Subscriber %p",
+               this, subscriberToDelete);
+
+    std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
+    while ( it != mSubscriberList.end() ) {
+
+        AgpsSubscriber* subscriber = *it;
+        if(subscriber && subscriber->equals(subscriberToDelete)){
+
+            it = mSubscriberList.erase(it);
+            delete subscriber;
+        }else{
+            it++;
+        }
+    }
+}
+
+bool AgpsStateMachine::anyActiveSubscribers(){
+
+    std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
+    for(; it != mSubscriberList.end(); it++){
+        AgpsSubscriber* subscriber = *it;
+        if(!subscriber->mIsInactive){
+            return true;
+        }
+    }
+    return false;
+}
+
+void AgpsStateMachine::setAPN(char* apn, unsigned int len){
+
+    if (NULL != mAPN) {
+        delete mAPN;
+    }
+
+    if(apn == NULL || len <= 0){
+        LOC_LOGD("Invalid apn len (%d) or null apn", len);
+        mAPN = NULL;
+        mAPNLen = 0;
+    }
+
+    if (NULL != apn) {
+        mAPN = new char[len+1];
+        memcpy(mAPN, apn, len);
+        mAPN[len] = '\0';
+        mAPNLen = len;
+    }
+}
+
+AgpsSubscriber* AgpsStateMachine::getSubscriber(int connHandle){
+
+    /* Go over the subscriber list */
+    std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
+    for(; it != mSubscriberList.end(); it++){
+        AgpsSubscriber* subscriber = *it;
+        if(subscriber->mConnHandle == connHandle){
+            return subscriber;
+        }
+    }
+
+    /* Not found, return NULL */
+    return NULL;
+}
+
+AgpsSubscriber* AgpsStateMachine::getFirstSubscriber(bool isInactive){
+
+    /* Go over the subscriber list */
+    std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
+    for(; it != mSubscriberList.end(); it++){
+        AgpsSubscriber* subscriber = *it;
+        if(subscriber->mIsInactive == isInactive){
+            return subscriber;
+        }
+    }
+
+    /* Not found, return NULL */
+    return NULL;
+}
+
+void AgpsStateMachine::dropAllSubscribers(){
+
+    LOC_LOGD("dropAllSubscribers(): SM %p", this);
+
+    /* Go over the subscriber list */
+    std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
+    while ( it != mSubscriberList.end() ){
+        AgpsSubscriber* subscriber = *it;
+        it = mSubscriberList.erase(it);
+        delete subscriber;
+    }
+}
+
+/* --------------------------------------------------------------------
+ *   DS State Machine Methods
+ * -------------------------------------------------------------------*/
+const int DSStateMachine::MAX_START_DATA_CALL_RETRIES = 4;
+const int DSStateMachine::DATA_CALL_RETRY_DELAY_MSEC = 500;
+
+/* Overridden method
+ * DS SM needs to handle one scenario differently */
+void DSStateMachine::processAgpsEvent(AgpsEvent event){
+
+    LOC_LOGD("DSStateMachine::processAgpsEvent() %d", event);
+
+    /* DS Client call setup APIs don't return failure/closure separately.
+     * Hence we receive RELEASED event in both cases.
+     * If we are in pending, we should consider RELEASED as DENIED */
+    if(event == AGPS_EVENT_RELEASED && mState == AGPS_STATE_PENDING){
+
+        LOC_LOGD("Translating RELEASED to DENIED event");
+        event = AGPS_EVENT_DENIED;
+    }
+
+    /* Redirect process to base class */
+    AgpsStateMachine::processAgpsEvent(event);
+}
+
+/* Timer Callback
+ * For the retry timer started in case of DS Client call setup failure */
+void delay_callback(void *callbackData, int result)
+{
+    LOC_LOGD("delay_callback(): cbData %p", callbackData);
+
+    (void)result;
+
+    if(callbackData == NULL) {
+        LOC_LOGE("delay_callback(): NULL argument received !");
+        return;
+    }
+    DSStateMachine* dsStateMachine = (DSStateMachine *)callbackData;
+    dsStateMachine->retryCallback();
+}
+
+/* Invoked from Timer Callback
+ * For the retry timer started in case of DS Client call setup failure */
+void DSStateMachine :: retryCallback()
+{
+    LOC_LOGD("DSStateMachine::retryCallback()");
+
+    /* Request SUPL ES
+     * There must be at least one active subscriber in list */
+    AgpsSubscriber* subscriber = getFirstSubscriber(false);
+    if(subscriber == NULL) {
+
+        LOC_LOGE("No active subscriber for DS Client call setup");
+        return;
+    }
+
+    /* Send message to retry */
+    mAgpsManager->mSendMsgToAdapterQueueFn(
+            new AgpsMsgRequestATL(
+                    mAgpsManager, subscriber->mConnHandle,
+                    LOC_AGPS_TYPE_SUPL_ES));
+}
+
+/* Overridden method
+ * Request or Release data connection
+ * bool request :
+ *      true  = Request data connection
+ *      false = Release data connection */
+int DSStateMachine::requestOrReleaseDataConn(bool request){
+
+    LOC_LOGD("DSStateMachine::requestOrReleaseDataConn(): "
+             "request %d", request);
+
+    /* Release data connection required ? */
+    if(!request && mAgpsManager->mDSClientStopDataCallFn){
+
+        mAgpsManager->mDSClientStopDataCallFn();
+        LOC_LOGD("DS Client release data call request sent !");
+        return 0;
+    }
+
+    /* Setup data connection request
+     * There must be at least one active subscriber in list */
+    AgpsSubscriber* subscriber = getFirstSubscriber(false);
+    if(subscriber == NULL) {
+
+        LOC_LOGE("No active subscriber for DS Client call setup");
+        return -1;
+    }
+
+    /* DS Client Fn registered ? */
+    if(!mAgpsManager->mDSClientOpenAndStartDataCallFn){
+
+        LOC_LOGE("DS Client start fn not registered, fallback to SUPL ATL");
+        notifyEventToSubscriber(AGPS_EVENT_DENIED, subscriber, false);
+        return -1;
+    }
+
+    /* Setup the call */
+    int ret = mAgpsManager->mDSClientOpenAndStartDataCallFn();
+
+    /* Check if data call start failed */
+    switch (ret) {
+
+        case LOC_API_ADAPTER_ERR_ENGINE_BUSY:
+            LOC_LOGE("DS Client open call failed, err: %d", ret);
+            mRetries++;
+            if(mRetries > MAX_START_DATA_CALL_RETRIES) {
+
+                LOC_LOGE("DS Client call retries exhausted, "
+                         "falling back to normal SUPL ATL");
+                notifyEventToSubscriber(AGPS_EVENT_DENIED, subscriber, false);
+            }
+            /* Retry DS Client call setup after some delay */
+            else if(loc_timer_start(
+                        DATA_CALL_RETRY_DELAY_MSEC, delay_callback, this)) {
+                    LOC_LOGE("Error: Could not start delay thread\n");
+                    return -1;
+                }
+            break;
+
+        case LOC_API_ADAPTER_ERR_UNSUPPORTED:
+            LOC_LOGE("No emergency profile found. Fall back to normal SUPL ATL");
+            notifyEventToSubscriber(AGPS_EVENT_DENIED, subscriber, false);
+            break;
+
+        case LOC_API_ADAPTER_ERR_SUCCESS:
+            LOC_LOGD("Request to start data call sent");
+            break;
+
+        default:
+            LOC_LOGE("Unrecognized return value: %d", ret);
+    }
+
+    return ret;
+}
+
+void DSStateMachine::notifyEventToSubscriber(
+        AgpsEvent event, AgpsSubscriber* subscriberToNotify,
+        bool deleteSubscriberPostNotify) {
+
+    LOC_LOGD("DSStateMachine::notifyEventToSubscriber");
+
+    switch (event){
+
+        case AGPS_EVENT_GRANTED:
+            mAgpsManager->mAtlOpenStatusCb(
+                    subscriberToNotify->mConnHandle, 1, NULL,
+                    AGPS_APN_BEARER_INVALID, LOC_AGPS_TYPE_SUPL_ES);
+            break;
+
+        case AGPS_EVENT_DENIED:
+            /* Now try with regular SUPL
+             * We need to send request via message queue */
+            mRetries = 0;
+            mAgpsManager->mSendMsgToAdapterQueueFn(
+                    new AgpsMsgRequestATL(
+                            mAgpsManager, subscriberToNotify->mConnHandle,
+                            LOC_AGPS_TYPE_SUPL));
+            break;
+
+        case AGPS_EVENT_UNSUBSCRIBE:
+            mAgpsManager->mAtlCloseStatusCb(subscriberToNotify->mConnHandle, 1);
+            break;
+
+        case AGPS_EVENT_RELEASED:
+            mAgpsManager->mDSClientCloseDataCallFn();
+            break;
+
+        default:
+            LOC_LOGE("Invalid event %d", event);
+    }
+
+    /* Search this subscriber in list and delete */
+    if (deleteSubscriberPostNotify) {
+        deleteSubscriber(subscriberToNotify);
+    }
+}
+
+/* --------------------------------------------------------------------
+ *   Loc AGPS Manager Methods
+ * -------------------------------------------------------------------*/
+
+/* CREATE AGPS STATE MACHINES
+ * Must be invoked in Msg Handler context */
+void AgpsManager::createAgpsStateMachines() {
+
+    LOC_LOGD("AgpsManager::createAgpsStateMachines");
+
+    bool agpsCapable =
+            ((loc_core::ContextBase::mGps_conf.CAPABILITIES & LOC_GPS_CAPABILITY_MSA) ||
+                    (loc_core::ContextBase::mGps_conf.CAPABILITIES & LOC_GPS_CAPABILITY_MSB));
+
+    if (NULL == mInternetNif) {
+        mInternetNif = new AgpsStateMachine(this, LOC_AGPS_TYPE_WWAN_ANY);
+        LOC_LOGD("Internet NIF: %p", mInternetNif);
+    }
+    if (agpsCapable) {
+        if (NULL == mAgnssNif) {
+            mAgnssNif = new AgpsStateMachine(this, LOC_AGPS_TYPE_SUPL);
+            LOC_LOGD("AGNSS NIF: %p", mAgnssNif);
+        }
+        if (NULL == mDsNif &&
+                loc_core::ContextBase::mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL){
+
+            if(!mDSClientInitFn){
+
+                LOC_LOGE("DS Client Init Fn not registered !");
+                return;
+            }
+            if(mDSClientInitFn(false) != 0){
+
+                LOC_LOGE("Failed to init data service client");
+                return;
+            }
+            mDsNif = new DSStateMachine(this);
+            LOC_LOGD("DS NIF: %p", mDsNif);
+        }
+    }
+}
+
+AgpsStateMachine* AgpsManager::getAgpsStateMachine(AGpsExtType agpsType) {
+
+    LOC_LOGD("AgpsManager::getAgpsStateMachine(): agpsType %d", agpsType);
+
+    switch (agpsType) {
+
+        case LOC_AGPS_TYPE_INVALID:
+        case LOC_AGPS_TYPE_SUPL:
+            if(mAgnssNif == NULL){
+                LOC_LOGE("NULL AGNSS NIF !");
+            }
+            return mAgnssNif;
+
+        case LOC_AGPS_TYPE_SUPL_ES:
+            if (loc_core::ContextBase::mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL) {
+                if (mDsNif == NULL) {
+                    createAgpsStateMachines();
+                }
+                return mDsNif;
+            } else {
+                return mAgnssNif;
+            }
+
+        default:
+            return mInternetNif;
+    }
+
+    LOC_LOGE("No SM found !");
+    return NULL;
+}
+
+void AgpsManager::requestATL(int connHandle, AGpsExtType agpsType){
+
+    LOC_LOGD("AgpsManager::requestATL(): connHandle %d, agpsType %d",
+               connHandle, agpsType);
+
+    AgpsStateMachine* sm = getAgpsStateMachine(agpsType);
+
+    if(sm == NULL){
+
+        LOC_LOGE("No AGPS State Machine for agpsType: %d", agpsType);
+        mAtlOpenStatusCb(
+                connHandle, 0, NULL, AGPS_APN_BEARER_INVALID, agpsType);
+        return;
+    }
+
+    /* Invoke AGPS SM processing */
+    AgpsSubscriber subscriber(connHandle);
+    sm->setCurrentSubscriber(&subscriber);
+
+    /* If DS State Machine, wait for close complete */
+    if(agpsType == LOC_AGPS_TYPE_SUPL_ES){
+        subscriber.mWaitForCloseComplete = true;
+    }
+
+    /* Send subscriber event */
+    sm->processAgpsEvent(AGPS_EVENT_SUBSCRIBE);
+}
+
+void AgpsManager::releaseATL(int connHandle){
+
+    LOC_LOGD("AgpsManager::releaseATL(): connHandle %d", connHandle);
+
+    /* First find the subscriber with specified handle.
+     * We need to search in all state machines. */
+    AgpsStateMachine* sm = NULL;
+    AgpsSubscriber* subscriber = NULL;
+
+    if (mAgnssNif &&
+            (subscriber = mAgnssNif->getSubscriber(connHandle)) != NULL) {
+        sm = mAgnssNif;
+    }
+    else if (mInternetNif &&
+            (subscriber = mInternetNif->getSubscriber(connHandle)) != NULL) {
+        sm = mInternetNif;
+    }
+    else if (mDsNif &&
+            (subscriber = mDsNif->getSubscriber(connHandle)) != NULL) {
+        sm = mDsNif;
+    }
+
+    if(sm == NULL){
+        LOC_LOGE("Subscriber with connHandle %d not found in any SM",
+                    connHandle);
+        mAtlCloseStatusCb(connHandle, 0);
+        return;
+    }
+
+    /* Now send unsubscribe event */
+    sm->setCurrentSubscriber(subscriber);
+    sm->processAgpsEvent(AGPS_EVENT_UNSUBSCRIBE);
+}
+
+void AgpsManager::reportDataCallOpened(){
+
+    LOC_LOGD("AgpsManager::reportDataCallOpened");
+
+    if (mDsNif) {
+        mDsNif->processAgpsEvent(AGPS_EVENT_GRANTED);
+    }
+}
+
+void AgpsManager::reportDataCallClosed(){
+
+    LOC_LOGD("AgpsManager::reportDataCallClosed");
+
+    if (mDsNif) {
+        mDsNif->processAgpsEvent(AGPS_EVENT_RELEASED);
+    }
+}
+
+void AgpsManager::reportAtlOpenSuccess(
+        AGpsExtType agpsType, char* apnName, int apnLen,
+        LocApnIpType ipType){
+
+    LOC_LOGD("AgpsManager::reportAtlOpenSuccess(): "
+             "AgpsType %d, APN [%s], Len %d, IPType %d",
+             agpsType, apnName, apnLen, ipType);
+
+    /* Find the state machine instance */
+    AgpsStateMachine* sm = getAgpsStateMachine(agpsType);
+
+    /* Convert LocApnIpType sent by framework to AGpsBearerType */
+    AGpsBearerType bearerType;
+    switch (ipType) {
+        case LOC_APN_IP_IPV4:
+            bearerType = AGPS_APN_BEARER_IPV4;
+            break;
+        case LOC_APN_IP_IPV6:
+            bearerType = AGPS_APN_BEARER_IPV6;
+            break;
+        case LOC_APN_IP_IPV4V6:
+            bearerType = AGPS_APN_BEARER_IPV4V6;
+            break;
+        default:
+            bearerType = AGPS_APN_BEARER_IPV4;
+            break;
+    }
+
+    /* Set bearer and apn info in state machine instance */
+    sm->setBearer(bearerType);
+    sm->setAPN(apnName, apnLen);
+
+    /* Send GRANTED event to state machine */
+    sm->processAgpsEvent(AGPS_EVENT_GRANTED);
+}
+
+void AgpsManager::reportAtlOpenFailed(AGpsExtType agpsType){
+
+    LOC_LOGD("AgpsManager::reportAtlOpenFailed(): AgpsType %d", agpsType);
+
+    /* Fetch SM and send DENIED event */
+    AgpsStateMachine* sm = getAgpsStateMachine(agpsType);
+    sm->processAgpsEvent(AGPS_EVENT_DENIED);
+}
+
+void AgpsManager::reportAtlClosed(AGpsExtType agpsType){
+
+    LOC_LOGD("AgpsManager::reportAtlClosed(): AgpsType %d", agpsType);
+
+    /* Fetch SM and send RELEASED event */
+    AgpsStateMachine* sm = getAgpsStateMachine(agpsType);
+    sm->processAgpsEvent(AGPS_EVENT_RELEASED);
+}
+
+void AgpsManager::handleModemSSR(){
+
+    LOC_LOGD("AgpsManager::handleModemSSR");
+
+    /* Drop subscribers from all state machines */
+    if (mAgnssNif){
+        mAgnssNif->dropAllSubscribers();
+    }
+    if (mInternetNif){
+        mInternetNif->dropAllSubscribers();
+    }
+    if(mDsNif){
+        mDsNif->dropAllSubscribers();
+    }
+
+    // reinitialize DS client in SSR mode
+    if(loc_core::ContextBase::mGps_conf.
+            USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL){
+
+        mDSClientStopDataCallFn();
+        mDSClientCloseDataCallFn();
+        mDSClientReleaseFn();
+
+        mDSClientInitFn(true);
+    }
+}
+
+AGpsBearerType AgpsUtils::ipTypeToBearerType(LocApnIpType ipType) {
+
+    switch (ipType) {
+
+        case LOC_APN_IP_IPV4:
+            return AGPS_APN_BEARER_IPV4;
+
+        case LOC_APN_IP_IPV6:
+            return AGPS_APN_BEARER_IPV6;
+
+        case LOC_APN_IP_IPV4V6:
+            return AGPS_APN_BEARER_IPV4V6;
+
+        default:
+            return AGPS_APN_BEARER_IPV4;
+    }
+}
+
+LocApnIpType AgpsUtils::bearerTypeToIpType(AGpsBearerType bearerType){
+
+    switch (bearerType) {
+
+        case AGPS_APN_BEARER_IPV4:
+            return LOC_APN_IP_IPV4;
+
+        case AGPS_APN_BEARER_IPV6:
+            return LOC_APN_IP_IPV6;
+
+        case AGPS_APN_BEARER_IPV4V6:
+            return LOC_APN_IP_IPV4V6;
+
+        default:
+            return LOC_APN_IP_IPV4;
+    }
+}
diff --git a/msm8998/gnss/Agps.h b/msm8998/gnss/Agps.h
new file mode 100644
index 0000000..1e95a42
--- /dev/null
+++ b/msm8998/gnss/Agps.h
@@ -0,0 +1,446 @@
+/* Copyright (c) 2012-2017, 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 AGPS_H
+#define AGPS_H
+
+#include <functional>
+#include <list>
+#include <MsgTask.h>
+#include <gps_extended_c.h>
+#include <platform_lib_log_util.h>
+
+/* ATL callback function pointers
+ * Passed in by Adapter to AgpsManager */
+typedef std::function<void(
+        int handle, int isSuccess, char* apn,
+        AGpsBearerType bearerType, AGpsExtType agpsType)>  AgpsAtlOpenStatusCb;
+
+typedef std::function<void(int handle, int isSuccess)>     AgpsAtlCloseStatusCb;
+
+/* DS Client control APIs
+ * Passed in by Adapter to AgpsManager */
+typedef std::function<int(bool isDueToSSR)>  AgpsDSClientInitFn;
+typedef std::function<int()>                 AgpsDSClientOpenAndStartDataCallFn;
+typedef std::function<void()>                AgpsDSClientStopDataCallFn;
+typedef std::function<void()>                AgpsDSClientCloseDataCallFn;
+typedef std::function<void()>                AgpsDSClientReleaseFn;
+
+/* Post message to adapter's message queue */
+typedef std::function<void(LocMsg* msg)>     SendMsgToAdapterMsgQueueFn;
+
+/* AGPS States */
+typedef enum {
+    AGPS_STATE_INVALID = 0,
+    AGPS_STATE_RELEASED,
+    AGPS_STATE_PENDING,
+    AGPS_STATE_ACQUIRED,
+    AGPS_STATE_RELEASING
+} AgpsState;
+
+typedef enum {
+    AGPS_EVENT_INVALID = 0,
+    AGPS_EVENT_SUBSCRIBE,
+    AGPS_EVENT_UNSUBSCRIBE,
+    AGPS_EVENT_GRANTED,
+    AGPS_EVENT_RELEASED,
+    AGPS_EVENT_DENIED
+} AgpsEvent;
+
+/* Notification Types sent to subscribers */
+typedef enum {
+    AGPS_NOTIFICATION_TYPE_INVALID = 0,
+
+    /* Meant for all subscribers, either active or inactive */
+    AGPS_NOTIFICATION_TYPE_FOR_ALL_SUBSCRIBERS,
+
+    /* Meant for only inactive subscribers */
+    AGPS_NOTIFICATION_TYPE_FOR_INACTIVE_SUBSCRIBERS,
+
+    /* Meant for only active subscribers */
+    AGPS_NOTIFICATION_TYPE_FOR_ACTIVE_SUBSCRIBERS
+} AgpsNotificationType;
+
+/* Framework AGNSS interface
+ * This interface is defined in IAGnssCallback provided by
+ * Android Framework.
+ * Must be kept in sync with that interface. */
+namespace AgpsFrameworkInterface {
+
+    /** AGNSS type **/
+    enum AGnssType : uint8_t {
+        TYPE_SUPL         = 1,
+        TYPE_C2K          = 2
+    };
+
+    enum AGnssStatusValue : uint8_t {
+        /** GNSS requests data connection for AGNSS. */
+        REQUEST_AGNSS_DATA_CONN  = 1,
+        /** GNSS releases the AGNSS data connection. */
+        RELEASE_AGNSS_DATA_CONN  = 2,
+        /** AGNSS data connection initiated */
+        AGNSS_DATA_CONNECTED     = 3,
+        /** AGNSS data connection completed */
+        AGNSS_DATA_CONN_DONE     = 4,
+        /** AGNSS data connection failed */
+        AGNSS_DATA_CONN_FAILED   = 5
+    };
+
+    /*
+     * Represents the status of AGNSS augmented to support IPv4.
+     */
+    struct AGnssStatusIpV4 {
+        AGnssType type;
+        AGnssStatusValue status;
+        /*
+         * 32-bit IPv4 address.
+         */
+        unsigned int ipV4Addr;
+    };
+
+    /*
+     * Represents the status of AGNSS augmented to support IPv6.
+     */
+    struct AGnssStatusIpV6 {
+        AGnssType type;
+        AGnssStatusValue status;
+        /*
+         * 128-bit IPv6 address.
+         */
+        unsigned char ipV6Addr[16];
+    };
+
+    /*
+     * Callback with AGNSS(IpV4) status information.
+     *
+     * @param status Will be of type AGnssStatusIpV4.
+     */
+    typedef void (*AgnssStatusIpV4Cb)(AGnssStatusIpV4 status);
+
+    /*
+     * Callback with AGNSS(IpV6) status information.
+     *
+     * @param status Will be of type AGnssStatusIpV6.
+     */
+    typedef void (*AgnssStatusIpV6Cb)(AGnssStatusIpV6 status);
+}
+
+/* Classes in this header */
+class AgpsSubscriber;
+class AgpsManager;
+class AgpsStateMachine;
+class DSStateMachine;
+
+
+/* SUBSCRIBER
+ * Each Subscriber instance corresponds to one AGPS request,
+ * received by the AGPS state machine */
+class AgpsSubscriber {
+
+public:
+    int mConnHandle;
+
+    /* Does this subscriber wait for data call close complete,
+     * before being notified ATL close ?
+     * While waiting for data call close, subscriber will be in
+     * inactive state. */
+    bool mWaitForCloseComplete;
+    bool mIsInactive;
+
+    inline AgpsSubscriber(int connHandle) :
+            mConnHandle(connHandle), mWaitForCloseComplete(false),
+            mIsInactive(false) {}
+    inline virtual ~AgpsSubscriber() {}
+
+    inline virtual bool equals(const AgpsSubscriber *s) const
+    { return (mConnHandle == s->mConnHandle); }
+
+    inline virtual AgpsSubscriber* clone()
+    { return new AgpsSubscriber(mConnHandle); }
+};
+
+/* AGPS STATE MACHINE */
+class AgpsStateMachine {
+protected:
+    /* AGPS Manager instance, from where this state machine is created */
+    AgpsManager* mAgpsManager;
+
+    /* List of all subscribers for this State Machine.
+     * Once a subscriber is notified for ATL open/close status,
+     * it is deleted */
+    std::list<AgpsSubscriber*> mSubscriberList;
+
+    /* Current subscriber, whose request this State Machine is
+     * currently processing */
+    AgpsSubscriber* mCurrentSubscriber;
+
+    /* Current state for this state machine */
+    AgpsState mState;
+
+private:
+    /* AGPS Type for this state machine
+       LOC_AGPS_TYPE_ANY           0
+       LOC_AGPS_TYPE_SUPL          1
+       LOC_AGPS_TYPE_WWAN_ANY      3
+       LOC_AGPS_TYPE_SUPL_ES       5 */
+    AGpsExtType mAgpsType;
+
+    /* APN and IP Type info for AGPS Call */
+    char* mAPN;
+    unsigned int mAPNLen;
+    AGpsBearerType mBearer;
+
+public:
+    /* CONSTRUCTOR */
+    AgpsStateMachine(AgpsManager* agpsManager, AGpsExtType agpsType):
+        mAgpsManager(agpsManager), mSubscriberList(),
+        mCurrentSubscriber(NULL), mState(AGPS_STATE_RELEASED),
+        mAgpsType(agpsType), mAPN(NULL), mAPNLen(0),
+        mBearer(AGPS_APN_BEARER_INVALID) {};
+
+    virtual ~AgpsStateMachine() { if(NULL != mAPN) delete[] mAPN; };
+
+    /* Getter/Setter methods */
+    void setAPN(char* apn, unsigned int len);
+    inline char* getAPN() const { return (char*)mAPN; }
+    inline void setBearer(AGpsBearerType bearer) { mBearer = bearer; }
+    inline AGpsBearerType getBearer() const { return mBearer; }
+    inline AGpsExtType getType() const { return mAgpsType; }
+    inline void setCurrentSubscriber(AgpsSubscriber* subscriber)
+    { mCurrentSubscriber = subscriber; }
+
+    /* Fetch subscriber with specified handle */
+    AgpsSubscriber* getSubscriber(int connHandle);
+
+    /* Fetch first active or inactive subscriber in list
+     * isInactive = true : fetch first inactive subscriber
+     * isInactive = false : fetch first active subscriber */
+    AgpsSubscriber* getFirstSubscriber(bool isInactive);
+
+    /* Process LOC AGPS Event being passed in
+     * onRsrcEvent */
+    virtual void processAgpsEvent(AgpsEvent event);
+
+    /* Drop all subscribers, in case of Modem SSR */
+    void dropAllSubscribers();
+
+protected:
+    /* Remove the specified subscriber from list if present.
+     * Also delete the subscriber instance. */
+    void deleteSubscriber(AgpsSubscriber* subscriber);
+
+private:
+    /* Send call setup request to framework
+     * sendRsrcRequest(LOC_GPS_REQUEST_AGPS_DATA_CONN)
+     * sendRsrcRequest(LOC_GPS_RELEASE_AGPS_DATA_CONN) */
+    virtual int requestOrReleaseDataConn(bool request);
+
+    /* Individual event processing methods */
+    void processAgpsEventSubscribe();
+    void processAgpsEventUnsubscribe();
+    void processAgpsEventGranted();
+    void processAgpsEventReleased();
+    void processAgpsEventDenied();
+
+    /* Clone the passed in subscriber and add to the subscriber list
+     * if not already present */
+    void addSubscriber(AgpsSubscriber* subscriber);
+
+    /* Notify subscribers about AGPS events */
+    void notifyAllSubscribers(
+            AgpsEvent event, bool deleteSubscriberPostNotify,
+            AgpsNotificationType notificationType);
+    virtual void notifyEventToSubscriber(
+            AgpsEvent event, AgpsSubscriber* subscriber,
+            bool deleteSubscriberPostNotify);
+
+    /* Do we have any subscribers in active state */
+    bool anyActiveSubscribers();
+
+    /* Transition state */
+    void transitionState(AgpsState newState);
+};
+
+/* DS STATE MACHINE */
+class DSStateMachine : public AgpsStateMachine {
+
+private:
+    static const int MAX_START_DATA_CALL_RETRIES;
+    static const int DATA_CALL_RETRY_DELAY_MSEC;
+
+    int mRetries;
+
+public:
+    /* CONSTRUCTOR */
+    DSStateMachine(AgpsManager* agpsManager):
+        AgpsStateMachine(agpsManager, LOC_AGPS_TYPE_SUPL_ES), mRetries(0) {}
+
+    /* Overridden method
+     * DS SM needs to handle one event differently */
+    void processAgpsEvent(AgpsEvent event);
+
+    /* Retry callback, used in case call failure */
+    void retryCallback();
+
+private:
+    /* Overridden method, different functionality for DS SM
+     * Send call setup request to framework
+     * sendRsrcRequest(LOC_GPS_REQUEST_AGPS_DATA_CONN)
+     * sendRsrcRequest(LOC_GPS_RELEASE_AGPS_DATA_CONN) */
+    int requestOrReleaseDataConn(bool request);
+
+    /* Overridden method, different functionality for DS SM */
+    void notifyEventToSubscriber(
+            AgpsEvent event, AgpsSubscriber* subscriber,
+            bool deleteSubscriberPostNotify);
+};
+
+/* LOC AGPS MANAGER */
+class AgpsManager {
+
+    friend class AgpsStateMachine;
+    friend class DSStateMachine;
+
+public:
+    /* CONSTRUCTOR */
+    AgpsManager():
+        mFrameworkStatusV4Cb(NULL),
+        mAtlOpenStatusCb(), mAtlCloseStatusCb(),
+        mDSClientInitFn(), mDSClientOpenAndStartDataCallFn(),
+        mDSClientStopDataCallFn(), mDSClientCloseDataCallFn(), mDSClientReleaseFn(),
+        mSendMsgToAdapterQueueFn(),
+        mAgnssNif(NULL), mInternetNif(NULL), mDsNif(NULL) {}
+
+    /* Register callbacks */
+    void registerCallbacks(
+            AgpsFrameworkInterface::AgnssStatusIpV4Cb
+                                                frameworkStatusV4Cb,
+
+            AgpsAtlOpenStatusCb                 atlOpenStatusCb,
+            AgpsAtlCloseStatusCb                atlCloseStatusCb,
+
+            AgpsDSClientInitFn                  dsClientInitFn,
+            AgpsDSClientOpenAndStartDataCallFn  dsClientOpenAndStartDataCallFn,
+            AgpsDSClientStopDataCallFn          dsClientStopDataCallFn,
+            AgpsDSClientCloseDataCallFn         dsClientCloseDataCallFn,
+            AgpsDSClientReleaseFn               dsClientReleaseFn,
+
+            SendMsgToAdapterMsgQueueFn          sendMsgToAdapterQueueFn ){
+
+        mFrameworkStatusV4Cb = frameworkStatusV4Cb;
+
+        mAtlOpenStatusCb = atlOpenStatusCb;
+        mAtlCloseStatusCb = atlCloseStatusCb;
+
+        mDSClientInitFn = dsClientInitFn;
+        mDSClientOpenAndStartDataCallFn = dsClientOpenAndStartDataCallFn;
+        mDSClientStopDataCallFn = dsClientStopDataCallFn;
+        mDSClientCloseDataCallFn = dsClientCloseDataCallFn;
+        mDSClientReleaseFn = dsClientReleaseFn;
+
+        mSendMsgToAdapterQueueFn = sendMsgToAdapterQueueFn;
+    }
+
+    /* Create all AGPS state machines */
+    void createAgpsStateMachines();
+
+    /* Process incoming ATL requests */
+    void requestATL(int connHandle, AGpsExtType agpsType);
+    void releaseATL(int connHandle);
+
+    /* Process incoming DS Client data call events */
+    void reportDataCallOpened();
+    void reportDataCallClosed();
+
+    /* Process incoming framework data call events */
+    void reportAtlOpenSuccess(
+            AGpsExtType agpsType, char* apnName, int apnLen,
+            LocApnIpType ipType);
+    void reportAtlOpenFailed(AGpsExtType agpsType);
+    void reportAtlClosed(AGpsExtType agpsType);
+
+    /* Handle Modem SSR */
+    void handleModemSSR();
+
+protected:
+    AgpsFrameworkInterface::AgnssStatusIpV4Cb mFrameworkStatusV4Cb;
+
+    AgpsAtlOpenStatusCb   mAtlOpenStatusCb;
+    AgpsAtlCloseStatusCb  mAtlCloseStatusCb;
+
+    AgpsDSClientInitFn                  mDSClientInitFn;
+    AgpsDSClientOpenAndStartDataCallFn  mDSClientOpenAndStartDataCallFn;
+    AgpsDSClientStopDataCallFn          mDSClientStopDataCallFn;
+    AgpsDSClientCloseDataCallFn         mDSClientCloseDataCallFn;
+    AgpsDSClientReleaseFn               mDSClientReleaseFn;
+
+    SendMsgToAdapterMsgQueueFn          mSendMsgToAdapterQueueFn;
+
+    AgpsStateMachine*   mAgnssNif;
+    AgpsStateMachine*   mInternetNif;
+    AgpsStateMachine*   mDsNif;
+
+private:
+    /* Fetch state machine for handling request ATL call */
+    AgpsStateMachine* getAgpsStateMachine(AGpsExtType agpsType);
+};
+
+/* Request SUPL/INTERNET/SUPL_ES ATL
+ * This LocMsg is defined in this header since it has to be used from more
+ * than one place, other Agps LocMsg are restricted to GnssAdapter and
+ * declared inline */
+struct AgpsMsgRequestATL: public LocMsg {
+
+    AgpsManager* mAgpsManager;
+    int mConnHandle;
+    AGpsExtType mAgpsType;
+
+    inline AgpsMsgRequestATL(AgpsManager* agpsManager, int connHandle,
+            AGpsExtType agpsType) :
+            LocMsg(), mAgpsManager(agpsManager), mConnHandle(connHandle), mAgpsType(
+                    agpsType) {
+
+        LOC_LOGV("AgpsMsgRequestATL");
+    }
+
+    inline virtual void proc() const {
+
+        LOC_LOGV("AgpsMsgRequestATL::proc()");
+        mAgpsManager->requestATL(mConnHandle, mAgpsType);
+    }
+};
+
+namespace AgpsUtils {
+
+AGpsBearerType ipTypeToBearerType(LocApnIpType ipType);
+LocApnIpType bearerTypeToIpType(AGpsBearerType bearerType);
+
+}
+
+#endif /* AGPS_H */
diff --git a/msm8998/gnss/Android.mk b/msm8998/gnss/Android.mk
new file mode 100644
index 0000000..1f0a549
--- /dev/null
+++ b/msm8998/gnss/Android.mk
@@ -0,0 +1,44 @@
+ifneq ($(BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE),)
+ifneq ($(BUILD_TINY_ANDROID),true)
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libgnss
+LOCAL_MODULE_OWNER := qti
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SHARED_LIBRARIES := \
+    libutils \
+    libcutils \
+    libdl \
+    liblog \
+    libloc_core \
+    libgps.utils
+
+LOCAL_SRC_FILES += \
+    location_gnss.cpp \
+    GnssAdapter.cpp \
+    Agps.cpp
+
+LOCAL_CFLAGS += \
+     -fno-short-enums \
+
+ifeq ($(TARGET_BUILD_VARIANT),user)
+   LOCAL_CFLAGS += -DTARGET_BUILD_VARIANT_USER
+endif
+
+LOCAL_C_INCLUDES:= \
+    $(TARGET_OUT_HEADERS)/gps.utils \
+    $(TARGET_OUT_HEADERS)/libloc_core \
+    $(TARGET_OUT_HEADERS)/libloc_pla \
+    $(TARGET_OUT_HEADERS)/liblocation_api
+
+LOCAL_PRELINK_MODULE := false
+
+include $(BUILD_SHARED_LIBRARY)
+
+endif # not BUILD_TINY_ANDROID
+endif # BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE
diff --git a/msm8998/gnss/GnssAdapter.cpp b/msm8998/gnss/GnssAdapter.cpp
new file mode 100644
index 0000000..ab9b80c
--- /dev/null
+++ b/msm8998/gnss/GnssAdapter.cpp
@@ -0,0 +1,3200 @@
+/* Copyright (c) 2017, 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_TAG "LocSvc_GnssAdapter"
+
+#include <sys/stat.h>
+#include <errno.h>
+#include <ctype.h>
+#include <cutils/properties.h>
+#include <math.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <GnssAdapter.h>
+#include <string>
+#include <loc_log.h>
+#include <Agps.h>
+
+using namespace loc_core;
+
+GnssAdapter::GnssAdapter() :
+    LocAdapterBase(0,
+                   LocDualContext::getLocFgContext(NULL,
+                                                   NULL,
+                                                   LocDualContext::mLocationHalName,
+                                                   false)),
+    mUlpProxy(new UlpProxyBase()),
+    mSuplMode(GNSS_SUPL_MODE_STANDALONE),
+    mUlpPositionMode(),
+    mGnssSvIdUsedInPosition(),
+    mGnssSvIdUsedInPosAvail(false),
+    mControlCallbacks(),
+    mPowerVoteId(0),
+    mNiData(),
+    mAgpsManager()
+{
+    LOC_LOGD("%s]: Constructor %p", __func__, this);
+    mUlpPositionMode.mode = LOC_POSITION_MODE_INVALID;
+    readConfigCommand();
+    setConfigCommand();
+
+}
+
+inline
+GnssAdapter::~GnssAdapter()
+{
+    LOC_LOGD("%s]: Destructor", __func__);
+    delete mUlpProxy;
+}
+
+void
+GnssAdapter::setControlCallbacksCommand(LocationControlCallbacks& controlCallbacks)
+{
+    struct MsgSetControlCallbacks : public LocMsg {
+        GnssAdapter& mAdapter;
+        const LocationControlCallbacks mControlCallbacks;
+        inline MsgSetControlCallbacks(GnssAdapter& adapter,
+                                      LocationControlCallbacks& controlCallbacks) :
+            LocMsg(),
+            mAdapter(adapter),
+            mControlCallbacks(controlCallbacks) {}
+        inline virtual void proc() const {
+            mAdapter.setControlCallbacks(mControlCallbacks);
+        }
+    };
+
+    sendMsg(new MsgSetControlCallbacks(*this, controlCallbacks));
+}
+
+void
+GnssAdapter::convertOptions(LocPosMode& out, const LocationOptions& options)
+{
+    LocPosMode locPosMode = {};
+    switch (options.mode) {
+    case GNSS_SUPL_MODE_MSB:
+        out.mode = LOC_POSITION_MODE_MS_BASED;
+        break;
+    case GNSS_SUPL_MODE_MSA:
+        out.mode = LOC_POSITION_MODE_MS_ASSISTED;
+        break;
+    default:
+        out.mode = LOC_POSITION_MODE_STANDALONE;
+        break;
+    }
+    out.share_position = true;
+    out.min_interval = options.minInterval;
+}
+
+void
+GnssAdapter::convertLocation(Location& out, const LocGpsLocation& locGpsLocation,
+                             const LocPosTechMask techMask)
+{
+    out.size = sizeof(Location);
+    if (LOC_GPS_LOCATION_HAS_LAT_LONG & locGpsLocation.flags) {
+        out.flags |= LOCATION_HAS_LAT_LONG_BIT;
+        out.latitude = locGpsLocation.latitude;
+        out.longitude = locGpsLocation.longitude;
+    }
+    if (LOC_GPS_LOCATION_HAS_ALTITUDE & locGpsLocation.flags) {
+        out.flags |= LOCATION_HAS_ALTITUDE_BIT;
+        out.altitude = locGpsLocation.altitude;
+    }
+    if (LOC_GPS_LOCATION_HAS_SPEED & locGpsLocation.flags) {
+        out.flags |= LOCATION_HAS_SPEED_BIT;
+        out.speed = locGpsLocation.speed;
+    }
+    if (LOC_GPS_LOCATION_HAS_BEARING & locGpsLocation.flags) {
+        out.flags |= LOCATION_HAS_BEARING_BIT;
+        out.bearing = locGpsLocation.bearing;
+    }
+    if (LOC_GPS_LOCATION_HAS_ACCURACY & locGpsLocation.flags) {
+        out.flags |= LOCATION_HAS_ACCURACY_BIT;
+        out.accuracy = locGpsLocation.accuracy;
+    }
+    out.timestamp = locGpsLocation.timestamp;
+    if (LOC_POS_TECH_MASK_SATELLITE & techMask) {
+        out.techMask |= LOCATION_TECHNOLOGY_GNSS_BIT;
+    }
+    if (LOC_POS_TECH_MASK_CELLID & techMask) {
+        out.techMask |= LOCATION_TECHNOLOGY_CELL_BIT;
+    }
+    if (LOC_POS_TECH_MASK_WIFI & techMask) {
+        out.techMask |= LOCATION_TECHNOLOGY_WIFI_BIT;
+    }
+    if (LOC_POS_TECH_MASK_SENSORS & techMask) {
+        out.techMask |= LOCATION_TECHNOLOGY_SENSORS_BIT;
+    }
+}
+
+void
+GnssAdapter::convertLocationInfo(GnssLocationInfoNotification& out,
+                                 const GpsLocationExtended& locationExtended)
+{
+    out.size = sizeof(GnssLocationInfoNotification);
+    if (GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL & locationExtended.flags) {
+        out.flags |= GNSS_LOCATION_INFO_ALTITUDE_MEAN_SEA_LEVEL_BIT;
+        out.altitudeMeanSeaLevel = locationExtended.altitudeMeanSeaLevel;
+    }
+    if (GPS_LOCATION_EXTENDED_HAS_DOP & locationExtended.flags) {
+        out.flags |= GNSS_LOCATION_INFO_DOP_BIT;
+        out.pdop = locationExtended.pdop;
+        out.hdop = locationExtended.hdop;
+        out.vdop = locationExtended.vdop;
+    }
+    if (GPS_LOCATION_EXTENDED_HAS_MAG_DEV & locationExtended.flags) {
+        out.flags |= GNSS_LOCATION_INFO_MAGNETIC_DEVIATION_BIT;
+        out.magneticDeviation = locationExtended.magneticDeviation;
+    }
+    if (GPS_LOCATION_EXTENDED_HAS_VERT_UNC & locationExtended.flags) {
+        out.flags |= GNSS_LOCATION_INFO_VER_ACCURACY_BIT;
+        out.verAccuracy = locationExtended.vert_unc;
+    }
+    if (GPS_LOCATION_EXTENDED_HAS_SPEED_UNC & locationExtended.flags) {
+        out.flags |= GNSS_LOCATION_INFO_SPEED_ACCURACY_BIT;
+        out.speedAccuracy = locationExtended.speed_unc;
+    }
+    if (GPS_LOCATION_EXTENDED_HAS_BEARING_UNC & locationExtended.flags) {
+        out.flags |= GNSS_LOCATION_INFO_BEARING_ACCURACY_BIT;
+        out.bearingAccuracy = locationExtended.bearing_unc;
+    }
+    if (GPS_LOCATION_EXTENDED_HAS_HOR_RELIABILITY & locationExtended.flags) {
+        out.flags |= GNSS_LOCATION_INFO_HOR_RELIABILITY_BIT;
+        switch (locationExtended.horizontal_reliability) {
+            case LOC_RELIABILITY_VERY_LOW:
+                out.horReliability = LOCATION_RELIABILITY_VERY_LOW;
+                break;
+            case LOC_RELIABILITY_LOW:
+                out.horReliability = LOCATION_RELIABILITY_LOW;
+                break;
+            case LOC_RELIABILITY_MEDIUM:
+                out.horReliability = LOCATION_RELIABILITY_MEDIUM;
+                break;
+            case LOC_RELIABILITY_HIGH:
+                out.horReliability = LOCATION_RELIABILITY_HIGH;
+                break;
+            default:
+                out.horReliability = LOCATION_RELIABILITY_NOT_SET;
+                break;
+        }
+    }
+    if (GPS_LOCATION_EXTENDED_HAS_VERT_RELIABILITY & locationExtended.flags) {
+        out.flags |= GNSS_LOCATION_INFO_VER_RELIABILITY_BIT;
+        switch (locationExtended.vertical_reliability) {
+            case LOC_RELIABILITY_VERY_LOW:
+                out.verReliability = LOCATION_RELIABILITY_VERY_LOW;
+                break;
+            case LOC_RELIABILITY_LOW:
+                out.verReliability = LOCATION_RELIABILITY_LOW;
+                break;
+            case LOC_RELIABILITY_MEDIUM:
+                out.verReliability = LOCATION_RELIABILITY_MEDIUM;
+                break;
+            case LOC_RELIABILITY_HIGH:
+                out.verReliability = LOCATION_RELIABILITY_HIGH;
+                break;
+            default:
+                out.verReliability = LOCATION_RELIABILITY_NOT_SET;
+                break;
+        }
+    }
+    if (GPS_LOCATION_EXTENDED_HAS_HOR_ELIP_UNC_MAJOR & locationExtended.flags) {
+        out.flags |= GNSS_LOCATION_INFO_HOR_ACCURACY_ELIP_SEMI_MAJOR_BIT;
+        out.horUncEllipseSemiMajor = locationExtended.horUncEllipseSemiMajor;
+    }
+    if (GPS_LOCATION_EXTENDED_HAS_HOR_ELIP_UNC_MINOR & locationExtended.flags) {
+        out.flags |= GNSS_LOCATION_INFO_HOR_ACCURACY_ELIP_SEMI_MINOR_BIT;
+        out.horUncEllipseSemiMinor = locationExtended.horUncEllipseSemiMinor;
+    }
+    if (GPS_LOCATION_EXTENDED_HAS_HOR_ELIP_UNC_AZIMUTH & locationExtended.flags) {
+        out.flags |= GNSS_LOCATION_INFO_HOR_ACCURACY_ELIP_AZIMUTH_BIT;
+        out.horUncEllipseOrientAzimuth = locationExtended.horUncEllipseOrientAzimuth;
+    }
+}
+
+inline uint32_t
+GnssAdapter::convertGpsLock(const GnssConfigGpsLock gpsLock)
+{
+    switch (gpsLock) {
+        case GNSS_CONFIG_GPS_LOCK_MO:
+            return 1;
+        case GNSS_CONFIG_GPS_LOCK_NI:
+            return 2;
+        case GNSS_CONFIG_GPS_LOCK_MO_AND_NI:
+            return 3;
+        case GNSS_CONFIG_GPS_LOCK_NONE:
+        default:
+            return 0;
+    }
+}
+
+inline GnssConfigGpsLock
+GnssAdapter::convertGpsLock(const uint32_t gpsLock)
+{
+    switch (gpsLock) {
+        case 1:
+            return GNSS_CONFIG_GPS_LOCK_MO;
+        case 2:
+            return GNSS_CONFIG_GPS_LOCK_NI;
+        case 3:
+            return GNSS_CONFIG_GPS_LOCK_MO_AND_NI;
+        case 0:
+        default:
+            return GNSS_CONFIG_GPS_LOCK_NONE;
+    }
+}
+
+inline uint32_t
+GnssAdapter::convertSuplVersion(const GnssConfigSuplVersion suplVersion)
+{
+    switch (suplVersion) {
+        case GNSS_CONFIG_SUPL_VERSION_2_0_0:
+            return 0x00020000;
+        case GNSS_CONFIG_SUPL_VERSION_2_0_2:
+            return 0x00020002;
+        case GNSS_CONFIG_SUPL_VERSION_1_0_0:
+        default:
+            return 0x00010000;
+    }
+}
+
+inline GnssConfigSuplVersion
+GnssAdapter::convertSuplVersion(const uint32_t suplVersion)
+{
+    switch (suplVersion) {
+        case 0x00020000:
+            return GNSS_CONFIG_SUPL_VERSION_2_0_0;
+        case 0x00020002:
+            return GNSS_CONFIG_SUPL_VERSION_2_0_2;
+        case 0x00010000:
+        default:
+            return GNSS_CONFIG_SUPL_VERSION_1_0_0;
+    }
+}
+
+inline uint32_t
+GnssAdapter::convertLppProfile(const GnssConfigLppProfile lppProfile)
+{
+    switch (lppProfile) {
+        case GNSS_CONFIG_LPP_PROFILE_USER_PLANE:
+            return 1;
+        case GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE:
+            return 2;
+        case GNSS_CONFIG_LPP_PROFILE_USER_PLANE_AND_CONTROL_PLANE:
+            return 3;
+        case GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE:
+        default:
+            return 0;
+    }
+}
+
+inline GnssConfigLppProfile
+GnssAdapter::convertLppProfile(const uint32_t lppProfile)
+{
+    switch (lppProfile) {
+        case 1:
+            return GNSS_CONFIG_LPP_PROFILE_USER_PLANE;
+        case 2:
+            return GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE;
+        case 3:
+            return GNSS_CONFIG_LPP_PROFILE_USER_PLANE_AND_CONTROL_PLANE;
+        case 0:
+        default:
+            return GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE;
+    }
+}
+
+uint32_t
+GnssAdapter::convertLppeCp(const GnssConfigLppeControlPlaneMask lppeControlPlaneMask)
+{
+    uint32_t mask = 0;
+    if (GNSS_CONFIG_LPPE_CONTROL_PLANE_DBH_BIT & lppeControlPlaneMask) {
+        mask |= (1<<0);
+    }
+    if (GNSS_CONFIG_LPPE_CONTROL_PLANE_WLAN_AP_MEASUREMENTS_BIT & lppeControlPlaneMask) {
+        mask |= (1<<1);
+    }
+    return mask;
+}
+
+GnssConfigLppeControlPlaneMask
+GnssAdapter::convertLppeCp(const uint32_t lppeControlPlaneMask)
+{
+    GnssConfigLppeControlPlaneMask mask = 0;
+    if ((1<<0) & lppeControlPlaneMask) {
+        mask |= GNSS_CONFIG_LPPE_CONTROL_PLANE_DBH_BIT;
+    }
+    if ((1<<1) & lppeControlPlaneMask) {
+        mask |= GNSS_CONFIG_LPPE_CONTROL_PLANE_WLAN_AP_MEASUREMENTS_BIT;
+    }
+    return mask;
+}
+
+
+uint32_t
+GnssAdapter::convertLppeUp(const GnssConfigLppeUserPlaneMask lppeUserPlaneMask)
+{
+    uint32_t mask = 0;
+    if (GNSS_CONFIG_LPPE_USER_PLANE_DBH_BIT & lppeUserPlaneMask) {
+        mask |= (1<<0);
+    }
+    if (GNSS_CONFIG_LPPE_USER_PLANE_WLAN_AP_MEASUREMENTS_BIT & lppeUserPlaneMask) {
+        mask |= (1<<1);
+    }
+    return mask;
+}
+
+GnssConfigLppeUserPlaneMask
+GnssAdapter::convertLppeUp(const uint32_t lppeUserPlaneMask)
+{
+    GnssConfigLppeUserPlaneMask mask = 0;
+    if ((1<<0) & lppeUserPlaneMask) {
+        mask |= GNSS_CONFIG_LPPE_USER_PLANE_DBH_BIT;
+    }
+    if ((1<<1) & lppeUserPlaneMask) {
+        mask |= GNSS_CONFIG_LPPE_USER_PLANE_WLAN_AP_MEASUREMENTS_BIT;
+    }
+    return mask;
+}
+
+uint32_t
+GnssAdapter::convertAGloProt(const GnssConfigAGlonassPositionProtocolMask aGloPositionProtocolMask)
+{
+    uint32_t mask = 0;
+    if (GNSS_CONFIG_RRC_CONTROL_PLANE_BIT & aGloPositionProtocolMask) {
+        mask |= (1<<0);
+    }
+    if (GNSS_CONFIG_RRLP_USER_PLANE_BIT & aGloPositionProtocolMask) {
+        mask |= (1<<1);
+    }
+    if (GNSS_CONFIG_LLP_USER_PLANE_BIT & aGloPositionProtocolMask) {
+        mask |= (1<<2);
+    }
+    if (GNSS_CONFIG_LLP_CONTROL_PLANE_BIT & aGloPositionProtocolMask) {
+        mask |= (1<<3);
+    }
+    return mask;
+}
+
+uint32_t
+GnssAdapter::convertEP4ES(const GnssConfigEmergencyPdnForEmergencySupl emergencyPdnForEmergencySupl)
+{
+    switch (emergencyPdnForEmergencySupl) {
+       case GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES:
+           return 1;
+       case GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO:
+       default:
+           return 0;
+    }
+}
+
+uint32_t
+GnssAdapter::convertSuplEs(const GnssConfigSuplEmergencyServices suplEmergencyServices)
+{
+    switch (suplEmergencyServices) {
+       case GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_YES:
+           return 1;
+       case GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_NO:
+       default:
+           return 0;
+    }
+}
+
+uint32_t
+GnssAdapter::convertSuplMode(const GnssConfigSuplModeMask suplModeMask)
+{
+    uint32_t mask = 0;
+    if (GNSS_CONFIG_SUPL_MODE_MSB & suplModeMask) {
+        mask |= (1<<0);
+    }
+    if (GNSS_CONFIG_SUPL_MODE_MSA & suplModeMask) {
+        mask |= (1<<1);
+    }
+    return mask;
+}
+
+bool
+GnssAdapter::resolveInAddress(const char* hostAddress, struct in_addr* inAddress)
+{
+    bool ret = true;
+
+    struct hostent* hp;
+    hp = gethostbyname(hostAddress);
+    if (hp != NULL) { /* DNS OK */
+        memcpy(inAddress, hp->h_addr_list[0], hp->h_length);
+    } else {
+        /* Try IP representation */
+        if (inet_aton(hostAddress, inAddress) == 0) {
+            /* IP not valid */
+            LOC_LOGE("%s]: DNS query on '%s' failed", __func__, hostAddress);
+            ret = false;
+        }
+    }
+
+    return ret;
+}
+
+void
+GnssAdapter::readConfigCommand()
+{
+    LOC_LOGD("%s]: ", __func__);
+
+    struct MsgReadConfig : public LocMsg {
+        GnssAdapter* mAdapter;
+        ContextBase& mContext;
+        inline MsgReadConfig(GnssAdapter* adapter,
+                             ContextBase& context) :
+            LocMsg(),
+            mAdapter(adapter),
+            mContext(context) {}
+        inline virtual void proc() const {
+            // reads config into mContext->mGps_conf
+            mContext.readConfig();
+            mContext.requestUlp((LocAdapterBase*)mAdapter, mContext.getCarrierCapabilities());
+        }
+    };
+
+    if (mContext != NULL) {
+        sendMsg(new MsgReadConfig(this, *mContext));
+    }
+}
+
+void
+GnssAdapter::setConfigCommand()
+{
+    LOC_LOGD("%s]: ", __func__);
+
+    struct MsgSetConfig : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocApiBase& mApi;
+        inline MsgSetConfig(GnssAdapter& adapter,
+                            LocApiBase& api) :
+            LocMsg(),
+            mAdapter(adapter),
+            mApi(api) {}
+        inline virtual void proc() const {
+            mApi.setSUPLVersion(mAdapter.convertSuplVersion(ContextBase::mGps_conf.SUPL_VER));
+            mApi.setLPPConfig(mAdapter.convertLppProfile(ContextBase::mGps_conf.LPP_PROFILE));
+            mApi.setSensorControlConfig(ContextBase::mSap_conf.SENSOR_USAGE,
+                                           ContextBase::mSap_conf.SENSOR_PROVIDER);
+            mApi.setAGLONASSProtocol(ContextBase::mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT);
+            mApi.setLPPeProtocolCp(
+                mAdapter.convertLppeCp(ContextBase::mGps_conf.LPPE_CP_TECHNOLOGY));
+            mApi.setLPPeProtocolUp(
+                mAdapter.convertLppeUp(ContextBase::mGps_conf.LPPE_UP_TECHNOLOGY));
+            if (NMEA_PROVIDER_MP == ContextBase::mGps_conf.NMEA_PROVIDER) {
+                mApi.setNMEATypes(LOC_NMEA_ALL_SUPPORTED_MASK);
+            }
+            mApi.setXtraVersionCheck(ContextBase::mGps_conf.XTRA_VERSION_CHECK);
+            if (ContextBase::mSap_conf.GYRO_BIAS_RANDOM_WALK_VALID ||
+                ContextBase::mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID ||
+                ContextBase::mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID ||
+                ContextBase::mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID ||
+                ContextBase::mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID ) {
+                mApi.setSensorProperties(
+                    ContextBase::mSap_conf.GYRO_BIAS_RANDOM_WALK_VALID,
+                    ContextBase::mSap_conf.GYRO_BIAS_RANDOM_WALK,
+                    ContextBase::mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
+                    ContextBase::mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY,
+                    ContextBase::mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
+                    ContextBase::mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY,
+                    ContextBase::mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
+                    ContextBase::mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY,
+                    ContextBase::mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
+                    ContextBase::mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY);
+            }
+            mApi.setSensorPerfControlConfig(
+                ContextBase::mSap_conf.SENSOR_CONTROL_MODE,
+                   ContextBase::mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH,
+                   ContextBase::mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC,
+                   ContextBase::mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH,
+                   ContextBase::mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC,
+                   ContextBase::mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH,
+                   ContextBase::mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH,
+                   ContextBase::mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH,
+                   ContextBase::mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH,
+                   ContextBase::mSap_conf.SENSOR_ALGORITHM_CONFIG_MASK);
+        }
+    };
+
+    sendMsg(new MsgSetConfig(*this, *mLocApi));
+}
+
+uint32_t*
+GnssAdapter::gnssUpdateConfigCommand(GnssConfig config)
+{
+    // count the number of bits set
+    GnssConfigFlagsMask flagsCopy = config.flags;
+    size_t count = 0;
+    while (flagsCopy > 0) {
+        if (flagsCopy & 1) {
+            count++;
+        }
+        flagsCopy >>= 1;
+    }
+    std::string idsString = "[";
+    uint32_t* ids = NULL;
+    if (count > 0) {
+        ids = new uint32_t[count];
+        for (size_t i=0; i < count; ++i) {
+            ids[i] = generateSessionId();
+            IF_LOC_LOGD {
+                idsString += std::to_string(ids[i]) + " ";
+            }
+        }
+    }
+    idsString += "]";
+
+    LOC_LOGD("%s]: ids %s flags 0x%X", __func__, idsString.c_str(), config.flags);
+
+    struct MsgGnssUpdateConfig : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocApiBase& mApi;
+        GnssConfig mConfig;
+        uint32_t* mIds;
+        size_t mCount;
+        inline MsgGnssUpdateConfig(GnssAdapter& adapter,
+                                   LocApiBase& api,
+                                   GnssConfig config,
+                                   uint32_t* ids,
+                                   size_t count) :
+            LocMsg(),
+            mAdapter(adapter),
+            mApi(api),
+            mConfig(config),
+            mIds(ids),
+            mCount(count) {}
+        inline virtual ~MsgGnssUpdateConfig()
+        {
+            delete[] mIds;
+        }
+        inline virtual void proc() const {
+            //const size_t MAX_BITS_COUNT = 10;
+            //LocationError errs[MAX_BITS_COUNT] = {};
+            LocationError* errs = new LocationError[mCount];
+            LocationError err = LOCATION_ERROR_SUCCESS;
+            uint32_t index = 0;
+
+            if (mConfig.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) {
+                uint32_t newGpsLock = mAdapter.convertGpsLock(mConfig.gpsLock);
+                ContextBase::mGps_conf.GPS_LOCK = newGpsLock;
+                if (0 == mAdapter.getPowerVoteId()) {
+                    err = mApi.setGpsLock(mConfig.gpsLock);
+                }
+                if (index < mCount) {
+                    errs[index++] = err;
+                }
+            }
+            if (mConfig.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) {
+                uint32_t newSuplVersion = mAdapter.convertSuplVersion(mConfig.suplVersion);
+                if (newSuplVersion != ContextBase::mGps_conf.SUPL_VER) {
+                    ContextBase::mGps_conf.SUPL_VER = newSuplVersion;
+                    err = mApi.setSUPLVersion(mConfig.suplVersion);
+                } else {
+                    err = LOCATION_ERROR_SUCCESS;
+                }
+                if (index < mCount) {
+                    errs[index++] = err;
+                }
+            }
+            if (mConfig.flags & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) {
+                if (GNSS_ASSISTANCE_TYPE_SUPL == mConfig.assistanceServer.type) {
+                    char serverUrl[MAX_URL_LEN] = {};
+                    uint32_t length = 0;
+                    const char noHost[] = "NONE";
+                    if (NULL == mConfig.assistanceServer.hostName ||
+                        strncasecmp(noHost,
+                                    mConfig.assistanceServer.hostName,
+                                    sizeof(noHost)) == 0) {
+                    } else {
+                        length = snprintf(serverUrl, sizeof(serverUrl), "%s:%u",
+                                          mConfig.assistanceServer.hostName,
+                                          mConfig.assistanceServer.port);
+                    }
+
+                    if (sizeof(serverUrl) > length) {
+                        err = mApi.setServer(serverUrl, length);
+                    } else {
+                        err = LOCATION_ERROR_INVALID_PARAMETER;
+                    }
+                } else if (GNSS_ASSISTANCE_TYPE_C2K == mConfig.assistanceServer.type) {
+                    struct in_addr addr;
+                    if (!mAdapter.resolveInAddress(mConfig.assistanceServer.hostName, &addr)) {
+                        LOC_LOGE("%s]: hostName %s cannot be resolved",
+                                 __func__, mConfig.assistanceServer.hostName);
+                        err = LOCATION_ERROR_INVALID_PARAMETER;
+                    } else {
+                        unsigned int ip = htonl(addr.s_addr);
+                        err = mApi.setServer(ip, mConfig.assistanceServer.port,
+                                                LOC_AGPS_CDMA_PDE_SERVER);
+                    }
+                } else {
+                    LOC_LOGE("%s]: Not a valid gnss assistance type %u",
+                             __func__, mConfig.assistanceServer.type);
+                    err = LOCATION_ERROR_INVALID_PARAMETER;
+                }
+                if (index < mCount) {
+                    errs[index++] = err;
+                }
+            }
+            if (mConfig.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) {
+                uint32_t newLppProfile = mAdapter.convertLppProfile(mConfig.lppProfile);
+                if (newLppProfile != ContextBase::mGps_conf.LPP_PROFILE) {
+                    ContextBase::mGps_conf.LPP_PROFILE = newLppProfile;
+                    err = mApi.setLPPConfig(mConfig.lppProfile);
+                } else {
+                    err = LOCATION_ERROR_SUCCESS;
+                }
+                if (index < mCount) {
+                    errs[index++] = err;
+                }
+            }
+            if (mConfig.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) {
+                uint32_t newLppeControlPlaneMask =
+                    mAdapter.convertLppeCp(mConfig.lppeControlPlaneMask);
+                if (newLppeControlPlaneMask != ContextBase::mGps_conf.LPPE_CP_TECHNOLOGY) {
+                    ContextBase::mGps_conf.LPPE_CP_TECHNOLOGY = newLppeControlPlaneMask;
+                    err = mApi.setLPPeProtocolCp(mConfig.lppeControlPlaneMask);
+                } else {
+                    err = LOCATION_ERROR_SUCCESS;
+                }
+                if (index < mCount) {
+                    errs[index++] = err;
+                }
+            }
+            if (mConfig.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) {
+                uint32_t newLppeUserPlaneMask =
+                    mAdapter.convertLppeUp(mConfig.lppeUserPlaneMask);
+                if (newLppeUserPlaneMask != ContextBase::mGps_conf.LPPE_UP_TECHNOLOGY) {
+                    ContextBase::mGps_conf.LPPE_UP_TECHNOLOGY = newLppeUserPlaneMask;
+                    err = mApi.setLPPeProtocolUp(mConfig.lppeUserPlaneMask);
+                } else {
+                    err = LOCATION_ERROR_SUCCESS;
+                }
+                if (index < mCount) {
+                    errs[index++] = err;
+                }
+            }
+            if (mConfig.flags & GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) {
+                uint32_t newAGloProtMask =
+                    mAdapter.convertAGloProt(mConfig.aGlonassPositionProtocolMask);
+                if (newAGloProtMask != ContextBase::mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT) {
+                    ContextBase::mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT = newAGloProtMask;
+                    err = mApi.setAGLONASSProtocol(mConfig.aGlonassPositionProtocolMask);
+                } else {
+                    err = LOCATION_ERROR_SUCCESS;
+                }
+                if (index < mCount) {
+                    errs[index++] = err;
+                }
+            }
+            if (mConfig.flags & GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT) {
+                uint32_t newEP4ES = mAdapter.convertEP4ES(mConfig.emergencyPdnForEmergencySupl);
+                if (newEP4ES != ContextBase::mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL) {
+                    ContextBase::mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL = newEP4ES;
+                }
+                err = LOCATION_ERROR_SUCCESS;
+                if (index < mCount) {
+                    errs[index++] = err;
+                }
+            }
+            if (mConfig.flags & GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT) {
+                uint32_t newSuplEs = mAdapter.convertSuplEs(mConfig.suplEmergencyServices);
+                if (newSuplEs != ContextBase::mGps_conf.SUPL_ES) {
+                    ContextBase::mGps_conf.SUPL_ES = newSuplEs;
+                }
+                err = LOCATION_ERROR_SUCCESS;
+                if (index < mCount) {
+                    errs[index++] = err;
+                }
+            }
+            if (mConfig.flags & GNSS_CONFIG_FLAGS_SUPL_MODE_BIT) {
+                uint32_t newSuplMode = mAdapter.convertSuplMode(mConfig.suplModeMask);
+                if (newSuplMode != ContextBase::mGps_conf.SUPL_MODE) {
+                    ContextBase::mGps_conf.SUPL_MODE = newSuplMode;
+                    mAdapter.getUlpProxy()->setCapabilities(
+                        ContextBase::getCarrierCapabilities());
+                }
+                err = LOCATION_ERROR_SUCCESS;
+                if (index < mCount) {
+                    errs[index++] = err;
+                }
+            }
+
+            mAdapter.reportResponse(index, errs, mIds);
+            delete[] errs;
+        }
+    };
+
+    if (NULL != ids) {
+        sendMsg(new MsgGnssUpdateConfig(*this, *mLocApi, config, ids, count));
+    } else {
+        LOC_LOGE("%s]: No GNSS config items to update", __func__);
+    }
+
+    return ids;
+}
+
+uint32_t
+GnssAdapter::gnssDeleteAidingDataCommand(GnssAidingData& data)
+{
+    uint32_t sessionId = generateSessionId();
+    LOC_LOGD("%s]: client %p id %u", __func__, sessionId);
+
+    struct MsgDeleteAidingData : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocApiBase& mApi;
+        uint32_t mSessionId;
+        GnssAidingData mData;
+        inline MsgDeleteAidingData(GnssAdapter& adapter,
+                                   LocApiBase& api,
+                                   uint32_t sessionId,
+                                   GnssAidingData& data) :
+            LocMsg(),
+            mAdapter(adapter),
+            mApi(api),
+            mSessionId(sessionId),
+            mData(data) {}
+        inline virtual void proc() const {
+            LocationError err = LOCATION_ERROR_SUCCESS;
+            #ifdef TARGET_BUILD_VARIANT_USER
+                err = LOCATION_ERROR_NOT_SUPPORTED;
+            #endif
+            if (LOCATION_ERROR_SUCCESS == err) {
+                err = mApi.deleteAidingData(mData);
+            }
+            mAdapter.reportResponse(err, mSessionId);
+        }
+    };
+
+    sendMsg(new MsgDeleteAidingData(*this, *mLocApi, sessionId, data));
+    return sessionId;
+}
+
+void
+GnssAdapter::injectLocationCommand(double latitude, double longitude, float accuracy)
+{
+    LOC_LOGD("%s]: latitude %8.4f longitude %8.4f accuracy %8.4f",
+             __func__, latitude, longitude, accuracy);
+
+    struct MsgInjectLocation : public LocMsg {
+        LocApiBase& mApi;
+        ContextBase& mContext;
+        double mLatitude;
+        double mLongitude;
+        float mAccuracy;
+        inline MsgInjectLocation(LocApiBase& api,
+                                 ContextBase& context,
+                                 double latitude,
+                                 double longitude,
+                                 float accuracy) :
+            LocMsg(),
+            mApi(api),
+            mContext(context),
+            mLatitude(latitude),
+            mLongitude(longitude),
+            mAccuracy(accuracy) {}
+        inline virtual void proc() const {
+            if (!mContext.hasCPIExtendedCapabilities()) {
+                mApi.injectPosition(mLatitude, mLongitude, mAccuracy);
+            }
+        }
+    };
+
+    sendMsg(new MsgInjectLocation(*mLocApi, *mContext, latitude, longitude, accuracy));
+}
+
+void
+GnssAdapter::injectTimeCommand(int64_t time, int64_t timeReference, int32_t uncertainty)
+{
+    LOC_LOGD("%s]: time %lld timeReference %lld uncertainty %d",
+             __func__, time, timeReference, uncertainty);
+
+    struct MsgInjectTime : public LocMsg {
+        LocApiBase& mApi;
+        ContextBase& mContext;
+        int64_t mTime;
+        int64_t mTimeReference;
+        int32_t mUncertainty;
+        inline MsgInjectTime(LocApiBase& api,
+                             ContextBase& context,
+                             int64_t time,
+                             int64_t timeReference,
+                             int32_t uncertainty) :
+            LocMsg(),
+            mApi(api),
+            mContext(context),
+            mTime(time),
+            mTimeReference(timeReference),
+            mUncertainty(uncertainty) {}
+        inline virtual void proc() const {
+            mApi.setTime(mTime, mTimeReference, mUncertainty);
+        }
+    };
+
+    sendMsg(new MsgInjectTime(*mLocApi, *mContext, time, timeReference, uncertainty));
+}
+
+void
+GnssAdapter::setUlpProxyCommand(UlpProxyBase* ulp)
+{
+    LOC_LOGD("%s]: ", __func__);
+
+    struct MsgSetUlpProxy : public LocMsg {
+        GnssAdapter& mAdapter;
+        UlpProxyBase* mUlp;
+        inline MsgSetUlpProxy(GnssAdapter& adapter,
+                              UlpProxyBase* ulp) :
+            LocMsg(),
+            mAdapter(adapter),
+            mUlp(ulp) {}
+        inline virtual void proc() const {
+            mAdapter.setUlpProxy(mUlp);
+        }
+    };
+
+    sendMsg(new MsgSetUlpProxy(*this, ulp));
+}
+
+void
+GnssAdapter::setUlpProxy(UlpProxyBase* ulp)
+{
+    if (ulp == mUlpProxy) {
+        //This takes care of the case when double initalization happens
+        //and we get the same object back for UlpProxyBase . Do nothing
+        return;
+    }
+
+    LOC_LOGV("%s]: %p", __func__, ulp);
+    if (NULL == ulp) {
+        LOC_LOGE("%s]: ulp pointer is NULL", __func__);
+        ulp = new UlpProxyBase();
+    }
+
+    if (LOC_POSITION_MODE_INVALID != mUlpProxy->mPosMode.mode) {
+        // need to send this mode and start msg to ULP
+        ulp->sendFixMode(mUlpProxy->mPosMode);
+    }
+
+    if (mUlpProxy->mFixSet) {
+        ulp->sendStartFix();
+    }
+
+    delete mUlpProxy;
+    mUlpProxy = ulp;
+}
+
+void
+GnssAdapter::addClientCommand(LocationAPI* client, const LocationCallbacks& callbacks)
+{
+    LOC_LOGD("%s]: client %p", __func__, client);
+
+    struct MsgAddClient : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocationAPI* mClient;
+        const LocationCallbacks mCallbacks;
+        inline MsgAddClient(GnssAdapter& adapter,
+                            LocationAPI* client,
+                            const LocationCallbacks& callbacks) :
+            LocMsg(),
+            mAdapter(adapter),
+            mClient(client),
+            mCallbacks(callbacks) {}
+        inline virtual void proc() const {
+            mAdapter.saveClient(mClient, mCallbacks);
+        }
+    };
+
+    sendMsg(new MsgAddClient(*this, client, callbacks));
+}
+
+void
+GnssAdapter::removeClientCommand(LocationAPI* client)
+{
+    LOC_LOGD("%s]: client %p", __func__, client);
+
+    struct MsgRemoveClient : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocationAPI* mClient;
+        inline MsgRemoveClient(GnssAdapter& adapter,
+                               LocationAPI* client) :
+            LocMsg(),
+            mAdapter(adapter),
+            mClient(client) {}
+        inline virtual void proc() const {
+            mAdapter.stopClientSessions(mClient);
+            mAdapter.eraseClient(mClient);
+        }
+    };
+
+    sendMsg(new MsgRemoveClient(*this, client));
+}
+
+void
+GnssAdapter::stopClientSessions(LocationAPI* client)
+{
+    LOC_LOGD("%s]: client %p", __func__, client);
+    for (auto it = mTrackingSessions.begin(); it != mTrackingSessions.end();) {
+        if (client == it->first.client) {
+            LocationError err = stopTrackingMultiplex(it->first.client, it->first.id);
+            if (LOCATION_ERROR_SUCCESS == err) {
+                it = mTrackingSessions.erase(it);
+                continue;
+            }
+        }
+        ++it; // increment only when not erasing an iterator
+    }
+
+}
+
+void
+GnssAdapter::updateClientsEventMask()
+{
+    LOC_API_ADAPTER_EVENT_MASK_T mask = 0;
+    for (auto it=mClientData.begin(); it != mClientData.end(); ++it) {
+        if (it->second.trackingCb != nullptr) {
+            mask |= LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT;
+        }
+        if (it->second.gnssNiCb != nullptr) {
+            mask |= LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST;
+        }
+        if (it->second.gnssSvCb != nullptr) {
+            mask |= LOC_API_ADAPTER_BIT_SATELLITE_REPORT;
+        }
+        if (it->second.gnssNmeaCb != nullptr &&
+            NMEA_PROVIDER_MP == ContextBase::mGps_conf.NMEA_PROVIDER) {
+            mask |= LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT;
+        }
+        if (it->second.gnssMeasurementsCb != nullptr) {
+            mask |= LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT;
+        }
+    }
+    updateEvtMask(mask, LOC_REGISTRATION_MASK_SET);
+}
+
+void
+GnssAdapter::handleEngineUpEvent()
+{
+    struct MsgRestartSessions : public LocMsg {
+        GnssAdapter& mAdapter;
+        inline MsgRestartSessions(GnssAdapter& adapter) :
+            LocMsg(),
+            mAdapter(adapter) {}
+        virtual void proc() const {
+            mAdapter.restartSessions();
+        }
+    };
+
+    setConfigCommand();
+    sendMsg(new MsgRestartSessions(*this));
+}
+
+void
+GnssAdapter::restartSessions()
+{
+    LOC_LOGD("%s]: ", __func__);
+
+    if (mTrackingSessions.empty()) {
+        return;
+    }
+
+    // get the LocationOptions that has the smallest interval, which should be the active one
+    LocationOptions smallestIntervalOptions = {}; // size is zero until set for the first time
+    for (auto it = mTrackingSessions.begin(); it != mTrackingSessions.end(); ++it) {
+        if (0 == smallestIntervalOptions.size || //size of zero means we havent set it yet
+            it->second.minInterval < smallestIntervalOptions.minInterval) {
+             smallestIntervalOptions = it->second;
+        }
+    }
+
+    startTracking(smallestIntervalOptions);
+}
+
+void
+GnssAdapter::requestCapabilitiesCommand(LocationAPI* client)
+{
+    LOC_LOGD("%s]: ", __func__);
+
+    struct MsgRequestCapabilities : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocApiBase& mApi;
+        LocationAPI* mClient;
+        inline MsgRequestCapabilities(GnssAdapter& adapter,
+                                      LocApiBase& api,
+                                      LocationAPI* client) :
+            LocMsg(),
+            mAdapter(adapter),
+            mApi(api),
+            mClient(client) {}
+        inline virtual void proc() const {
+            LocationCallbacks callbacks = mAdapter.getClientCallbacks(mClient);
+            if (callbacks.capabilitiesCb == nullptr) {
+                LOC_LOGE("%s]: capabilitiesCb is NULL", __func__);
+                return;
+            }
+
+            LocationCapabilitiesMask mask = {};
+            // time based tracking always supported
+            mask |= LOCATION_CAPABILITIES_TIME_BASED_TRACKING_BIT;
+            if (mApi.isMessageSupported(LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_LOCATION_BATCHING)){
+                mask |= LOCATION_CAPABILITIES_TIME_BASED_BATCHING_BIT |
+                        LOCATION_CAPABILITIES_DISTANCE_BASED_BATCHING_BIT;
+            }
+            if (mApi.isMessageSupported(LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_TRACKING)) {
+                mask |= LOCATION_CAPABILITIES_DISTANCE_BASED_TRACKING_BIT;
+            }
+            // geofence always supported
+            mask |= LOCATION_CAPABILITIES_GEOFENCE_BIT;
+            if (mApi.gnssConstellationConfig()) {
+                mask |= LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT;
+            }
+            uint32_t carrierCapabilities = ContextBase::getCarrierCapabilities();
+            if (carrierCapabilities & LOC_GPS_CAPABILITY_MSB) {
+                mask |= LOCATION_CAPABILITIES_GNSS_MSB_BIT;
+            }
+            if (LOC_GPS_CAPABILITY_MSA & carrierCapabilities) {
+                mask |= LOCATION_CAPABILITIES_GNSS_MSA_BIT;
+            }
+
+            callbacks.capabilitiesCb(mask);
+        }
+    };
+
+    sendMsg(new MsgRequestCapabilities(*this, *mLocApi, client));
+}
+
+LocationCallbacks
+GnssAdapter::getClientCallbacks(LocationAPI* client)
+{
+    LocationCallbacks callbacks = {};
+    auto it = mClientData.find(client);
+    if (it != mClientData.end()) {
+        callbacks = it->second;
+    }
+    return callbacks;
+}
+
+void
+GnssAdapter::saveClient(LocationAPI* client, const LocationCallbacks& callbacks)
+{
+    mClientData[client] = callbacks;
+    updateClientsEventMask();
+}
+
+void
+GnssAdapter::eraseClient(LocationAPI* client)
+{
+    auto it = mClientData.find(client);
+    if (it != mClientData.end()) {
+        mClientData.erase(it);
+    }
+    updateClientsEventMask();
+}
+
+bool
+GnssAdapter::hasTrackingCallback(LocationAPI* client)
+{
+    auto it = mClientData.find(client);
+    return (it != mClientData.end() && it->second.trackingCb);
+}
+
+bool
+GnssAdapter::hasMeasurementsCallback(LocationAPI* client)
+{
+    auto it = mClientData.find(client);
+    return (it != mClientData.end() && it->second.gnssMeasurementsCb);
+}
+
+bool
+GnssAdapter::isTrackingSession(LocationAPI* client, uint32_t sessionId)
+{
+    LocationSessionKey key(client, sessionId);
+    return (mTrackingSessions.find(key) != mTrackingSessions.end());
+}
+
+void
+GnssAdapter::saveTrackingSession(LocationAPI* client, uint32_t sessionId,
+                                 const LocationOptions& options)
+{
+    LocationSessionKey key(client, sessionId);
+    mTrackingSessions[key] = options;
+}
+
+void
+GnssAdapter::eraseTrackingSession(LocationAPI* client, uint32_t sessionId)
+{
+    LocationSessionKey key(client, sessionId);
+    auto it = mTrackingSessions.find(key);
+    if (it != mTrackingSessions.end()) {
+        mTrackingSessions.erase(it);
+    }
+
+}
+
+void
+GnssAdapter::reportResponse(LocationAPI* client, LocationError err, uint32_t sessionId)
+{
+    LOC_LOGD("%s]: client %p id %u err %u", __func__, client, sessionId, err);
+
+    auto it = mClientData.find(client);
+    if (it != mClientData.end() &&
+        it->second.responseCb != nullptr) {
+        it->second.responseCb(err, sessionId);
+    } else {
+        LOC_LOGW("%s]: client %p id %u not found in data", __func__, client, sessionId);
+    }
+}
+
+void
+GnssAdapter::reportResponse(LocationError err, uint32_t sessionId)
+{
+    LOC_LOGD("%s]: id %u err %u", __func__, sessionId, err);
+
+    if (mControlCallbacks.size > 0 && mControlCallbacks.responseCb != nullptr) {
+        mControlCallbacks.responseCb(err, sessionId);
+    } else {
+        LOC_LOGW("%s]: control client response callback not found", __func__);
+    }
+}
+
+void
+GnssAdapter::reportResponse(size_t count, LocationError* errs, uint32_t* ids)
+{
+    IF_LOC_LOGD {
+        std::string idsString = "[";
+        std::string errsString = "[";
+        if (NULL != ids && NULL != errs) {
+            for (size_t i=0; i < count; ++i) {
+                idsString += std::to_string(ids[i]) + " ";
+                errsString += std::to_string(errs[i]) + " ";
+            }
+        }
+        idsString += "]";
+        errsString += "]";
+
+        LOC_LOGD("%s]: ids %s errs %s",
+                 __func__, idsString.c_str(), errsString.c_str());
+    }
+
+    if (mControlCallbacks.size > 0 && mControlCallbacks.collectiveResponseCb != nullptr) {
+        mControlCallbacks.collectiveResponseCb(count, errs, ids);
+    } else {
+        LOC_LOGW("%s]: control client callback not found", __func__);
+    }
+}
+
+uint32_t
+GnssAdapter::startTrackingCommand(LocationAPI* client, LocationOptions& options)
+{
+    uint32_t sessionId = generateSessionId();
+    LOC_LOGD("%s]: client %p id %u minInterval %u mode %u",
+             __func__, client, sessionId, options.minInterval, options.mode);
+
+    struct MsgStartTracking : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocApiBase& mApi;
+        LocationAPI* mClient;
+        uint32_t mSessionId;
+        LocationOptions mOptions;
+        inline MsgStartTracking(GnssAdapter& adapter,
+                               LocApiBase& api,
+                               LocationAPI* client,
+                               uint32_t sessionId,
+                               LocationOptions options) :
+            LocMsg(),
+            mAdapter(adapter),
+            mApi(api),
+            mClient(client),
+            mSessionId(sessionId),
+            mOptions(options) {}
+        inline virtual void proc() const {
+            LocationError err = LOCATION_ERROR_SUCCESS;
+            if (!mAdapter.hasTrackingCallback(mClient) &&
+                !mAdapter.hasMeasurementsCallback(mClient)) {
+                err = LOCATION_ERROR_CALLBACK_MISSING;
+            } else if (0 == mOptions.size) {
+                err = LOCATION_ERROR_INVALID_PARAMETER;
+            } else {
+                // Api doesn't support multiple clients for time based tracking, so mutiplex
+                err = mAdapter.startTrackingMultiplex(mOptions);
+                if (LOCATION_ERROR_SUCCESS == err) {
+                    mAdapter.saveTrackingSession(mClient, mSessionId, mOptions);
+                }
+            }
+            mAdapter.reportResponse(mClient, err, mSessionId);
+        }
+    };
+
+    sendMsg(new MsgStartTracking(*this, *mLocApi, client, sessionId, options));
+    return sessionId;
+
+}
+
+LocationError
+GnssAdapter::startTrackingMultiplex(const LocationOptions& options)
+{
+    LocationError err = LOCATION_ERROR_SUCCESS;
+    bool updateTrackingSession = false;
+
+    if (mTrackingSessions.empty()) {
+        err = startTracking(options);
+    } else {
+        // get the LocationOptions that has the smallest interval, which should be the active one
+        LocationOptions smallestIntervalOptions = {}; // size is zero until set for the first time
+        for (auto it = mTrackingSessions.begin(); it != mTrackingSessions.end(); ++it) {
+            if (0 == smallestIntervalOptions.size || //size of zero means we havent set it yet
+                it->second.minInterval < smallestIntervalOptions.minInterval) {
+                 smallestIntervalOptions = it->second;
+            }
+        }
+        // if new session's minInterval is smaller than any in other sessions
+        if (options.minInterval < smallestIntervalOptions.minInterval) {
+            // restart time based tracking with new options
+            err = startTracking(options);
+        }
+    }
+
+    return err;
+}
+
+LocationError
+GnssAdapter::startTracking(const LocationOptions& options)
+{
+    LocationError err = LOCATION_ERROR_SUCCESS;
+    LocPosMode locPosMode = {};
+    convertOptions(locPosMode, options);
+    if (!mUlpProxy->sendFixMode(locPosMode)) {
+        // do nothing
+    }
+    if (!mUlpProxy->sendStartFix()) {
+        loc_api_adapter_err apiErr = mLocApi->startFix(locPosMode);
+        if (LOC_API_ADAPTER_ERR_SUCCESS == apiErr) {
+            err = LOCATION_ERROR_SUCCESS;
+            // save supl mode, which is used for NMEA generation
+            setSuplMode(options.mode);
+        } else {
+            err = LOCATION_ERROR_GENERAL_FAILURE;
+        }
+    }
+
+    return err;
+}
+
+void
+GnssAdapter::setPositionModeCommand(LocPosMode& locPosMode)
+{
+    LOC_LOGD("%s]: min_interval %u mode %u",
+             __func__, locPosMode.min_interval, locPosMode.mode);
+
+    struct MsgSetPositionMode : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocApiBase& mApi;
+        LocPosMode mLocPosMode;
+        inline MsgSetPositionMode(GnssAdapter& adapter,
+                                  LocApiBase& api,
+                                  LocPosMode& locPosMode) :
+            LocMsg(),
+            mAdapter(adapter),
+            mApi(api),
+            mLocPosMode(locPosMode) {}
+        inline virtual void proc() const {
+             // saves the mode in adapter to be used when startTrackingCommand is called from ULP
+            mAdapter.setUlpPositionMode(mLocPosMode);
+            mApi.setPositionMode(mLocPosMode);
+        }
+    };
+
+    sendMsg(new MsgSetPositionMode(*this, *mLocApi, locPosMode));
+}
+
+void
+GnssAdapter::startTrackingCommand()
+{
+    LOC_LOGD("%s]: ", __func__);
+
+    struct MsgStartTracking : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocApiBase& mApi;
+        inline MsgStartTracking(GnssAdapter& adapter,
+                                LocApiBase& api) :
+            LocMsg(),
+            mAdapter(adapter),
+            mApi(api) {}
+        inline virtual void proc() const {
+            // we get this call from ULP, so just call LocApi without multiplexing because
+            // ulp would be doing the multiplexing for us if it is present
+            LocPosMode& ulpPositionMode = mAdapter.getUlpPositionMode();
+            mApi.startFix(ulpPositionMode);
+            // save supl mode, which is used for NMEA generation
+            mAdapter.setSuplMode((GnssSuplMode)ulpPositionMode.mode);
+        }
+    };
+
+    sendMsg(new MsgStartTracking(*this, *mLocApi));
+}
+
+void
+GnssAdapter::updateTrackingOptionsCommand(LocationAPI* client, uint32_t id,
+                                          LocationOptions& options)
+{
+    LOC_LOGD("%s]: client %p id %u minInterval %u mode %u",
+             __func__, client, id, options.minInterval, options.mode);
+
+    struct MsgUpdateTracking : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocApiBase& mApi;
+        LocationAPI* mClient;
+        uint32_t mSessionId;
+        LocationOptions mOptions;
+        inline MsgUpdateTracking(GnssAdapter& adapter,
+                                LocApiBase& api,
+                                LocationAPI* client,
+                                uint32_t sessionId,
+                                LocationOptions options) :
+            LocMsg(),
+            mAdapter(adapter),
+            mApi(api),
+            mClient(client),
+            mSessionId(sessionId),
+            mOptions(options) {}
+        inline virtual void proc() const {
+            if (mAdapter.isTrackingSession(mClient, mSessionId)) {
+                LocationError err = LOCATION_ERROR_SUCCESS;
+                if (0 == mOptions.size) {
+                    err = LOCATION_ERROR_INVALID_PARAMETER;
+                } else {
+                    // Api doesn't support multiple clients for time based tracking, so mutiplex
+                    err = mAdapter.startTrackingMultiplex(mOptions);
+                    if (LOCATION_ERROR_SUCCESS == err) {
+                        mAdapter.saveTrackingSession(mClient, mSessionId, mOptions);
+                    }
+                }
+                mAdapter.reportResponse(mClient, err, mSessionId);
+            }
+            // we do not reportResponse for the case where there is no existing tracking session
+            // for the client and id being used, since updateTrackingCommand can be sent to both
+            // GnssAdapter & FlpAdapter by LocationAPI and we want to avoid incorrect error response
+        }
+    };
+
+    sendMsg(new MsgUpdateTracking(*this, *mLocApi, client, id, options));
+}
+
+void
+GnssAdapter::stopTrackingCommand(LocationAPI* client, uint32_t id)
+{
+    LOC_LOGD("%s]: client %p id %u", __func__, client, id);
+
+    struct MsgStopTracking : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocApiBase& mApi;
+        LocationAPI* mClient;
+        uint32_t mSessionId;
+        inline MsgStopTracking(GnssAdapter& adapter,
+                               LocApiBase& api,
+                               LocationAPI* client,
+                               uint32_t sessionId) :
+            LocMsg(),
+            mAdapter(adapter),
+            mApi(api),
+            mClient(client),
+            mSessionId(sessionId) {}
+        inline virtual void proc() const {
+            if (mAdapter.isTrackingSession(mClient, mSessionId)) {
+                LocationError err = LOCATION_ERROR_SUCCESS;
+                // Api doesn't support multiple clients for time based tracking, so mutiplex
+                err = mAdapter.stopTrackingMultiplex(mClient, mSessionId);
+                if (LOCATION_ERROR_SUCCESS == err) {
+                    mAdapter.eraseTrackingSession(mClient, mSessionId);
+                }
+                mAdapter.reportResponse(mClient, err, mSessionId);
+            }
+            // we do not reportResponse for the case where there is no existing tracking session
+            // for the client and id being used, since stopTrackingCommand can be sent to both
+            // GnssAdapter & FlpAdapter by LocationAPI and we want to avoid incorrect error response
+
+        }
+    };
+
+    sendMsg(new MsgStopTracking(*this, *mLocApi, client, id));
+}
+
+LocationError
+GnssAdapter::stopTrackingMultiplex(LocationAPI* client, uint32_t id)
+{
+    LocationError err = LOCATION_ERROR_SUCCESS;
+
+    if (1 == mTrackingSessions.size()) {
+        err = stopTracking();
+    } else {
+        LocationSessionKey key(client, id);
+
+        // get the session we are stopping
+        auto it = mTrackingSessions.find(key);
+        if (it != mTrackingSessions.end()) {
+            // find the next smallest interval, other than the session we are stopping
+            LocationOptions smallestIntervalOptions; // size will be zero until set for the first time
+            for (auto it2 = mTrackingSessions.begin(); it2 != mTrackingSessions.end(); ++it2) {
+                // if session is not the one we are stopping and either smallest interval is not set
+                // or there is a new smallest interval, then set the new smallest interval
+                if (it2->first != key && (0 == smallestIntervalOptions.size ||
+                    it2->second.minInterval < smallestIntervalOptions.minInterval)) {
+                     smallestIntervalOptions = it2->second;
+                }
+            }
+            // if session we are stopping has smaller interval then next smallest
+            if (it->second.minInterval < smallestIntervalOptions.minInterval) {
+                // restart time based tracking with next smallest interval
+                err = startTracking(smallestIntervalOptions);
+            }
+        }
+    }
+
+    return err;
+}
+
+LocationError
+GnssAdapter::stopTracking()
+{
+    LocationError err = LOCATION_ERROR_SUCCESS;
+    if (!mUlpProxy->sendStopFix()) {
+        loc_api_adapter_err apiErr = mLocApi->stopFix();
+        if (LOC_API_ADAPTER_ERR_SUCCESS == apiErr) {
+            err = LOCATION_ERROR_SUCCESS;
+        } else {
+            err = LOCATION_ERROR_GENERAL_FAILURE;
+        }
+    }
+
+    return err;
+}
+
+void
+GnssAdapter::stopTrackingCommand()
+{
+    LOC_LOGD("%s]: ", __func__);
+
+    struct MsgStopTracking : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocApiBase& mApi;
+        inline MsgStopTracking(GnssAdapter& adapter,
+                               LocApiBase& api) :
+            LocMsg(),
+            mAdapter(adapter),
+            mApi(api) {}
+        inline virtual void proc() const {
+            // clear the position mode
+            LocPosMode mLocPosMode = {};
+            mLocPosMode.mode = LOC_POSITION_MODE_INVALID;
+            mAdapter.setUlpPositionMode(mLocPosMode);
+            // don't need to multiplex because ULP will do that for us if it is present
+            mApi.stopFix();
+        }
+    };
+
+    sendMsg(new MsgStopTracking(*this, *mLocApi));
+}
+
+void
+GnssAdapter::getZppCommand()
+{
+    LOC_LOGD("%s]: ", __func__);
+
+    struct MsgGetZpp : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocApiBase& mApi;
+        inline MsgGetZpp(GnssAdapter& adapter,
+                         LocApiBase& api) :
+            LocMsg(),
+            mAdapter(adapter),
+            mApi(api) {}
+        inline virtual void proc() const {
+            UlpLocation location = {};
+            LocPosTechMask techMask = LOC_POS_TECH_MASK_DEFAULT;
+            GpsLocationExtended locationExtended = {};
+            locationExtended.size = sizeof(locationExtended);
+
+            mApi.getBestAvailableZppFix(location.gpsLocation, techMask);
+            //Mark the location source as from ZPP
+            location.gpsLocation.flags |= LOCATION_HAS_SOURCE_INFO;
+            location.position_source = ULP_LOCATION_IS_FROM_ZPP;
+
+            mAdapter.getUlpProxy()->reportPosition(location,
+                                                   locationExtended,
+                                                   LOC_SESS_SUCCESS,
+                                                   techMask);
+        }
+    };
+
+    sendMsg(new MsgGetZpp(*this, *mLocApi));
+}
+
+bool
+GnssAdapter::hasNiNotifyCallback(LocationAPI* client)
+{
+    auto it = mClientData.find(client);
+    return (it != mClientData.end() && it->second.gnssNiCb);
+}
+
+void
+GnssAdapter::gnssNiResponseCommand(LocationAPI* client,
+                                   uint32_t id,
+                                   GnssNiResponse response)
+{
+    LOC_LOGD("%s]: client %p id %u response %u", __func__, client, id, response);
+
+    struct MsgGnssNiResponse : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocationAPI* mClient;
+        uint32_t mSessionId;
+        GnssNiResponse mResponse;
+        inline MsgGnssNiResponse(GnssAdapter& adapter,
+                                 LocationAPI* client,
+                                 uint32_t sessionId,
+                                 GnssNiResponse response) :
+            LocMsg(),
+            mAdapter(adapter),
+            mClient(client),
+            mSessionId(sessionId),
+            mResponse(response) {}
+        inline virtual void proc() const {
+            NiData& niData = mAdapter.getNiData();
+            LocationError err = LOCATION_ERROR_SUCCESS;
+            if (!mAdapter.hasNiNotifyCallback(mClient)) {
+                err = LOCATION_ERROR_ID_UNKNOWN;
+            } else {
+                NiSession* pSession = NULL;
+                if (mSessionId == niData.sessionEs.reqID &&
+                    NULL != niData.sessionEs.rawRequest) {
+                    pSession = &niData.sessionEs;
+                    // ignore any SUPL NI non-Es session if a SUPL NI ES is accepted
+                    if (mResponse == GNSS_NI_RESPONSE_ACCEPT &&
+                        NULL != niData.session.rawRequest) {
+                            pthread_mutex_lock(&niData.session.tLock);
+                            niData.session.resp = GNSS_NI_RESPONSE_IGNORE;
+                            niData.session.respRecvd = true;
+                            pthread_cond_signal(&niData.session.tCond);
+                            pthread_mutex_unlock(&niData.session.tLock);
+                    }
+                } else if (mSessionId == niData.session.reqID &&
+                    NULL != niData.session.rawRequest) {
+                    pSession = &niData.session;
+                }
+
+                if (pSession) {
+                    LOC_LOGI("%s]: gnssNiResponseCommand: send user mResponse %u for id %u",
+                             __func__, mResponse, mSessionId);
+                    pthread_mutex_lock(&pSession->tLock);
+                    pSession->resp = mResponse;
+                    pSession->respRecvd = true;
+                    pthread_cond_signal(&pSession->tCond);
+                    pthread_mutex_unlock(&pSession->tLock);
+                } else {
+                    err = LOCATION_ERROR_ID_UNKNOWN;
+                    LOC_LOGE("%s]: gnssNiResponseCommand: id %u not an active session",
+                             __func__, mSessionId);
+                }
+            }
+            mAdapter.reportResponse(mClient, err, mSessionId);
+        }
+    };
+
+    sendMsg(new MsgGnssNiResponse(*this, client, id, response));
+
+}
+
+void
+GnssAdapter::gnssNiResponseCommand(GnssNiResponse response, void* rawRequest)
+{
+    LOC_LOGD("%s]: response %u", __func__, response);
+
+    struct MsgGnssNiResponse : public LocMsg {
+        LocApiBase& mApi;
+        const GnssNiResponse mResponse;
+        const void* mPayload;
+        inline MsgGnssNiResponse(LocApiBase& api,
+                                 const GnssNiResponse response,
+                                 const void* rawRequest) :
+            LocMsg(),
+            mApi(api),
+            mResponse(response),
+            mPayload(rawRequest) {}
+        inline virtual ~MsgGnssNiResponse() {
+            // this is a bit weird since mPayload is not
+            // allocated by this class.  But there is no better way.
+            // mPayload actually won't be NULL here.
+            free((void*)mPayload);
+        }
+        inline virtual void proc() const {
+            mApi.informNiResponse(mResponse, mPayload);
+        }
+    };
+
+    sendMsg(new MsgGnssNiResponse(*mLocApi, response, rawRequest));
+
+}
+
+uint32_t
+GnssAdapter::enableCommand(LocationTechnologyType techType)
+{
+    uint32_t sessionId = generateSessionId();
+    LOC_LOGD("%s]: id %u techType %u", __func__, sessionId, techType);
+
+    struct MsgEnableGnss : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocApiBase& mApi;
+        ContextBase& mContext;
+        uint32_t mSessionId;
+        LocationTechnologyType mTechType;
+        inline MsgEnableGnss(GnssAdapter& adapter,
+                             LocApiBase& api,
+                             ContextBase& context,
+                             uint32_t sessionId,
+                             LocationTechnologyType techType) :
+            LocMsg(),
+            mAdapter(adapter),
+            mApi(api),
+            mContext(context),
+            mSessionId(sessionId),
+            mTechType(techType) {}
+        inline virtual void proc() const {
+            LocationError err = LOCATION_ERROR_SUCCESS;
+            uint32_t powerVoteId = mAdapter.getPowerVoteId();
+            if (mTechType != LOCATION_TECHNOLOGY_TYPE_GNSS) {
+                err = LOCATION_ERROR_INVALID_PARAMETER;
+            } else if (powerVoteId > 0) {
+                err = LOCATION_ERROR_ALREADY_STARTED;
+            } else {
+                mContext.modemPowerVote(true);
+                mAdapter.setPowerVoteId(mSessionId);
+                mApi.setGpsLock(GNSS_CONFIG_GPS_LOCK_NONE);
+            }
+            mAdapter.reportResponse(err, mSessionId);
+        }
+    };
+
+    if (mContext != NULL) {
+        sendMsg(new MsgEnableGnss(*this, *mLocApi, *mContext, sessionId, techType));
+    } else {
+        LOC_LOGE("%s]: Context is NULL", __func__);
+    }
+
+    return sessionId;
+}
+
+void
+GnssAdapter::disableCommand(uint32_t id)
+{
+    LOC_LOGD("%s]: id %u", __func__, id);
+
+    struct MsgDisableGnss : public LocMsg {
+        GnssAdapter& mAdapter;
+        LocApiBase& mApi;
+        ContextBase& mContext;
+        uint32_t mSessionId;
+        inline MsgDisableGnss(GnssAdapter& adapter,
+                             LocApiBase& api,
+                             ContextBase& context,
+                             uint32_t sessionId) :
+            LocMsg(),
+            mAdapter(adapter),
+            mApi(api),
+            mContext(context),
+            mSessionId(sessionId) {}
+        inline virtual void proc() const {
+            LocationError err = LOCATION_ERROR_SUCCESS;
+            uint32_t powerVoteId = mAdapter.getPowerVoteId();
+            if (powerVoteId != mSessionId) {
+                err = LOCATION_ERROR_ID_UNKNOWN;
+            } else {
+                mContext.modemPowerVote(false);
+                mAdapter.setPowerVoteId(0);
+                mApi.setGpsLock(mAdapter.convertGpsLock(ContextBase::mGps_conf.GPS_LOCK));
+            }
+            mAdapter.reportResponse(err, mSessionId);
+        }
+    };
+
+    if (mContext != NULL) {
+        sendMsg(new MsgDisableGnss(*this, *mLocApi, *mContext, id));
+    }
+
+}
+
+void
+GnssAdapter::reportPositionEvent(const UlpLocation& ulpLocation,
+                                 const GpsLocationExtended& locationExtended,
+                                 enum loc_sess_status status,
+                                 LocPosTechMask techMask,
+                                 bool fromUlp)
+{
+    LOC_LOGD("%s]: fromUlp %u status %u", __func__, fromUlp, status);
+
+    // if this event is not called from ULP, then try to call into ULP and return if successfull
+    if (!fromUlp) {
+        if (mUlpProxy->reportPosition(ulpLocation, locationExtended,
+                                 status, techMask)) {
+            return;
+        }
+    }
+
+    struct MsgReportPosition : public LocMsg {
+        GnssAdapter& mAdapter;
+        const UlpLocation mUlpLocation;
+        const GpsLocationExtended mLocationExtended;
+        loc_sess_status mStatus;
+        LocPosTechMask mTechMask;
+        inline MsgReportPosition(GnssAdapter& adapter,
+                                 const UlpLocation& ulpLocation,
+                                 const GpsLocationExtended& locationExtended,
+                                 loc_sess_status status,
+                                 LocPosTechMask techMask) :
+            LocMsg(),
+            mAdapter(adapter),
+            mUlpLocation(ulpLocation),
+            mLocationExtended(locationExtended),
+            mStatus(status),
+            mTechMask(techMask) {}
+        inline virtual void proc() const {
+            mAdapter.reportPosition(mUlpLocation, mLocationExtended, mStatus, mTechMask);
+        }
+    };
+
+    sendMsg(new MsgReportPosition(*this, ulpLocation, locationExtended, status, techMask));
+}
+
+void
+GnssAdapter::reportPosition(const UlpLocation& ulpLocation,
+                            const GpsLocationExtended& locationExtended,
+                            enum loc_sess_status status,
+                            LocPosTechMask techMask)
+{
+    bool reported = false;
+    if (LOC_SESS_FAILURE == status) {
+        Location invalidLocation = {};
+        invalidLocation.size = sizeof(Location);
+        for (auto it=mClientData.begin(); it != mClientData.end(); ++it) {
+            if (nullptr != it->second.trackingCb) {
+                it->second.trackingCb(invalidLocation);
+            }
+        }
+        reported = true;
+    }
+    // what's in the else if is... (line by line)
+    // 1. this is a final fix; and
+    //   1.1 it is a Satellite fix; or
+    //   1.2 it is a sensor fix
+    // 2. (must be intermediate fix... implicit)
+    //   2.1 we accepte intermediate; and
+    //   2.2 it is NOT the case that
+    //   2.2.1 there is inaccuracy; and
+    //   2.2.2 we care about inaccuracy; and
+    //   2.2.3 the inaccuracy exceeds our tolerance
+    else if ((LOC_SESS_SUCCESS == status &&
+              ((LOC_POS_TECH_MASK_SATELLITE |
+                LOC_POS_TECH_MASK_SENSORS   |
+                LOC_POS_TECH_MASK_HYBRID) &
+               techMask)) ||
+             (LOC_SESS_INTERMEDIATE == ContextBase::mGps_conf.INTERMEDIATE_POS &&
+              !((ulpLocation.gpsLocation.flags &
+                 LOC_GPS_LOCATION_HAS_ACCURACY) &&
+                (ContextBase::mGps_conf.ACCURACY_THRES != 0) &&
+                (ulpLocation.gpsLocation.accuracy >
+                 ContextBase::mGps_conf.ACCURACY_THRES)))) {
+        if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_GNSS_SV_USED_DATA) {
+            mGnssSvIdUsedInPosAvail = true;
+            mGnssSvIdUsedInPosition = locationExtended.gnss_sv_used_ids;
+        }
+        for (auto it=mClientData.begin(); it != mClientData.end(); ++it) {
+            if (nullptr != it->second.trackingCb) {
+                Location location = {};
+                convertLocation(location, ulpLocation.gpsLocation, techMask);
+                it->second.trackingCb(location);
+            }
+            if (nullptr != it->second.gnssLocationInfoCb) {
+                GnssLocationInfoNotification locationInfo = {};
+                convertLocationInfo(locationInfo, locationExtended);
+                it->second.gnssLocationInfoCb(locationInfo);
+            }
+        }
+        reported = true;
+    }
+
+    if (NMEA_PROVIDER_AP == ContextBase::mGps_conf.NMEA_PROVIDER && !mTrackingSessions.empty()) {
+        if (reported && status != LOC_SESS_FAILURE) {
+            generateNmea(ulpLocation, locationExtended);
+        } else {
+            generateNmeaBlank();
+        }
+    }
+
+    // Free the allocated memory for rawData
+    UlpLocation* gp = (UlpLocation*)&(ulpLocation);
+    if (gp != NULL && gp->rawData != NULL)
+    {
+        delete (char*)gp->rawData;
+        gp->rawData = NULL;
+        gp->rawDataSize = 0;
+    }
+}
+
+void
+GnssAdapter::reportSvEvent(const GnssSvNotification& svNotify,
+                           bool fromUlp)
+{
+    LOC_LOGD("%s]: fromUlp %u", __func__, fromUlp);
+
+    // if this event is not called from ULP, then try to call into ULP and return if successfull
+    if (!fromUlp) {
+        if (mUlpProxy->reportSv(svNotify)) {
+            return;
+        }
+    }
+
+    struct MsgReportSv : public LocMsg {
+        GnssAdapter& mAdapter;
+        const GnssSvNotification mSvNotify;
+        inline MsgReportSv(GnssAdapter& adapter,
+                           const GnssSvNotification& svNotify) :
+            LocMsg(),
+            mAdapter(adapter),
+            mSvNotify(svNotify) {}
+        inline virtual void proc() const {
+            mAdapter.reportSv((GnssSvNotification&)mSvNotify);
+        }
+    };
+
+    sendMsg(new MsgReportSv(*this, svNotify));
+}
+
+void
+GnssAdapter::reportSv(GnssSvNotification& svNotify)
+{
+    if (mGnssSvIdUsedInPosAvail) {
+        int numSv = svNotify.count;
+        int16_t gnssSvId = 0;
+        int prnMin = 0;
+        uint64_t svUsedIdMask = 0;
+        for (int i=0; i < numSv; i++) {
+            gnssSvId = svNotify.gnssSvs[i].svId;
+            if (gnssSvId <= GPS_SV_PRN_MAX) {
+                svUsedIdMask = mGnssSvIdUsedInPosition.gps_sv_used_ids_mask;
+                prnMin = GPS_SV_PRN_MIN;
+            } else if ((gnssSvId >= GLO_SV_PRN_MIN) && (gnssSvId <= GLO_SV_PRN_MAX)) {
+                svUsedIdMask = mGnssSvIdUsedInPosition.glo_sv_used_ids_mask;
+                prnMin = GLO_SV_PRN_MIN;
+            } else if ((gnssSvId >= BDS_SV_PRN_MIN) && (gnssSvId <= BDS_SV_PRN_MAX)) {
+                svUsedIdMask = mGnssSvIdUsedInPosition.bds_sv_used_ids_mask;
+                prnMin = BDS_SV_PRN_MIN;
+            } else if ((gnssSvId >= GAL_SV_PRN_MIN) && (gnssSvId <= GAL_SV_PRN_MAX)) {
+                svUsedIdMask = mGnssSvIdUsedInPosition.gal_sv_used_ids_mask;
+                prnMin = GAL_SV_PRN_MIN;
+            }
+
+            // If SV ID was used in previous position fix, then set USED_IN_FIX
+            // flag, else clear the USED_IN_FIX flag.
+            if (svUsedIdMask & (1 << (gnssSvId - prnMin))) {
+                svNotify.gnssSvs[i].gnssSvOptionsMask |= GNSS_SV_OPTIONS_USED_IN_FIX_BIT;
+            } else {
+                svNotify.gnssSvs[i].gnssSvOptionsMask &= ~GNSS_SV_OPTIONS_USED_IN_FIX_BIT;
+            }
+        }
+    }
+
+    for (auto it=mClientData.begin(); it != mClientData.end(); ++it) {
+        if (nullptr != it->second.gnssSvCb) {
+            it->second.gnssSvCb(svNotify);
+        }
+    }
+
+    if (NMEA_PROVIDER_AP == ContextBase::mGps_conf.NMEA_PROVIDER && !mTrackingSessions.empty()) {
+        generateNmea(svNotify);
+    }
+
+    mGnssSvIdUsedInPosAvail = false;
+}
+
+void
+GnssAdapter::reportNmeaEvent(const char* nmea, size_t length, bool fromUlp)
+{
+    //LOC_LOGD("%s]: fromUlp %u", __func__, fromUlp);
+
+    // if this event is not called from ULP, then try to call into ULP and return if successfull
+    if (!fromUlp) {
+        if (mUlpProxy->reportNmea(nmea, length)) {
+            return;
+        }
+    }
+
+    struct MsgReportNmea : public LocMsg {
+        GnssAdapter& mAdapter;
+        const char* mNmea;
+        size_t mLength;
+        inline MsgReportNmea(GnssAdapter& adapter,
+                             const char* nmea,
+                             size_t length) :
+            LocMsg(),
+            mAdapter(adapter),
+            mNmea(new char[length]),
+            mLength(length) {
+                memcpy((void*)mNmea, (void*)nmea, length);
+            }
+        inline virtual ~MsgReportNmea()
+        {
+            delete[] mNmea;
+        }
+        inline virtual void proc() const {
+            mAdapter.reportNmea(mNmea, mLength);
+        }
+    };
+
+    sendMsg(new MsgReportNmea(*this, nmea, length));
+}
+
+void
+GnssAdapter::reportNmea(const char* nmea, size_t length)
+{
+    GnssNmeaNotification nmeaNotification = {};
+    nmeaNotification.size = sizeof(GnssNmeaNotification);
+
+    struct timeval tv;
+    gettimeofday(&tv, (struct timezone *) NULL);
+    int64_t now = tv.tv_sec * 1000LL + tv.tv_usec / 1000;
+    nmeaNotification.timestamp = now;
+    nmeaNotification.nmea = nmea;
+    nmeaNotification.length = length;
+
+    for (auto it=mClientData.begin(); it != mClientData.end(); ++it) {
+        if (nullptr != it->second.gnssNmeaCb) {
+            it->second.gnssNmeaCb(nmeaNotification);
+        }
+    }
+
+}
+
+bool
+GnssAdapter::requestNiNotifyEvent(const GnssNiNotification &notify, const void* data)
+{
+    LOC_LOGI("%s]: notif_type: %d, timeout: %d, default_resp: %d"
+             "requestor_id: %s (encoding: %d) text: %s text (encoding: %d) extras: %s",
+             __func__, notify.type, notify.timeout, notify.timeoutResponse,
+             notify.requestor, notify.requestorEncoding,
+             notify.message, notify.messageEncoding, notify.extras);
+
+    struct MsgReportNiNotify : public LocMsg {
+        GnssAdapter& mAdapter;
+        const GnssNiNotification mNotify;
+        const void* mData;
+        inline MsgReportNiNotify(GnssAdapter& adapter,
+                                 const GnssNiNotification& notify,
+                                 const void* data) :
+            LocMsg(),
+            mAdapter(adapter),
+            mNotify(notify),
+            mData(data) {}
+        inline virtual void proc() const {
+            mAdapter.requestNiNotify(mNotify, mData);
+        }
+    };
+
+    sendMsg(new MsgReportNiNotify(*this, notify, data));
+
+    return true;
+}
+
+static void* niThreadProc(void *args)
+{
+    NiSession* pSession = (NiSession*)args;
+    int rc = 0;          /* return code from pthread calls */
+
+    struct timeval present_time;
+    struct timespec expire_time;
+
+    pthread_mutex_lock(&pSession->tLock);
+    /* Calculate absolute expire time */
+    gettimeofday(&present_time, NULL);
+    expire_time.tv_sec  = present_time.tv_sec + pSession->respTimeLeft;
+    expire_time.tv_nsec = present_time.tv_usec * 1000;
+    LOC_LOGD("%s]: time out set for abs time %ld with delay %d sec",
+             __func__, (long)expire_time.tv_sec, pSession->respTimeLeft);
+
+    while (!pSession->respRecvd) {
+        rc = pthread_cond_timedwait(&pSession->tCond,
+                                    &pSession->tLock,
+                                    &expire_time);
+        if (rc == ETIMEDOUT) {
+            pSession->resp = GNSS_NI_RESPONSE_NO_RESPONSE;
+            LOC_LOGD("%s]: time out after valting for specified time. Ret Val %d",
+                     __func__, rc);
+            break;
+        }
+    }
+    LOC_LOGD("%s]: Java layer has sent us a user response and return value from "
+             "pthread_cond_timedwait = %d pSession->resp is %u", __func__, rc, pSession->resp);
+    pSession->respRecvd = false; /* Reset the user response flag for the next session*/
+
+    // adding this check to support modem restart, in which case, we need the thread
+    // to exit without calling sending data. We made sure that rawRequest is NULL in
+    // loc_eng_ni_reset_on_engine_restart()
+    GnssAdapter* adapter = pSession->adapter;
+    GnssNiResponse resp;
+    void* rawRequest = NULL;
+    bool sendResponse = false;
+
+    if (NULL != pSession->rawRequest) {
+        if (pSession->resp != GNSS_NI_RESPONSE_IGNORE) {
+            resp = pSession->resp;
+            rawRequest = pSession->rawRequest;
+            sendResponse = true;
+        } else {
+            free(pSession->rawRequest);
+        }
+        pSession->rawRequest = NULL;
+    }
+    pthread_mutex_unlock(&pSession->tLock);
+
+    pSession->respTimeLeft = 0;
+    pSession->reqID = 0;
+
+    if (sendResponse) {
+        adapter->gnssNiResponseCommand(resp, rawRequest);
+    }
+
+    return NULL;
+}
+
+bool
+GnssAdapter::requestNiNotify(const GnssNiNotification& notify, const void* data)
+{
+    NiSession* pSession = NULL;
+    gnssNiCallback gnssNiCb = nullptr;
+
+    for (auto it=mClientData.begin(); it != mClientData.end(); ++it) {
+        if (nullptr != it->second.gnssNiCb) {
+            gnssNiCb = it->second.gnssNiCb;
+            break;
+        }
+    }
+    if (nullptr == gnssNiCb) {
+        EXIT_LOG(%s, "no clients with gnssNiCb.");
+        return false;
+    }
+
+    if (notify.type == GNSS_NI_TYPE_EMERGENCY_SUPL) {
+        if (NULL != mNiData.sessionEs.rawRequest) {
+            LOC_LOGI("%s]: supl es NI in progress, new supl es NI ignored, type: %d",
+                     __func__, notify.type);
+            if (NULL != data) {
+                free((void*)data);
+            }
+        } else {
+            pSession = &mNiData.sessionEs;
+        }
+    } else {
+        if (NULL != mNiData.session.rawRequest ||
+            NULL != mNiData.sessionEs.rawRequest) {
+            LOC_LOGI("%s]: supl NI in progress, new supl NI ignored, type: %d",
+                     __func__, notify.type);
+            if (NULL != data) {
+                free((void*)data);
+            }
+        } else {
+            pSession = &mNiData.session;
+        }
+    }
+
+    if (pSession) {
+        /* Save request */
+        pSession->rawRequest = (void*)data;
+        pSession->reqID = ++mNiData.reqIDCounter;
+        pSession->adapter = this;
+
+        int sessionId = pSession->reqID;
+
+        /* For robustness, spawn a thread at this point to timeout to clear up the notification
+         * status, even though the OEM layer in java does not do so.
+         **/
+        pSession->respTimeLeft =
+             5 + (notify.timeout != 0 ? notify.timeout : LOC_NI_NO_RESPONSE_TIME);
+
+        int rc = 0;
+        rc = pthread_create(&pSession->thread, NULL, niThreadProc, pSession);
+        if (rc) {
+            LOC_LOGE("%s]: Loc NI thread is not created.", __func__);
+        }
+        rc = pthread_detach(pSession->thread);
+        if (rc) {
+            LOC_LOGE("%s]: Loc NI thread is not detached.", __func__);
+        }
+
+        if (nullptr != gnssNiCb) {
+            gnssNiCb(sessionId, notify);
+        }
+    }
+
+    return true;
+}
+
+void
+GnssAdapter::reportGnssMeasurementDataEvent(const GnssMeasurementsNotification& measurementsNotify)
+{
+    LOC_LOGD("%s]: ", __func__);
+
+    struct MsgReportGnssMeasurementData : public LocMsg {
+        GnssAdapter& mAdapter;
+        const GnssMeasurementsNotification mMeasurementsNotify;
+        inline MsgReportGnssMeasurementData(GnssAdapter& adapter,
+                                           const GnssMeasurementsNotification& measurementsNotify) :
+            LocMsg(),
+            mAdapter(adapter),
+            mMeasurementsNotify(measurementsNotify) {}
+        inline virtual void proc() const {
+            mAdapter.reportGnssMeasurementData(mMeasurementsNotify);
+        }
+    };
+
+    sendMsg(new MsgReportGnssMeasurementData(*this, measurementsNotify));
+}
+
+void
+GnssAdapter::reportGnssMeasurementData(const GnssMeasurementsNotification& measurementsNotify)
+{
+    for (auto it=mClientData.begin(); it != mClientData.end(); ++it) {
+        if (nullptr != it->second.gnssMeasurementsCb) {
+            it->second.gnssMeasurementsCb(measurementsNotify);
+        }
+    }
+}
+
+void
+GnssAdapter::reportSvMeasurementEvent(GnssSvMeasurementSet &svMeasurementSet)
+{
+    LOC_LOGD("%s]: ", __func__);
+
+    // We send SvMeasurementSet to AmtProxy/ULPProxy to be forwarded as necessary.
+    mUlpProxy->reportSvMeasurement(svMeasurementSet);
+}
+
+void
+GnssAdapter::reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial)
+{
+    LOC_LOGD("%s]: ", __func__);
+
+    // We send SvMeasurementSet to AmtProxy/ULPProxy to be forwarded as necessary.
+    mUlpProxy->reportSvPolynomial(svPolynomial);
+}
+
+int
+GnssAdapter::nmeaPutChecksum(char *nmea, size_t maxSize)
+{
+    uint8_t checksum = 0;
+    int length = 0;
+
+    nmea++; //skip the $
+    while (*nmea != '\0') {
+        checksum ^= *nmea++;
+        length++;
+    }
+
+    // length now contains nmea sentence string length not including $ sign.
+    int checksumLength = snprintf(nmea,(maxSize-length-1),"*%02X\r\n", checksum);
+
+    // total length of nmea sentence is length of nmea sentence inc $ sign plus
+    // length of checksum (+1 is to cover the $ character in the length).
+    return (length + checksumLength + 1);
+}
+
+void
+GnssAdapter::generateNmea(const GnssSvNotification& svNotify)
+{
+    char sentence[NMEA_SENTENCE_MAX_LENGTH] = {0};
+
+    // ------$GPGSV------
+    NmeaSvMeta gpsSvMeta =
+        {GNSS_SV_TYPE_GPS, "GP", 0, 0};
+    generateNmeaGSV(svNotify, gpsSvMeta, sentence, sizeof(sentence));
+
+    // ------$GLGSV------
+    NmeaSvMeta gloSvMeta =
+        {GNSS_SV_TYPE_GLONASS, "GL", 0, GLONASS_SV_ID_OFFSET};
+    generateNmeaGSV(svNotify, gloSvMeta, sentence, sizeof(sentence));
+
+    // ------$GAGSV------
+    NmeaSvMeta galSvMeta =
+        {GNSS_SV_TYPE_GALILEO, "GA", 0, 0};
+    generateNmeaGSV(svNotify, galSvMeta, sentence, sizeof(sentence));
+}
+
+void
+GnssAdapter::generateNmea(const UlpLocation& ulpLocation,
+                          const GpsLocationExtended& locationExtended)
+{
+
+    char sentence[NMEA_SENTENCE_MAX_LENGTH] = {0};
+
+    time_t utcTime(ulpLocation.gpsLocation.timestamp/1000);
+    tm * pTm = gmtime(&utcTime);
+    if (NULL == pTm) {
+        LOC_LOGE("%s]: gmtime failed", __func__);
+        return;
+    }
+
+    uint32_t svUsedCount = 0;
+    uint32_t count = 0;
+    bool isCombinedFix = (mGnssSvIdUsedInPosition.gps_sv_used_ids_mask ? 1 : 0) +
+                         (mGnssSvIdUsedInPosition.glo_sv_used_ids_mask ? 1 : 0) +
+                         (mGnssSvIdUsedInPosition.gal_sv_used_ids_mask ? 1 : 0) > 1;
+    NmeaSvMeta gnssSvMeta =
+        {GNSS_SV_TYPE_GPS, isCombinedFix ? "GN" : "GP",
+         mGnssSvIdUsedInPosition.gps_sv_used_ids_mask, 0};
+
+    // ---$GPGSA/$GNGSA---
+    NmeaSvMeta gpsSvMeta =
+        {GNSS_SV_TYPE_GPS, isCombinedFix ? "GN" : "GP",
+         mGnssSvIdUsedInPosition.gps_sv_used_ids_mask, 0};
+    count = generateNmeaGSA(locationExtended, gpsSvMeta, sentence, sizeof(sentence));
+    if (count > 0) {
+        svUsedCount += count;
+        gnssSvMeta = gpsSvMeta;
+    }
+
+    // ---$GLGSA/$GNGSA---
+    NmeaSvMeta gloSvMeta =
+        {GNSS_SV_TYPE_GLONASS, isCombinedFix ? "GN" : "GL",
+         mGnssSvIdUsedInPosition.glo_sv_used_ids_mask, GLONASS_SV_ID_OFFSET};
+    count = generateNmeaGSA(locationExtended, gloSvMeta, sentence, sizeof(sentence));
+    if (count > 0) {
+        svUsedCount += count;
+        gnssSvMeta = gloSvMeta;
+    }
+
+    // ---$GAGSA/$GNGSA---
+    NmeaSvMeta galSvMeta =
+        {GNSS_SV_TYPE_GALILEO, isCombinedFix ? "GN" : "GA",
+         mGnssSvIdUsedInPosition.gal_sv_used_ids_mask, 0};
+    count = generateNmeaGSA(locationExtended, galSvMeta, sentence, sizeof(sentence));
+    if (count > 0) {
+        svUsedCount += count;
+        gnssSvMeta = galSvMeta;
+    }
+
+    // ---$GPVTG/$GLVTG/$GAVTG/$GNVTG---
+    generateNmeaVTG(ulpLocation, locationExtended, gnssSvMeta,
+                    sentence, sizeof(sentence));
+
+    // ---$GPRMC/$GLRMC/$GARMC/$GNRMC---
+    generateNmeaRMC(ulpLocation, locationExtended, gnssSvMeta,
+                    *pTm, sentence, sizeof(sentence));
+
+    // ---$GPGGA/$GLGGA/$GAGGA/$GNGGA---
+    generateNmeaGGA(ulpLocation, locationExtended, gnssSvMeta,
+                    *pTm, svUsedCount, sentence, sizeof(sentence));
+
+}
+
+void
+GnssAdapter::generateNmeaBlank()
+{
+    char sentence[NMEA_SENTENCE_MAX_LENGTH] = {0};
+    int length = 0;
+
+    strlcpy(sentence, "$GPGSA,A,1,,,,,,,,,,,,,,,", sizeof(sentence));
+    length = nmeaPutChecksum(sentence, sizeof(sentence));
+    reportNmeaEvent(sentence, length);
+
+    strlcpy(sentence, "$GNGSA,A,1,,,,,,,,,,,,,,,", sizeof(sentence));
+    length = nmeaPutChecksum(sentence, sizeof(sentence));
+    reportNmeaEvent(sentence, length);
+
+    strlcpy(sentence, "$GPVTG,,T,,M,,N,,K,N", sizeof(sentence));
+    length = nmeaPutChecksum(sentence, sizeof(sentence));
+    reportNmeaEvent(sentence, length);
+
+    strlcpy(sentence, "$GPRMC,,V,,,,,,,,,,N", sizeof(sentence));
+    length = nmeaPutChecksum(sentence, sizeof(sentence));
+    reportNmeaEvent(sentence, length);
+
+    strlcpy(sentence, "$GPGGA,,,,,,0,,,,,,,,", sizeof(sentence));
+    length = nmeaPutChecksum(sentence, sizeof(sentence));
+    reportNmeaEvent(sentence, length);
+}
+
+void
+GnssAdapter::generateNmeaGSV(const GnssSvNotification& svNotify, NmeaSvMeta& svMeta,
+                             char* sentence, size_t size)
+{
+    if (!sentence || size == 0) {
+        LOC_LOGE("%s]: NMEA Error invalid argument.", __func__);
+        return;
+    }
+
+    char* pMarker = sentence;
+    int lengthRemaining = size;
+    int length = 0;
+    int sentenceCount = 0;
+    int sentenceNumber = 1;
+    int svCount = 0;
+    int sv = 1;
+
+    for (sv=1; sv <= svNotify.count; sv++) {
+        if (svMeta.svType == svNotify.gnssSvs[sv - 1].type) {
+            // cache the used in fix mask, as it will be needed to send $GPGSA
+            // during the position report
+            if (LOC_GNSS_SV_FLAGS_USED_IN_FIX ==
+                (svNotify.gnssSvs[sv - 1].gnssSvOptionsMask & GNSS_SV_OPTIONS_USED_IN_FIX_BIT)) {
+                svCount++;
+            }
+        }
+    }
+
+    if (svCount == 0) {
+        // no svs in view, so just send a blank $--GSV sentence
+        snprintf(sentence, lengthRemaining, "$%sGSV,1,1,0,", svMeta.talker);
+        length = nmeaPutChecksum(sentence, size);
+        reportNmeaEvent(sentence, length);
+        return;
+    }
+
+    sv = 1;
+    sentenceNumber = 1;
+    sentenceCount = svCount / 4 + (svCount % 4 != 0);
+
+    while (sentenceNumber <= sentenceCount) {
+        pMarker = sentence;
+        lengthRemaining = size;
+
+        length = snprintf(pMarker, lengthRemaining, "$%sGSV,%d,%d,%02d",
+                          svMeta.talker, sentenceCount, sentenceNumber, svCount);
+
+        if (length < 0 || length >= lengthRemaining) {
+            LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+            return;
+        }
+        pMarker += length;
+        lengthRemaining -= length;
+
+        for (int i=0; (sv <= svNotify.count) && (i < 4);  sv++) {
+            if (svMeta.svType == svNotify.gnssSvs[sv - 1].type) {
+                length = snprintf(pMarker, lengthRemaining,",%02d,%02d,%03d,",
+                    svNotify.gnssSvs[sv - 1].svId,
+                    (int)(0.5 + svNotify.gnssSvs[sv - 1].elevation), //float to int
+                    (int)(0.5 + svNotify.gnssSvs[sv - 1].azimuth)); //float to int
+
+                if (length < 0 || length >= lengthRemaining) {
+                    LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+                    return;
+                }
+                pMarker += length;
+                lengthRemaining -= length;
+
+                if (svNotify.gnssSvs[sv - 1].cN0Dbhz > 0) {
+                    length = snprintf(pMarker, lengthRemaining,"%02d",
+                        (int)(0.5 + svNotify.gnssSvs[sv - 1].cN0Dbhz)); //float to int
+
+                    if (length < 0 || length >= lengthRemaining) {
+                        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+                        return;
+                    }
+                    pMarker += length;
+                    lengthRemaining -= length;
+                }
+                i++;
+            }
+        }
+
+        length = nmeaPutChecksum(sentence, size);
+        reportNmeaEvent(sentence, length);
+        sentenceNumber++;
+    }  //while
+}
+
+uint8_t
+GnssAdapter::generateNmeaGSA(const GpsLocationExtended& locationExtended,
+                             NmeaSvMeta& svMeta, char* sentence, size_t size)
+{
+    if (!sentence || size == 0) {
+        LOC_LOGE("%s]: NMEA Error invalid arguments.", __func__);
+        return 0;
+    }
+
+    char* pMarker = sentence;
+    int lengthRemaining = size;
+    int length = 0;
+
+    uint8_t svUsedCount = 0;
+    uint32_t svUsedList[32] = {0};
+
+    char fixType = '\0';
+
+    uint32_t svIdOffset = svMeta.svIdOffset;
+    uint32_t mask = svMeta.mask;
+
+    for (uint8_t i = 1; mask > 0 && svUsedCount < 32; i++) {
+        if (mask & 1) {
+            svUsedList[svUsedCount++] = i + svIdOffset;
+        }
+        mask = mask >> 1;
+    }
+
+    if (svUsedCount == 0 && LOC_GNSS_CONSTELLATION_GPS != svMeta.svType) {
+        return 0;
+    }
+
+    if (svUsedCount == 0) {
+        fixType = '1'; // no fix
+    } else if (svUsedCount <= 3) {
+        fixType = '2'; // 2D fix
+    } else {
+        fixType = '3'; // 3D fix
+    }
+
+    // Start printing the sentence
+    // Format: $--GSA,a,x,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,p.p,h.h,v.v*cc
+    // a : Mode  : A : Automatic, allowed to automatically switch 2D/3D
+    // x : Fixtype : 1 (no fix), 2 (2D fix), 3 (3D fix)
+    // xx : 12 SV ID
+    // p.p : Position DOP (Dilution of Precision)
+    // h.h : Horizontal DOP
+    // v.v : Vertical DOP
+    // cc : Checksum value
+    length = snprintf(pMarker, lengthRemaining, "$%sGSA,A,%c,", svMeta.talker, fixType);
+
+    if (length < 0 || length >= lengthRemaining) {
+        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);;
+        return 0;
+    }
+    pMarker += length;
+    lengthRemaining -= length;
+
+    // Add first 12 satellite IDs
+    for (uint8_t i = 0; i < 12; i++) {
+        if (i < svUsedCount) {
+            length = snprintf(pMarker, lengthRemaining, "%02d,", svUsedList[i]);
+        } else {
+            length = snprintf(pMarker, lengthRemaining, ",");
+        }
+        if (length < 0 || length >= lengthRemaining) {
+            LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+            return 0;
+        }
+        pMarker += length;
+        lengthRemaining -= length;
+    }
+
+    // Add the position/horizontal/vertical DOP values
+    if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_DOP) {
+        length = snprintf(pMarker, lengthRemaining, "%.1f,%.1f,%.1f",
+                locationExtended.pdop,
+                locationExtended.hdop,
+                locationExtended.vdop);
+    } else {
+        length = snprintf(pMarker, lengthRemaining, ",,");
+    }
+
+    /* Sentence is ready, add checksum and broadcast */
+    length = nmeaPutChecksum(sentence, size);
+    reportNmeaEvent(sentence, length);
+
+    return svUsedCount;
+}
+
+void
+GnssAdapter::generateNmeaVTG(const UlpLocation& ulpLocation,
+                             const GpsLocationExtended& locationExtended,
+                             NmeaSvMeta& svMeta, char* sentence, size_t size)
+{
+    if (!sentence || size == 0) {
+        LOC_LOGE("%s]: NMEA Error invalid arguments.", __func__);
+        return;
+    }
+
+    char* pMarker = sentence;
+    int lengthRemaining = size;
+    int length = 0;
+
+    if (ulpLocation.gpsLocation.flags & LOC_GPS_LOCATION_HAS_BEARING)
+    {
+        float magTrack = ulpLocation.gpsLocation.bearing;
+        if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_MAG_DEV)
+        {
+            float magTrack = ulpLocation.gpsLocation.bearing - locationExtended.magneticDeviation;
+            if (magTrack < 0.0)
+                magTrack += 360.0;
+            else if (magTrack > 360.0)
+                magTrack -= 360.0;
+        }
+
+        length = snprintf(pMarker, lengthRemaining, "$%sVTG,%.1lf,T,%.1lf,M,",
+                          svMeta.talker, ulpLocation.gpsLocation.bearing, magTrack);
+    }
+    else
+    {
+        length = snprintf(pMarker, lengthRemaining, "$%sVTG,,T,,M,", svMeta.talker);
+    }
+
+    if (length < 0 || length >= lengthRemaining)
+    {
+        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+        return;
+    }
+    pMarker += length;
+    lengthRemaining -= length;
+
+    if (ulpLocation.gpsLocation.flags & LOC_GPS_LOCATION_HAS_SPEED)
+    {
+        float speedKnots = ulpLocation.gpsLocation.speed * (3600.0/1852.0);
+        float speedKmPerHour = ulpLocation.gpsLocation.speed * 3.6;
+
+        length = snprintf(pMarker, lengthRemaining, "%.1lf,N,%.1lf,K,", speedKnots, speedKmPerHour);
+    }
+    else
+    {
+        length = snprintf(pMarker, lengthRemaining, ",N,,K,");
+    }
+
+    if (length < 0 || length >= lengthRemaining)
+    {
+        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+        return;
+    }
+    pMarker += length;
+    lengthRemaining -= length;
+
+    if (!(ulpLocation.gpsLocation.flags & LOC_GPS_LOCATION_HAS_LAT_LONG))
+        length = snprintf(pMarker, lengthRemaining, "%c", 'N'); // N means no fix
+    else if (GNSS_SUPL_MODE_STANDALONE == mSuplMode)
+        length = snprintf(pMarker, lengthRemaining, "%c", 'A'); // A means autonomous
+    else
+        length = snprintf(pMarker, lengthRemaining, "%c", 'D'); // D means differential
+
+    length = nmeaPutChecksum(sentence, size);
+    reportNmeaEvent(sentence, length);
+}
+
+void
+GnssAdapter::generateNmeaRMC(const UlpLocation& ulpLocation,
+                             const GpsLocationExtended& locationExtended,
+                             NmeaSvMeta& svMeta, tm& utcTime,
+                             char* sentence, size_t size)
+{
+    if (!sentence || size == 0) {
+        LOC_LOGE("NMEA Error invalid arguments.");
+        return;
+    }
+
+    int utcYear = utcTime.tm_year % 100; // 2 digit year
+    int utcMonth = utcTime.tm_mon + 1; // tm_mon starts at zero
+    int utcDay = utcTime.tm_mday;
+    int utcHours = utcTime.tm_hour;
+    int utcMinutes = utcTime.tm_min;
+    int utcSeconds = utcTime.tm_sec;
+    int utcMSeconds = (ulpLocation.gpsLocation.timestamp)%1000;
+
+    char* pMarker = sentence;
+    int lengthRemaining = size;
+    int length = 0;
+
+    length = snprintf(pMarker, lengthRemaining, "$%sRMC,%02d%02d%02d.%02d,A," ,
+                      svMeta.talker, utcHours, utcMinutes, utcSeconds,utcMSeconds/10);
+
+    if (length < 0 || length >= lengthRemaining) {
+        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+        return;
+    }
+    pMarker += length;
+    lengthRemaining -= length;
+
+    if (ulpLocation.gpsLocation.flags & LOC_GPS_LOCATION_HAS_LAT_LONG) {
+        double latitude = ulpLocation.gpsLocation.latitude;
+        double longitude = ulpLocation.gpsLocation.longitude;
+        char latHemisphere;
+        char lonHemisphere;
+        double latMinutes;
+        double lonMinutes;
+
+        if (latitude > 0) {
+            latHemisphere = 'N';
+        } else {
+            latHemisphere = 'S';
+            latitude *= -1.0;
+        }
+
+        if (longitude < 0) {
+            lonHemisphere = 'W';
+            longitude *= -1.0;
+        } else {
+            lonHemisphere = 'E';
+        }
+
+        latMinutes = fmod(latitude * 60.0 , 60.0);
+        lonMinutes = fmod(longitude * 60.0 , 60.0);
+
+        length = snprintf(pMarker, lengthRemaining, "%02d%09.6lf,%c,%03d%09.6lf,%c,",
+                          (uint8_t)floor(latitude), latMinutes, latHemisphere,
+                          (uint8_t)floor(longitude),lonMinutes, lonHemisphere);
+    } else {
+        length = snprintf(pMarker, lengthRemaining,",,,,");
+    }
+
+    if (length < 0 || length >= lengthRemaining) {
+        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+        return;
+    }
+    pMarker += length;
+    lengthRemaining -= length;
+
+    if (ulpLocation.gpsLocation.flags & LOC_GPS_LOCATION_HAS_SPEED) {
+        float speedKnots = ulpLocation.gpsLocation.speed * (3600.0/1852.0);
+        length = snprintf(pMarker, lengthRemaining, "%.1lf,", speedKnots);
+    } else {
+        length = snprintf(pMarker, lengthRemaining, ",");
+    }
+
+    if (length < 0 || length >= lengthRemaining) {
+        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+        return;
+    }
+    pMarker += length;
+    lengthRemaining -= length;
+
+    if (ulpLocation.gpsLocation.flags & LOC_GPS_LOCATION_HAS_BEARING) {
+        length = snprintf(pMarker, lengthRemaining, "%.1lf,", ulpLocation.gpsLocation.bearing);
+    } else {
+        length = snprintf(pMarker, lengthRemaining, ",");
+    }
+
+    if (length < 0 || length >= lengthRemaining) {
+        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+        return;
+    }
+    pMarker += length;
+    lengthRemaining -= length;
+
+    length = snprintf(pMarker, lengthRemaining, "%2.2d%2.2d%2.2d,",
+                      utcDay, utcMonth, utcYear);
+
+    if (length < 0 || length >= lengthRemaining) {
+        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+        return;
+    }
+    pMarker += length;
+    lengthRemaining -= length;
+
+    if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_MAG_DEV) {
+        float magneticVariation = locationExtended.magneticDeviation;
+        char direction;
+        if (magneticVariation < 0.0) {
+            direction = 'W';
+            magneticVariation *= -1.0;
+        } else {
+            direction = 'E';
+        }
+
+        length = snprintf(pMarker, lengthRemaining, "%.1lf,%c,",
+                          magneticVariation, direction);
+    } else {
+        length = snprintf(pMarker, lengthRemaining, ",,");
+    }
+
+    if (length < 0 || length >= lengthRemaining) {
+        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+        return;
+    }
+    pMarker += length;
+    lengthRemaining -= length;
+
+    if (!(ulpLocation.gpsLocation.flags & LOC_GPS_LOCATION_HAS_LAT_LONG)) {
+        length = snprintf(pMarker, lengthRemaining, "%c", 'N'); // N means no fix
+    } else if (GNSS_SUPL_MODE_STANDALONE == mSuplMode) {
+        length = snprintf(pMarker, lengthRemaining, "%c", 'A'); // A means autonomous
+    } else {
+        length = snprintf(pMarker, lengthRemaining, "%c", 'D'); // D means differential
+    }
+
+    length = nmeaPutChecksum(sentence, size);
+    reportNmeaEvent(sentence, length);
+}
+
+void
+GnssAdapter::generateNmeaGGA(const UlpLocation& ulpLocation,
+                             const GpsLocationExtended& locationExtended,
+                             NmeaSvMeta& svMeta, tm& utcTime, uint32_t svUsedCount,
+                             char* sentence, size_t size)
+{
+    if (!sentence || size == 0) {
+        LOC_LOGE("NMEA Error invalid arguments.");
+        return;
+    }
+
+    int utcYear = utcTime.tm_year % 100; // 2 digit year
+    int utcMonth = utcTime.tm_mon + 1; // tm_mon starts at zero
+    int utcDay = utcTime.tm_mday;
+    int utcHours = utcTime.tm_hour;
+    int utcMinutes = utcTime.tm_min;
+    int utcSeconds = utcTime.tm_sec;
+    int utcMSeconds = (ulpLocation.gpsLocation.timestamp)%1000;
+
+    char* pMarker = sentence;
+    int lengthRemaining = size;
+    int length = 0;
+
+    length = snprintf(pMarker, lengthRemaining, "$%sGGA,%02d%02d%02d.%02d," ,
+                      svMeta.talker, utcHours, utcMinutes, utcSeconds, utcMSeconds/10);
+
+    if (length < 0 || length >= lengthRemaining) {
+        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+        return;
+    }
+    pMarker += length;
+    lengthRemaining -= length;
+
+    if (ulpLocation.gpsLocation.flags & LOC_GPS_LOCATION_HAS_LAT_LONG) {
+        double latitude = ulpLocation.gpsLocation.latitude;
+        double longitude = ulpLocation.gpsLocation.longitude;
+        char latHemisphere;
+        char lonHemisphere;
+        double latMinutes;
+        double lonMinutes;
+
+        if (latitude > 0) {
+            latHemisphere = 'N';
+        } else {
+            latHemisphere = 'S';
+            latitude *= -1.0;
+        }
+
+        if (longitude < 0) {
+            lonHemisphere = 'W';
+            longitude *= -1.0;
+        } else {
+            lonHemisphere = 'E';
+        }
+
+        latMinutes = fmod(latitude * 60.0 , 60.0);
+        lonMinutes = fmod(longitude * 60.0 , 60.0);
+
+        length = snprintf(pMarker, lengthRemaining, "%02d%09.6lf,%c,%03d%09.6lf,%c,",
+                          (uint8_t)floor(latitude), latMinutes, latHemisphere,
+                          (uint8_t)floor(longitude),lonMinutes, lonHemisphere);
+    } else {
+        length = snprintf(pMarker, lengthRemaining,",,,,");
+    }
+
+    if (length < 0 || length >= lengthRemaining) {
+        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+        return;
+    }
+    pMarker += length;
+    lengthRemaining -= length;
+
+    char gpsQuality;
+    if (!(ulpLocation.gpsLocation.flags & LOC_GPS_LOCATION_HAS_LAT_LONG)) {
+        gpsQuality = '0'; // 0 means no fix
+    } else if (GNSS_SUPL_MODE_STANDALONE == mSuplMode) {
+        gpsQuality = '1'; // 1 means GPS fix
+    } else {
+        gpsQuality = '2'; // 2 means DGPS fix
+    }
+
+    // Number of satellites in use, 00-12
+    if (svUsedCount > MAX_SATELLITES_IN_USE) {
+        svUsedCount = MAX_SATELLITES_IN_USE;
+    }
+
+    // Add the position/horizontal/vertical DOP values
+    if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_DOP) {
+        length = snprintf(pMarker, lengthRemaining, "%c,%02d,%.1f,",
+                          gpsQuality, svUsedCount, locationExtended.hdop);
+    } else {
+        length = snprintf(pMarker, lengthRemaining, "%c,%02d,,",
+                          gpsQuality, svUsedCount);
+    }
+
+    if (length < 0 || length >= lengthRemaining) {
+        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+        return;
+    }
+    pMarker += length;
+    lengthRemaining -= length;
+
+    if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL) {
+        length = snprintf(pMarker, lengthRemaining, "%.1lf,M,",
+                          locationExtended.altitudeMeanSeaLevel);
+    } else {
+        length = snprintf(pMarker, lengthRemaining,",,");
+    }
+
+    if (length < 0 || length >= lengthRemaining) {
+        LOC_LOGE("%s:%d]: NMEA Error in string formatting", __func__, __LINE__);
+        return;
+    }
+    pMarker += length;
+    lengthRemaining -= length;
+
+    if ((ulpLocation.gpsLocation.flags & LOC_GPS_LOCATION_HAS_ALTITUDE) &&
+        (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL)) {
+        length = snprintf(pMarker, lengthRemaining, "%.1lf,M,,",
+                          ulpLocation.gpsLocation.altitude - locationExtended.altitudeMeanSeaLevel);
+    } else {
+        length = snprintf(pMarker, lengthRemaining,",,,");
+    }
+
+    length = nmeaPutChecksum(sentence, size);
+    reportNmeaEvent(sentence, length);
+}
+
+/* INIT LOC AGPS MANAGER */
+void GnssAdapter::initAgpsCommand(void* statusV4Cb){
+
+    LOC_LOGI("GnssAdapter::initAgpsCommand");
+
+    /* Set ATL open/close callbacks */
+    AgpsAtlOpenStatusCb atlOpenStatusCb =
+            [this](int handle, int isSuccess, char* apn,
+                    AGpsBearerType bearerType, AGpsExtType agpsType) {
+
+                mLocApi->atlOpenStatus(
+                        handle, isSuccess, apn, bearerType, agpsType);
+            };
+    AgpsAtlCloseStatusCb atlCloseStatusCb =
+            [this](int handle, int isSuccess) {
+
+                mLocApi->atlCloseStatus(handle, isSuccess);
+            };
+
+    /* Register DS Client APIs */
+    AgpsDSClientInitFn dsClientInitFn =
+            [this](bool isDueToSSR) {
+
+                return mLocApi->initDataServiceClient(isDueToSSR);
+            };
+
+    AgpsDSClientOpenAndStartDataCallFn dsClientOpenAndStartDataCallFn =
+            [this] {
+
+                return mLocApi->openAndStartDataCall();
+            };
+
+    AgpsDSClientStopDataCallFn dsClientStopDataCallFn =
+            [this] {
+
+                mLocApi->stopDataCall();
+            };
+
+    AgpsDSClientCloseDataCallFn dsClientCloseDataCallFn =
+            [this] {
+
+                mLocApi->closeDataCall();
+            };
+
+    AgpsDSClientReleaseFn dsClientReleaseFn =
+            [this] {
+
+                mLocApi->releaseDataServiceClient();
+            };
+
+    /* Send Msg function */
+    SendMsgToAdapterMsgQueueFn sendMsgFn =
+            [this](LocMsg* msg) {
+
+                sendMsg(msg);
+            };
+
+    /* Message to initialize AGPS module */
+    struct AgpsMsgInit: public LocMsg {
+
+        AgpsManager* mAgpsManager;
+
+        AgpsFrameworkInterface::AgnssStatusIpV4Cb mFrameworkStatusV4Cb;
+
+        AgpsAtlOpenStatusCb mAtlOpenStatusCb;
+        AgpsAtlCloseStatusCb mAtlCloseStatusCb;
+
+        AgpsDSClientInitFn mDSClientInitFn;
+        AgpsDSClientOpenAndStartDataCallFn mDSClientOpenAndStartDataCallFn;
+        AgpsDSClientStopDataCallFn mDSClientStopDataCallFn;
+        AgpsDSClientCloseDataCallFn mDSClientCloseDataCallFn;
+        AgpsDSClientReleaseFn mDSClientReleaseFn;
+
+        SendMsgToAdapterMsgQueueFn mSendMsgFn;
+
+        inline AgpsMsgInit(AgpsManager* agpsManager,
+                AgpsFrameworkInterface::AgnssStatusIpV4Cb frameworkStatusV4Cb,
+                AgpsAtlOpenStatusCb atlOpenStatusCb,
+                AgpsAtlCloseStatusCb atlCloseStatusCb,
+                AgpsDSClientInitFn dsClientInitFn,
+                AgpsDSClientOpenAndStartDataCallFn dsClientOpenAndStartDataCallFn,
+                AgpsDSClientStopDataCallFn dsClientStopDataCallFn,
+                AgpsDSClientCloseDataCallFn dsClientCloseDataCallFn,
+                AgpsDSClientReleaseFn dsClientReleaseFn,
+                SendMsgToAdapterMsgQueueFn sendMsgFn) :
+                LocMsg(), mAgpsManager(agpsManager), mFrameworkStatusV4Cb(
+                        frameworkStatusV4Cb), mAtlOpenStatusCb(atlOpenStatusCb), mAtlCloseStatusCb(
+                        atlCloseStatusCb), mDSClientInitFn(dsClientInitFn), mDSClientOpenAndStartDataCallFn(
+                        dsClientOpenAndStartDataCallFn), mDSClientStopDataCallFn(
+                        dsClientStopDataCallFn), mDSClientCloseDataCallFn(
+                        dsClientCloseDataCallFn), mDSClientReleaseFn(
+                        dsClientReleaseFn), mSendMsgFn(sendMsgFn) {
+
+            LOC_LOGV("AgpsMsgInit");
+        }
+
+        inline virtual void proc() const {
+
+            LOC_LOGV("AgpsMsgInit::proc()");
+
+            mAgpsManager->registerCallbacks(mFrameworkStatusV4Cb, mAtlOpenStatusCb,
+                    mAtlCloseStatusCb, mDSClientInitFn,
+                    mDSClientOpenAndStartDataCallFn, mDSClientStopDataCallFn,
+                    mDSClientCloseDataCallFn, mDSClientReleaseFn, mSendMsgFn);
+
+            mAgpsManager->createAgpsStateMachines();
+        }
+    };
+
+    /* Send message to initialize AGPS Manager */
+    sendMsg(new AgpsMsgInit(
+                &mAgpsManager,
+                (AgpsFrameworkInterface::AgnssStatusIpV4Cb)statusV4Cb,
+                atlOpenStatusCb, atlCloseStatusCb,
+                dsClientInitFn, dsClientOpenAndStartDataCallFn,
+                dsClientStopDataCallFn, dsClientCloseDataCallFn,
+                dsClientReleaseFn,
+                sendMsgFn));
+}
+
+/* GnssAdapter::requestATL
+ * Method triggered in QMI thread as part of handling below message:
+ * eQMI_LOC_SERVER_REQUEST_OPEN_V02
+ * Triggers the AGPS state machine to setup AGPS call for below WWAN types:
+ * eQMI_LOC_WWAN_TYPE_INTERNET_V02
+ * eQMI_LOC_WWAN_TYPE_AGNSS_V02 */
+bool GnssAdapter::requestATL(int connHandle, LocAGpsType agpsType){
+
+    LOC_LOGI("GnssAdapter::requestATL");
+
+    sendMsg( new AgpsMsgRequestATL(
+             &mAgpsManager, connHandle, (AGpsExtType)agpsType));
+
+    return true;
+}
+
+/* GnssAdapter::requestSuplES
+ * Method triggered in QMI thread as part of handling below message:
+ * eQMI_LOC_SERVER_REQUEST_OPEN_V02
+ * Triggers the AGPS state machine to setup AGPS call for below WWAN types:
+ * eQMI_LOC_WWAN_TYPE_AGNSS_EMERGENCY_V02 */
+bool GnssAdapter::requestSuplES(int connHandle){
+
+    LOC_LOGI("GnssAdapter::requestSuplES");
+
+    sendMsg( new AgpsMsgRequestATL(
+             &mAgpsManager, connHandle, LOC_AGPS_TYPE_SUPL_ES));
+
+    return true;
+}
+
+/* GnssAdapter::releaseATL
+ * Method triggered in QMI thread as part of handling below message:
+ * eQMI_LOC_SERVER_REQUEST_CLOSE_V02
+ * Triggers teardown of an existing AGPS call */
+bool GnssAdapter::releaseATL(int connHandle){
+
+    LOC_LOGI("GnssAdapter::releaseATL");
+
+    /* Release SUPL/INTERNET/SUPL_ES ATL */
+    struct AgpsMsgReleaseATL: public LocMsg {
+
+        AgpsManager* mAgpsManager;
+        int mConnHandle;
+
+        inline AgpsMsgReleaseATL(AgpsManager* agpsManager, int connHandle) :
+                LocMsg(), mAgpsManager(agpsManager), mConnHandle(connHandle) {
+
+            LOC_LOGV("AgpsMsgReleaseATL");
+        }
+
+        inline virtual void proc() const {
+
+            LOC_LOGV("AgpsMsgReleaseATL::proc()");
+            mAgpsManager->releaseATL(mConnHandle);
+        }
+    };
+
+    sendMsg( new AgpsMsgReleaseATL(&mAgpsManager, connHandle));
+
+    return true;
+}
+
+/* GnssAdapter::reportDataCallOpened
+ * DS Client data call opened successfully.
+ * Send message to AGPS Manager to handle. */
+bool GnssAdapter::reportDataCallOpened(){
+
+    LOC_LOGI("GnssAdapter::reportDataCallOpened");
+
+    struct AgpsMsgSuplEsOpened: public LocMsg {
+
+        AgpsManager* mAgpsManager;
+
+        inline AgpsMsgSuplEsOpened(AgpsManager* agpsManager) :
+                LocMsg(), mAgpsManager(agpsManager) {
+
+            LOC_LOGV("AgpsMsgSuplEsOpened");
+        }
+
+        inline virtual void proc() const {
+
+            LOC_LOGV("AgpsMsgSuplEsOpened::proc()");
+            mAgpsManager->reportDataCallOpened();
+        }
+    };
+
+    sendMsg( new AgpsMsgSuplEsOpened(&mAgpsManager));
+
+    return true;
+}
+
+/* GnssAdapter::reportDataCallClosed
+ * DS Client data call closed.
+ * Send message to AGPS Manager to handle. */
+bool GnssAdapter::reportDataCallClosed(){
+
+    LOC_LOGI("GnssAdapter::reportDataCallClosed");
+
+    struct AgpsMsgSuplEsClosed: public LocMsg {
+
+        AgpsManager* mAgpsManager;
+
+        inline AgpsMsgSuplEsClosed(AgpsManager* agpsManager) :
+                LocMsg(), mAgpsManager(agpsManager) {
+
+            LOC_LOGV("AgpsMsgSuplEsClosed");
+        }
+
+        inline virtual void proc() const {
+
+            LOC_LOGV("AgpsMsgSuplEsClosed::proc()");
+            mAgpsManager->reportDataCallClosed();
+        }
+    };
+
+    sendMsg( new AgpsMsgSuplEsClosed(&mAgpsManager));
+
+    return true;
+}
+
+void GnssAdapter::dataConnOpenCommand(
+        AGpsExtType agpsType,
+        const char* apnName, int apnLen, LocApnIpType ipType){
+
+    LOC_LOGI("GnssAdapter::frameworkDataConnOpen");
+
+    struct AgpsMsgAtlOpenSuccess: public LocMsg {
+
+        AgpsManager* mAgpsManager;
+        AGpsExtType mAgpsType;
+        char* mApnName;
+        int mApnLen;
+        LocApnIpType mIpType;
+
+        inline AgpsMsgAtlOpenSuccess(AgpsManager* agpsManager, AGpsExtType agpsType,
+                const char* apnName, int apnLen, LocApnIpType ipType) :
+                LocMsg(), mAgpsManager(agpsManager), mAgpsType(agpsType), mApnName(
+                        new char[apnLen + 1]), mApnLen(apnLen), mIpType(ipType) {
+
+            LOC_LOGV("AgpsMsgAtlOpenSuccess");
+            memcpy(mApnName, apnName, apnLen);
+            mApnName[apnLen] = 0;
+        }
+
+        inline ~AgpsMsgAtlOpenSuccess() {
+            delete[] mApnName;
+        }
+
+        inline virtual void proc() const {
+
+            LOC_LOGV("AgpsMsgAtlOpenSuccess::proc()");
+            mAgpsManager->reportAtlOpenSuccess(mAgpsType, mApnName, mApnLen,
+                    mIpType);
+        }
+    };
+
+    sendMsg( new AgpsMsgAtlOpenSuccess(
+            &mAgpsManager, (AGpsExtType)agpsType, apnName, apnLen, ipType));
+}
+
+void GnssAdapter::dataConnClosedCommand(AGpsExtType agpsType){
+
+    LOC_LOGI("GnssAdapter::frameworkDataConnClosed");
+
+    struct AgpsMsgAtlClosed: public LocMsg {
+
+        AgpsManager* mAgpsManager;
+        AGpsExtType mAgpsType;
+
+        inline AgpsMsgAtlClosed(AgpsManager* agpsManager, AGpsExtType agpsType) :
+                LocMsg(), mAgpsManager(agpsManager), mAgpsType(agpsType) {
+
+            LOC_LOGV("AgpsMsgAtlClosed");
+        }
+
+        inline virtual void proc() const {
+
+            LOC_LOGV("AgpsMsgAtlClosed::proc()");
+            mAgpsManager->reportAtlClosed(mAgpsType);
+        }
+    };
+
+    sendMsg( new AgpsMsgAtlClosed(&mAgpsManager, (AGpsExtType)agpsType));
+}
+
+void GnssAdapter::dataConnFailedCommand(AGpsExtType agpsType){
+
+    LOC_LOGI("GnssAdapter::frameworkDataConnFailed");
+
+    struct AgpsMsgAtlOpenFailed: public LocMsg {
+
+        AgpsManager* mAgpsManager;
+        AGpsExtType mAgpsType;
+
+        inline AgpsMsgAtlOpenFailed(AgpsManager* agpsManager, AGpsExtType agpsType) :
+                LocMsg(), mAgpsManager(agpsManager), mAgpsType(agpsType) {
+
+            LOC_LOGV("AgpsMsgAtlOpenFailed");
+        }
+
+        inline virtual void proc() const {
+
+            LOC_LOGV("AgpsMsgAtlOpenFailed::proc()");
+            mAgpsManager->reportAtlOpenFailed(mAgpsType);
+        }
+    };
+
+    sendMsg( new AgpsMsgAtlOpenFailed(&mAgpsManager, (AGpsExtType)agpsType));
+}
diff --git a/msm8998/gnss/GnssAdapter.h b/msm8998/gnss/GnssAdapter.h
new file mode 100644
index 0000000..cfba4ed
--- /dev/null
+++ b/msm8998/gnss/GnssAdapter.h
@@ -0,0 +1,279 @@
+/* Copyright (c) 2017, 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 GNSS_ADAPTER_H
+#define GNSS_ADAPTER_H
+
+#include <LocAdapterBase.h>
+#include <LocDualContext.h>
+#include <UlpProxyBase.h>
+#include <LocationAPI.h>
+#include <Agps.h>
+
+#define MAX_URL_LEN 256
+#define NMEA_SENTENCE_MAX_LENGTH 200
+#define GLONASS_SV_ID_OFFSET 64
+#define MAX_SATELLITES_IN_USE 12
+#define LOC_NI_NO_RESPONSE_TIME 20
+#define LOC_GPS_NI_RESPONSE_IGNORE 4
+
+class GnssAdapter;
+
+typedef struct {
+    pthread_t               thread;        /* NI thread */
+    uint32_t                respTimeLeft;  /* examine time for NI response */
+    bool                    respRecvd;     /* NI User reponse received or not from Java layer*/
+    void*                   rawRequest;
+    uint32_t                reqID;         /* ID to check against response */
+    GnssNiResponse          resp;
+    pthread_cond_t          tCond;
+    pthread_mutex_t         tLock;
+    GnssAdapter*            adapter;
+} NiSession;
+typedef struct {
+    NiSession session;    /* SUPL NI Session */
+    NiSession sessionEs;  /* Emergency SUPL NI Session */
+    uint32_t reqIDCounter;
+} NiData;
+
+typedef enum {
+    NMEA_PROVIDER_AP = 0, // Application Processor Provider of NMEA
+    NMEA_PROVIDER_MP      // Modem Processor Provider of NMEA
+} NmeaProviderType;
+typedef struct {
+    GnssSvType svType;
+    const char* talker;
+    uint64_t mask;
+    uint32_t svIdOffset;
+} NmeaSvMeta;
+
+using namespace loc_core;
+
+class GnssAdapter : public LocAdapterBase {
+    /* ==== ULP ============================================================================ */
+    UlpProxyBase* mUlpProxy;
+
+    /* ==== CLIENT ========================================================================= */
+    typedef std::map<LocationAPI*, LocationCallbacks> ClientDataMap;
+    ClientDataMap mClientData;
+
+    /* ==== TRACKING ======================================================================= */
+    LocationSessionMap mTrackingSessions;
+    GnssSuplMode mSuplMode;
+    LocPosMode mUlpPositionMode;
+    GnssSvUsedInPosition mGnssSvIdUsedInPosition;
+    bool mGnssSvIdUsedInPosAvail;
+
+    /* ==== CONTROL ======================================================================== */
+    LocationControlCallbacks mControlCallbacks;
+    uint32_t mPowerVoteId;
+
+    /* ==== NI ============================================================================= */
+    NiData mNiData;
+
+    /* ==== AGPS ========================================================*/
+    // This must be initialized via initAgps()
+    AgpsManager mAgpsManager;
+
+    /*==== CONVERSION ===================================================================*/
+    static void convertOptions(LocPosMode& out, const LocationOptions& options);
+    static void convertLocation(Location& out, const LocGpsLocation& locGpsLocation,
+                                const LocPosTechMask techMask);
+    static void convertLocationInfo(GnssLocationInfoNotification& out,
+                                    const GpsLocationExtended& locationExtended);
+
+public:
+
+    GnssAdapter();
+    virtual ~GnssAdapter();
+
+    /* ==== SSR ============================================================================ */
+    /* ======== EVENTS ====(Called from QMI Thread)========================================= */
+    virtual void handleEngineUpEvent();
+    /* ======== UTILITIES ================================================================== */
+    void restartSessions();
+
+    /* ==== ULP ============================================================================ */
+    /* ======== COMMANDS ====(Called from ULP Thread)==================================== */
+    virtual void setUlpProxyCommand(UlpProxyBase* ulp);
+    /* ======== UTILITIES ================================================================== */
+    void setUlpProxy(UlpProxyBase* ulp);
+    inline UlpProxyBase* getUlpProxy() { return mUlpProxy; }
+
+    /* ==== CLIENT ========================================================================= */
+    /* ======== COMMANDS ====(Called from Client Thread)==================================== */
+    void addClientCommand(LocationAPI* client, const LocationCallbacks& callbacks);
+    void removeClientCommand(LocationAPI* client);
+    void requestCapabilitiesCommand(LocationAPI* client);
+    /* ======== UTILITIES ================================================================== */
+    void saveClient(LocationAPI* client, const LocationCallbacks& callbacks);
+    void eraseClient(LocationAPI* client);
+    void updateClientsEventMask();
+    void stopClientSessions(LocationAPI* client);
+    LocationCallbacks getClientCallbacks(LocationAPI* client);
+
+    /* ==== TRACKING ======================================================================= */
+    /* ======== COMMANDS ====(Called from Client Thread)==================================== */
+    uint32_t startTrackingCommand(LocationAPI* client, LocationOptions& options);
+    void updateTrackingOptionsCommand(LocationAPI* client, uint32_t id, LocationOptions& options);
+    void stopTrackingCommand(LocationAPI* client, uint32_t id);
+    /* ======================(Called from ULP Thread)======================================= */
+    virtual void setPositionModeCommand(LocPosMode& locPosMode);
+    virtual void startTrackingCommand();
+    virtual void stopTrackingCommand();
+    virtual void getZppCommand();
+    /* ======== RESPONSES ================================================================== */
+    void reportResponse(LocationAPI* client, LocationError err, uint32_t sessionId);
+    /* ======== UTILITIES ================================================================== */
+    bool hasTrackingCallback(LocationAPI* client);
+    bool hasMeasurementsCallback(LocationAPI* client);
+    bool isTrackingSession(LocationAPI* client, uint32_t sessionId);
+    void saveTrackingSession(LocationAPI* client, uint32_t sessionId,
+                             const LocationOptions& options);
+    void eraseTrackingSession(LocationAPI* client, uint32_t sessionId);
+    void setUlpPositionMode(const LocPosMode& mode) { mUlpPositionMode = mode; }
+    LocPosMode& getUlpPositionMode() { return mUlpPositionMode; }
+    void setSuplMode(GnssSuplMode mode) { mSuplMode = mode; }
+    LocationError startTrackingMultiplex(const LocationOptions& options);
+    LocationError startTracking(const LocationOptions& options);
+    LocationError stopTrackingMultiplex(LocationAPI* client, uint32_t id);
+    LocationError stopTracking();
+
+    /* ==== NI ============================================================================= */
+    /* ======== COMMANDS ====(Called from Client Thread)==================================== */
+    void gnssNiResponseCommand(LocationAPI* client, uint32_t id, GnssNiResponse response);
+    /* ======================(Called from NI Thread)======================================== */
+    void gnssNiResponseCommand(GnssNiResponse response, void* rawRequest);
+    /* ======== UTILITIES ================================================================== */
+    bool hasNiNotifyCallback(LocationAPI* client);
+    NiData& getNiData() { return mNiData; }
+
+    /* ==== CONTROL ======================================================================== */
+    /* ======== COMMANDS ====(Called from Client Thread)==================================== */
+    uint32_t enableCommand(LocationTechnologyType techType);
+    void disableCommand(uint32_t id);
+    void setControlCallbacksCommand(LocationControlCallbacks& controlCallbacks);
+    void readConfigCommand();
+    void setConfigCommand();
+    uint32_t* gnssUpdateConfigCommand(GnssConfig config);
+    uint32_t gnssDeleteAidingDataCommand(GnssAidingData& data);
+
+    void initAgpsCommand(void* statusV4Cb);
+    void dataConnOpenCommand(
+            AGpsExtType agpsType,
+            const char* apnName, int apnLen, LocApnIpType ipType);
+    void dataConnClosedCommand(AGpsExtType agpsType);
+    void dataConnFailedCommand(AGpsExtType agpsType);
+
+    /* ======== RESPONSES ================================================================== */
+    void reportResponse(LocationError err, uint32_t sessionId);
+    void reportResponse(size_t count, LocationError* errs, uint32_t* ids);
+    /* ======== UTILITIES ================================================================== */
+    LocationControlCallbacks& getControlCallbacks() { return mControlCallbacks; }
+    void setControlCallbacks(const LocationControlCallbacks& controlCallbacks)
+    { mControlCallbacks = controlCallbacks; }
+    void setPowerVoteId(uint32_t id) { mPowerVoteId = id; }
+    uint32_t getPowerVoteId() { return mPowerVoteId; }
+    bool resolveInAddress(const char* hostAddress, struct in_addr* inAddress);
+
+    /* ==== REPORTS ======================================================================== */
+    /* ======== EVENTS ====(Called from QMI/ULP Thread)===================================== */
+    virtual void reportPositionEvent(const UlpLocation& ulpLocation,
+                                     const GpsLocationExtended& locationExtended,
+                                     enum loc_sess_status status,
+                                     LocPosTechMask techMask,
+                                     bool fromUlp=false);
+    virtual void reportSvEvent(const GnssSvNotification& svNotify, bool fromUlp=false);
+    virtual void reportNmeaEvent(const char* nmea, size_t length, bool fromUlp=false);
+    virtual bool requestNiNotifyEvent(const GnssNiNotification& notify, const void* data);
+    virtual void reportGnssMeasurementDataEvent(const GnssMeasurementsNotification& measurementsNotify);
+    virtual void reportSvMeasurementEvent(GnssSvMeasurementSet &svMeasurementSet);
+    virtual void reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial);
+
+    virtual bool requestATL(int connHandle, LocAGpsType agps_type);
+    virtual bool releaseATL(int connHandle);
+    virtual bool requestSuplES(int connHandle);
+    virtual bool reportDataCallOpened();
+    virtual bool reportDataCallClosed();
+
+    /* ======== UTILITIES ================================================================= */
+    void reportPosition(const UlpLocation &ulpLocation,
+                        const GpsLocationExtended &locationExtended,
+                        enum loc_sess_status status,
+                        LocPosTechMask techMask);
+    void reportSv(GnssSvNotification& svNotify);
+    void reportNmea(const char* nmea, size_t length);
+    bool requestNiNotify(const GnssNiNotification& notify, const void* data);
+    void reportGnssMeasurementData(const GnssMeasurementsNotification& measurementsNotify);
+
+    /*==== NMEA Generation =============================================================== */
+    /*======== SVS ======================================================================= */
+    void generateNmea(const GnssSvNotification& svNotify);
+    void generateNmeaGSV(const GnssSvNotification& svNotify,
+                         NmeaSvMeta& svMeta, char* sentence, size_t size);
+    /*======== POSITION ================================================================== */
+    void generateNmea(const UlpLocation& ulpLocation,
+                      const GpsLocationExtended& locationExtended);
+    void generateNmeaBlank();
+    uint8_t generateNmeaGSA(const GpsLocationExtended& locationExtended,
+                            NmeaSvMeta& svMeta, char* sentence, size_t size);
+    void generateNmeaVTG(const UlpLocation& ulpLocation,
+                         const GpsLocationExtended& locationExtended,
+                         NmeaSvMeta& svMeta, char* sentence, size_t size);
+    void generateNmeaRMC(const UlpLocation& ulpLocation,
+                         const GpsLocationExtended& locationExtended,
+                         NmeaSvMeta& svMeta, tm& utcTime, char* sentence, size_t size);
+    void generateNmeaGGA(const UlpLocation& ulpLocation,
+                         const GpsLocationExtended& locationExtended,
+                         NmeaSvMeta& svMeta, tm& utcTime, uint32_t svUsedCount,
+                         char* sentence, size_t size);
+    /*======== UTILITIES ================================================================*/
+    int nmeaPutChecksum(char *nmea, size_t maxSize);
+
+    /*==== CONVERSION ===================================================================*/
+    static uint32_t convertGpsLock(const GnssConfigGpsLock gpsLock);
+    static GnssConfigGpsLock convertGpsLock(const uint32_t gpsLock);
+    static uint32_t convertSuplVersion(const GnssConfigSuplVersion suplVersion);
+    static GnssConfigSuplVersion convertSuplVersion(const uint32_t suplVersion);
+    static uint32_t convertLppProfile(const GnssConfigLppProfile lppProfile);
+    static GnssConfigLppProfile convertLppProfile(const uint32_t lppProfile);
+    static uint32_t convertEP4ES(const GnssConfigEmergencyPdnForEmergencySupl);
+    static uint32_t convertSuplEs(const GnssConfigSuplEmergencyServices suplEmergencyServices);
+    static uint32_t convertLppeCp(const GnssConfigLppeControlPlaneMask lppeControlPlaneMask);
+    static GnssConfigLppeControlPlaneMask convertLppeCp(const uint32_t lppeControlPlaneMask);
+    static uint32_t convertLppeUp(const GnssConfigLppeUserPlaneMask lppeUserPlaneMask);
+    static GnssConfigLppeUserPlaneMask convertLppeUp(const uint32_t lppeUserPlaneMask);
+    static uint32_t convertAGloProt(const GnssConfigAGlonassPositionProtocolMask);
+    static uint32_t convertSuplMode(const GnssConfigSuplModeMask suplModeMask);
+    
+    void injectLocationCommand(double latitude, double longitude, float accuracy);
+    void injectTimeCommand(int64_t time, int64_t timeReference, int32_t uncertainty);
+
+};
+
+#endif //GNSS_ADAPTER_H
diff --git a/msm8998/gnss/location_gnss.cpp b/msm8998/gnss/location_gnss.cpp
new file mode 100644
index 0000000..0995f4b
--- /dev/null
+++ b/msm8998/gnss/location_gnss.cpp
@@ -0,0 +1,241 @@
+/* Copyright (c) 2017, 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 "GnssAdapter.h"
+#include "location_interface.h"
+
+static GnssAdapter* gGnssAdapter = NULL;
+
+static void initialize();
+static void deinitialize();
+
+static void addClient(LocationAPI* client, const LocationCallbacks& callbacks);
+static void removeClient(LocationAPI* client);
+static void requestCapabilities(LocationAPI* client);
+
+static uint32_t startTracking(LocationAPI* client, LocationOptions& options);
+static void updateTrackingOptions(LocationAPI* client, uint32_t id, LocationOptions& options);
+static void stopTracking(LocationAPI* client, uint32_t id);
+
+static void gnssNiResponse(LocationAPI* client, uint32_t id, GnssNiResponse response);
+static uint32_t gnssDeleteAidingData(GnssAidingData& data);
+
+static void setControlCallbacks(LocationControlCallbacks& controlCallbacks);
+static uint32_t enable(LocationTechnologyType techType);
+static void disable(uint32_t id);
+static uint32_t* gnssUpdateConfig(GnssConfig config);
+
+static void injectLocation(double latitude, double longitude, float accuracy);
+static void injectTime(int64_t time, int64_t timeReference, int32_t uncertainty);
+
+static void agpsInit(void* statusV4Cb);
+static void agpsDataConnOpen(AGpsExtType agpsType, const char* apnName, int apnLen, int ipType);
+static void agpsDataConnClosed(AGpsExtType agpsType);
+static void agpsDataConnFailed(AGpsExtType agpsType);
+
+static const GnssInterface gGnssInterface = {
+    sizeof(GnssInterface),
+    initialize,
+    deinitialize,
+    addClient,
+    removeClient,
+    requestCapabilities,
+    startTracking,
+    updateTrackingOptions,
+    stopTracking,
+    gnssNiResponse,
+    setControlCallbacks,
+    enable,
+    disable,
+    gnssUpdateConfig,
+    gnssDeleteAidingData,
+    injectLocation,
+    injectTime,
+    agpsInit,
+    agpsDataConnOpen,
+    agpsDataConnClosed,
+    agpsDataConnFailed
+};
+
+#ifndef DEBUG_X86
+extern "C" const GnssInterface* getGnssInterface()
+#else
+const GnssInterface* getGnssInterface()
+#endif // DEBUG_X86
+{
+   return &gGnssInterface;
+}
+
+static void initialize()
+{
+    if (NULL == gGnssAdapter) {
+        gGnssAdapter = new GnssAdapter();
+    }
+}
+
+static void deinitialize()
+{
+    if (NULL != gGnssAdapter) {
+        delete gGnssAdapter;
+        gGnssAdapter = NULL;
+    }
+}
+
+static void addClient(LocationAPI* client, const LocationCallbacks& callbacks)
+{
+    if (NULL != gGnssAdapter) {
+        gGnssAdapter->addClientCommand(client, callbacks);
+    }
+}
+
+static void removeClient(LocationAPI* client)
+{
+    if (NULL != gGnssAdapter) {
+        gGnssAdapter->removeClientCommand(client);
+    }
+}
+
+static void requestCapabilities(LocationAPI* client)
+{
+    if (NULL != gGnssAdapter) {
+        gGnssAdapter->requestCapabilitiesCommand(client);
+    }
+}
+
+static uint32_t startTracking(LocationAPI* client, LocationOptions& options)
+{
+    if (NULL != gGnssAdapter) {
+        return gGnssAdapter->startTrackingCommand(client, options);
+    } else {
+        return 0;
+    }
+}
+
+static void updateTrackingOptions(LocationAPI* client, uint32_t id, LocationOptions& options)
+{
+    if (NULL != gGnssAdapter) {
+        gGnssAdapter->updateTrackingOptionsCommand(client, id, options);
+    }
+}
+
+static void stopTracking(LocationAPI* client, uint32_t id)
+{
+    if (NULL != gGnssAdapter) {
+        gGnssAdapter->stopTrackingCommand(client, id);
+    }
+}
+
+static void gnssNiResponse(LocationAPI* client, uint32_t id, GnssNiResponse response)
+{
+    if (NULL != gGnssAdapter) {
+        gGnssAdapter->gnssNiResponseCommand(client, id, response);
+    }
+}
+
+static void setControlCallbacks(LocationControlCallbacks& controlCallbacks)
+{
+    if (NULL != gGnssAdapter) {
+        return gGnssAdapter->setControlCallbacksCommand(controlCallbacks);
+    }
+}
+
+static uint32_t enable(LocationTechnologyType techType)
+{
+    if (NULL != gGnssAdapter) {
+        return gGnssAdapter->enableCommand(techType);
+    } else {
+        return 0;
+    }
+}
+
+static void disable(uint32_t id)
+{
+    if (NULL != gGnssAdapter) {
+        return gGnssAdapter->disableCommand(id);
+    }
+}
+
+static uint32_t* gnssUpdateConfig(GnssConfig config)
+{
+    if (NULL != gGnssAdapter) {
+        return gGnssAdapter->gnssUpdateConfigCommand(config);
+    } else {
+        return NULL;
+    }
+}
+
+static uint32_t gnssDeleteAidingData(GnssAidingData& data)
+{
+    if (NULL != gGnssAdapter) {
+        return gGnssAdapter->gnssDeleteAidingDataCommand(data);
+    } else {
+        return NULL;
+    }
+}
+
+static void injectLocation(double latitude, double longitude, float accuracy)
+{
+   if (NULL != gGnssAdapter) {
+       gGnssAdapter->injectLocationCommand(latitude, longitude, accuracy);
+   }
+}
+
+static void injectTime(int64_t time, int64_t timeReference, int32_t uncertainty)
+{
+   if (NULL != gGnssAdapter) {
+       gGnssAdapter->injectTimeCommand(time, timeReference, uncertainty);
+   }
+}
+
+static void agpsInit(void* statusV4Cb) {
+
+    if (NULL != gGnssAdapter) {
+        gGnssAdapter->initAgpsCommand(statusV4Cb);
+    }
+}
+static void agpsDataConnOpen(
+        AGpsExtType agpsType, const char* apnName, int apnLen, int ipType) {
+
+    if (NULL != gGnssAdapter) {
+        gGnssAdapter->dataConnOpenCommand(
+                agpsType, apnName, apnLen, ipType);
+    }
+}
+static void agpsDataConnClosed(AGpsExtType agpsType) {
+
+    if (NULL != gGnssAdapter) {
+        gGnssAdapter->dataConnClosedCommand(agpsType);
+    }
+}
+static void agpsDataConnFailed(AGpsExtType agpsType) {
+
+    if (NULL != gGnssAdapter) {
+        gGnssAdapter->dataConnFailedCommand(agpsType);
+    }
+}
diff --git a/msm8998/loc_api/Android.mk b/msm8998/loc_api/Android.mk
deleted file mode 100644
index 743b386..0000000
--- a/msm8998/loc_api/Android.mk
+++ /dev/null
@@ -1,17 +0,0 @@
-ifneq ($(BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE),)
-
-LOCAL_PATH := $(call my-dir)
-
-# add RPC dirs if RPC is available
-ifneq ($(TARGET_NO_RPC),true)
-
-GPS_DIR_LIST += $(LOCAL_PATH)/libloc_api-rpc-50001/
-
-endif #TARGET_NO_RPC
-
-GPS_DIR_LIST += $(LOCAL_PATH)/libloc_api_50001/
-
-#call the subfolders
-include $(addsuffix Android.mk, $(GPS_DIR_LIST))
-
-endif#BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE
diff --git a/msm8998/loc_api/Makefile.am b/msm8998/loc_api/Makefile.am
deleted file mode 100644
index d9ae87a..0000000
--- a/msm8998/loc_api/Makefile.am
+++ /dev/null
@@ -1,120 +0,0 @@
-AM_CFLAGS = \
-     -I./ \
-     -I../core \
-     -I./libloc_api_50001 \
-     -I../utils \
-     $(LOCPLA_CFLAGS) \
-     -fno-short-enums \
-     -D__func__=__PRETTY_FUNCTION__ \
-     -DTARGET_USES_QCOM_BSP \
-     -std=c++11
-
-AM_CPPFLAGS = \
-     -std=c++11
-
-libloc_eng_so_la_h_sources = \
-     loc_eng_dmn_conn_glue_msg.h \
-     loc_eng_dmn_conn_glue_pipe.h \
-     loc_eng_dmn_conn.h \
-     loc_eng_dmn_conn_handler.h \
-     loc_eng_dmn_conn_thread_helper.h
-
-libloc_eng_so_la_SOURCES = \
-    libloc_api_50001/loc.cpp \
-    libloc_api_50001/loc_eng.cpp \
-    libloc_api_50001/loc_eng_agps.cpp \
-    libloc_api_50001/loc_eng_xtra.cpp \
-    libloc_api_50001/loc_eng_ni.cpp \
-    libloc_api_50001/loc_eng_log.cpp \
-    libloc_api_50001/loc_eng_nmea.cpp \
-    libloc_api_50001/LocEngAdapter.cpp \
-    libloc_api_50001/loc_eng_dmn_conn.cpp \
-    libloc_api_50001/loc_eng_dmn_conn_handler.cpp \
-    libloc_api_50001/loc_eng_dmn_conn_thread_helper.c \
-    libloc_api_50001/loc_eng_dmn_conn_glue_msg.c \
-    libloc_api_50001/loc_eng_dmn_conn_glue_pipe.c
-
-libloc_eng_so_la_SOURCES += libloc_eng_so_la_h_sources
-
-if USE_GLIB
-libloc_eng_so_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@
-libloc_eng_so_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0
-libloc_eng_so_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@
-else
-libloc_eng_so_la_CFLAGS = $(AM_CFLAGS)
-libloc_eng_so_la_LDFLAGS = -Wl,-z,defs -lpthread -shared -version-info 1:0:0
-libloc_eng_so_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS)
-endif
-
-libloc_eng_so_la_LIBADD = -lstdc++ -ldl -llog $(LOCPLA_LIBS) ../utils/libgps_utils_so.la ../core/libloc_core.la
-
-libloc_ds_api_CFLAGS = \
-     $(QMIF_CFLAGS) \
-     $(QMI_CFLAGS) \
-     $(DATA_CFLAGS) \
-     -I$(WORKSPACE)/qcom-opensource/location/loc_api/ds_api
-
-libloc_ds_api_la_SOURCES = \
-     $(WORKSPACE)/qcom-opensource/location/loc_api/ds_api/ds_client.c
-
-if USE_GLIB
-libloc_ds_api_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(libloc_ds_api_CFLAGS) @GLIB_CFLAGS@
-libloc_ds_api_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0
-libloc_ds_api_la_LDFLAGS += -Wl,--export-dynamic
-libloc_ds_api_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(libloc_ds_api_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@
-else
-libloc_ds_api_la_CFLAGS = $(AM_CFLAGS) $(libloc_ds_api_CFLAGS)
-libloc_ds_api_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread -Wl,--export-dynamic -shared -version-info 1:0:0
-libloc_ds_api_la_LDFLAGS += -Wl,--export-dynamic
-libloc_ds_api_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) $(libloc_ds_api_CFLAGS)
-endif
-
-libloc_ds_api_la_LIBADD = -lstdc++ $(QMIF_LIBS) -lqmiservices -ldsi_netctrl $(LOCPLA_LIBS) ../utils/libgps_utils_so.la
-#libloc_ds_api_la_LIBADD = -lstdc++ $(QMIF_LIBS) -lqmiservices $(LOCPLA_LIBS) ../utils/libgps_utils_so.la
-
-libloc_api_v02_CFLAGS = \
-     $(QMIF_CFLAGS) \
-     -I$(WORKSPACE)/qcom-opensource/location/loc_api/ds_api \
-     -I$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02
-
-libloc_api_v02_la_SOURCES = \
-    $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/LocApiV02.cpp \
-    $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_v02_log.c \
-    $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_v02_client.c \
-    $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_sync_req.c \
-    $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/location_service_v02.c
-
-if USE_GLIB
-libloc_api_v02_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(libloc_api_v02_CFLAGS) @GLIB_CFLAGS@
-libloc_api_v02_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0
-libloc_api_v02_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(libloc_api_v02_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@
-else
-libloc_api_v02_la_CFLAGS = $(AM_CFLAGS) $(libloc_api_v02_CFLAGS)
-libloc_api_v02_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread -shared -version-info 1:0:0
-libloc_api_v02_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) $(libloc_api_v02_CFLAGS)
-endif
-
-libloc_api_v02_la_CXXFLAGS = -std=c++0x
-libloc_api_v02_la_LIBADD = -lstdc++ -lqmi_cci -lqmi_common_so $(QMIF_LIBS) $(LOCPLA_LIBS) ../core/libloc_core.la ../utils/libgps_utils_so.la libloc_ds_api.la
-
-library_include_HEADERS = \
-   libloc_api_50001/LocEngAdapter.h \
-   libloc_api_50001/loc.h \
-   libloc_api_50001/loc_eng.h \
-   libloc_api_50001/loc_eng_xtra.h \
-   libloc_api_50001/loc_eng_ni.h \
-   libloc_api_50001/loc_eng_agps.h \
-   libloc_api_50001/loc_eng_msg.h \
-   libloc_api_50001/loc_eng_log.h \
-   $(WORKSPACE)/qcom-opensource/location/loc_api/ds_api/ds_client.h \
-   $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/location_service_v02.h \
-   $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_v02_log.h \
-   $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_v02_client.h \
-   $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_sync_req.h \
-   $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/LocApiV02.h \
-   $(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_util_log.h
-
-library_includedir = $(pkgincludedir)
-
-#Create and Install libraries
-lib_LTLIBRARIES = libloc_eng_so.la libloc_ds_api.la libloc_api_v02.la
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/Android.mk b/msm8998/loc_api/libloc_api-rpc-50001/Android.mk
deleted file mode 100644
index 6c5d533..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/Android.mk
+++ /dev/null
@@ -1,3 +0,0 @@
-ifeq ($(BOARD_VENDOR_QCOM_GPS_LOC_API_AMSS_VERSION),50001)
-include $(call all-subdir-makefiles)
-endif
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/Android.mk b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/Android.mk
deleted file mode 100644
index bb3d924..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/Android.mk
+++ /dev/null
@@ -1,60 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-RPC_INC:=rpc_inc
-
-source_files:= \
-    src/loc_api_rpc_glue.c \
-    src/loc_api_sync_call.c \
-    src/loc_apicb_appinit.c \
-    src/loc_api_fixup.c \
-    src/loc_api_log.c \
-    src/LocApiRpc.cpp
-
-LOCAL_SRC_FILES:= $(source_files)
-
-LOCAL_CFLAGS:=-fno-short-enums
-LOCAL_CFLAGS+=-DDEBUG -DUSE_QCOM_AUTO_RPC -DUSE_QCOM_AUTO_RPC
-LOCAL_CFLAGS+=$(GPS_FEATURES)
-
-# for loc_api_fixup.c
-LOCAL_CFLAGS+=-DADD_XDR_FLOAT -DADD_XDR_BOOL
-
-LOCAL_SHARED_LIBRARIES:= \
-    librpc \
-    libutils \
-    libcutils \
-    libcommondefs \
-    libgps.utils \
-    libloc_core
-
-LOCAL_STATIC_LIBRARIES := \
-    libloc_api_rpcgen
-
-LOCAL_PRELINK_MODULE:= false
-
-LOCAL_C_INCLUDES:= \
-    $(LOCAL_PATH) \
-    $(LOCAL_PATH)/rpc_inc \
-    $(TARGET_OUT_HEADERS)/gps.utils \
-    $(TARGET_OUT_HEADERS)/libloc_core \
-    $(TARGET_OUT_HEADERS)/loc_api/rpcgen/inc \
-    $(TARGET_OUT_HEADERS)/libcommondefs/rpcgen/inc \
-    $(TARGET_OUT_HEADERS)/librpc \
-    $(TARGET_OUT_HEADERS)/libloc-rpc/rpc_inc \
-    $(TOP)/hardware/msm7k/librpc
-
-LOCAL_COPY_HEADERS_TO:= libloc_api-rpc-qc/$(RPC_INC)
-LOCAL_COPY_HEADERS:= \
-    $(RPC_INC)/loc_api_rpc_glue.h \
-    $(RPC_INC)/loc_api_fixup.h \
-    $(RPC_INC)/loc_api_sync_call.h \
-    $(RPC_INC)/loc_apicb_appinit.h \
-    $(RPC_INC)/LocApiRpc.h
-
-LOCAL_MODULE:= libloc_api-rpc-qc
-LOCAL_MODULE_OWNER := qcom
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/Makefile.am b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/Makefile.am
deleted file mode 100644
index 7f2e9d3..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/Makefile.am
+++ /dev/null
@@ -1,46 +0,0 @@
-AM_CFLAGS = \
-   -I../../../utils \
-   -I../../../platform_lib_abstractions \
-   -I./rpc_inc \
-   -I../libloc_api-rpc-stub/inc \
-   -I../../libloc_api_50001 \
-   $(MSM7K_CFLAGS) \
-   -DUSE_QCOM_AUTO_RPC
-
-requiredlibs = \
-   ../../../utils/libgps_utils_so.la \
-   $(MSM7K_LIBS)
-
-h_sources = \
-    rpc_inc/loc_api_rpc_glue.h \
-    rpc_inc/loc_api_fixup.h \
-    rpc_inc/loc_api_sync_call.h \
-    rpc_inc/loc_apicb_appinit.h \
-
-c_sources = \
-    src/loc_api_rpc_glue.c \
-    src/loc_api_sync_call.c \
-    src/loc_apicb_appinit.c \
-    src/loc_api_fixup.c \
-    src/loc_api_log.c \
-    src/LocApiRpcAdapter.cpp \
-
-
-library_includedir = $(pkgincludedir)/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc
-library_include_HEADERS = $(h_sources)
-libloc_api_rpc_qc_la_SOURCES = $(c_sources) $(h_sources)
-
-if USE_GLIB
-libloc_api_rpc_qc_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@
-libloc_api_rpc_qc_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0
-libloc_api_rpc_qc_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@
-else
-libloc_api_rpc_qc_la_CFLAGS = $(AM_CFLAGS)
-libloc_api_rpc_qc_la_LDFLAGS = -Wl,-z,defs -lpthread -shared -version-info 1:0:0
-libloc_api_rpc_qc_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS)
-endif
-
-libloc_api_rpc_qc_la_LIBADD = $(requiredlibs) -lstdc++
-
-#Create and Install Libraries
-lib_LTLIBRARIES = libloc_api_rpc_qc.la
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/LocApiRpc.h b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/LocApiRpc.h
deleted file mode 100644
index b2b4e2a..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/LocApiRpc.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/* 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_RPC_H
-#define LOC_API_RPC_H
-
-#include <rpc/rpc.h>
-#include <loc_api_rpcgen_common_rpc.h>
-#include <loc_api_rpc_glue.h>
-#include <LocApiBase.h>
-#include <loc_log.h>
-
-using namespace loc_core;
-
-class LocApiRpc : public LocApiBase {
-protected:
-    // RPC communication establishment
-    rpc_loc_client_handle_type client_handle;
-
-private:
-    int dataEnableLastSet;
-    char apnLastSet[MAX_APN_LEN];
-
-    static const LOC_API_ADAPTER_EVENT_MASK_T maskAll;
-    static const rpc_loc_event_mask_type locBits[];
-    static rpc_loc_event_mask_type convertMask(LOC_API_ADAPTER_EVENT_MASK_T mask);
-    static rpc_loc_lock_e_type convertGpsLockMask(LOC_GPS_LOCK_MASK lockMask);
-    static enum loc_api_adapter_err convertErr(int rpcErr);
-    static LocGpsNiEncodingType convertNiEncodingType(int loc_encoding);
-    static int NIEventFillVerfiyType(LocGpsNiNotification &notif,
-                              rpc_loc_ni_notify_verify_e_type notif_priv);
-
-    void reportPosition(const rpc_loc_parsed_position_s_type *location_report_ptr);
-    void reportSv(const rpc_loc_gnss_info_s_type *gnss_report_ptr);
-    void reportStatus(const rpc_loc_status_event_s_type *status_report_ptr);
-    void reportNmea(const rpc_loc_nmea_report_s_type *nmea_report_ptr);
-    void ATLEvent(const rpc_loc_server_request_s_type *server_request_ptr);
-    void NIEvent(const rpc_loc_ni_event_s_type *ni_req_ptr);
-
-protected:
-    virtual enum loc_api_adapter_err
-        open(LOC_API_ADAPTER_EVENT_MASK_T mask);
-    virtual enum loc_api_adapter_err
-        close();
-    LocApiRpc(const MsgTask* msgTask,
-              LOC_API_ADAPTER_EVENT_MASK_T exMask);
-
-public:
-    static LocApiRpc* createLocApiRpc(const MsgTask* msgTask,
-              LOC_API_ADAPTER_EVENT_MASK_T exMask);
-    ~LocApiRpc();
-
-    virtual int locEventCB(rpc_loc_client_handle_type client_handle,
-                   rpc_loc_event_mask_type loc_event,
-                   const rpc_loc_event_payload_u_type* loc_event_payload);
-
-    void locRpcGlobalCB(CLIENT* clnt, enum rpc_reset_event event);
-
-    // RPC adapter interface implementations
-    virtual enum loc_api_adapter_err
-        startFix(const LocPosMode& posMode);
-    virtual enum loc_api_adapter_err
-        stopFix();
-    virtual enum loc_api_adapter_err
-        setPositionMode(const LocPosMode& mode);
-    inline virtual enum loc_api_adapter_err
-        enableData(int enable) { return enableData(enable, false); }
-    virtual enum loc_api_adapter_err
-        enableData(int enable, boolean force);
-    virtual enum loc_api_adapter_err
-        setTime(LocGpsUtcTime time, int64_t timeReference, int uncertainty);
-    virtual enum loc_api_adapter_err
-        injectPosition(double latitude, double longitude, float accuracy);
-    virtual enum loc_api_adapter_err
-        deleteAidingData(LocGpsAidingData f);
-    virtual enum loc_api_adapter_err
-        informNiResponse(LocGpsUserResponseType userResponse, const void* passThroughData);
-    inline virtual enum loc_api_adapter_err
-        setAPN(char* apn, int len) { return setAPN(apn, len, false); }
-    virtual enum loc_api_adapter_err
-        setAPN(char* apn, int len, boolean force);
-    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
-        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, LocAGpsType agpsType);
-    virtual enum loc_api_adapter_err
-        atlCloseStatus(int handle, int is_succ);
-    virtual enum loc_api_adapter_err
-        setSUPLVersion(uint32_t version);
-    virtual void setInSession(bool inSession);
-
-    /*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);
-};
-
-extern "C" LocApiBase* getLocApi(const MsgTask* msgTask,
-                                 LOC_API_ADAPTER_EVENT_MASK_T exMask,
-                                 ContextBase *context);
-
-#endif //LOC_API_RPC_H
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/debug.h b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/debug.h
deleted file mode 100644
index 49a6d0b..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/debug.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/* 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 DEBUG_H
-#define DEBUG_H
-
-#include <stdio.h>
-
-#define LOG_TAG "LocSvc_rpc"
-#include <utils/Log.h>
-
-#define PRINT(x...) do {                                    \
-        fprintf(stdout, "%s(%d) ", __FUNCTION__, __LINE__); \
-        fprintf(stdout, ##x);                               \
-        ALOGD(x);                               \
-    } while(0)
-
-#ifdef DEBUG
-#define D PRINT
-#else
-#define D(x...) do { } while(0)
-#endif
-
-#ifdef VERBOSE
-#define V PRINT
-#else
-#define V(x...) do { } while(0)
-#endif
-
-#define E(x...) do {                                        \
-        fprintf(stderr, "%s(%d) ", __FUNCTION__, __LINE__); \
-        fprintf(stderr, ##x);                               \
-        ALOGE(x);                                            \
-    } while(0)
-
-#define FAILIF(cond, msg...) do {                                              \
-        if (__builtin_expect (cond, 0)) {                                      \
-            fprintf(stderr, "%s:%s:(%d): ", __FILE__, __FUNCTION__, __LINE__); \
-            fprintf(stderr, ##msg);                                            \
-            ALOGE(##msg);                                                       \
-        }                                                                      \
-    } while(0)
-
-#endif/*DEBUG_H*/
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_api_fixup.h b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_api_fixup.h
deleted file mode 100644
index c483b4a..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_api_fixup.h
+++ /dev/null
@@ -1,226 +0,0 @@
-/* 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  LOC_API_FIXUP_H
-#define LOC_API_FIXUP_H
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#ifndef NULLPROC
-#define NULLPROC 0
-#endif /* NULLPROC */
-
-#ifdef ADD_XDR_FLOAT
-
-extern bool_t xdr_float (XDR *__xdrs, float *__fp);
-extern bool_t xdr_double (XDR *__xdrs, double *__dp);
-
-#endif /* ADD_XDR_FLOAT */
-
-#ifdef ADD_XDR_BOOL
-extern bool_t xdr_bool(XDR *__xdrs, int *__bp);
-#endif /* ADD_XDR_BOOL */
-
-#define RPC_LOC_API_MAJOR_VERSION_NUMBER   1
-#define RPC_LOC_API_MINOR_VERSION_NUMBER   0
-
-// Return value for loc_open in case of failure.
-#define RPC_LOC_CLIENT_HANDLE_INVALID     -1
-
-// Return value of loc api calls for loc_close, loc_start_fix, loc_stop_fix and loc_ioctl
-// These are also the status for the ioctl callback
-#define RPC_LOC_API_SUCCESS           0
-#define RPC_LOC_API_GENERAL_FAILURE   1
-#define RPC_LOC_API_UNSUPPORTED       2
-#define RPC_LOC_API_INVALID_HANDLE    4
-#define RPC_LOC_API_INVALID_PARAMETER 5
-#define RPC_LOC_API_ENGINE_BUSY       6
-#define RPC_LOC_API_PHONE_OFFLINE     7
-#define RPC_LOC_API_TIMEOUT           8
-
-// Special return value for loc api calls in case of RPC failure
-#define RPC_LOC_API_RPC_FAILURE       (-1234)
-// Special return value for modem restart incurred RPC failure
-#define RPC_LOC_API_RPC_MODEM_RESTART       (-1235)
-
-#define RPC_LOC_API_MAX_SV_COUNT                      80
-#define RPC_LOC_API_MAX_NMEA_STRING_LENGTH            1200
-
-// Maximum server address that will be used in location API
-#define RPC_LOC_API_MAX_SERVER_ADDR_LENGTH            256
-#define RPC_LOC_API_MAX_NUM_PREDICTED_ORBITS_SERVERS  3
-#define RPC_LOC_API_MAX_NUM_NTP_SERVERS               3
-
-#define RPC_LOC_EVENT_PARSED_POSITION_REPORT             0x00000001 // Position report comes in loc_parsed_position_s_type
-#define RPC_LOC_EVENT_SATELLITE_REPORT                   0x00000002 // Satellite in view report
-#define RPC_LOC_EVENT_NMEA_1HZ_REPORT                    0x00000004 // NMEA report at 1HZ rate
-#define RPC_LOC_EVENT_NMEA_POSITION_REPORT               0x00000008 // NMEA report at position report rate
-#define RPC_LOC_EVENT_NI_NOTIFY_VERIFY_REQUEST           0x00000010 // NI notification/verification request
-#define RPC_LOC_EVENT_ASSISTANCE_DATA_REQUEST            0x00000020 // Assistance data, eg: time, predicted orbits request
-#define RPC_LOC_EVENT_LOCATION_SERVER_REQUEST            0x00000040 // Request for location server
-#define RPC_LOC_EVENT_IOCTL_REPORT                       0x00000080 // Callback report for loc_ioctl
-#define RPC_LOC_EVENT_STATUS_REPORT                      0x00000100 // Misc status report: eg, engine state
-
-#define RPC_LOC_POS_VALID_SESSION_STATUS                 0x00000001
-#define RPC_LOC_POS_VALID_TIMESTAMP_CALENDAR             0x00000002
-#define RPC_LOC_POS_VALID_TIMESTAMP_UTC                  0x00000004
-#define RPC_LOC_POS_VALID_LEAP_SECONDS                   0x00000008
-#define RPC_LOC_POS_VALID_TIME_UNC                       0x00000010
-#define RPC_LOC_POS_VALID_LATITUDE                       0x00000020
-#define RPC_LOC_POS_VALID_LONGITUDE                      0x00000040
-#define RPC_LOC_POS_VALID_ALTITUDE_WRT_ELLIPSOID         0x00000080
-#define RPC_LOC_POS_VALID_ALTITUDE_WRT_MEAN_SEA_LEVEL    0x00000100
-#define RPC_LOC_POS_VALID_SPEED_HORIZONTAL               0x00000200
-#define RPC_LOC_POS_VALID_SPEED_VERTICAL                 0x00000400
-#define RPC_LOC_POS_VALID_HEADING                        0x00000800
-#define RPC_LOC_POS_VALID_HOR_UNC_CIRCULAR               0x00001000
-#define RPC_LOC_POS_VALID_HOR_UNC_ELLI_SEMI_MAJ          0x00002000
-#define RPC_LOC_POS_VALID_HOR_UNC_ELLI_SEMI_MIN          0x00004000
-#define RPC_LOC_POS_VALID_HOR_UNC_ELLI_ORIENT_AZIMUTH    0x00008000
-#define RPC_LOC_POS_VALID_VERTICAL_UNC                   0x00010000
-#define RPC_LOC_POS_VALID_SPEED_UNC                      0x00020000
-#define RPC_LOC_POS_VALID_HEADING_UNC                    0x00040000
-#define RPC_LOC_POS_VALID_CONFIDENCE_HORIZONTAL          0x00080000
-#define RPC_LOC_POS_VALID_CONFIDENCE_VERTICAL            0x00100000
-#define RPC_LOC_POS_VALID_MAGNETIC_VARIATION             0x00200000
-#define RPC_LOC_POS_VALID_TECHNOLOGY_MASK                0x00400000
-
-#define RPC_LOC_POS_TECH_SATELLITE 0x00000001
-#define RPC_LOC_POS_TECH_CELLID    0x00000002
-#define RPC_LOC_POS_TECH_WIFI      0x00000004
-
-#define RPC_LOC_SV_INFO_VALID_SYSTEM         0x00000001
-#define RPC_LOC_SV_INFO_VALID_PRN            0x00000002
-#define RPC_LOC_SV_INFO_VALID_HEALTH_STATUS  0x00000004
-#define RPC_LOC_SV_INFO_VALID_PROCESS_STATUS 0x00000008
-#define RPC_LOC_SV_INFO_VALID_HAS_EPH        0x00000010
-#define RPC_LOC_SV_INFO_VALID_HAS_ALM        0x00000020
-#define RPC_LOC_SV_INFO_VALID_ELEVATION      0x00000040
-#define RPC_LOC_SV_INFO_VALID_AZIMUTH        0x00000080
-#define RPC_LOC_SV_INFO_VALID_SNR            0x00000100
-
-#define RPC_LOC_GNSS_INFO_VALID_POS_DOP           0x00000001
-#define RPC_LOC_GNSS_INFO_VALID_HOR_DOP           0x00000002
-#define RPC_LOC_GNSS_INFO_VALID_VERT_DOP          0x00000004
-#define RPC_LOC_GNSS_INFO_VALID_ALTITUDE_ASSUMED  0x00000008
-#define RPC_LOC_GNSS_INFO_VALID_SV_COUNT          0x00000010
-#define RPC_LOC_GNSS_INFO_VALID_SV_LIST           0x00000020
-
-#define RPC_LOC_NI_MAX_REQUESTOR_ID_LENGTH          200
-#define RPC_LOC_NI_SUPL_HASH_LENGTH                 8
-#define RPC_LOC_NI_SUPL_SLP_SESSION_ID_BYTE_LENGTH  4
-#define RPC_LOC_NI_MAX_CLIENT_NAME_LENGTH           64
-#define RPC_LOC_NI_MAX_EXT_CLIENT_ADDRESS           20
-#define RPC_LOC_NI_CODEWORD_LENGTH                  20
-
-#define RPC_LOC_NI_SUPL_QOP_VALID         0x01
-#define RPC_LOC_NI_SUPL_QOP_VERACC_VALID  0x02
-#define RPC_LOC_NI_SUPL_QOP_MAXAGE_VALID  0x04
-#define RPC_LOC_NI_SUPL_QOP_DELAY_VALID   0x08
-
-#define RPC_LOC_FIX_CRIT_VALID_RECURRENCE_TYPE                  0x00000001
-#define RPC_LOC_FIX_CRIT_VALID_PREFERRED_OPERATION_MODE         0x00000002
-#define RPC_LOC_FIX_CRIT_VALID_PREFERRED_ACCURACY               0x00000004
-#define RPC_LOC_FIX_CRIT_VALID_PREFERRED_RESPONSE_TIME          0x00000008
-#define RPC_LOC_FIX_CRIT_VALID_INTERMEDIATE_POS_REPORT_ENABLED  0x00000010
-#define RPC_LOC_FIX_CRIT_VALID_NOTIFY_TYPE                      0x00000020
-#define RPC_LOC_FIX_CRIT_VALID_MIN_INTERVAL                     0x00000040
-#define RPC_LOC_FIX_CRIT_VALID_MIN_DISTANCE                     0x00000080
-#define RPC_LOC_FIX_CRIT_VALID_MIN_DIST_SAMPLE_INTERVAL         0x00000100
-
-#define RPC_LOC_ASSIST_POS_VALID_TIMESTAMP_UTC                0x00000001
-#define RPC_LOC_ASSIST_POS_VALID_LATITUDE                     0x00000002
-#define RPC_LOC_ASSIST_POS_VALID_LONGITUDE                    0x00000004
-#define RPC_LOC_ASSIST_POS_VALID_ALTITUDE_WRT_ELLIPSOID       0x00000008
-#define RPC_LOC_ASSIST_POS_VALID_ALTITUDE_WRT_MEAN_SEA_LEVEL  0x00000010
-#define RPC_LOC_ASSIST_POS_VALID_HOR_UNC_CIRCULAR             0x00000020
-#define RPC_LOC_ASSIST_POS_VALID_VERT_UNC                     0x00000040
-#define RPC_LOC_ASSIST_POS_VALID_CONFIDENCE_HORIZONTAL        0x00000080
-#define RPC_LOC_ASSIST_POS_VALID_CONFIDENCE_VERTICAL          0x00000100
-#define RPC_LOC_ASSIST_POS_VALID_TIMESTAMP_AGE                0x00000200
-
-#define RPC_LOC_ASSIST_DATA_ALL         0xFFFFFFFF
-
-#define RPC_LOC_NMEA_MASK_ALL    0xffff
-#define RPC_LOC_NMEA_MASK_GGA    0x0001
-#define RPC_LOC_NMEA_MASK_RMC    0x0002
-#define RPC_LOC_NMEA_MASK_GSV    0x0004
-#define RPC_LOC_NMEA_MASK_GSA    0x0008
-#define RPC_LOC_NMEA_MASK_VTG    0x0010
-
-/* EFS data access */
-#define RPC_LOC_EFS_MAX_PATH_LEN_BYTES  64     /* Max file name length in bytes that can be written*/
-#define RPC_LOC_EFS_MAX_FILE_LEN_BYTES  2000   /* Max file size in bytes that can be written */
-
-/* WIPER valid information flag in log report */
-#define RPC_LOC_WIPER_LOG_TIME_VALID 0x01
-#define RPC_LOC_WIPER_LOG_POS_VALID 0x02
-#define RPC_LOC_WIPER_LOG_AP_SET_VALID 0x04
-
-/* General WIPER defines */
-#define RPC_LOC_WIPER_MAC_ADDR_LENGTH  6              // Do not change this number since it affects RPC and log packet sizes
-#define RPC_LOC_WIPER_MAX_REPORTED_APS_PER_LOG_MSG 50 // Do not change this number since it affects RPC and log packet sizes
-
-/* WIPER AP Qualifier */
-#define RPC_LOC_WIPER_AP_QUALIFIER_BEING_USED 0x1  /* AP is being used by WPS */
-#define RPC_LOC_WIPER_AP_QUALIFIER_HIDDEN_SSID 0x2 /* AP does not broadcast SSID */
-#define RPC_LOC_WIPER_AP_QUALIFIER_PRIVATE 0x4     /* AP has encryption turned on */
-#define RPC_LOC_WIPER_AP_QUALIFIER_INFRASTRUCTURE_MODE 0x8     /* AP is in infrastructure mode and not in ad-hoc/unknown mode */
-
-/* flags for notification */
-#define  RPC_LOC_NI_CLIENT_NAME_PRESENT             0x0001
-#define  RPC_LOC_NI_CLIENT_EXTADDR_PRESENT          0x0002
-#define  RPC_LOC_NI_DEF_LOCATION_TYPE_PRESENT       0x0010
-#define  RPC_LOC_NI_REQUESTOR_ID_PRESENT            0x0020
-#define  RPC_LOC_NI_CODEWORD_PRESENT                0x0040
-#define  RPC_LOC_NI_SERVICE_TYPE_ID_PRESENT         0x0080
-#define  RPC_LOC_NI_ENCODING_TYPE_PRESENT           0x0100
-
-/* below are for RPC_LOC_IOCTL_SET_LBS_APN_PROFILE data */
-/* values for apn_profiles[0].srv_system_type */
-#define LOC_APN_PROFILE_SRV_SYS_CDMA  0x01
-#define LOC_APN_PROFILE_SRV_SYS_HDR   0x02
-#define LOC_APN_PROFILE_SRV_SYS_GSM   0x04
-#define LOC_APN_PROFILE_SRV_SYS_WCDMA 0x08
-#define LOC_APN_PROFILE_SRV_SYS_LTE   0x10
-#define LOC_APN_PROFILE_SRV_SYS_MAX   0x1F
-/* values for apn_profiles[0].pdp_type */
-#define LOC_APN_PROFILE_PDN_TYPE_IPV4    0x01
-#define LOC_APN_PROFILE_PDN_TYPE_IPV6    0x02
-#define LOC_APN_PROFILE_PDN_TYPE_IPV4V6  0x03
-#define LOC_APN_PROFILE_PDN_TYPE_PPP     0x04
-#define LOC_APN_PROFILE_PDN_TYPE_MAX     0x04
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LOC_API_FIXUP_H */
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_api_log.h b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_api_log.h
deleted file mode 100644
index f037428..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_api_log.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* 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 LOC_API_LOG_H
-#define LOC_API_LOG_H
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include <ctype.h>
-#include "loc_api_rpcgen_common_rpc.h"
-
-extern int loc_callback_log(
-      rpc_loc_event_mask_type               loc_event,              /* event mask           */
-      const rpc_loc_event_payload_u_type*   loc_event_payload       /* payload              */
-);
-
-extern const char* loc_get_event_atl_open_name(rpc_loc_server_request_e_type loc_event_atl_open);
-extern const char* loc_get_event_name(rpc_loc_event_mask_type loc_event_mask);
-extern const char* loc_get_ioctl_type_name(rpc_loc_ioctl_e_type ioctl_type);
-extern const char* loc_get_ioctl_status_name(uint32 status);
-extern const char* loc_get_sess_status_name(rpc_loc_session_status_e_type status);
-extern const char* loc_get_engine_state_name(rpc_loc_engine_state_e_type state);
-extern const char* loc_get_fix_session_state_name(rpc_loc_fix_session_state_e_type state);
-extern const char* loc_get_rpc_reset_event_name(enum rpc_reset_event event);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LOC_API_LOG_H */
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_api_rpc_glue.h b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_api_rpc_glue.h
deleted file mode 100644
index 6df33ae..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_api_rpc_glue.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/* 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 LOC_API_RPC_GLUE_H
-#define LOC_API_RPC_GLUE_H
-
-/* Include RPC headers */
-#ifdef USE_LOCAL_RPC
-#include "rpc_inc/loc_api_common.h"
-#include "rpc_inc/loc_api.h"
-#include "rpc_inc/loc_api_cb.h"
-#endif
-
-#ifdef USE_QCOM_AUTO_RPC
-#include "loc_api_rpcgen_rpc.h"
-#include "loc_api_rpcgen_common_rpc.h"
-#include "loc_api_rpcgen_cb_rpc.h"
-#endif
-
-/* Boolean */
-/* Other data types in comdef.h are defined in rpc stubs, so fix it here */
-typedef unsigned char boolean;
-#define TRUE 1
-#define FALSE 0
-
-#include "loc_api_fixup.h"
-#include "loc_api_sync_call.h"
-#include <rpc/clnt.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-extern int loc_api_glue_init(void);
-extern int loc_api_null(void);
-
-typedef int32 (loc_event_cb_f_type)(
-    void*                                 userData,
-    rpc_loc_client_handle_type            loc_handle,             /* handle of the client */
-    rpc_loc_event_mask_type               loc_event,              /* event mask           */
-    const rpc_loc_event_payload_u_type*   loc_event_payload       /* payload              */
-);
-
-typedef void (loc_reset_notif_cb_f_type)(
-    void*                                 userData,
-    CLIENT*                               clnt,
-    enum rpc_reset_event                  event
-);
-
-extern rpc_loc_client_handle_type loc_open(
-    rpc_loc_event_mask_type       event_reg_mask,
-    loc_event_cb_f_type           *event_callback,
-    loc_reset_notif_cb_f_type     *rpc_global_cb,
-    void*                         userData
-);
-
-extern int32 loc_close
-(
-      rpc_loc_client_handle_type handle
-);
-
-extern void loc_clear
-(
-      rpc_loc_client_handle_type handle
-);
-
-extern int32 loc_start_fix
-(
-      rpc_loc_client_handle_type handle
-);
-
-extern int32 loc_stop_fix
-(
-      rpc_loc_client_handle_type handle
-);
-
-extern int32 loc_ioctl
-(
-      rpc_loc_client_handle_type           handle,
-      rpc_loc_ioctl_e_type                 ioctl_type,
-      rpc_loc_ioctl_data_u_type*           ioctl_data
-);
-
-extern int loc_eng_ioctl
-(
-      rpc_loc_client_handle_type           handle,
-      rpc_loc_ioctl_e_type                 ioctl_type,
-      rpc_loc_ioctl_data_u_type*           ioctl_data_ptr,
-      uint32                               timeout_msec,
-      rpc_loc_ioctl_callback_s_type       *cb_data_ptr
-);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LOC_API_RPC_GLUE_H */
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_api_sync_call.h b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_api_sync_call.h
deleted file mode 100644
index 43208bd..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_api_sync_call.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/* 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 LOC_API_CB_SYNC_H
-#define LOC_API_CB_SYNC_H
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-#include "loc_api_rpc_glue.h"
-#define LOC_SYNC_CALL_SLOTS_MAX 8
-
-typedef struct {
-   pthread_mutex_t                lock;
-
-   /* Client ID */
-   rpc_loc_client_handle_type     loc_handle;
-
-   /* Callback waiting conditional variable */
-   pthread_cond_t                 loc_cb_arrived_cond;
-
-   /* Callback waiting data block, protected by loc_cb_data_mutex */
-   boolean                        in_use;
-   boolean                        signal_sent;
-   boolean                        not_available;
-   rpc_loc_event_mask_type        loc_cb_wait_event_mask;        /* event to wait for */
-   rpc_loc_ioctl_e_type           ioctl_type;                    /* ioctl to wait for */
-   rpc_loc_event_payload_u_type   loc_cb_received_payload;       /* received payload */
-   rpc_loc_event_mask_type        loc_cb_received_event_mask;    /* received event   */
-} loc_sync_call_slot_s_type;
-
-typedef struct {
-   int                            num_of_slots;
-   loc_sync_call_slot_s_type      slots[LOC_SYNC_CALL_SLOTS_MAX];
-} loc_sync_call_slot_array_s_type;
-
-/* Init function */
-void loc_api_sync_call_init();
-
-/* Destroy function */
-void loc_api_sync_call_destroy();
-
-/* Process Loc API callbacks to wake up blocked user threads */
-void loc_api_callback_process_sync_call(
-      rpc_loc_client_handle_type            loc_handle,             /* handle of the client */
-      rpc_loc_event_mask_type               loc_event,              /* event mask           */
-      const rpc_loc_event_payload_u_type*   loc_event_payload       /* payload              */
-);
-
-/* Reentrant synchronous IOCTL call, using Loc API return code */
-int loc_api_sync_ioctl
-(
-      rpc_loc_client_handle_type           handle,
-      rpc_loc_ioctl_e_type                 ioctl_type,
-      rpc_loc_ioctl_data_u_type*           ioctl_data_ptr,
-      uint32                               timeout_msec,
-      rpc_loc_ioctl_callback_s_type       *cb_data_ptr
-);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LOC_API_CB_SYNC_H */
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_apicb_appinit.h b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_apicb_appinit.h
deleted file mode 100644
index ba41d08..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/loc_apicb_appinit.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/* 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 LOC_APICB_APPINIT_H
-#define LOC_APICB_APPINIT_H
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
- /* Initialization function for callbacks */
-extern int loc_apicb_app_init();
-extern void loc_apicb_app_deinit();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LOC_APICB_APPINIT_H */
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/LocApiRpc.cpp b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/LocApiRpc.cpp
deleted file mode 100644
index f0f84b5..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/LocApiRpc.cpp
+++ /dev/null
@@ -1,1475 +0,0 @@
-/* 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_api_rpc"
-
-#include <unistd.h>
-#include <math.h>
-#ifndef USE_GLIB
-#include <utils/SystemClock.h>
-#endif /* USE_GLIB */
-#include <LocApiRpc.h>
-#include <LocAdapterBase.h>
-#include <loc_api_fixup.h>
-#include <loc_api_rpc_glue.h>
-#include <loc_log.h>
-#include <loc_api_log.h>
-#ifdef USE_GLIB
-#include <glib.h>
-#endif
-#include <librpc.h>
-#include <platform_lib_includes.h>
-
-using namespace loc_core;
-
-#define LOC_XTRA_INJECT_DEFAULT_TIMEOUT (3100)
-#define XTRA_BLOCK_SIZE                 (3072)
-#define LOC_IOCTL_DEFAULT_TIMEOUT 1000 // 1000 milli-seconds
-#define LOC_NI_NOTIF_KEY_ADDRESS           "Address"
-
-/*===========================================================================
-FUNCTION    loc_event_cb
-
-DESCRIPTION
-   This is the callback function registered by loc_open.
-
-DEPENDENCIES
-   N/A
-
-RETURN VALUE
-   RPC_LOC_API_SUCCESS
-
-SIDE EFFECTS
-   N/A
-
-===========================================================================*/
-static int32 loc_event_cb
-(
-    void*                                user,
-    rpc_loc_client_handle_type           client_handle,
-    rpc_loc_event_mask_type              loc_event,
-    const rpc_loc_event_payload_u_type*  loc_event_payload
-)
-{
-    MODEM_LOG_CALLFLOW(%s, loc_get_event_name(loc_event));
-    loc_callback_log(loc_event, loc_event_payload);
-    int32 ret_val = ((LocApiRpc*)user)->locEventCB(client_handle, loc_event, loc_event_payload);
-    EXIT_LOG(%d, ret_val);
-    return ret_val;
-}
-
-/*===========================================================================
-FUNCTION    loc_eng_rpc_global_cb
-
-DESCRIPTION
-   This is the callback function registered by loc_open for RPC global events
-
-DEPENDENCIES
-   N/A
-
-RETURN VALUE
-   RPC_LOC_API_SUCCESS
-
-SIDE EFFECTS
-   N/A
-
-===========================================================================*/
-static void loc_rpc_global_cb(void* user, CLIENT* clnt, enum rpc_reset_event event)
-{
-    MODEM_LOG_CALLFLOW(%s, loc_get_rpc_reset_event_name(event));
-    ((LocApiRpc*)user)->locRpcGlobalCB(clnt, event);
-    EXIT_LOG(%p, VOID_RET);
-}
-
-const LOC_API_ADAPTER_EVENT_MASK_T LocApiRpc::maskAll =
-    LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT |
-    LOC_API_ADAPTER_BIT_SATELLITE_REPORT |
-    LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST |
-    LOC_API_ADAPTER_BIT_ASSISTANCE_DATA_REQUEST |
-    LOC_API_ADAPTER_BIT_IOCTL_REPORT |
-    LOC_API_ADAPTER_BIT_STATUS_REPORT |
-    LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT |
-    LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST;
-
-const rpc_loc_event_mask_type LocApiRpc::locBits[] =
-{
-    RPC_LOC_EVENT_PARSED_POSITION_REPORT,
-    RPC_LOC_EVENT_SATELLITE_REPORT,
-    RPC_LOC_EVENT_NMEA_1HZ_REPORT,
-    RPC_LOC_EVENT_NMEA_POSITION_REPORT,
-    RPC_LOC_EVENT_NI_NOTIFY_VERIFY_REQUEST,
-    RPC_LOC_EVENT_ASSISTANCE_DATA_REQUEST,
-    RPC_LOC_EVENT_LOCATION_SERVER_REQUEST,
-    RPC_LOC_EVENT_IOCTL_REPORT,
-    RPC_LOC_EVENT_STATUS_REPORT,
-    RPC_LOC_EVENT_WPS_NEEDED_REQUEST
-};
-
-LocApiRpc*
-LocApiRpc::createLocApiRpc(const MsgTask* msgTask,
-                     LOC_API_ADAPTER_EVENT_MASK_T exMask,
-                     ContextBase* context)
-{
-    if (NULL == msgTask) {
-        return NULL;
-    }
-    return new LocApiRpc(msgTask, exMask, context);
-}
-
-// constructor
-LocApiRpc::LocApiRpc(const MsgTask* msgTask,
-                     LOC_API_ADAPTER_EVENT_MASK_T exMask,
-                     ContextBase* context) :
-    LocApiBase(msgTask, exMask, context),
-    client_handle(RPC_LOC_CLIENT_HANDLE_INVALID),
-    dataEnableLastSet(-1)
-{
-    memset(apnLastSet, 0, sizeof(apnLastSet));
-    loc_api_glue_init();
-}
-
-LocApiRpc::~LocApiRpc()
-{
-    close();
-}
-
-rpc_loc_event_mask_type
-LocApiRpc::convertMask(LOC_API_ADAPTER_EVENT_MASK_T mask)
-{
-    rpc_loc_event_mask_type newMask = 0;
-
-    for (unsigned int i = 0, bit=1; 0 != mask; i++, bit<<=1) {
-        if (mask & bit) {
-            newMask |= locBits[i];
-            mask ^= bit;
-        }
-    }
-
-    return newMask;
-}
-
-rpc_loc_lock_e_type
-LocApiRpc::convertGpsLockMask(LOC_GPS_LOCK_MASK lockMask)
-{
-    if (isGpsLockAll(lockMask))
-        return RPC_LOC_LOCK_ALL;
-    if (isGpsLockMO(lockMask))
-        return RPC_LOC_LOCK_MI;
-    if (isGpsLockMT(lockMask))
-        return RPC_LOC_LOCK_MT;
-    if (isGpsLockNone(lockMask))
-        return RPC_LOC_LOCK_NONE;
-    return (rpc_loc_lock_e_type)lockMask;
-}
-
-enum loc_api_adapter_err
-LocApiRpc::convertErr(int rpcErr)
-{
-    switch(rpcErr)
-    {
-    case RPC_LOC_API_SUCCESS:
-        return LOC_API_ADAPTER_ERR_SUCCESS;
-    case RPC_LOC_API_GENERAL_FAILURE:
-        return LOC_API_ADAPTER_ERR_GENERAL_FAILURE;
-    case RPC_LOC_API_UNSUPPORTED:
-        return LOC_API_ADAPTER_ERR_UNSUPPORTED;
-    case RPC_LOC_API_INVALID_HANDLE:
-        return LOC_API_ADAPTER_ERR_INVALID_HANDLE;
-    case RPC_LOC_API_INVALID_PARAMETER:
-        return LOC_API_ADAPTER_ERR_INVALID_PARAMETER;
-    case RPC_LOC_API_ENGINE_BUSY:
-        return LOC_API_ADAPTER_ERR_ENGINE_BUSY;
-    case RPC_LOC_API_PHONE_OFFLINE:
-        return LOC_API_ADAPTER_ERR_PHONE_OFFLINE;
-    case RPC_LOC_API_TIMEOUT:
-        return LOC_API_ADAPTER_ERR_TIMEOUT;
-    case RPC_LOC_API_RPC_MODEM_RESTART:
-        return LOC_API_ADAPTER_ERR_ENGINE_DOWN;
-    case RPC_LOC_API_RPC_FAILURE:
-        return LOC_API_ADAPTER_ERR_FAILURE;
-    default:
-        return LOC_API_ADAPTER_ERR_UNKNOWN;
-    }
-}
-
-void LocApiRpc::locRpcGlobalCB(CLIENT* clnt, enum rpc_reset_event event)
-{
-    static rpc_loc_engine_state_e_type last_state = RPC_LOC_ENGINE_STATE_MAX;
-
-    switch (event) {
-    case RPC_SUBSYSTEM_RESTART_BEGIN:
-        if (RPC_LOC_ENGINE_STATE_OFF != last_state) {
-            last_state = RPC_LOC_ENGINE_STATE_OFF;
-            handleEngineDownEvent();
-        }
-        break;
-    case RPC_SUBSYSTEM_RESTART_END:
-        if (RPC_LOC_ENGINE_STATE_ON != last_state) {
-            last_state = RPC_LOC_ENGINE_STATE_ON;
-            handleEngineUpEvent();
-        }
-        break;
-    }
-}
-
-int32 LocApiRpc::locEventCB(rpc_loc_client_handle_type client_handle,
-                     rpc_loc_event_mask_type loc_event,
-                     const rpc_loc_event_payload_u_type* loc_event_payload)
-{
-    // Parsed report
-    if (loc_event & RPC_LOC_EVENT_PARSED_POSITION_REPORT)
-    {
-        reportPosition(&loc_event_payload->rpc_loc_event_payload_u_type_u.
-                       parsed_location_report);
-    }
-
-    // Satellite report
-    if (loc_event & RPC_LOC_EVENT_SATELLITE_REPORT)
-    {
-        reportSv(&loc_event_payload->rpc_loc_event_payload_u_type_u.gnss_report);
-    }
-
-    // Status report
-    if (loc_event & RPC_LOC_EVENT_STATUS_REPORT)
-    {
-        reportStatus(&loc_event_payload->rpc_loc_event_payload_u_type_u.status_report);
-    }
-
-    // NMEA
-    if (loc_event & RPC_LOC_EVENT_NMEA_1HZ_REPORT)
-    {
-        reportNmea(&(loc_event_payload->rpc_loc_event_payload_u_type_u.nmea_report));
-    }
-    // XTRA support: supports only XTRA download
-    if (loc_event & RPC_LOC_EVENT_ASSISTANCE_DATA_REQUEST)
-    {
-        if (loc_event_payload->rpc_loc_event_payload_u_type_u.assist_data_request.event ==
-            RPC_LOC_ASSIST_DATA_PREDICTED_ORBITS_REQ)
-        {
-            requestXtraData();
-        } else if (loc_event_payload->rpc_loc_event_payload_u_type_u.assist_data_request.event ==
-                   RPC_LOC_ASSIST_DATA_TIME_REQ)
-        {
-            requestTime();
-        } else if (loc_event_payload->rpc_loc_event_payload_u_type_u.assist_data_request.event ==
-                   RPC_LOC_ASSIST_DATA_POSITION_INJECTION_REQ)
-        {
-            requestLocation();
-        }
-    }
-
-    // AGPS data request
-    if (loc_event & RPC_LOC_EVENT_LOCATION_SERVER_REQUEST)
-    {
-        ATLEvent(&loc_event_payload->rpc_loc_event_payload_u_type_u.
-                 loc_server_request);
-    }
-
-    // NI notify request
-    if (loc_event & RPC_LOC_EVENT_NI_NOTIFY_VERIFY_REQUEST)
-    {
-        NIEvent(&loc_event_payload->rpc_loc_event_payload_u_type_u.ni_request);
-    }
-
-    return RPC_LOC_API_SUCCESS;//We simply want to return sucess here as we do not want to
-    // cause any issues in RPC thread context
-}
-
-enum loc_api_adapter_err
-LocApiRpc::open(LOC_API_ADAPTER_EVENT_MASK_T mask)
-{
-    enum loc_api_adapter_err ret_val = LOC_API_ADAPTER_ERR_SUCCESS;
-
-    // RPC does not dynamically update the event mask. And in the
-    // case of RPC, all we support are positioning (gps + agps)
-    // masks anyways, so we simply mask all of them on always.
-    // After doing so the first time in a power cycle, we know there
-    // will the following if condition will never be true any more.
-    mask = maskAll;
-
-    if (mask != mMask) {
-        if (RPC_LOC_CLIENT_HANDLE_INVALID != client_handle) {
-            close();
-        }
-
-        mMask = mask;
-        // it is important to cap the mask here, because not all LocApi's
-        // can enable the same bits, e.g. foreground and bckground.
-        client_handle = loc_open(convertMask(mask),
-                                 loc_event_cb,
-                                 loc_rpc_global_cb, this);
-
-        if (client_handle < 0) {
-            mMask = 0;
-            client_handle = RPC_LOC_CLIENT_HANDLE_INVALID;
-            ret_val = LOC_API_ADAPTER_ERR_INVALID_HANDLE;
-        }
-    }
-
-    return ret_val;
-}
-
-enum loc_api_adapter_err
-LocApiRpc::close()
-{
-    if (RPC_LOC_CLIENT_HANDLE_INVALID != client_handle) {
-        loc_clear(client_handle);
-    }
-
-    loc_close(client_handle);
-    mMask = 0;
-    client_handle = RPC_LOC_CLIENT_HANDLE_INVALID;
-
-    return LOC_API_ADAPTER_ERR_SUCCESS;
-}
-
-enum loc_api_adapter_err
-LocApiRpc::startFix(const LocPosMode& posMode) {
-   LOC_LOGD("LocApiRpc::startFix() called");
-   return convertErr(
-       loc_start_fix(client_handle)
-       );
-}
-
-enum loc_api_adapter_err
-LocApiRpc::stopFix() {
-   LOC_LOGD("LocApiRpc::stopFix() called");
-   return convertErr(
-       loc_stop_fix(client_handle)
-       );
-}
-
-enum loc_api_adapter_err
-LocApiRpc::setPositionMode(const LocPosMode& posMode)
-{
-    rpc_loc_ioctl_data_u_type    ioctl_data;
-    rpc_loc_fix_criteria_s_type *fix_criteria_ptr =
-        &ioctl_data.rpc_loc_ioctl_data_u_type_u.fix_criteria;
-    rpc_loc_ioctl_e_type         ioctl_type = RPC_LOC_IOCTL_SET_FIX_CRITERIA;
-    rpc_loc_operation_mode_e_type op_mode;
-    int                          ret_val;
-    const LocPosMode* fixCriteria = &posMode;
-
-    ALOGD ("loc_eng_set_position mode, client = %d, interval = %d, mode = %d\n",
-          (int32) client_handle, fixCriteria->min_interval, fixCriteria->mode);
-
-    switch (fixCriteria->mode)
-    {
-    case LOC_POSITION_MODE_MS_BASED:
-        op_mode = RPC_LOC_OPER_MODE_MSB;
-        break;
-    case LOC_POSITION_MODE_MS_ASSISTED:
-        op_mode = RPC_LOC_OPER_MODE_MSA;
-        break;
-    case LOC_POSITION_MODE_RESERVED_1:
-        op_mode = RPC_LOC_OPER_MODE_SPEED_OPTIMAL;
-        break;
-    case LOC_POSITION_MODE_RESERVED_2:
-        op_mode = RPC_LOC_OPER_MODE_ACCURACY_OPTIMAL;
-        break;
-    case LOC_POSITION_MODE_RESERVED_3:
-        op_mode = RPC_LOC_OPER_MODE_DATA_OPTIMAL;
-        break;
-    case LOC_POSITION_MODE_RESERVED_4:
-    case LOC_POSITION_MODE_RESERVED_5:
-        op_mode = RPC_LOC_OPER_MODE_MSA;
-        fix_criteria_ptr->preferred_response_time  = 0;
-        break;
-    default:
-        op_mode = RPC_LOC_OPER_MODE_STANDALONE;
-    }
-
-    fix_criteria_ptr->valid_mask = RPC_LOC_FIX_CRIT_VALID_PREFERRED_OPERATION_MODE |
-                                   RPC_LOC_FIX_CRIT_VALID_RECURRENCE_TYPE;
-    fix_criteria_ptr->min_interval = fixCriteria->min_interval;
-    fix_criteria_ptr->preferred_operation_mode = op_mode;
-
-    fix_criteria_ptr->min_interval = fixCriteria->min_interval;
-    fix_criteria_ptr->valid_mask |= RPC_LOC_FIX_CRIT_VALID_MIN_INTERVAL;
-
-    if (fixCriteria->preferred_accuracy > 0) {
-        fix_criteria_ptr->preferred_accuracy = fixCriteria->preferred_accuracy;
-        fix_criteria_ptr->valid_mask |= RPC_LOC_FIX_CRIT_VALID_PREFERRED_ACCURACY;
-    }
-    if (fixCriteria->preferred_time > 0) {
-        fix_criteria_ptr->preferred_response_time = fixCriteria->preferred_time;
-        fix_criteria_ptr->valid_mask |= RPC_LOC_FIX_CRIT_VALID_PREFERRED_RESPONSE_TIME;
-    }
-
-    switch (fixCriteria->recurrence) {
-    case LOC_GPS_POSITION_RECURRENCE_SINGLE:
-        fix_criteria_ptr->recurrence_type = RPC_LOC_SINGLE_FIX;
-        break;
-    case LOC_GPS_POSITION_RECURRENCE_PERIODIC:
-    default:
-        fix_criteria_ptr->recurrence_type = RPC_LOC_PERIODIC_FIX;
-        break;
-    }
-    ioctl_data.disc = ioctl_type;
-
-    ret_val = loc_eng_ioctl (client_handle,
-                             ioctl_type,
-                             &ioctl_data,
-                             LOC_IOCTL_DEFAULT_TIMEOUT,
-                             NULL /* No output information is expected*/);
-
-    return convertErr(ret_val);
-}
-
-enum loc_api_adapter_err
-LocApiRpc::setTime(LocGpsUtcTime time, int64_t timeReference, int uncertainty)
-{
-    rpc_loc_ioctl_data_u_type        ioctl_data;
-    rpc_loc_assist_data_time_s_type *time_info_ptr;
-    rpc_loc_ioctl_e_type             ioctl_type = RPC_LOC_IOCTL_INJECT_UTC_TIME;
-    int                              ret_val;
-
-    LOC_LOGD ("loc_eng_inject_time, uncertainty = %d\n", uncertainty);
-
-    time_info_ptr = &ioctl_data.rpc_loc_ioctl_data_u_type_u.assistance_data_time;
-    time_info_ptr->time_utc = time;
-    time_info_ptr->time_utc += (int64_t)(ELAPSED_MILLIS_SINCE_BOOT_PLATFORM_LIB_ABSTRACTION - timeReference);
-    time_info_ptr->uncertainty = uncertainty; // Uncertainty in ms
-
-    ioctl_data.disc = ioctl_type;
-
-    ret_val = loc_eng_ioctl (client_handle,
-                             ioctl_type,
-                             &ioctl_data,
-                             LOC_IOCTL_DEFAULT_TIMEOUT,
-                             NULL /* No output information is expected*/);
-
-    return convertErr(ret_val);
-}
-
-enum loc_api_adapter_err
-LocApiRpc::injectPosition(double latitude, double longitude, float accuracy)
-{
-    /* IOCTL data */
-    rpc_loc_ioctl_data_u_type ioctl_data;
-    rpc_loc_assist_data_pos_s_type *assistance_data_position =
-        &ioctl_data.rpc_loc_ioctl_data_u_type_u.assistance_data_position;
-    int                          ret_val;
-
-    /************************************************
-     * Fill in latitude, longitude & accuracy
-     ************************************************/
-
-    /* This combo is required */
-    assistance_data_position->valid_mask =
-        RPC_LOC_ASSIST_POS_VALID_LATITUDE |
-        RPC_LOC_ASSIST_POS_VALID_LONGITUDE |
-        RPC_LOC_ASSIST_POS_VALID_HOR_UNC_CIRCULAR |
-        RPC_LOC_ASSIST_POS_VALID_CONFIDENCE_HORIZONTAL;
-
-    assistance_data_position->latitude = latitude;
-    assistance_data_position->longitude = longitude;
-    assistance_data_position->hor_unc_circular = accuracy; /* Meters assumed */
-    assistance_data_position->confidence_horizontal = 63;  /* 63% (1 std dev) assumed */
-
-    /* Log */
-    LOC_LOGD("Inject coarse position Lat=%lf, Lon=%lf, Acc=%.2lf\n",
-             (double) assistance_data_position->latitude,
-             (double) assistance_data_position->longitude,
-             (double) assistance_data_position->hor_unc_circular);
-
-    ret_val = loc_eng_ioctl( client_handle,
-                             RPC_LOC_IOCTL_INJECT_POSITION,
-                             &ioctl_data,
-                             LOC_IOCTL_DEFAULT_TIMEOUT,
-                             NULL /* No output information is expected*/);
-    return convertErr(ret_val);
-}
-
-enum loc_api_adapter_err
-LocApiRpc::informNiResponse(LocGpsUserResponseType userResponse,
-                                   const void* passThroughData)
-{
-    rpc_loc_ioctl_data_u_type data;
-    rpc_loc_ioctl_callback_s_type callback_payload;
-
-    memcpy(&data.rpc_loc_ioctl_data_u_type_u.user_verify_resp.ni_event_pass_back,
-           passThroughData, sizeof (rpc_loc_ni_event_s_type));
-
-    rpc_loc_ni_user_resp_e_type resp;
-    switch (userResponse)
-    {
-    case LOC_GPS_NI_RESPONSE_ACCEPT:
-        data.rpc_loc_ioctl_data_u_type_u.user_verify_resp.user_resp =
-            RPC_LOC_NI_LCS_NOTIFY_VERIFY_ACCEPT;
-        break;
-    case LOC_GPS_NI_RESPONSE_DENY:
-        data.rpc_loc_ioctl_data_u_type_u.user_verify_resp.user_resp =
-            RPC_LOC_NI_LCS_NOTIFY_VERIFY_DENY;
-        break;
-    case LOC_GPS_NI_RESPONSE_NORESP:
-    default:
-        data.rpc_loc_ioctl_data_u_type_u.user_verify_resp.user_resp =
-            RPC_LOC_NI_LCS_NOTIFY_VERIFY_NORESP;
-        break;
-    }
-
-    return convertErr(
-        loc_eng_ioctl(client_handle,
-                      RPC_LOC_IOCTL_INFORM_NI_USER_RESPONSE,
-                      &data,
-                      LOC_IOCTL_DEFAULT_TIMEOUT,
-                      &callback_payload)
-        );
-}
-
-enum loc_api_adapter_err
-LocApiRpc::setAPN(char* apn, int len, boolean force)
-{
-    enum loc_api_adapter_err rtv = LOC_API_ADAPTER_ERR_SUCCESS;
-    int size = sizeof(apnLastSet);
-    if (force || memcmp(apnLastSet, apn, size)) {
-        if (len < size) {
-            // size will be not larger than its original value
-            size = len + 1;
-        }
-        memcpy(apnLastSet, apn, size);
-
-        if (!isInSession()) {
-            rpc_loc_ioctl_data_u_type ioctl_data = {RPC_LOC_IOCTL_SET_LBS_APN_PROFILE, {0}};
-            ioctl_data.rpc_loc_ioctl_data_u_type_u.apn_profiles[0].srv_system_type = LOC_APN_PROFILE_SRV_SYS_MAX;
-            ioctl_data.rpc_loc_ioctl_data_u_type_u.apn_profiles[0].pdp_type = LOC_APN_PROFILE_PDN_TYPE_IPV4;
-            memcpy(&(ioctl_data.rpc_loc_ioctl_data_u_type_u.apn_profiles[0].apn_name), apn, size);
-
-            rtv = convertErr(
-                loc_eng_ioctl (client_handle,
-                               RPC_LOC_IOCTL_SET_LBS_APN_PROFILE,
-                               &ioctl_data,
-                               LOC_IOCTL_DEFAULT_TIMEOUT,
-                               NULL)
-                );
-        }
-    }
-    return rtv;
-}
-
-void LocApiRpc::setInSession(bool inSession)
-{
-    if (!inSession) {
-        enableData(dataEnableLastSet, true);
-        setAPN(apnLastSet, sizeof(apnLastSet)-1, true);
-    }
-}
-
-enum loc_api_adapter_err
-LocApiRpc::setServer(const char* url, int len)
-{
-    rpc_loc_ioctl_data_u_type         ioctl_data;
-    rpc_loc_server_info_s_type       *server_info_ptr;
-    rpc_loc_ioctl_e_type              ioctl_cmd;
-
-    ioctl_cmd = RPC_LOC_IOCTL_SET_UMTS_SLP_SERVER_ADDR;
-    ioctl_data.disc = ioctl_cmd;
-    server_info_ptr = &ioctl_data.rpc_loc_ioctl_data_u_type_u.server_addr;
-    server_info_ptr->addr_type = RPC_LOC_SERVER_ADDR_URL;
-    server_info_ptr->addr_info.disc = server_info_ptr->addr_type;
-    server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.url.length = len;
-#if (AMSS_VERSION==3200)
-    server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.url.addr.addr_val = (char*) url;
-    server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.url.addr.addr_len= len;
-#else
-    strlcpy(server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.url.addr, url,
-            sizeof server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.url.addr);
-#endif /* #if (AMSS_VERSION==3200) */
-    LOC_LOGD ("loc_eng_set_server, addr = %s\n", url);
-
-    return convertErr(
-        loc_eng_ioctl (client_handle,
-                       ioctl_cmd,
-                       &ioctl_data,
-                       LOC_IOCTL_DEFAULT_TIMEOUT,
-                       NULL /* No output information is expected*/)
-        );
-}
-
-enum loc_api_adapter_err
-LocApiRpc::setServer(unsigned int ip, int port, LocServerType type)
-{
-    rpc_loc_ioctl_data_u_type         ioctl_data;
-    rpc_loc_server_info_s_type       *server_info_ptr;
-    rpc_loc_ioctl_e_type              ioctl_cmd;
-
-    switch (type) {
-    case LOC_AGPS_MPC_SERVER:
-        ioctl_cmd = RPC_LOC_IOCTL_SET_CDMA_MPC_SERVER_ADDR;
-        break;
-    case LOC_AGPS_CUSTOM_PDE_SERVER:
-        ioctl_cmd = RPC_LOC_IOCTL_SET_CUSTOM_PDE_SERVER_ADDR;
-        break;
-    default:
-        ioctl_cmd = RPC_LOC_IOCTL_SET_CDMA_PDE_SERVER_ADDR;
-        break;
-    }
-    ioctl_data.disc = ioctl_cmd;
-    server_info_ptr = &ioctl_data.rpc_loc_ioctl_data_u_type_u.server_addr;
-    server_info_ptr->addr_type = RPC_LOC_SERVER_ADDR_IPV4;
-    server_info_ptr->addr_info.disc = server_info_ptr->addr_type;
-    server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.ipv4.addr = ip;
-    server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.ipv4.port = port;
-    LOC_LOGD ("setServer, addr = %X:%d\n", (unsigned int) ip, (unsigned int) port);
-
-    return convertErr(
-        loc_eng_ioctl (client_handle,
-                       ioctl_cmd,
-                       &ioctl_data,
-                       LOC_IOCTL_DEFAULT_TIMEOUT,
-                       NULL /* No output information is expected*/)
-        );
-}
-
-enum loc_api_adapter_err
-LocApiRpc::enableData(int enable, boolean force)
-{
-    enum loc_api_adapter_err rtv = LOC_API_ADAPTER_ERR_SUCCESS;
-    if (force || dataEnableLastSet != enable) {
-        dataEnableLastSet = enable;
-
-        if (!isInSession()) {
-            rpc_loc_ioctl_data_u_type ioctl_data = {RPC_LOC_IOCTL_SET_DATA_ENABLE, {0}};
-
-            ioctl_data.rpc_loc_ioctl_data_u_type_u.data_enable = enable;
-            rtv =  convertErr(
-                loc_eng_ioctl (client_handle,
-                               RPC_LOC_IOCTL_SET_DATA_ENABLE,
-                               &ioctl_data,
-                               LOC_IOCTL_DEFAULT_TIMEOUT,
-                               NULL)
-                );
-        }
-    }
-    return rtv;
-}
-
-enum loc_api_adapter_err
-LocApiRpc::deleteAidingData(LocGpsAidingData bits)
-{
-    rpc_loc_ioctl_data_u_type ioctl_data = {RPC_LOC_IOCTL_DELETE_ASSIST_DATA, {0}};
-    ioctl_data.rpc_loc_ioctl_data_u_type_u.assist_data_delete.type = bits;
-
-    return convertErr(
-        loc_eng_ioctl (client_handle,
-                       RPC_LOC_IOCTL_DELETE_ASSIST_DATA,
-                       &ioctl_data,
-                       LOC_IOCTL_DEFAULT_TIMEOUT,
-                       NULL)
-        );
-}
-
-void LocApiRpc::reportPosition(const rpc_loc_parsed_position_s_type *location_report_ptr)
-{
-    LocPosTechMask tech_Mask = LOC_POS_TECH_MASK_DEFAULT;
-
-    UlpLocation location = {0};
-    GpsLocationExtended locationExtended = {0};
-
-    location.size = sizeof(location);
-    locationExtended.size = sizeof(locationExtended);
-    if (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_SESSION_STATUS)
-    {
-        // Process the position from final and intermediate reports
-        if (location_report_ptr->session_status == RPC_LOC_SESS_STATUS_SUCCESS ||
-            location_report_ptr->session_status == RPC_LOC_SESS_STATUS_IN_PROGESS)
-        {
-            // Latitude & Longitude
-            if ((location_report_ptr->valid_mask & RPC_LOC_POS_VALID_LATITUDE) &&
-                (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_LONGITUDE) &&
-                (location_report_ptr->latitude != 0 ||
-                 location_report_ptr->longitude != 0))
-            {
-                location.gpsLocation.flags    |= LOC_GPS_LOCATION_HAS_LAT_LONG;
-                location.gpsLocation.latitude  = location_report_ptr->latitude;
-                location.gpsLocation.longitude = location_report_ptr->longitude;
-
-                // Time stamp (UTC)
-                if (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_TIMESTAMP_UTC)
-                {
-                    location.gpsLocation.timestamp = location_report_ptr->timestamp_utc;
-                }
-
-                // Altitude
-                if (location_report_ptr->valid_mask &  RPC_LOC_POS_VALID_ALTITUDE_WRT_ELLIPSOID )
-                {
-                    location.gpsLocation.flags    |= LOC_GPS_LOCATION_HAS_ALTITUDE;
-                    location.gpsLocation.altitude = location_report_ptr->altitude_wrt_ellipsoid;
-                }
-
-                // Speed
-                if (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_SPEED_HORIZONTAL)
-                {
-                    location.gpsLocation.flags    |= LOC_GPS_LOCATION_HAS_SPEED;
-                    location.gpsLocation.speed = location_report_ptr->speed_horizontal;
-                }
-
-                // Heading
-                if (location_report_ptr->valid_mask &  RPC_LOC_POS_VALID_HEADING)
-                {
-                    location.gpsLocation.flags    |= LOC_GPS_LOCATION_HAS_BEARING;
-                    location.gpsLocation.bearing = location_report_ptr->heading;
-                }
-
-                // Uncertainty (circular)
-                if ( (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_HOR_UNC_CIRCULAR) )
-                {
-                    location.gpsLocation.flags    |= LOC_GPS_LOCATION_HAS_ACCURACY;
-                    location.gpsLocation.accuracy = location_report_ptr->hor_unc_circular;
-                }
-
-                // Technology Mask
-
-                tech_Mask  |= location_report_ptr->technology_mask;
-                //Mark the location source as from GNSS
-                location.gpsLocation.flags |= LOCATION_HAS_SOURCE_INFO;
-                location.position_source = ULP_LOCATION_IS_FROM_GNSS;
-                if (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_ALTITUDE_WRT_MEAN_SEA_LEVEL)
-                {
-                    locationExtended.flags |= GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL;
-                    locationExtended.altitudeMeanSeaLevel = location_report_ptr->altitude_wrt_mean_sea_level;
-                }
-
-                if (location_report_ptr->valid_mask &  RPC_LOC_POS_VALID_MAGNETIC_VARIATION )
-                {
-                    locationExtended.flags |= GPS_LOCATION_EXTENDED_HAS_MAG_DEV;
-                    locationExtended.magneticDeviation = location_report_ptr->magnetic_deviation;
-                }
-
-                if (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_VERTICAL_UNC)
-                {
-                   locationExtended.flags |= GPS_LOCATION_EXTENDED_HAS_VERT_UNC;
-                   locationExtended.vert_unc = location_report_ptr->vert_unc;
-                }
-
-                if (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_SPEED_UNC)
-                {
-                   locationExtended.flags |= GPS_LOCATION_EXTENDED_HAS_SPEED_UNC;
-                   locationExtended.speed_unc = location_report_ptr->speed_unc;
-                }
-
-                LOC_LOGV("reportPosition: fire callback\n");
-                enum loc_sess_status fixStatus =
-                    (location_report_ptr->session_status
-                     == RPC_LOC_SESS_STATUS_IN_PROGESS ?
-                     LOC_SESS_INTERMEDIATE : LOC_SESS_SUCCESS);
-                LocApiBase::reportPosition(location,
-                                           locationExtended,
-                                           (void*)location_report_ptr,
-                                           fixStatus,
-                                           tech_Mask);
-            }
-        }
-        else
-        {
-            LocApiBase::reportPosition(location,
-                                       locationExtended,
-                                       NULL,
-                                       LOC_SESS_FAILURE);
-            LOC_LOGV("loc_eng_report_position: ignore position report "
-                     "when session status = %d\n",
-                     location_report_ptr->session_status);
-        }
-    }
-    else
-    {
-        LOC_LOGV("loc_eng_report_position: ignore position report "
-                 "when session status is not set\n");
-    }
-}
-
-void LocApiRpc::reportSv(const rpc_loc_gnss_info_s_type *gnss_report_ptr)
-{
-    QtiGnssSvStatus     SvStatus = {0};
-    GpsLocationExtended locationExtended = {0};
-    locationExtended.size = sizeof(locationExtended);
-    int             num_svs_max = 0;
-    const rpc_loc_sv_info_s_type *sv_info_ptr;
-
-    if (gnss_report_ptr->valid_mask & RPC_LOC_GNSS_INFO_VALID_SV_COUNT)
-    {
-        num_svs_max = gnss_report_ptr->sv_count;
-        if (num_svs_max > LOC_GPS_MAX_SVS)
-        {
-            num_svs_max = LOC_GPS_MAX_SVS;
-        }
-    }
-
-    if (gnss_report_ptr->valid_mask & RPC_LOC_GNSS_INFO_VALID_SV_LIST)
-    {
-        SvStatus.num_svs = 0;
-
-        for (int i = 0; i < num_svs_max; i++)
-        {
-            sv_info_ptr = &(gnss_report_ptr->sv_list.sv_list_val[i]);
-            if (sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_SYSTEM)
-            {
-                if (sv_info_ptr->system == RPC_LOC_SV_SYSTEM_GPS)
-                {
-                    SvStatus.sv_list[SvStatus.num_svs].size = sizeof(LocGpsSvInfo);
-                    SvStatus.sv_list[SvStatus.num_svs].prn = sv_info_ptr->prn;
-
-                    // We only have the data field to report gps eph and alm mask
-                    if ((sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_HAS_EPH) &&
-                        (sv_info_ptr->has_eph == 1))
-                    {
-                        SvStatus.ephemeris_mask |= (1 << (sv_info_ptr->prn-1));
-                    }
-
-                    if ((sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_HAS_ALM) &&
-                        (sv_info_ptr->has_alm == 1))
-                    {
-                        SvStatus.almanac_mask |= (1 << (sv_info_ptr->prn-1));
-                    }
-
-                    if ((sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_PROCESS_STATUS) &&
-                        (sv_info_ptr->process_status == RPC_LOC_SV_STATUS_TRACK))
-                    {
-                        SvStatus.gps_used_in_fix_mask |= (1 << (sv_info_ptr->prn-1));
-                    }
-                }
-                // SBAS: GPS RPN: 120-151,
-                // In exteneded measurement report, we follow nmea standard, which is from 33-64.
-                else if (sv_info_ptr->system == RPC_LOC_SV_SYSTEM_SBAS)
-                {
-                    SvStatus.sv_list[SvStatus.num_svs].prn = sv_info_ptr->prn + 33 - 120;
-                }
-                // Gloness: Slot id: 1-32
-                // In extended measurement report, we follow nmea standard, which is 65-96
-                else if (sv_info_ptr->system == RPC_LOC_SV_SYSTEM_GLONASS)
-                {
-                    if ((sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_PROCESS_STATUS) &&
-                        (sv_info_ptr->process_status == RPC_LOC_SV_STATUS_TRACK))
-                    {
-                        SvStatus.glo_used_in_fix_mask |= (1 << (sv_info_ptr->prn-1));
-                    }
-
-                    SvStatus.sv_list[SvStatus.num_svs].prn = sv_info_ptr->prn + (65-1);
-                }
-                // Unsupported SV system
-                else
-                {
-                    continue;
-                }
-            }
-
-            if (sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_SNR)
-            {
-                SvStatus.sv_list[SvStatus.num_svs].snr = sv_info_ptr->snr;
-            }
-
-            if (sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_ELEVATION)
-            {
-                SvStatus.sv_list[SvStatus.num_svs].elevation = sv_info_ptr->elevation;
-            }
-
-            if (sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_AZIMUTH)
-            {
-                SvStatus.sv_list[SvStatus.num_svs].azimuth = sv_info_ptr->azimuth;
-            }
-
-            SvStatus.num_svs++;
-        }
-    }
-
-    if ((gnss_report_ptr->valid_mask & RPC_LOC_GNSS_INFO_VALID_POS_DOP) &&
-        (gnss_report_ptr->valid_mask & RPC_LOC_GNSS_INFO_VALID_HOR_DOP) &&
-        (gnss_report_ptr->valid_mask & RPC_LOC_GNSS_INFO_VALID_VERT_DOP))
-    {
-        locationExtended.flags |= GPS_LOCATION_EXTENDED_HAS_DOP;
-        locationExtended.pdop = gnss_report_ptr->position_dop;
-        locationExtended.hdop = gnss_report_ptr->horizontal_dop;
-        locationExtended.vdop = gnss_report_ptr->vertical_dop;
-    }
-
-    if (SvStatus.num_svs >= 0)
-    {
-        LocApiBase::reportSv(SvStatus,
-                             locationExtended,
-                             (void*)gnss_report_ptr);
-    }
-}
-
-void LocApiRpc::reportStatus(const rpc_loc_status_event_s_type *status_report_ptr)
-{
-
-    if (status_report_ptr->event == RPC_LOC_STATUS_EVENT_ENGINE_STATE) {
-        if (status_report_ptr->payload.rpc_loc_status_event_payload_u_type_u.engine_state == RPC_LOC_ENGINE_STATE_ON)
-        {
-            LocApiBase::reportStatus(LOC_GPS_STATUS_ENGINE_ON);
-            LocApiBase::reportStatus(LOC_GPS_STATUS_SESSION_BEGIN);
-        }
-        else if (status_report_ptr->payload.rpc_loc_status_event_payload_u_type_u.engine_state == RPC_LOC_ENGINE_STATE_OFF)
-        {
-            LocApiBase::reportStatus(LOC_GPS_STATUS_SESSION_END);
-            LocApiBase::reportStatus(LOC_GPS_STATUS_ENGINE_OFF);
-        }
-        else
-        {
-            LocApiBase::reportStatus(LOC_GPS_STATUS_NONE);
-        }
-    }
-
-}
-
-void LocApiRpc::reportNmea(const rpc_loc_nmea_report_s_type *nmea_report_ptr)
-{
-
-#if (AMSS_VERSION==3200)
-    LocApiBase::reportNmea(nmea_report_ptr->nmea_sentences.nmea_sentences_val,
-                           nmea_report_ptr->nmea_sentences.nmea_sentences_len);
-#else
-    LocApiBase::reportNmea(nmea_report_ptr->nmea_sentences,
-                           nmea_report_ptr->length);
-    LOC_LOGD("loc_eng_report_nmea: $%c%c%c\n",
-             nmea_report_ptr->nmea_sentences[3],
-             nmea_report_ptr->nmea_sentences[4],
-             nmea_report_ptr->nmea_sentences[5]);
-#endif /* #if (AMSS_VERSION==3200) */
-}
-
-enum loc_api_adapter_err
-LocApiRpc::setXtraData(char* data, int length)
-{
-    int     rpc_ret_val = RPC_LOC_API_GENERAL_FAILURE;
-    int     total_parts;
-    uint8   part;
-    uint16  part_len;
-    uint16  len_injected;
-    rpc_loc_ioctl_data_u_type            ioctl_data;
-    rpc_loc_ioctl_e_type                 ioctl_type = RPC_LOC_IOCTL_INJECT_PREDICTED_ORBITS_DATA;
-    rpc_loc_predicted_orbits_data_s_type *predicted_orbits_data_ptr;
-
-    LOC_LOGD("qct_loc_eng_inject_xtra_data, xtra size = %d, data ptr = 0x%lx\n", length, (long) data);
-
-    predicted_orbits_data_ptr = &ioctl_data.rpc_loc_ioctl_data_u_type_u.predicted_orbits_data;
-    predicted_orbits_data_ptr->format_type = RPC_LOC_PREDICTED_ORBITS_XTRA;
-    predicted_orbits_data_ptr->total_size = length;
-    total_parts = (length - 1) / XTRA_BLOCK_SIZE + 1;
-    predicted_orbits_data_ptr->total_parts = total_parts;
-
-    len_injected = 0; // O bytes injected
-    ioctl_data.disc = ioctl_type;
-
-    // XTRA injection starts with part 1
-    for (part = 1; part <= total_parts; part++)
-    {
-        predicted_orbits_data_ptr->part = part;
-        predicted_orbits_data_ptr->part_len = XTRA_BLOCK_SIZE;
-        if (XTRA_BLOCK_SIZE > (length - len_injected))
-        {
-            predicted_orbits_data_ptr->part_len = length - len_injected;
-        }
-        predicted_orbits_data_ptr->data_ptr.data_ptr_len = predicted_orbits_data_ptr->part_len;
-        predicted_orbits_data_ptr->data_ptr.data_ptr_val = data + len_injected;
-
-        LOC_LOGD("qct_loc_eng_inject_xtra_data, part %d/%d, len = %d, total = %d\n",
-                 predicted_orbits_data_ptr->part,
-                 total_parts,
-                 predicted_orbits_data_ptr->part_len,
-                 len_injected);
-
-        if (part < total_parts)
-        {
-            // No callback in this case
-            rpc_ret_val = loc_ioctl (client_handle,
-                                     ioctl_type,
-                                     &ioctl_data);
-
-            if (rpc_ret_val != RPC_LOC_API_SUCCESS)
-            {
-                LOC_LOGE("loc_ioctl for xtra error: %s\n", loc_get_ioctl_status_name(rpc_ret_val));
-                break;
-            }
-            //Add a delay of 10 ms so that repeated RPC calls dont starve the modem processor
-            usleep(10 * 1000);
-        }
-        else // part == total_parts
-        {
-            // Last part injection, will need to wait for callback
-            if (!loc_eng_ioctl(client_handle,
-                               ioctl_type,
-                               &ioctl_data,
-                               LOC_XTRA_INJECT_DEFAULT_TIMEOUT,
-                               NULL))
-            {
-                rpc_ret_val = RPC_LOC_API_GENERAL_FAILURE;
-            }
-            break; // done with injection
-        }
-
-        len_injected += predicted_orbits_data_ptr->part_len;
-        LOC_LOGD("loc_ioctl XTRA injected length: %d\n", len_injected);
-    }
-
-    return convertErr(rpc_ret_val);
-}
-
-/* Request the Xtra Server Url from the modem */
-enum loc_api_adapter_err
-LocApiRpc::requestXtraServer()
-{
-    loc_api_adapter_err           err;
-    rpc_loc_ioctl_data_u_type     data;
-    rpc_loc_ioctl_callback_s_type callback_data;
-
-    err = convertErr(loc_eng_ioctl(client_handle,
-                                   RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE,
-                                   &data,
-                                   LOC_IOCTL_DEFAULT_TIMEOUT,
-                                   &callback_data));
-
-    if (LOC_API_ADAPTER_ERR_SUCCESS != err)
-    {
-        LOC_LOGE("RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE failed!: err=%d\n", err);
-        return err;
-    }
-    else if (RPC_LOC_SESS_STATUS_SUCCESS != callback_data.status)
-    {
-        LOC_LOGE("RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE failed!: status=%ld\n", callback_data.status);
-        return LOC_API_ADAPTER_ERR_GENERAL_FAILURE;
-    }
-    else if (RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE != callback_data.type)
-    {
-        LOC_LOGE("RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE is not the type expected! type=%d\n", callback_data.type);
-        return LOC_API_ADAPTER_ERR_GENERAL_FAILURE;
-    }
-    else if (RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE != callback_data.data.disc)
-    {
-        LOC_LOGE("RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE is not the disc expected! disc=%d\n", callback_data.data.disc);
-        return LOC_API_ADAPTER_ERR_GENERAL_FAILURE;
-    }
-
-    reportXtraServer(callback_data.data.rpc_loc_ioctl_callback_data_u_type_u.
-                     predicted_orbits_data_source.servers[0],
-                     callback_data.data.rpc_loc_ioctl_callback_data_u_type_u.
-                     predicted_orbits_data_source.servers[1],
-                     callback_data.data.rpc_loc_ioctl_callback_data_u_type_u.
-                     predicted_orbits_data_source.servers[2],
-                     255);
-
-    return LOC_API_ADAPTER_ERR_SUCCESS;
-}
-
-enum loc_api_adapter_err
-LocApiRpc::atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bearer, LocAGpsType agpsType)
-{
-    rpc_loc_server_open_status_e_type open_status = is_succ ? RPC_LOC_SERVER_OPEN_SUCCESS : RPC_LOC_SERVER_OPEN_FAIL;
-   rpc_loc_ioctl_data_u_type           ioctl_data;
-
-    if (LOC_AGPS_TYPE_INVALID == agpsType) {
-        rpc_loc_server_open_status_s_type  *conn_open_status_ptr =
-            &ioctl_data.rpc_loc_ioctl_data_u_type_u.conn_open_status;
-
-        // Fill in data
-        ioctl_data.disc = RPC_LOC_IOCTL_INFORM_SERVER_OPEN_STATUS;
-        conn_open_status_ptr->conn_handle = handle;
-        conn_open_status_ptr->open_status = open_status;
-#if (AMSS_VERSION==3200)
-        conn_open_status_ptr->apn_name = apn; /* requires APN */
-#else
-        if (is_succ) {
-            strlcpy(conn_open_status_ptr->apn_name, apn,
-                    sizeof conn_open_status_ptr->apn_name);
-        } else {
-            conn_open_status_ptr->apn_name[0] = 0;
-        }
-#endif /* #if (AMSS_VERSION==3200) */
-
-        LOC_LOGD("ATL RPC_LOC_IOCTL_INFORM_SERVER_OPEN_STATUS open %s, APN name = [%s]\n",
-                 log_succ_fail_string(is_succ),
-                 apn);
-    } else {
-        rpc_loc_server_multi_open_status_s_type  *conn_multi_open_status_ptr =
-            &ioctl_data.rpc_loc_ioctl_data_u_type_u.multi_conn_open_status;
-
-        // Fill in data
-        ioctl_data.disc = RPC_LOC_IOCTL_INFORM_SERVER_MULTI_OPEN_STATUS;
-        conn_multi_open_status_ptr->conn_handle = handle;
-        conn_multi_open_status_ptr->open_status = open_status;
-        if (is_succ) {
-            strlcpy(conn_multi_open_status_ptr->apn_name, apn,
-                    sizeof conn_multi_open_status_ptr->apn_name);
-        } else {
-            conn_multi_open_status_ptr->apn_name[0] = 0;
-        }
-
-        switch(bearer)
-        {
-        case AGPS_APN_BEARER_IPV4:
-            conn_multi_open_status_ptr->pdp_type = RPC_LOC_SERVER_PDP_IP;
-            break;
-        case AGPS_APN_BEARER_IPV6:
-            conn_multi_open_status_ptr->pdp_type = RPC_LOC_SERVER_PDP_IPV6;
-            break;
-        case AGPS_APN_BEARER_IPV4V6:
-            conn_multi_open_status_ptr->pdp_type = RPC_LOC_SERVER_PDP_IPV4V6;
-            break;
-        default:
-            conn_multi_open_status_ptr->pdp_type = RPC_LOC_SERVER_PDP_PPP;
-        }
-
-        LOC_LOGD("ATL RPC_LOC_IOCTL_INFORM_SERVER_MULTI_OPEN_STATUS open %s, APN name = [%s], pdp_type = %d\n",
-                 log_succ_fail_string(is_succ),
-                 apn,
-                 conn_multi_open_status_ptr->pdp_type);
-    }
-
-    // Make the IOCTL call
-    return convertErr(
-        loc_eng_ioctl(client_handle,
-                      ioctl_data.disc,
-                      &ioctl_data,
-                      LOC_IOCTL_DEFAULT_TIMEOUT,
-                      NULL)
-        );
-}
-
-enum loc_api_adapter_err
-LocApiRpc::atlCloseStatus(int handle, int is_succ)
-{
-    rpc_loc_ioctl_data_u_type           ioctl_data;
-    ioctl_data.disc = RPC_LOC_IOCTL_INFORM_SERVER_CLOSE_STATUS;
-
-    rpc_loc_server_close_status_s_type *conn_close_status_ptr =
-        &ioctl_data.rpc_loc_ioctl_data_u_type_u.conn_close_status;
-    conn_close_status_ptr->conn_handle = handle;
-    conn_close_status_ptr->close_status = is_succ ? RPC_LOC_SERVER_CLOSE_SUCCESS : RPC_LOC_SERVER_CLOSE_FAIL;
-
-    // Make the IOCTL call
-    return convertErr(
-        loc_eng_ioctl(client_handle,
-                      ioctl_data.disc,
-                      &ioctl_data,
-                      LOC_IOCTL_DEFAULT_TIMEOUT,
-                      NULL)
-        );
-}
-
-void LocApiRpc::ATLEvent(const rpc_loc_server_request_s_type *server_request_ptr)
-{
-    int connHandle;
-    LocAGpsType agps_type;
-
-    LOC_LOGV("RPC_LOC_EVENT_ASSISTANCE_DATA_REQUEST event %s)",
-             loc_get_event_atl_open_name(server_request_ptr->event));
-    switch (server_request_ptr->event)
-    {
-    case RPC_LOC_SERVER_REQUEST_MULTI_OPEN:
-        connHandle = server_request_ptr->payload.rpc_loc_server_request_u_type_u.multi_open_req.conn_handle;
-        if (server_request_ptr->payload.rpc_loc_server_request_u_type_u.multi_open_req.connection_type
-            == RPC_LOC_SERVER_CONNECTION_LBS) {
-            agps_type = LOC_AGPS_TYPE_SUPL;
-            LOC_LOGV("ATLEvent: event - RPC_LOC_SERVER_REQUEST_MULTI_OPEN\n            type - LOC_AGPS_TYPE_SUPL\n            handle - %d", connHandle);
-        } else {
-            agps_type = LOC_AGPS_TYPE_WWAN_ANY;
-            LOC_LOGV("ATLEvent: event - RPC_LOC_SERVER_REQUEST_MULTI_OPEN\n            type - LOC_AGPS_TYPE_WWAN_ANY\n            handle - %d", connHandle);
-        }
-        requestATL(connHandle, agps_type);
-        break;
-    case RPC_LOC_SERVER_REQUEST_OPEN:
-        connHandle = server_request_ptr->payload.rpc_loc_server_request_u_type_u.open_req.conn_handle;
-        LOC_LOGV("ATLEvent: event - RPC_LOC_SERVER_REQUEST_OPEN\n            handle - %d", connHandle);
-        requestATL(connHandle, LOC_AGPS_TYPE_INVALID);
-        break;
-    case RPC_LOC_SERVER_REQUEST_CLOSE:
-        connHandle = server_request_ptr->payload.rpc_loc_server_request_u_type_u.close_req.conn_handle;
-        LOC_LOGV("ATLEvent: event - RPC_LOC_SERVER_REQUEST_CLOSE\n            handle - %d", connHandle);
-        releaseATL(connHandle);
-        break;
-    default:
-        LOC_LOGE("ATLEvent: event type %d invalid", server_request_ptr->event);
-   }
-}
-
-void LocApiRpc::NIEvent(const rpc_loc_ni_event_s_type *ni_req)
-{
-    LocGpsNiNotification notif = {0};
-
-    switch (ni_req->event)
-    {
-    case RPC_LOC_NI_EVENT_VX_NOTIFY_VERIFY_REQ:
-    {
-        const rpc_loc_ni_vx_notify_verify_req_s_type *vx_req =
-            &ni_req->payload.rpc_loc_ni_event_payload_u_type_u.vx_req;
-        LOC_LOGI("VX Notification");
-        notif.ni_type = LOC_GPS_NI_TYPE_VOICE;
-        // Requestor ID
-        hexcode(notif.requestor_id, sizeof notif.requestor_id,
-                vx_req->requester_id.requester_id,
-                vx_req->requester_id.requester_id_length);
-        notif.text_encoding = 0; // No text and no encoding
-        notif.requestor_id_encoding = convertNiEncodingType(vx_req->encoding_scheme);
-        NIEventFillVerfiyType(notif, vx_req->notification_priv_type);
-    }
-        break;
-
-    case RPC_LOC_NI_EVENT_UMTS_CP_NOTIFY_VERIFY_REQ:
-    {
-        const rpc_loc_ni_umts_cp_notify_verify_req_s_type *umts_cp_req =
-            &ni_req->payload.rpc_loc_ni_event_payload_u_type_u.umts_cp_req;
-        LOC_LOGI("UMTS CP Notification\n");
-        notif.ni_type= LOC_GPS_NI_TYPE_UMTS_CTRL_PLANE;         // Stores notification text
-#if (AMSS_VERSION==3200)
-        hexcode(notif.text, sizeof notif.text,
-                umts_cp_req->notification_text.notification_text_val,
-                umts_cp_req->notification_length);
-        hexcode(notif.requestor_id, sizeof notif.requestor_id,
-                umts_cp_req->requestor_id.requestor_id_string.requestor_id_string_val,
-                umts_cp_req->requestor_id.string_len);
-#else
-        hexcode(notif.text, sizeof notif.text,
-                umts_cp_req->notification_text,
-                umts_cp_req->notification_length);
-        hexcode(notif.requestor_id, sizeof notif.requestor_id,
-                umts_cp_req->requestor_id.requestor_id_string,
-                umts_cp_req->requestor_id.string_len);
-#endif
-        notif.text_encoding = convertNiEncodingType(umts_cp_req->datacoding_scheme);
-        notif.requestor_id_encoding = notif.text_encoding;
-        NIEventFillVerfiyType(notif, umts_cp_req->notification_priv_type);
-
-        // LCS address (using extras field)
-        if (umts_cp_req->ext_client_address_data.ext_client_address_len != 0)
-        {
-            // Copy LCS Address into notif.extras in the format: Address = 012345
-            strlcat(notif.extras, LOC_NI_NOTIF_KEY_ADDRESS, sizeof notif.extras);
-            strlcat(notif.extras, " = ", sizeof notif.extras);
-            int addr_len = 0;
-            const char *address_source = NULL;
-
-#if (AMSS_VERSION==3200)
-            address_source = umts_cp_req->ext_client_address_data.ext_client_address.ext_client_address_val;
-#else
-            address_source = umts_cp_req->ext_client_address_data.ext_client_address;
-#endif /* #if (AMSS_VERSION==3200) */
-
-            char lcs_addr[32]; // Decoded LCS address for UMTS CP NI
-            addr_len = decodeAddress(lcs_addr, sizeof lcs_addr, address_source,
-                                     umts_cp_req->ext_client_address_data.ext_client_address_len);
-
-            // The address is ASCII string
-            if (addr_len)
-            {
-                strlcat(notif.extras, lcs_addr, sizeof notif.extras);
-            }
-        }
-    }
-        break;
-
-    case RPC_LOC_NI_EVENT_SUPL_NOTIFY_VERIFY_REQ:
-    {
-        const rpc_loc_ni_supl_notify_verify_req_s_type *supl_req =
-            &ni_req->payload.rpc_loc_ni_event_payload_u_type_u.supl_req;
-        LOC_LOGI("SUPL Notification\n");
-        notif.ni_type = LOC_GPS_NI_TYPE_UMTS_SUPL;
-
-        if (supl_req->flags & RPC_LOC_NI_CLIENT_NAME_PRESENT)
-        {
-#if (AMSS_VERSION==3200)
-            hexcode(notif.text, sizeof notif.text,
-                    supl_req->client_name.client_name_string.client_name_string_val,   /* buffer */
-                    supl_req->client_name.string_len                                   /* length */
-            );
-#else
-            hexcode(notif.text, sizeof notif.text,
-                            supl_req->client_name.client_name_string,   /* buffer */
-                            supl_req->client_name.string_len            /* length */
-            );
-#endif /* #if (AMSS_VERSION==3200) */
-            LOC_LOGV("SUPL NI: client_name: %s len=%d", notif.text, supl_req->client_name.string_len);
-        }
-        else {
-            LOC_LOGV("SUPL NI: client_name not present.");
-        }
-
-        // Requestor ID
-        if (supl_req->flags & RPC_LOC_NI_REQUESTOR_ID_PRESENT)
-        {
-#if (AMSS_VERSION==3200)
-            hexcode(notif.requestor_id, sizeof notif.requestor_id,
-                    supl_req->requestor_id.requestor_id_string.requestor_id_string_val,  /* buffer */
-                    supl_req->requestor_id.string_len                                    /* length */
-                );
-#else
-            hexcode(notif.requestor_id, sizeof notif.requestor_id,
-                    supl_req->requestor_id.requestor_id_string,  /* buffer */
-                    supl_req->requestor_id.string_len            /* length */
-                );
-#endif /* #if (AMSS_VERSION==3200) */
-            LOC_LOGV("SUPL NI: requestor_id: %s len=%d", notif.requestor_id, supl_req->requestor_id.string_len);
-        }
-        else {
-            LOC_LOGV("SUPL NI: requestor_id not present.");
-        }
-
-        // Encoding type
-        if (supl_req->flags & RPC_LOC_NI_ENCODING_TYPE_PRESENT)
-        {
-            notif.text_encoding = convertNiEncodingType(supl_req->datacoding_scheme);
-            notif.requestor_id_encoding = notif.text_encoding;
-        }
-        else {
-            notif.text_encoding = notif.requestor_id_encoding = LOC_GPS_ENC_UNKNOWN;
-        }
-
-        NIEventFillVerfiyType(notif, ni_req->payload.rpc_loc_ni_event_payload_u_type_u.supl_req.notification_priv_type);
-    }
-        break;
-
-    default:
-        LOC_LOGE("Unknown NI event: %x\n", (int) ni_req->event);
-        return;
-    }
-
-    // this copy will get freed in loc_eng_ni when loc_ni_respond() is called
-    rpc_loc_ni_event_s_type *copy = (rpc_loc_ni_event_s_type *)malloc(sizeof(*copy));
-    memcpy(copy, ni_req, sizeof(*copy));
-    requestNiNotify(notif, (const void*)copy);
-}
-
-int LocApiRpc::NIEventFillVerfiyType(LocGpsNiNotification &notif,
-                                rpc_loc_ni_notify_verify_e_type notif_priv)
-{
-   switch (notif_priv)
-   {
-   case RPC_LOC_NI_USER_NO_NOTIFY_NO_VERIFY:
-       notif.notify_flags = 0;
-       notif.default_response = LOC_GPS_NI_RESPONSE_NORESP;
-       return 1;
-   case RPC_LOC_NI_USER_NOTIFY_ONLY:
-       notif.notify_flags = LOC_GPS_NI_NEED_NOTIFY;
-       notif.default_response = LOC_GPS_NI_RESPONSE_NORESP;
-       return 1;
-   case RPC_LOC_NI_USER_NOTIFY_VERIFY_ALLOW_NO_RESP:
-       notif.notify_flags = LOC_GPS_NI_NEED_NOTIFY | LOC_GPS_NI_NEED_VERIFY;
-       notif.default_response = LOC_GPS_NI_RESPONSE_ACCEPT;
-       return 1;
-   case RPC_LOC_NI_USER_NOTIFY_VERIFY_NOT_ALLOW_NO_RESP:
-       notif.notify_flags = LOC_GPS_NI_NEED_NOTIFY | LOC_GPS_NI_NEED_VERIFY;
-       notif.default_response = LOC_GPS_NI_RESPONSE_DENY;
-       return 1;
-   case RPC_LOC_NI_USER_PRIVACY_OVERRIDE:
-       notif.notify_flags = LOC_GPS_NI_PRIVACY_OVERRIDE;
-       notif.default_response = LOC_GPS_NI_RESPONSE_NORESP;
-       return 1;
-   default:
-      return 0;
-   }
-}
-
-enum loc_api_adapter_err
-LocApiRpc::setSUPLVersion(uint32_t version)
-{
-   rpc_loc_ioctl_data_u_type ioctl_data = {RPC_LOC_IOCTL_SET_SUPL_VERSION, {0}};
-   ioctl_data.rpc_loc_ioctl_data_u_type_u.supl_version = (int)version;
-   return convertErr(
-       loc_eng_ioctl (client_handle,
-                      RPC_LOC_IOCTL_SET_SUPL_VERSION,
-                      &ioctl_data,
-                      LOC_IOCTL_DEFAULT_TIMEOUT,
-                      NULL)
-       );
-}
-
-LocGpsNiEncodingType LocApiRpc::convertNiEncodingType(int loc_encoding)
-{
-   switch (loc_encoding)
-   {
-   case RPC_LOC_NI_SUPL_UTF8:
-       return LOC_GPS_ENC_SUPL_UTF8;
-   case RPC_LOC_NI_SUPL_UCS2:
-       return LOC_GPS_ENC_SUPL_UCS2;
-   case RPC_LOC_NI_SUPL_GSM_DEFAULT:
-      return LOC_GPS_ENC_SUPL_GSM_DEFAULT;
-   case RPC_LOC_NI_SS_LANGUAGE_UNSPEC:
-      return LOC_GPS_ENC_SUPL_GSM_DEFAULT; // SS_LANGUAGE_UNSPEC = GSM
-   default:
-       return LOC_GPS_ENC_UNKNOWN;
-   }
-}
-
-LocApiBase* getLocApi(const MsgTask* msgTask,
-                      LOC_API_ADAPTER_EVENT_MASK_T exMask,
-                      ContextBase *context) {
-    return new LocApiRpc(msgTask, exMask, context);
-}
-
-/*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
-*/
-int LocApiRpc::setGpsLock(LOC_GPS_LOCK_MASK lockMask)
-{
-    rpc_loc_ioctl_data_u_type    ioctl_data;
-    boolean ret_val;
-    LOC_LOGD("%s:%d]: lock: %x\n", __func__, __LINE__, lockMask);
-    ioctl_data.rpc_loc_ioctl_data_u_type_u.engine_lock = convertGpsLockMask(lockMask);
-    ioctl_data.disc = RPC_LOC_IOCTL_SET_ENGINE_LOCK;
-    ret_val = loc_eng_ioctl (loc_eng_data.client_handle,
-                            RPC_LOC_IOCTL_SET_ENGINE_LOCK,
-                            &ioctl_data,
-                            LOC_IOCTL_DEFAULT_TIMEOUT,
-                            NULL /* No output information is expected*/);
-
-    LOC_LOGD("%s:%d]: ret_val: %d\n", __func__, __LINE__, (int)ret_val);
-    return (ret_val == TRUE ? 0 : -1);
-}
-
-/*
-  Returns
-  Current value of GPS lock on success
-  -1 on failure
-*/
-int LocApiRpc :: getGpsLock()
-{
-    rpc_loc_ioctl_data_u_type    ioctl_data;
-    rpc_loc_ioctl_callback_s_type callback_payload;
-    boolean ret_val;
-    int ret=0;
-    LOC_LOGD("%s:%d]: Enter\n", __func__, __LINE__);
-    ret_val = loc_eng_ioctl (loc_eng_data.client_handle,
-                            RPC_LOC_IOCTL_GET_ENGINE_LOCK,
-                            &ioctl_data,
-                            LOC_IOCTL_DEFAULT_TIMEOUT,
-                            &callback_payload);
-    if(ret_val == TRUE) {
-        ret = (int)callback_payload.data.engine_lock;
-        LOC_LOGD("%s:%d]: Lock type: %d\n", __func__, __LINE__, ret);
-    }
-    else {
-        LOC_LOGE("%s:%d]: Ioctl failed", __func__, __LINE__);
-        ret = -1;
-    }
-    LOC_LOGD("%s:%d]: Exit\n", __func__, __LINE__);
-    return ret;
-}
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_api_fixup.c b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_api_fixup.c
deleted file mode 100644
index 837ef11..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_api_fixup.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/* 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 <rpc/rpc.h>
-
-#include "loc_api_fixup.h"
-
-#ifdef ADD_XDR_FLOAT
-
-int
-xdr_float(xdrp, fp)
-        XDR *xdrp;
-        float *fp;
-{
-        return xdr_long(xdrp, (long*)fp);
-}
-
-int
-xdr_double(xdrp, dp)
-        XDR *xdrp;
-        double *dp;
-{
-                return xdr_long(xdrp, (long*)dp + 1)
-                                && xdr_long(xdrp, (long*)dp);
-}
-
-#endif /* ADD_XDR_FLOAT */
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_api_log.c b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_api_log.c
deleted file mode 100644
index eb685fd..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_api_log.c
+++ /dev/null
@@ -1,344 +0,0 @@
-/* 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_api_rpc_glue"
-
-#include "loc_api_log.h"
-#include "loc_log.h"
-#include "platform_lib_includes.h"
-#include "rpc/rpc.h"
-#include "loc_api_fixup.h"
-
-/* Event names */
-loc_name_val_s_type loc_event_name[] =
-   {
-      NAME_VAL( RPC_LOC_EVENT_PARSED_POSITION_REPORT ),
-      NAME_VAL( RPC_LOC_EVENT_SATELLITE_REPORT ),
-      NAME_VAL( RPC_LOC_EVENT_NMEA_1HZ_REPORT ),
-      NAME_VAL( RPC_LOC_EVENT_NMEA_POSITION_REPORT ),
-      NAME_VAL( RPC_LOC_EVENT_NI_NOTIFY_VERIFY_REQUEST ),
-      NAME_VAL( RPC_LOC_EVENT_ASSISTANCE_DATA_REQUEST ),
-      NAME_VAL( RPC_LOC_EVENT_LOCATION_SERVER_REQUEST ),
-      NAME_VAL( RPC_LOC_EVENT_IOCTL_REPORT ),
-      NAME_VAL( RPC_LOC_EVENT_STATUS_REPORT ),
-      NAME_VAL( RPC_LOC_EVENT_WPS_NEEDED_REQUEST ),
-   };
-int loc_event_num = sizeof loc_event_name / sizeof(loc_name_val_s_type);
-
-/* Event names */
-loc_name_val_s_type loc_event_atl_open_name[] =
-   {
-      NAME_VAL( RPC_LOC_SERVER_REQUEST_OPEN ),
-      NAME_VAL( RPC_LOC_SERVER_REQUEST_CLOSE ),
-      NAME_VAL( RPC_LOC_SERVER_REQUEST_MULTI_OPEN )
-   };
-int loc_event_atl_open_num = sizeof loc_event_atl_open_name / sizeof(loc_name_val_s_type);
-
-/* Finds the first event found in the mask */
-const char* loc_get_event_atl_open_name(rpc_loc_server_request_e_type loc_event_atl_open)
-{
-   return loc_get_name_from_val(loc_event_atl_open_name, loc_event_atl_open_num,
-         (long) loc_event_atl_open);
-}
-
-/* IOCTL Type names */
-loc_name_val_s_type loc_ioctl_type_name[] =
-   {
-      NAME_VAL( RPC_LOC_IOCTL_GET_API_VERSION ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_FIX_CRITERIA ),
-      NAME_VAL( RPC_LOC_IOCTL_GET_FIX_CRITERIA ),
-      NAME_VAL( RPC_LOC_IOCTL_INFORM_NI_USER_RESPONSE ),
-      NAME_VAL( RPC_LOC_IOCTL_INJECT_PREDICTED_ORBITS_DATA ),
-      NAME_VAL( RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_VALIDITY ),
-      NAME_VAL( RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_PREDICTED_ORBITS_DATA_AUTO_DOWNLOAD ),
-      NAME_VAL( RPC_LOC_IOCTL_INJECT_UTC_TIME ),
-      NAME_VAL( RPC_LOC_IOCTL_INJECT_RTC_VALUE ),
-      NAME_VAL( RPC_LOC_IOCTL_INJECT_POSITION ),
-      NAME_VAL( RPC_LOC_IOCTL_QUERY_ENGINE_STATE ),
-      NAME_VAL( RPC_LOC_IOCTL_ERROR_ESTIMATE_CONFIG),
-      NAME_VAL( RPC_LOC_IOCTL_INFORM_SERVER_MULTI_OPEN_STATUS ),
-      NAME_VAL( RPC_LOC_IOCTL_INFORM_SERVER_OPEN_STATUS ),
-      NAME_VAL( RPC_LOC_IOCTL_INFORM_SERVER_CLOSE_STATUS ),
-      NAME_VAL( RPC_LOC_IOCTL_SEND_WIPER_POSITION_REPORT ),
-      NAME_VAL( RPC_LOC_IOCTL_NOTIFY_WIPER_STATUS ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_ENGINE_LOCK ),
-      NAME_VAL( RPC_LOC_IOCTL_GET_ENGINE_LOCK ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_SBAS_CONFIG ),
-      NAME_VAL( RPC_LOC_IOCTL_GET_SBAS_CONFIG ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_NMEA_TYPES ),
-      NAME_VAL( RPC_LOC_IOCTL_GET_NMEA_TYPES ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_CDMA_PDE_SERVER_ADDR ),
-      NAME_VAL( RPC_LOC_IOCTL_GET_CDMA_PDE_SERVER_ADDR ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_CDMA_MPC_SERVER_ADDR ),
-      NAME_VAL( RPC_LOC_IOCTL_GET_CDMA_MPC_SERVER_ADDR ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_UMTS_SLP_SERVER_ADDR ),
-      NAME_VAL( RPC_LOC_IOCTL_GET_UMTS_SLP_SERVER_ADDR ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_ON_DEMAND_LPM ),
-      NAME_VAL( RPC_LOC_IOCTL_GET_ON_DEMAND_LPM ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_XTRA_T_SESSION_CONTROL ),
-      NAME_VAL( RPC_LOC_IOCTL_GET_XTRA_T_SESSION_CONTROL ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_LBS_APN_PROFILE ),
-      NAME_VAL( RPC_LOC_IOCTL_GET_LBS_APN_PROFILE ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_XTRA_APN_PROFILE ),
-      NAME_VAL( RPC_LOC_IOCTL_GET_XTRA_APN_PROFILE ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_DATA_ENABLE ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_SUPL_VERSION ),
-      NAME_VAL( RPC_LOC_IOCTL_GET_SUPL_VERSION ),
-      NAME_VAL( RPC_LOC_IOCTL_DELETE_ASSIST_DATA ),
-      NAME_VAL( RPC_LOC_IOCTL_SET_CUSTOM_PDE_SERVER_ADDR ),
-      NAME_VAL( RPC_LOC_IOCTL_GET_CUSTOM_PDE_SERVER_ADDR ),
-   };
-int loc_ioctl_type_num = sizeof loc_ioctl_type_name / sizeof(loc_name_val_s_type);
-
-/* IOCTL Status names */
-loc_name_val_s_type loc_ioctl_status_name[] =
-   {
-      NAME_VAL( RPC_LOC_API_SUCCESS ),
-      NAME_VAL( RPC_LOC_API_GENERAL_FAILURE ),
-      NAME_VAL( RPC_LOC_API_UNSUPPORTED ),
-      NAME_VAL( RPC_LOC_API_INVALID_HANDLE ),
-      NAME_VAL( RPC_LOC_API_INVALID_PARAMETER ),
-      NAME_VAL( RPC_LOC_API_ENGINE_BUSY ),
-      NAME_VAL( RPC_LOC_API_PHONE_OFFLINE ),
-      NAME_VAL( RPC_LOC_API_TIMEOUT ),
-      NAME_VAL( RPC_LOC_API_RPC_FAILURE ),
-      NAME_VAL( RPC_LOC_API_RPC_MODEM_RESTART )
-   };
-int loc_ioctl_status_num = sizeof loc_ioctl_status_name / sizeof(loc_name_val_s_type);
-
-/* Fix session status names */
-loc_name_val_s_type loc_sess_status_name[] =
-   {
-      NAME_VAL( RPC_LOC_SESS_STATUS_SUCCESS ),
-      NAME_VAL( RPC_LOC_SESS_STATUS_IN_PROGESS ),
-      NAME_VAL( RPC_LOC_SESS_STATUS_GENERAL_FAILURE ),
-      NAME_VAL( RPC_LOC_SESS_STATUS_TIMEOUT ),
-      NAME_VAL( RPC_LOC_SESS_STATUS_USER_END ),
-      NAME_VAL( RPC_LOC_SESS_STATUS_BAD_PARAMETER ),
-      NAME_VAL( RPC_LOC_SESS_STATUS_PHONE_OFFLINE ),
-      NAME_VAL( RPC_LOC_SESS_STATUS_USER_END ),
-      NAME_VAL( RPC_LOC_SESS_STATUS_ENGINE_LOCKED )
-   };
-int loc_sess_status_num = sizeof loc_sess_status_name / sizeof(loc_name_val_s_type);
-
-/* Engine state names */
-loc_name_val_s_type loc_engine_state_name[] =
-   {
-      NAME_VAL( RPC_LOC_ENGINE_STATE_ON ),
-      NAME_VAL( RPC_LOC_ENGINE_STATE_OFF )
-   };
-int loc_engine_state_num = sizeof loc_engine_state_name / sizeof(loc_name_val_s_type);
-
-/* Fix session state names */
-loc_name_val_s_type loc_fix_session_state_name[] =
-   {
-      NAME_VAL( RPC_LOC_FIX_SESSION_STATE_BEGIN ),
-      NAME_VAL( RPC_LOC_FIX_SESSION_STATE_END )
-   };
-int loc_fix_session_state_num = sizeof loc_fix_session_state_name / sizeof(loc_name_val_s_type);
-
-
-static const char* log_final_interm_string(int is_final)
-{
-   return is_final ? "final" : "intermediate";
-}
-
-/* Logs parsed report */
-static void log_parsed_report(const rpc_loc_parsed_position_s_type *parsed_report)
-{
-   rpc_loc_session_status_e_type status = parsed_report->session_status;
-   LOC_LOGD("Session status: %s   Valid mask: 0x%X\n",
-         loc_get_sess_status_name(status),
-         (uint) parsed_report->valid_mask);
-   LOC_LOGD("Latitude:  %.7f (%s)\n", parsed_report->latitude,
-         log_final_interm_string(
-               (parsed_report->valid_mask & RPC_LOC_POS_VALID_LATITUDE) &&
-               parsed_report->session_status == RPC_LOC_SESS_STATUS_SUCCESS));
-   LOC_LOGD("Longitude: %.7f\n", parsed_report->longitude);
-   LOC_LOGD("Accuracy: %.7f\n", parsed_report->hor_unc_circular);
-}
-
-/* Logs status report */
-static void log_status_report(const rpc_loc_status_event_s_type *status_event)
-{
-   rpc_loc_status_event_e_type event = status_event->event;
-   switch (event) {
-   case RPC_LOC_STATUS_EVENT_ENGINE_STATE:
-      LOC_LOGD("Engine state: %s\n",
-            loc_get_engine_state_name(
-                  status_event->payload.rpc_loc_status_event_payload_u_type_u.engine_state));
-      break;
-   case RPC_LOC_STATUS_EVENT_FIX_SESSION_STATE:
-      LOC_LOGD("Fix session state: %s\n",
-            loc_get_fix_session_state_name(
-                  status_event->payload.rpc_loc_status_event_payload_u_type_u.fix_session_state));
-      break;
-   default:
-      break;
-   }
-}
-
-/* Logs valid fields in the GNSS SV constellation report */
-static void log_satellite_report(const rpc_loc_gnss_info_s_type *gnss)
-{
-   if (gnss->valid_mask & RPC_LOC_GNSS_INFO_VALID_POS_DOP)
-   {
-      LOC_LOGV("position dop: %.3f\n", (float) gnss->position_dop);
-   }
-   if (gnss->valid_mask & RPC_LOC_GNSS_INFO_VALID_HOR_DOP)
-   {
-      LOC_LOGV("horizontal dop: %.3f\n", (float) gnss->horizontal_dop);
-   }
-   if (gnss->valid_mask & RPC_LOC_GNSS_INFO_VALID_VERT_DOP)
-   {
-      LOC_LOGV("vertical dop: %.3f\n", (float) gnss->vertical_dop);
-   }
-   if (gnss->valid_mask & RPC_LOC_GNSS_INFO_VALID_ALTITUDE_ASSUMED)
-   {
-      LOC_LOGV("altitude assumed: %d\n", (int) gnss->altitude_assumed);
-   }
-   if (gnss->valid_mask & RPC_LOC_GNSS_INFO_VALID_SV_COUNT)
-   {
-      LOC_LOGD("sv count: %d\n", (int) gnss->sv_count);
-   }
-   if (gnss->valid_mask & RPC_LOC_GNSS_INFO_VALID_SV_LIST)
-   {
-      LOC_LOGV("sv list: ");
-
-      if (gnss->sv_count)
-      {
-         LOC_LOGV("\n\tsys\tprn\thlth\tproc\teph\talm\telev\tazi\tsnr\n");
-      }
-      else {
-         LOC_LOGV("empty\n");
-      }
-
-      int i;
-      for (i = 0; i < gnss->sv_count; i++)
-      {
-         const rpc_loc_sv_info_s_type *sv = &gnss->sv_list.sv_list_val[i];
-         rpc_loc_sv_info_valid_mask_type mask = sv->valid_mask;
-         LOC_LOGV("  %d: \t%d\t%d\t%d\t%d\t%d\t%d\t%.3f\t%.3f\t%.3f\n", i,
-               CHECK_MASK(int,   sv->system,         mask, RPC_LOC_SV_INFO_VALID_SYSTEM),
-               CHECK_MASK(int,   sv->prn,            mask, RPC_LOC_SV_INFO_VALID_PRN),
-               CHECK_MASK(int,   sv->health_status,  mask, RPC_LOC_SV_INFO_VALID_HEALTH_STATUS),
-               CHECK_MASK(int,   sv->process_status, mask, RPC_LOC_SV_INFO_VALID_PROCESS_STATUS),
-               CHECK_MASK(int,   sv->has_eph,        mask, RPC_LOC_SV_INFO_VALID_HAS_EPH),
-               CHECK_MASK(int,   sv->has_alm,        mask, RPC_LOC_SV_INFO_VALID_HAS_ALM),
-               CHECK_MASK(float, sv->elevation,      mask, RPC_LOC_SV_INFO_VALID_ELEVATION),
-               CHECK_MASK(float, sv->azimuth,        mask, RPC_LOC_SV_INFO_VALID_AZIMUTH),
-               CHECK_MASK(float, sv->snr,            mask, RPC_LOC_SV_INFO_VALID_SNR)
-         );
-      }
-   }
-}
-
-/* Logs a callback event */
-int loc_callback_log(
-      rpc_loc_event_mask_type               loc_event,              /* event mask           */
-      const rpc_loc_event_payload_u_type*   loc_event_payload       /* payload              */
-)
-{
-   switch (loc_event)
-   {
-   case RPC_LOC_EVENT_SATELLITE_REPORT:
-      log_satellite_report(&loc_event_payload->
-            rpc_loc_event_payload_u_type_u.gnss_report);
-      break;
-   case RPC_LOC_EVENT_STATUS_REPORT:
-      log_status_report(&loc_event_payload->
-            rpc_loc_event_payload_u_type_u.status_report);
-      break;
-   case RPC_LOC_EVENT_PARSED_POSITION_REPORT:
-      log_parsed_report(&loc_event_payload->
-            rpc_loc_event_payload_u_type_u.parsed_location_report);
-      break;
-   default:
-      break;
-   }
-
-   return 0;
-}
-
-/* Finds the first event found in the mask */
-const char* loc_get_event_name(rpc_loc_event_mask_type loc_event_mask)
-{
-   return loc_get_name_from_mask(loc_event_name, loc_event_num,
-         (long) loc_event_mask);
-}
-
-/* Finds IOCTL type name */
-const char* loc_get_ioctl_type_name(rpc_loc_ioctl_e_type ioctl_type)
-{
-   return loc_get_name_from_val(loc_ioctl_type_name, loc_ioctl_type_num,
-         (long) ioctl_type);
-}
-
-/* Finds IOCTL status name */
-const char* loc_get_ioctl_status_name(uint32 status)
-{
-   return loc_get_name_from_val(loc_ioctl_status_name, loc_ioctl_status_num,
-         (long) status);
-}
-
-/* Finds session status name */
-const char* loc_get_sess_status_name(rpc_loc_session_status_e_type status)
-{
-   return loc_get_name_from_val(loc_sess_status_name, loc_sess_status_num,
-         (long) status);
-}
-
-/* Find engine state name */
-const char* loc_get_engine_state_name(rpc_loc_engine_state_e_type state)
-{
-   return loc_get_name_from_val(loc_engine_state_name, loc_engine_state_num,
-         (long) state);
-}
-
-/* Find engine state name */
-const char* loc_get_fix_session_state_name(rpc_loc_fix_session_state_e_type state)
-{
-   return loc_get_name_from_val(loc_fix_session_state_name, loc_fix_session_state_num,
-         (long) state);
-}
-
-/* Event names */
-loc_name_val_s_type rpc_reset_event_name[] =
-{
-    NAME_VAL( RPC_SUBSYSTEM_RESTART_BEGIN ),
-    NAME_VAL( RPC_SUBSYSTEM_RESTART_END )
-};
-int rpc_reset_event_num = sizeof rpc_reset_event_name / sizeof(loc_name_val_s_type);
-
-const char* loc_get_rpc_reset_event_name(enum rpc_reset_event event)
-{
-    return loc_get_name_from_val(rpc_reset_event_name, rpc_reset_event_num, event);
-}
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_api_rpc_glue.c b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_api_rpc_glue.c
deleted file mode 100644
index 8c12426..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_api_rpc_glue.c
+++ /dev/null
@@ -1,635 +0,0 @@
-/* Copyright (c) 2011-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 FILES FOR MODULE
-
-======================================================================*/
-#include <stdio.h>
-#include <pthread.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/select.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <loc_api_log.h>
-
-#include <rpc/rpc.h>
-
-/* Include RPC headers */
-#include "rpc_inc/loc_api_rpc_glue.h"
-
-/* Callback init */
-#include "rpc_inc/loc_apicb_appinit.h"
-
-/* Logging */
-#define LOG_TAG "LocSvc_api_rpc_glue"
-#define LOG_NDDEBUG 0
-#ifndef USE_GLIB
-#include <utils/Log.h>
-#endif /* USE_GLIB */
-
-/* Logging Improvement */
-#include "platform_lib_includes.h"
-/*Maximum number of Modem init*/
-#define RPC_TRY_NUM 10
-
-/*Maximum number of Modem init*/
-#define RPC_TRY_NUM 10
-
-/* Uncomment to force ALOGD messages */
-// #define ALOGD ALOGI
-
-/*=====================================================================
-     External declarations
-======================================================================*/
-
-CLIENT* loc_api_clnt = NULL;
-
-/* Callback ID and pointer */
-#define LOC_API_CB_MAX_CLIENTS 16
-typedef struct
-{
-    uint32 cb_id;                        /* same as rpc/types.h */
-    loc_event_cb_f_type *cb_func;      /* callback func */
-    loc_reset_notif_cb_f_type *rpc_cb; /* callback from RPC */
-    rpc_loc_client_handle_type handle; /* stores handle for client closing */
-    void* user;                        /* user's own data handle */
-} loc_glue_cb_entry_s_type;
-
-loc_glue_cb_entry_s_type loc_glue_callback_table[LOC_API_CB_MAX_CLIENTS];
-
-#define RPC_FUNC_VERSION_BASE(a,b) a ## b
-#define RPC_FUNC_VERSION(a,b) RPC_FUNC_VERSION_BASE(a,b)
-
-#define RPC_CALLBACK_FUNC_VERSION_BASE(a,v,b) a ## v ## b
-#define RPC_CALLBACK_FUNC_VERSION(a,v,b) RPC_CALLBACK_FUNC_VERSION_BASE(a,v,b)
-
-#define LOC_GLUE_CHECK_INIT(ret_type) \
-   if (loc_api_clnt == NULL) { EXIT_LOG_CALLFLOW(%d, RPC_LOC_API_RPC_FAILURE); return (ret_type) RPC_LOC_API_RPC_FAILURE; }
-
-#define LOC_GLUE_CHECK_RESULT(stat, ret_type) \
-  if (stat != RPC_SUCCESS) { \
-      LOC_LOGE("%s:%d] failure code %d", __func__, __LINE__, stat); \
-      return (ret_type)((stat == RPC_SUBSYSTEM_RESTART) ? \
-                        RPC_LOC_API_RPC_MODEM_RESTART : RPC_LOC_API_RPC_FAILURE); \
-  }
-
-/* Callback functions */
-/* Returns 1 if successful */
-bool_t rpc_loc_event_cb_f_type_svc(
-      rpc_loc_event_cb_f_type_args *argp,
-      rpc_loc_event_cb_f_type_rets *ret,
-      struct svc_req *req)
-{
-    // The lower word of cd_id is the index
-    int index = argp->cb_id & 0xFFFF;
-
-    /* Callback not registered, or unexpected ID (shouldn't happen) */
-    if (index >= LOC_API_CB_MAX_CLIENTS || loc_glue_callback_table[index].cb_func == NULL)
-    {
-        LOC_LOGE("Warning: No callback handler %d.\n", index);
-        ret->loc_event_cb_f_type_result = 0;
-        return 1; /* simply return */
-    }
-
-    LOC_LOGV("proc: %x  prog: %x  vers: %x\n",
-         (int) req->rq_proc,
-         (int) req->rq_prog,
-         (int) req->rq_vers);
-
-    LOC_LOGV("Callback received: %x (cb_id=%p handle=%d ret_ptr=%d)\n",
-         (int) argp->loc_event,
-               argp->cb_id,
-         (int) argp->loc_handle,
-         (int) ret);
-
-    /* Forward callback to real callback procedure */
-    rpc_loc_client_handle_type        loc_handle = argp->loc_handle;
-    rpc_loc_event_mask_type           loc_event  = argp->loc_event;
-    const rpc_loc_event_payload_u_type*  loc_event_payload =
-        (const rpc_loc_event_payload_u_type*) argp->loc_event_payload;
-
-    /* Gives control to synchronous call handler */
-    loc_api_callback_process_sync_call(loc_handle, loc_event, loc_event_payload);
-
-    int32 rc = (loc_glue_callback_table[index].cb_func)(loc_glue_callback_table[index].user,
-                                                        loc_handle, loc_event, loc_event_payload);
-
-    LOC_LOGV("cb_func=%p", loc_glue_callback_table[index].cb_func);
-
-    ret->loc_event_cb_f_type_result = rc;
-
-    return 1; /* ok */
-}
-
-int loc_apicbprog_freeresult (SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result)
-{
-   xdr_free (xdr_result, result);
-
-   /*
-    * Insert additional freeing code here, if needed
-    */
-   // LOC_LOGD("***** loc_apicbprog_freeresult\n");
-
-   return 1;
-}
-
-/*===========================================================================
-
-FUNCTION rpc_loc_event_cb_f_type_<version>_svc (MACRO)
-
-DESCRIPTION
-   Callback function for Loc API
-
-RETURN VALUE
-   1 for success
-   0 for failure
-
-===========================================================================*/
-bool_t RPC_CALLBACK_FUNC_VERSION(rpc_loc_event_cb_f_type_, RPC_LOC_EVENT_CB_F_TYPE_VERSION, _svc) (
-      rpc_loc_event_cb_f_type_args *argp,
-      rpc_loc_event_cb_f_type_rets *ret,
-      struct svc_req *req)
-{
-   return rpc_loc_event_cb_f_type_svc(argp, ret, req);
-}
-
-/*===========================================================================
-
-FUNCTION loc_apicbprog_<version>_freeresult (MACRO)
-
-DESCRIPTION
-   Free up RPC data structure
-
-RETURN VALUE
-   1 for success
-   0 for failure
-
-===========================================================================*/
-#define VERSION_CONCAT(MAJOR,MINOR) MAJOR##MINOR
-#define loc_apicb_prog_VER_freeresult(M,N) \
-int RPC_CALLBACK_FUNC_VERSION(loc_apicbprog_, VERSION_CONCAT(M,N), _freeresult) \
-(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result) \
-{ \
-   return loc_apicbprog_freeresult(transp, xdr_result, result); \
-}
-
-/* Define all of the possible minors */
-loc_apicb_prog_VER_freeresult(RPC_LOC_API_API_MAJOR_NUM, 0001);
-loc_apicb_prog_VER_freeresult(RPC_LOC_API_API_MAJOR_NUM, 0002);
-loc_apicb_prog_VER_freeresult(RPC_LOC_API_API_MAJOR_NUM, 0003);
-loc_apicb_prog_VER_freeresult(RPC_LOC_API_API_MAJOR_NUM, 0004);
-loc_apicb_prog_VER_freeresult(RPC_LOC_API_API_MAJOR_NUM, 0005);
-loc_apicb_prog_VER_freeresult(RPC_LOC_API_API_MAJOR_NUM, 0006);
-
-/*===========================================================================
-
-FUNCTION rpc_loc_api_cb_null_<version>_svc (MACRO) [Patch for wrong RPCGEN stubs]
-
-DESCRIPTION
-   Null callback function for Loc API
-
-RETURN VALUE
-   1 for success
-
-===========================================================================*/
-#define rpc_loc_api_cb_null_VER_svc(M,N) \
-bool_t RPC_CALLBACK_FUNC_VERSION(rpc_loc_api_cb_null_, VERSION_CONCAT(M,N), _svc) ( \
-      void *a, int *b, struct svc_req *req) \
-{ \
-   return 1; \
-}
-
-/* Define all of the possible minors */
-rpc_loc_api_cb_null_VER_svc(RPC_LOC_API_API_MAJOR_NUM, 0001);
-rpc_loc_api_cb_null_VER_svc(RPC_LOC_API_API_MAJOR_NUM, 0002);
-rpc_loc_api_cb_null_VER_svc(RPC_LOC_API_API_MAJOR_NUM, 0003);
-rpc_loc_api_cb_null_VER_svc(RPC_LOC_API_API_MAJOR_NUM, 0004);
-rpc_loc_api_cb_null_VER_svc(RPC_LOC_API_API_MAJOR_NUM, 0005);
-rpc_loc_api_cb_null_VER_svc(RPC_LOC_API_API_MAJOR_NUM, 0006);
-
-static void loc_api_glue_rpc_cb(CLIENT* client, enum rpc_reset_event event)
-{
-    int i;
-    for (i = 0; i < LOC_API_CB_MAX_CLIENTS; i++) {
-        if (NULL != loc_glue_callback_table[i].rpc_cb) {
-            loc_glue_callback_table[i].rpc_cb(loc_glue_callback_table[i].user, client, event);
-        }
-    }
-}
-
-/*===========================================================================
-
-FUNCTION loc_api_glue_init
-
-DESCRIPTION
-   Initiates the RPC client
-
-RETURN VALUE
-   1 for success
-   0 for failure
-
-===========================================================================*/
-int loc_api_glue_init(void)
-{
-   if (loc_api_clnt == NULL)
-   {
-      /* Initialize data */
-      int i;
-      int pid = getpid();
-      for (i = 0; i < LOC_API_CB_MAX_CLIENTS; i++)
-      {
-          loc_glue_callback_table[i].cb_id = i | (pid << 16);
-          loc_glue_callback_table[i].cb_func = NULL;
-          loc_glue_callback_table[i].handle = -1;
-          loc_glue_callback_table[i].rpc_cb = NULL;
-          loc_glue_callback_table[i].user = NULL;
-      }
-
-      /* Print msg */
-      LOC_LOGV("Trying to create RPC client...\n");
-      loc_api_clnt = clnt_create(NULL, LOC_APIPROG, LOC_APIVERS, NULL);
-      LOC_LOGV("Created loc_api_clnt ---- %x\n", (unsigned int)loc_api_clnt);
-
-      if (loc_api_clnt == NULL)
-      {
-         LOC_LOGE("Error: cannot create RPC client.\n");
-         return 0;
-      }
-
-      /* Init RPC callbacks */
-      loc_api_sync_call_init();
-
-      int rc = loc_apicb_app_init();
-      if (rc >= 0)
-      {
-         LOC_LOGD("Loc API RPC client initialized.\n");
-         clnt_register_reset_notification_cb(loc_api_clnt, loc_api_glue_rpc_cb);
-      }
-      else {
-         LOC_LOGE("Loc API callback initialization failed.\n");
-         return 0;
-      }
-   }
-
-   return 1;
-}
-
-rpc_loc_client_handle_type loc_open (
-    rpc_loc_event_mask_type       event_reg_mask,
-    loc_event_cb_f_type           *event_callback,
-    loc_reset_notif_cb_f_type     *rpc_cb,
-    void*                         userData
-)
-{
-    int try_num = RPC_TRY_NUM;
-    ENTRY_LOG();
-    LOC_GLUE_CHECK_INIT(rpc_loc_client_handle_type);
-
-    rpc_loc_client_handle_type ret_val;
-
-    rpc_loc_open_args args;
-    args.event_reg_mask = event_reg_mask;
-
-    int i, j = LOC_API_CB_MAX_CLIENTS;
-    for (i = 0; i < LOC_API_CB_MAX_CLIENTS; i++)
-    {
-        if (loc_glue_callback_table[i].user == userData)
-        {
-            LOC_LOGW("Client already opened service (callback=%p)...\n",
-                  event_callback);
-            break;
-        } else if (j == LOC_API_CB_MAX_CLIENTS &&
-                   loc_glue_callback_table[i].user == NULL) {
-            j = i;
-        }
-    }
-
-    if (i == LOC_API_CB_MAX_CLIENTS)
-    {
-        i = j;
-    }
-
-    if (i == LOC_API_CB_MAX_CLIENTS)
-    {
-        LOC_LOGE("Too many clients opened at once...\n");
-        return RPC_LOC_CLIENT_HANDLE_INVALID;
-    }
-
-    loc_glue_callback_table[i].cb_func = event_callback;
-    loc_glue_callback_table[i].rpc_cb = rpc_cb;
-    loc_glue_callback_table[i].user = userData;
-
-    args.event_callback = loc_glue_callback_table[i].cb_id;
-    LOC_LOGV("cb_id=%d, func=0x%x", i, (unsigned int) event_callback);
-
-    rpc_loc_open_rets rets;
-    enum clnt_stat stat = RPC_SUCCESS;
-
-    EXIT_LOG_CALLFLOW(%s, "loc client open");
-
-     /*try more for rpc_loc_open_xx()*/
-
-    do
-    {
-        stat = RPC_FUNC_VERSION(rpc_loc_open_, RPC_LOC_OPEN_VERSION)(&args, &rets, loc_api_clnt);
-        ret_val = (rpc_loc_client_handle_type) rets.loc_open_result;
-        try_num--;
-
-    }while( (RPC_SUCCESS != stat||0 > ret_val) && 0 != try_num );
-
-    LOC_GLUE_CHECK_RESULT(stat, int32);
-
-    /* save the handle in the table */
-    loc_glue_callback_table[i].handle = (rpc_loc_client_handle_type) rets.loc_open_result;
-
-    return ret_val;
-
-}
-
-int32 loc_close
-(
-      rpc_loc_client_handle_type handle
-)
-{
-    ENTRY_LOG();
-    LOC_GLUE_CHECK_INIT(int32);
-
-    int32 ret_val;
-
-    rpc_loc_close_args args;
-    args.handle = handle;
-
-    rpc_loc_close_rets rets;
-    enum clnt_stat stat = RPC_SUCCESS;
-
-    EXIT_LOG_CALLFLOW(%s, "loc client close");
-    stat = RPC_FUNC_VERSION(rpc_loc_close_, RPC_LOC_CLOSE_VERSION)(&args, &rets, loc_api_clnt);
-
-    loc_clear(handle);
-
-    LOC_GLUE_CHECK_RESULT(stat, int32);
-    ret_val = (int32) rets.loc_close_result;
-
-    return ret_val;
-}
-
-void loc_clear(rpc_loc_client_handle_type handle) {
-    /* Clean the client's callback function in callback table */
-    int i;
-    for (i = 0; i < LOC_API_CB_MAX_CLIENTS; i++)
-    {
-        if (loc_glue_callback_table[i].handle == handle)
-        {
-            /* Found the client */
-            loc_glue_callback_table[i].cb_func = NULL;
-            loc_glue_callback_table[i].rpc_cb = NULL;
-            loc_glue_callback_table[i].handle = -1;
-            loc_glue_callback_table[i].user = NULL;
-            break;
-        }
-    }
-
-    if (i == LOC_API_CB_MAX_CLIENTS)
-    {
-        LOC_LOGW("Handle not found (handle=%d)...\n", (int) handle);
-    }
-}
-
-int32 loc_start_fix
-(
-      rpc_loc_client_handle_type handle
-)
-{
-    ENTRY_LOG();
-    LOC_GLUE_CHECK_INIT(int32);
-
-    int32 ret_val;
-
-    rpc_loc_start_fix_args args;
-    args.handle = handle;
-
-    rpc_loc_start_fix_rets rets;
-    enum clnt_stat stat = RPC_SUCCESS;
-
-    EXIT_LOG_CALLFLOW(%s, "loc start fix");
-    stat = RPC_FUNC_VERSION(rpc_loc_start_fix_, RPC_LOC_START_FIX_VERSION)(&args, &rets, loc_api_clnt);
-    LOC_GLUE_CHECK_RESULT(stat, int32);
-
-    ret_val = (int32) rets.loc_start_fix_result;
-
-    return ret_val;
-}
-
-int32 loc_stop_fix
-(
-      rpc_loc_client_handle_type handle
-)
-{
-    ENTRY_LOG();
-    LOC_GLUE_CHECK_INIT(int32);
-
-    int32 ret_val;
-
-    rpc_loc_stop_fix_args args;
-    args.handle = handle;
-
-    rpc_loc_stop_fix_rets rets;
-    enum clnt_stat stat = RPC_SUCCESS;
-
-    EXIT_LOG_CALLFLOW(%s, "loc stop fix");
-    stat = RPC_FUNC_VERSION(rpc_loc_stop_fix_, RPC_LOC_STOP_FIX_VERSION)(&args, &rets, loc_api_clnt);
-    LOC_GLUE_CHECK_RESULT(stat, int32);
-
-    ret_val = (int32) rets.loc_stop_fix_result;
-
-    return ret_val;
-}
-
-int32 loc_ioctl
-(
-      rpc_loc_client_handle_type           handle,
-      rpc_loc_ioctl_e_type                 ioctl_type,
-      rpc_loc_ioctl_data_u_type*           ioctl_data
-)
-{
-    ENTRY_LOG();
-    LOC_GLUE_CHECK_INIT(int32);
-
-    int32 ret_val;
-
-    rpc_loc_ioctl_args args;
-    args.handle = handle;
-    args.ioctl_data = ioctl_data;
-    args.ioctl_type = ioctl_type;
-    if (ioctl_data != NULL)
-    {
-        /* Assign ioctl union discriminator */
-        ioctl_data->disc = ioctl_type;
-
-        /* In case the user hasn't filled in other disc fields,
-           automatically fill them in here */
-        switch (ioctl_type)
-        {
-        case RPC_LOC_IOCTL_GET_API_VERSION:
-            break;
-        case RPC_LOC_IOCTL_SET_FIX_CRITERIA:
-            break;
-        case RPC_LOC_IOCTL_GET_FIX_CRITERIA:
-            break;
-        case RPC_LOC_IOCTL_INFORM_NI_USER_RESPONSE:
-            break;
-        case RPC_LOC_IOCTL_INJECT_PREDICTED_ORBITS_DATA:
-            break;
-        case RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_VALIDITY:
-            break;
-        case RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE:
-            break;
-        case RPC_LOC_IOCTL_SET_PREDICTED_ORBITS_DATA_AUTO_DOWNLOAD:
-            break;
-        case RPC_LOC_IOCTL_INJECT_UTC_TIME:
-            break;
-        case RPC_LOC_IOCTL_INJECT_RTC_VALUE:
-            break;
-        case RPC_LOC_IOCTL_INJECT_POSITION:
-            break;
-        case RPC_LOC_IOCTL_QUERY_ENGINE_STATE:
-            break;
-        case RPC_LOC_IOCTL_INFORM_SERVER_OPEN_STATUS:
-            break;
-        case RPC_LOC_IOCTL_INFORM_SERVER_CLOSE_STATUS:
-            break;
-        case RPC_LOC_IOCTL_SET_ENGINE_LOCK:
-            break;
-        case RPC_LOC_IOCTL_GET_ENGINE_LOCK:
-            break;
-        case RPC_LOC_IOCTL_SET_SBAS_CONFIG:
-            break;
-        case RPC_LOC_IOCTL_GET_SBAS_CONFIG:
-            break;
-        case RPC_LOC_IOCTL_SET_NMEA_TYPES:
-            break;
-        case RPC_LOC_IOCTL_GET_NMEA_TYPES:
-            break;
-        case RPC_LOC_IOCTL_SET_CDMA_PDE_SERVER_ADDR:
-        case RPC_LOC_IOCTL_SET_CDMA_MPC_SERVER_ADDR:
-        case RPC_LOC_IOCTL_SET_UMTS_SLP_SERVER_ADDR:
-        case RPC_LOC_IOCTL_SET_CUSTOM_PDE_SERVER_ADDR:
-            args.ioctl_data->rpc_loc_ioctl_data_u_type_u.server_addr.addr_info.disc =
-                args.ioctl_data->rpc_loc_ioctl_data_u_type_u.server_addr.addr_type;
-            break;
-        case RPC_LOC_IOCTL_GET_CDMA_PDE_SERVER_ADDR:
-        case RPC_LOC_IOCTL_GET_CDMA_MPC_SERVER_ADDR:
-        case RPC_LOC_IOCTL_GET_UMTS_SLP_SERVER_ADDR:
-        case RPC_LOC_IOCTL_GET_CUSTOM_PDE_SERVER_ADDR:
-            break;
-        case RPC_LOC_IOCTL_SET_ON_DEMAND_LPM:
-            break;
-        case RPC_LOC_IOCTL_GET_ON_DEMAND_LPM:
-            break;
-        case RPC_LOC_IOCTL_DELETE_ASSIST_DATA:
-            break;
-        default:
-            break;
-        } /* switch */
-    } /* ioctl_data != NULL */
-
-    rpc_loc_ioctl_rets rets;
-    enum clnt_stat stat = RPC_SUCCESS;
-
-    EXIT_LOG_CALLFLOW(%s, loc_get_ioctl_type_name(ioctl_type));
-    stat = RPC_FUNC_VERSION(rpc_loc_ioctl_, RPC_LOC_IOCTL_VERSION)(&args, &rets, loc_api_clnt);
-    LOC_GLUE_CHECK_RESULT(stat, int32);
-
-    ret_val = (int32) rets.loc_ioctl_result;
-
-    return ret_val;
-}
-
-/* Returns 0 if error */
-int32 loc_api_null(void)
-{
-    LOC_GLUE_CHECK_INIT(int32);
-
-    int32 rets;
-    enum clnt_stat stat = RPC_SUCCESS;
-
-    clnt_unregister_reset_notification_cb(loc_api_clnt);
-    stat = RPC_FUNC_VERSION(rpc_loc_api_null_, RPC_LOC_API_NULL_VERSION)(NULL, &rets, loc_api_clnt);
-    LOC_GLUE_CHECK_RESULT(stat, int32);
-
-    return (int32) rets;
-}
-
-/*===========================================================================
-
-FUNCTION    loc_eng_ioctl
-
-DESCRIPTION
-   This function calls loc_ioctl and waits for the callback result before
-   returning back to the user.
-
-DEPENDENCIES
-   N/A
-
-RETURN VALUE
-   TRUE                 if successful
-   FALSE                if failed
-
-SIDE EFFECTS
-   N/A
-
-===========================================================================*/
-int loc_eng_ioctl
-(
-      rpc_loc_client_handle_type           handle,
-      rpc_loc_ioctl_e_type                 ioctl_type,
-      rpc_loc_ioctl_data_u_type*           ioctl_data_ptr,
-      uint32                               timeout_msec,
-      rpc_loc_ioctl_callback_s_type       *cb_data_ptr
-)
-{
-    int ret_val = RPC_LOC_API_SUCCESS;
-
-    ret_val = loc_api_sync_ioctl(handle, ioctl_type, ioctl_data_ptr, timeout_msec, cb_data_ptr);
-
-    LOC_LOGD("loc_eng_ioctl result: client = %d, ioctl_type = %s, returt %s\n",
-             (int32) handle,
-             loc_get_ioctl_type_name(ioctl_type),
-             loc_get_ioctl_status_name(ret_val) );
-
-    return ret_val;
-}
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_api_sync_call.c b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_api_sync_call.c
deleted file mode 100644
index ae629d7..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_api_sync_call.c
+++ /dev/null
@@ -1,565 +0,0 @@
-/* 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 <stdio.h>
-#include <assert.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <string.h>
-#include <pthread.h>
-
-#include <rpc/rpc.h>
-#include <loc_api_rpc_glue.h>
-#include "loc_api_sync_call.h"
-
-/* Logging */
-#define LOG_TAG "LocSvc_api_rpc_glue"
-// #define LOG_NDDEBUG 0
-#ifndef USE_GLIB
-#include <utils/Log.h>
-#endif /* USE_GLIB */
-
-/***************************************************************************
- *                 DATA FOR ASYNCHRONOUS RPC PROCESSING
- **************************************************************************/
-loc_sync_call_slot_array_s_type loc_sync_data;
-
-pthread_mutex_t loc_sync_call_mutex = PTHREAD_MUTEX_INITIALIZER;
-boolean loc_sync_call_inited = 0;
-
-/*===========================================================================
-
-FUNCTION    loc_api_sync_call_init
-
-DESCRIPTION
-   Initialize this module
-
-DEPENDENCIES
-   N/A
-
-RETURN VALUE
-   none
-
-SIDE EFFECTS
-   N/A
-
-===========================================================================*/
-void loc_api_sync_call_init()
-{
-   pthread_mutex_lock(&loc_sync_call_mutex);
-   if (loc_sync_call_inited == 1) {
-       pthread_mutex_unlock(&loc_sync_call_mutex);
-       return;
-   }
-   loc_sync_call_inited = 1;
-
-   loc_sync_data.num_of_slots = LOC_SYNC_CALL_SLOTS_MAX;
-
-   int i;
-   for (i = 0; i < loc_sync_data.num_of_slots; i++)
-   {
-      loc_sync_call_slot_s_type *slot = &loc_sync_data.slots[i];
-
-      pthread_mutex_init(&slot->lock, NULL);
-      pthread_cond_init(&slot->loc_cb_arrived_cond, NULL);
-
-      slot->not_available = 0;
-      slot->in_use = 0;
-      slot->loc_handle = -1;
-      slot->loc_cb_wait_event_mask = 0;       /* event to wait   */
-      slot->loc_cb_received_event_mask = 0;   /* received event   */
-   }
-
-   pthread_mutex_unlock(&loc_sync_call_mutex);
-}
-
-/*===========================================================================
-
-FUNCTION    loc_api_sync_call_destroy
-
-DESCRIPTION
-   Initialize this module
-
-DEPENDENCIES
-   N/A
-
-RETURN VALUE
-   none
-
-SIDE EFFECTS
-   N/A
-
-===========================================================================*/
-void loc_api_sync_call_destroy()
-{
-   int i;
-
-   pthread_mutex_lock(&loc_sync_call_mutex);
-   if (loc_sync_call_inited == 0) {
-       pthread_mutex_unlock(&loc_sync_call_mutex);
-       return;
-   }
-   loc_sync_call_inited = 0;
-
-   for (i = 0; i < loc_sync_data.num_of_slots; i++)
-   {
-      loc_sync_call_slot_s_type *slot = &loc_sync_data.slots[i];
-
-      pthread_mutex_lock(&slot->lock);
-
-      slot->not_available = 1;
-
-      pthread_mutex_unlock(&slot->lock);
-
-      pthread_cond_destroy(&slot->loc_cb_arrived_cond);
-      pthread_mutex_destroy(&slot->lock);
-   }
-
-   pthread_mutex_unlock(&loc_sync_call_mutex);
-}
-
-/*===========================================================================
-
-FUNCTION    loc_match_callback
-
-DESCRIPTION
-   Checks if an awaited event has arrived
-
-RETURN VALUE
-   TRUE                 arrived
-   FALSE                not matching
-
-===========================================================================*/
-static boolean loc_match_callback(
-      rpc_loc_event_mask_type             wait_mask,
-      rpc_loc_ioctl_e_type                wait_ioctl,
-      rpc_loc_event_mask_type             event_mask,
-      const rpc_loc_event_payload_u_type  *callback_payload
-)
-{
-   if ((event_mask & wait_mask) == 0) return FALSE;
-
-   if (event_mask != RPC_LOC_EVENT_IOCTL_REPORT || wait_ioctl == 0 ||
-        ( (callback_payload != NULL) &&
-         callback_payload->rpc_loc_event_payload_u_type_u.ioctl_report.type == wait_ioctl) )
-      return TRUE;
-
-   return FALSE;
-}
-
-/*===========================================================================
-
-FUNCTION    loc_api_callback_process_sync_call
-
-DESCRIPTION
-   Wakes up blocked API calls to check if the needed callback has arrived
-
-DEPENDENCIES
-   N/A
-
-RETURN VALUE
-   none
-
-SIDE EFFECTS
-   N/A
-
-===========================================================================*/
-void loc_api_callback_process_sync_call(
-      rpc_loc_client_handle_type            loc_handle,             /* handle of the client */
-      rpc_loc_event_mask_type               loc_event,              /* event mask           */
-      const rpc_loc_event_payload_u_type*   loc_event_payload       /* payload              */
-)
-{
-   int i;
-
-   ALOGV("loc_handle = 0x%lx, loc_event = 0x%lx", loc_handle, loc_event);
-   for (i = 0; i < loc_sync_data.num_of_slots; i++)
-   {
-      loc_sync_call_slot_s_type *slot = &loc_sync_data.slots[i];
-
-      pthread_mutex_lock(&slot->lock);
-
-      if (slot->in_use &&
-          slot->signal_sent == 0 &&
-          slot->loc_handle == loc_handle &&
-          loc_match_callback(slot->loc_cb_wait_event_mask, slot->ioctl_type, loc_event, loc_event_payload))
-      {
-         memcpy(&slot->loc_cb_received_payload, loc_event_payload, sizeof (rpc_loc_event_payload_u_type));
-
-         slot->loc_cb_received_event_mask = loc_event;
-
-         ALOGV("signal slot %d in_use %d, loc_handle 0x%lx, event_mask 0x%1x, ioctl_type %d", i, slot->in_use, slot->loc_handle, (int) slot->loc_cb_wait_event_mask, (int) slot->ioctl_type);
-         pthread_cond_signal(&slot->loc_cb_arrived_cond);
-         slot->signal_sent = 1;
-
-         pthread_mutex_unlock(&slot->lock);
-         break;
-      } else {
-         /* do nothing */
-      }
-
-      pthread_mutex_unlock(&slot->lock);
-   }
-}
-
-/*===========================================================================
-
-FUNCTION    loc_lock_a_slot
-
-DESCRIPTION
-   Allocates a buffer slot for the synchronous API call
-
-DEPENDENCIES
-   N/A
-
-RETURN VALUE
-   Select ID (>=0)     : successful
-   -1                  : buffer full
-
-SIDE EFFECTS
-   N/A
-
-===========================================================================*/
-static int loc_lock_a_slot()
-{
-   int i, select_id = -1; /* no free buffer */
-
-   for (i = 0; i < loc_sync_data.num_of_slots; i++)
-   {
-      loc_sync_call_slot_s_type *slot = &loc_sync_data.slots[i];
-      if (pthread_mutex_trylock(&slot->lock) == EBUSY)
-      {
-         ALOGV("trylock EBUSY : %d", i);
-         continue;
-      }
-
-      if (!slot->in_use && !slot->not_available)
-      {
-         select_id = i;
-         /* Return from here and leave the mutex locked.
-          * will unlock it in loc_unlock_slot()
-          */
-         break;
-      }
-      /* ALOGV("slot %d in_use = %d, not_available = %d : %d", i, slot->in_use, slot->not_available, i); */
-      pthread_mutex_unlock(&slot->lock);
-   }
-
-   return select_id;
-}
-
-/*===========================================================================
-
-FUNCTION    loc_unlock_slot
-
-DESCRIPTION
-   Unlocks a buffer slot
-
-DEPENDENCIES
-   N/A
-
-RETURN VALUE
-   None
-
-SIDE EFFECTS
-   N/A
-
-===========================================================================*/
-static void loc_unlock_slot(int select_id)
-{
-   pthread_mutex_unlock(&loc_sync_data.slots[select_id].lock);
-}
-
-/*===========================================================================
-
-FUNCTION    loc_lock_slot
-
-DESCRIPTION
-   Locks a specific slot that was previously locked from loc_lock_a_slot
-
-DEPENDENCIES
-   N/A
-
-RETURN VALUE
-   None
-
-SIDE EFFECTS
-   N/A
-
-===========================================================================*/
-static void loc_lock_slot(int select_id)
-{
-    pthread_mutex_lock(&loc_sync_data.slots[select_id].lock);
-}
-
-/*===========================================================================
-
-FUNCTION    loc_set_slot_in_use
-
-DESCRIPTION
-   Sets the in_use flag of slot to true or false.
-   Should be called only after the slot is locked
-
-DEPENDENCIES
-   N/A
-
-RETURN VALUE
-   None
-
-SIDE EFFECTS
-   N/A
-
-===========================================================================*/
-static void loc_set_slot_in_use(int select_id, boolean in_use)
-{
-    loc_sync_data.slots[select_id].in_use = in_use;
-    if (in_use == 1)
-        loc_sync_data.slots[select_id].signal_sent = 0;
-}
-
-/*===========================================================================
-
-FUNCTION    loc_api_save_callback
-
-DESCRIPTION
-   Selects which callback or IOCTL event to wait for.
-
-   The event_mask specifies the event(s). If it is RPC_LOC_EVENT_IOCTL_REPORT,
-   then ioctl_type specifies the IOCTL event.
-
-   If ioctl_type is non-zero, RPC_LOC_EVENT_IOCTL_REPORT is automatically added.
-
-DEPENDENCIES
-   N/A
-
-RETURN VALUE
-   Select ID (>=0)     : successful
-   -1                  : out of buffer
-
-SIDE EFFECTS
-   N/A
-
-===========================================================================*/
-static void loc_api_save_callback(
-      int                              select_id,            /* Selected slot */
-      rpc_loc_client_handle_type       loc_handle,           /* Client handle */
-      rpc_loc_event_mask_type          event_mask,           /* Event mask to wait for */
-      rpc_loc_ioctl_e_type             ioctl_type            /* IOCTL type to wait for */
-)
-{
-   loc_sync_call_slot_s_type *slot = &loc_sync_data.slots[select_id];
-
-   slot->loc_handle = loc_handle;
-
-   slot->loc_cb_wait_event_mask = event_mask;
-   slot->ioctl_type = ioctl_type;
-   if (ioctl_type) slot->loc_cb_wait_event_mask |= RPC_LOC_EVENT_IOCTL_REPORT;
-
-   return;
-}
-
-/*===========================================================================
-
-FUNCTION    loc_save_user_payload
-
-DESCRIPTION
-   Saves received payload into user data structures
-
-RETURN VALUE
-   None
-
-===========================================================================*/
-static void loc_save_user_payload(
-      rpc_loc_event_payload_u_type  *user_cb_payload,
-      rpc_loc_ioctl_callback_s_type *user_ioctl_buffer,
-      const rpc_loc_event_payload_u_type  *received_cb_payload
-)
-{
-   if (user_cb_payload)
-   {
-      memcpy(user_cb_payload, received_cb_payload,
-            sizeof (rpc_loc_event_payload_u_type));
-   }
-   if (user_ioctl_buffer)
-   {
-      memcpy(user_ioctl_buffer,
-            &received_cb_payload->rpc_loc_event_payload_u_type_u.ioctl_report,
-            sizeof *user_ioctl_buffer);
-   }
-}
-
-/*===========================================================================
-
-FUNCTION    loc_api_wait_callback
-
-DESCRIPTION
-   Waits for a selected callback. The wait expires in timeout_seconds seconds.
-
-   If the function is called before an existing wait has finished, it will
-   immediately return EBUSY.
-
-DEPENDENCIES
-   N/A
-
-RETURN VALUE
-   RPC_LOC_API_SUCCESS              if successful (0)
-   RPC_LOC_API_TIMEOUT              if timed out
-   RPC_LOC_API_ENGINE_BUSY          if already in a wait
-   RPC_LOC_API_INVALID_PARAMETER    if callback is not yet selected
-
-SIDE EFFECTS
-   N/A
-
-===========================================================================*/
-static int loc_api_wait_callback(
-      int select_id,        /* ID from loc_select_callback() */
-      int timeout_seconds,  /* Timeout in this number of seconds  */
-      rpc_loc_event_payload_u_type     *callback_payload,    /* Pointer to callback payload buffer, can be NULL */
-      rpc_loc_ioctl_callback_s_type    *ioctl_payload        /* Pointer to IOCTL payload, can be NULL */
-)
-{
-   int ret_val = RPC_LOC_API_SUCCESS;  /* the return value of this function: 0 = no error */
-   int rc = 0;                         /* return code from pthread calls */
-
-   struct timespec expire_time;
-
-   loc_sync_call_slot_s_type *slot = &loc_sync_data.slots[select_id];
-
-   clock_gettime(CLOCK_REALTIME, &expire_time);
-   expire_time.tv_sec += timeout_seconds;
-
-   /* Waiting */
-   while (slot->signal_sent == 0 && rc != ETIMEDOUT) {
-       rc = pthread_cond_timedwait(&slot->loc_cb_arrived_cond,
-             &slot->lock, &expire_time);
-   }
-
-   if (rc == ETIMEDOUT)
-   {
-      ret_val = RPC_LOC_API_TIMEOUT; /* Timed out */
-      ALOGE("TIMEOUT: %d", select_id);
-   }
-   else {
-      /* Obtained the first awaited callback */
-      ret_val = RPC_LOC_API_SUCCESS;       /* Successful */
-      loc_save_user_payload(callback_payload, ioctl_payload, &slot->loc_cb_received_payload);
-   }
-
-   return ret_val;
-}
-
-/*===========================================================================
-
-FUNCTION    loc_api_sync_ioctl
-
-DESCRIPTION
-   Synchronous IOCTL call (reentrant version)
-
-DEPENDENCIES
-   N/A
-
-RETURN VALUE
-   Loc API error code (0 = success)
-
-SIDE EFFECTS
-   N/A
-
-===========================================================================*/
-int loc_api_sync_ioctl
-(
-      rpc_loc_client_handle_type           handle,
-      rpc_loc_ioctl_e_type                 ioctl_type,
-      rpc_loc_ioctl_data_u_type*           ioctl_data_ptr,
-      uint32                               timeout_msec,
-      rpc_loc_ioctl_callback_s_type       *cb_data_ptr
-)
-{
-   int                              rc = -1;
-   int                              select_id;
-   rpc_loc_ioctl_callback_s_type    callback_data;
-
-   select_id = loc_lock_a_slot();
-
-   if (select_id < 0 || select_id >= loc_sync_data.num_of_slots)
-   {
-      ALOGE("slot not available ioctl_type = %s",
-           loc_get_ioctl_type_name(ioctl_type));
-      return rc;
-   }
-
-   loc_set_slot_in_use(select_id, 1); // set slot in use to true
-
-   // Select the callback we are waiting for
-   loc_api_save_callback(select_id, handle, 0, ioctl_type);
-
-   loc_unlock_slot(select_id); // slot is unlocked, but in_use is still true
-
-   // we want to avoid keeping the slot locked during the loc_ioctl because the rpc
-   // framework will also lock a different mutex during this call, and typically
-   // locking two different mutexes at the same time can lead to deadlock.
-   rc =  loc_ioctl(handle, ioctl_type, ioctl_data_ptr);
-
-   loc_lock_slot(select_id);
-
-   if (rc != RPC_LOC_API_SUCCESS)
-   {
-      ALOGE("loc_ioctl failed select_id = %d, ioctl_type %s, returned %s",
-           select_id, loc_get_ioctl_type_name(ioctl_type), loc_get_ioctl_status_name(rc));
-   }
-   else {
-      ALOGV("select_id = %d, ioctl_type %d, returned RPC_LOC_API_SUCCESS",
-          select_id, ioctl_type);
-      // Wait for the callback of loc_ioctl
-      if ((rc = loc_api_wait_callback(select_id, timeout_msec / 1000, NULL, &callback_data)) != 0)
-      {
-         // Callback waiting failed
-         ALOGE("callback wait failed select_id = %d, ioctl_type %s, returned %s",
-              select_id, loc_get_ioctl_type_name(ioctl_type), loc_get_ioctl_status_name(rc));
-      }
-      else
-      {
-         if (cb_data_ptr) memcpy(cb_data_ptr, &callback_data, sizeof *cb_data_ptr);
-         if (callback_data.status != RPC_LOC_API_SUCCESS)
-         {
-            rc = callback_data.status;
-            ALOGE("callback status failed select_id = %d, ioctl_type %s, returned %s",
-                 select_id, loc_get_ioctl_type_name(ioctl_type), loc_get_ioctl_status_name(rc));
-         } else {
-            ALOGV("callback status success select_id = %d, ioctl_type %d, returned %d",
-                select_id, ioctl_type, rc);
-         }
-      } /* wait callback */
-   } /* loc_ioctl */
-
-   loc_set_slot_in_use(select_id, 0); // set slot in use to false
-   loc_unlock_slot(select_id);
-
-   return rc;
-}
-
-
diff --git a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_apicb_appinit.c b/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_apicb_appinit.c
deleted file mode 100644
index db5b291..0000000
--- a/msm8998/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/loc_apicb_appinit.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/* 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 CO