1bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
2bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *
3bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * Redistribution and use in source and binary forms, with or without
4bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * modification, are permitted provided that the following conditions are
5bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * met:
6bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *     * Redistributions of source code must retain the above copyright
7bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *       notice, this list of conditions and the following disclaimer.
8bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *     * Redistributions in binary form must reproduce the above
9bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *       copyright notice, this list of conditions and the following
10bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *       disclaimer in the documentation and/or other materials provided
11bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *       with the distribution.
12bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *     * Neither the name of The Linux Foundation, nor the names of its
13bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *       contributors may be used to endorse or promote products derived
14bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *       from this software without specific prior written permission.
15bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *
16bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *
28bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo */
29bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define LOG_NDDEBUG 0
30bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define LOG_TAG "LocSvc_api_rpc"
31bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
32bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <unistd.h>
33bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <math.h>
34bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#ifndef USE_GLIB
35bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <utils/SystemClock.h>
36bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#endif /* USE_GLIB */
37bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <LocApiRpc.h>
38bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <LocAdapterBase.h>
39bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <loc_api_fixup.h>
40bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <loc_api_rpc_glue.h>
41bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <log_util.h>
42bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <loc_log.h>
43bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <loc_api_log.h>
44bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#ifdef USE_GLIB
45bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <glib.h>
46bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#endif
47bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <librpc.h>
48bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <platform_lib_includes.h>
49bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
50bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russousing namespace loc_core;
51bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
52bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define LOC_XTRA_INJECT_DEFAULT_TIMEOUT (3100)
53bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define XTRA_BLOCK_SIZE                 (3072)
54bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define LOC_IOCTL_DEFAULT_TIMEOUT 1000 // 1000 milli-seconds
55bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define LOC_NI_NOTIF_KEY_ADDRESS           "Address"
56bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
57bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo/*===========================================================================
58bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoFUNCTION    loc_event_cb
59bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
60bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoDESCRIPTION
61bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   This is the callback function registered by loc_open.
62bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
63bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoDEPENDENCIES
64bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   N/A
65bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
66bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoRETURN VALUE
67bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   RPC_LOC_API_SUCCESS
68bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
69bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoSIDE EFFECTS
70bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   N/A
71bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
72bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo===========================================================================*/
73bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russostatic int32 loc_event_cb
74bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo(
75bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    void*                                user,
76bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_client_handle_type           client_handle,
77bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_event_mask_type              loc_event,
78bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    const rpc_loc_event_payload_u_type*  loc_event_payload
79bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo)
80bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
81bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    MODEM_LOG_CALLFLOW(%s, loc_get_event_name(loc_event));
82bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    loc_callback_log(loc_event, loc_event_payload);
83bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    int32 ret_val = ((LocApiRpc*)user)->locEventCB(client_handle, loc_event, loc_event_payload);
84bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    EXIT_LOG(%d, ret_val);
85bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return ret_val;
86bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
87bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
88bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo/*===========================================================================
89bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoFUNCTION    loc_eng_rpc_global_cb
90bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
91bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoDESCRIPTION
92bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   This is the callback function registered by loc_open for RPC global events
93bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
94bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoDEPENDENCIES
95bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   N/A
96bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
97bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoRETURN VALUE
98bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   RPC_LOC_API_SUCCESS
99bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
100bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoSIDE EFFECTS
101bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   N/A
102bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
103bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo===========================================================================*/
104bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russostatic void loc_rpc_global_cb(void* user, CLIENT* clnt, enum rpc_reset_event event)
105bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
106bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    MODEM_LOG_CALLFLOW(%s, loc_get_rpc_reset_event_name(event));
107bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ((LocApiRpc*)user)->locRpcGlobalCB(clnt, event);
108bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    EXIT_LOG(%p, VOID_RET);
109bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
110bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
111bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoconst LOC_API_ADAPTER_EVENT_MASK_T LocApiRpc::maskAll =
112bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT |
113bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_API_ADAPTER_BIT_SATELLITE_REPORT |
114bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST |
115bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_API_ADAPTER_BIT_ASSISTANCE_DATA_REQUEST |
116bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_API_ADAPTER_BIT_IOCTL_REPORT |
117bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_API_ADAPTER_BIT_STATUS_REPORT |
118bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT |
119bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST;
120bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
121bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoconst rpc_loc_event_mask_type LocApiRpc::locBits[] =
122bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
123bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    RPC_LOC_EVENT_PARSED_POSITION_REPORT,
124bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    RPC_LOC_EVENT_SATELLITE_REPORT,
125bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    RPC_LOC_EVENT_NMEA_1HZ_REPORT,
126bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    RPC_LOC_EVENT_NMEA_POSITION_REPORT,
127bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    RPC_LOC_EVENT_NI_NOTIFY_VERIFY_REQUEST,
128bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    RPC_LOC_EVENT_ASSISTANCE_DATA_REQUEST,
129bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    RPC_LOC_EVENT_LOCATION_SERVER_REQUEST,
130bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    RPC_LOC_EVENT_IOCTL_REPORT,
131bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    RPC_LOC_EVENT_STATUS_REPORT,
132bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    RPC_LOC_EVENT_WPS_NEEDED_REQUEST
133bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo};
134bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
135bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo// constructor
136bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::LocApiRpc(const MsgTask* msgTask,
137bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     LOC_API_ADAPTER_EVENT_MASK_T exMask,
138bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     ContextBase* context) :
139bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LocApiBase(msgTask, exMask, context),
140bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    client_handle(RPC_LOC_CLIENT_HANDLE_INVALID),
141bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    dataEnableLastSet(-1)
142bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
143bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    memset(apnLastSet, 0, sizeof(apnLastSet));
144bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    loc_api_glue_init();
145bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
146bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
147bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::~LocApiRpc()
148bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
149bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    close();
150bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
151bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
152bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russorpc_loc_event_mask_type
153bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::convertMask(LOC_API_ADAPTER_EVENT_MASK_T mask)
154bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
155bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_event_mask_type newMask = 0;
156bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
157bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    for (unsigned int i = 0, bit=1; 0 != mask; i++, bit<<=1) {
158bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (mask & bit) {
159bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            newMask |= locBits[i];
160bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            mask ^= bit;
161bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
162bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
163bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
164bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return newMask;
165bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
166bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
167bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russorpc_loc_lock_e_type
168bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::convertGpsLockMask(LOC_GPS_LOCK_MASK lockMask)
169bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
170bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (isGpsLockAll(lockMask))
171bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return RPC_LOC_LOCK_ALL;
172bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (isGpsLockMO(lockMask))
173bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return RPC_LOC_LOCK_MI;
174bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (isGpsLockMT(lockMask))
175bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return RPC_LOC_LOCK_MT;
176bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (isGpsLockNone(lockMask))
177bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return RPC_LOC_LOCK_NONE;
178bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return (rpc_loc_lock_e_type)lockMask;
179bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
180bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
181bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
182bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::convertErr(int rpcErr)
183bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
184bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    switch(rpcErr)
185bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
186bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_API_SUCCESS:
187bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_SUCCESS;
188bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_API_GENERAL_FAILURE:
189bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_GENERAL_FAILURE;
190bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_API_UNSUPPORTED:
191bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_UNSUPPORTED;
192bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_API_INVALID_HANDLE:
193bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_INVALID_HANDLE;
194bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_API_INVALID_PARAMETER:
195bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_INVALID_PARAMETER;
196bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_API_ENGINE_BUSY:
197bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_ENGINE_BUSY;
198bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_API_PHONE_OFFLINE:
199bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_PHONE_OFFLINE;
200bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_API_TIMEOUT:
201bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_TIMEOUT;
202bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_API_RPC_MODEM_RESTART:
203bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_ENGINE_DOWN;
204bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_API_RPC_FAILURE:
205bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_FAILURE;
206bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    default:
207bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_UNKNOWN;
208bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
209bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
210bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
211bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russovoid LocApiRpc::locRpcGlobalCB(CLIENT* clnt, enum rpc_reset_event event)
212bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
213bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    static rpc_loc_engine_state_e_type last_state = RPC_LOC_ENGINE_STATE_MAX;
214bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
215bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    switch (event) {
216bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_SUBSYSTEM_RESTART_BEGIN:
217bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (RPC_LOC_ENGINE_STATE_OFF != last_state) {
218bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            last_state = RPC_LOC_ENGINE_STATE_OFF;
219bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            handleEngineDownEvent();
220bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
221bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
222bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_SUBSYSTEM_RESTART_END:
223bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (RPC_LOC_ENGINE_STATE_ON != last_state) {
224bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            last_state = RPC_LOC_ENGINE_STATE_ON;
225bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            handleEngineUpEvent();
226bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
227bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
228bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
229bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
230bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
231bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoint32 LocApiRpc::locEventCB(rpc_loc_client_handle_type client_handle,
232bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     rpc_loc_event_mask_type loc_event,
233bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     const rpc_loc_event_payload_u_type* loc_event_payload)
234bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
235bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // Parsed report
236bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (loc_event & RPC_LOC_EVENT_PARSED_POSITION_REPORT)
237bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
238bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        reportPosition(&loc_event_payload->rpc_loc_event_payload_u_type_u.
239bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                       parsed_location_report);
240bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
241bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
242bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // Satellite report
243bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (loc_event & RPC_LOC_EVENT_SATELLITE_REPORT)
244bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
245bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        reportSv(&loc_event_payload->rpc_loc_event_payload_u_type_u.gnss_report);
246bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
247bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
248bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // Status report
249bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (loc_event & RPC_LOC_EVENT_STATUS_REPORT)
250bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
251bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        reportStatus(&loc_event_payload->rpc_loc_event_payload_u_type_u.status_report);
252bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
253bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
254bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // NMEA
255bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (loc_event & RPC_LOC_EVENT_NMEA_1HZ_REPORT)
256bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
257bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        reportNmea(&(loc_event_payload->rpc_loc_event_payload_u_type_u.nmea_report));
258bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
259bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // XTRA support: supports only XTRA download
260bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (loc_event & RPC_LOC_EVENT_ASSISTANCE_DATA_REQUEST)
261bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
262bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (loc_event_payload->rpc_loc_event_payload_u_type_u.assist_data_request.event ==
263bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            RPC_LOC_ASSIST_DATA_PREDICTED_ORBITS_REQ)
264bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
265bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            requestXtraData();
266bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        } else if (loc_event_payload->rpc_loc_event_payload_u_type_u.assist_data_request.event ==
267bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                   RPC_LOC_ASSIST_DATA_TIME_REQ)
268bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
269bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            requestTime();
270bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        } else if (loc_event_payload->rpc_loc_event_payload_u_type_u.assist_data_request.event ==
271bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                   RPC_LOC_ASSIST_DATA_POSITION_INJECTION_REQ)
272bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
273bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            requestLocation();
274bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
275bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
276bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
277bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // AGPS data request
278bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (loc_event & RPC_LOC_EVENT_LOCATION_SERVER_REQUEST)
279bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
280bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        ATLEvent(&loc_event_payload->rpc_loc_event_payload_u_type_u.
281bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                 loc_server_request);
282bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
283bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
284bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // NI notify request
285bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (loc_event & RPC_LOC_EVENT_NI_NOTIFY_VERIFY_REQUEST)
286bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
287bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        NIEvent(&loc_event_payload->rpc_loc_event_payload_u_type_u.ni_request);
288bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
289bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
290bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return RPC_LOC_API_SUCCESS;//We simply want to return sucess here as we do not want to
291bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // cause any issues in RPC thread context
292bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
293bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
294bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
295bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::open(LOC_API_ADAPTER_EVENT_MASK_T mask)
296bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
297bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    enum loc_api_adapter_err ret_val = LOC_API_ADAPTER_ERR_SUCCESS;
298bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
299bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // RPC does not dynamically update the event mask. And in the
300bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // case of RPC, all we support are positioning (gps + agps)
301bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // masks anyways, so we simply mask all of them on always.
302bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // After doing so the first time in a power cycle, we know there
303bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // will the following if condition will never be true any more.
304bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    mask = maskAll;
305bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
306bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (mask != mMask) {
307bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (RPC_LOC_CLIENT_HANDLE_INVALID != client_handle) {
308bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            close();
309bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
310bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
311bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        mMask = mask;
312bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        // it is important to cap the mask here, because not all LocApi's
313bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        // can enable the same bits, e.g. foreground and bckground.
314bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        client_handle = loc_open(convertMask(mask),
315bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                 loc_event_cb,
316bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                 loc_rpc_global_cb, this);
317bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
318bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (client_handle < 0) {
319bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            mMask = 0;
320bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            client_handle = RPC_LOC_CLIENT_HANDLE_INVALID;
321bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            ret_val = LOC_API_ADAPTER_ERR_INVALID_HANDLE;
322bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
323bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
324bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
325bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return ret_val;
326bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
327bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
328bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
329bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::close()
330bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
331bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (RPC_LOC_CLIENT_HANDLE_INVALID != client_handle) {
332bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        loc_clear(client_handle);
333bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
334bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
335bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    loc_close(client_handle);
336bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    mMask = 0;
337bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    client_handle = RPC_LOC_CLIENT_HANDLE_INVALID;
338bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
339bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return LOC_API_ADAPTER_ERR_SUCCESS;
340bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
341bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
342bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
343bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::startFix(const LocPosMode& posMode) {
344bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   LOC_LOGD("LocApiRpc::startFix() called");
345bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   return convertErr(
346bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       loc_start_fix(client_handle)
347bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       );
348bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
349bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
350bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
351bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::stopFix() {
352bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   LOC_LOGD("LocApiRpc::stopFix() called");
353bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   return convertErr(
354bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       loc_stop_fix(client_handle)
355bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       );
356bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
357bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
358bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
359bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::setPositionMode(const LocPosMode& posMode)
360bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
361bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_data_u_type    ioctl_data;
362bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_fix_criteria_s_type *fix_criteria_ptr =
363bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        &ioctl_data.rpc_loc_ioctl_data_u_type_u.fix_criteria;
364bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_e_type         ioctl_type = RPC_LOC_IOCTL_SET_FIX_CRITERIA;
365bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_operation_mode_e_type op_mode;
366bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    int                          ret_val;
367bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    const LocPosMode* fixCriteria = &posMode;
368bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
369bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ALOGD ("loc_eng_set_position mode, client = %d, interval = %d, mode = %d\n",
370bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo          (int32) client_handle, fixCriteria->min_interval, fixCriteria->mode);
371bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
372bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    switch (fixCriteria->mode)
373bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
374bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case LOC_POSITION_MODE_MS_BASED:
375bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        op_mode = RPC_LOC_OPER_MODE_MSB;
376bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
377bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case LOC_POSITION_MODE_MS_ASSISTED:
378bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        op_mode = RPC_LOC_OPER_MODE_MSA;
379bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
380bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case LOC_POSITION_MODE_RESERVED_1:
381bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        op_mode = RPC_LOC_OPER_MODE_SPEED_OPTIMAL;
382bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
383bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case LOC_POSITION_MODE_RESERVED_2:
384bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        op_mode = RPC_LOC_OPER_MODE_ACCURACY_OPTIMAL;
385bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
386bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case LOC_POSITION_MODE_RESERVED_3:
387bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        op_mode = RPC_LOC_OPER_MODE_DATA_OPTIMAL;
388bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
389bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case LOC_POSITION_MODE_RESERVED_4:
390bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case LOC_POSITION_MODE_RESERVED_5:
391bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        op_mode = RPC_LOC_OPER_MODE_MSA;
392bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        fix_criteria_ptr->preferred_response_time  = 0;
393bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
394bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    default:
395bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        op_mode = RPC_LOC_OPER_MODE_STANDALONE;
396bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
397bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
398bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    fix_criteria_ptr->valid_mask = RPC_LOC_FIX_CRIT_VALID_PREFERRED_OPERATION_MODE |
399bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                   RPC_LOC_FIX_CRIT_VALID_RECURRENCE_TYPE;
400bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    fix_criteria_ptr->min_interval = fixCriteria->min_interval;
401bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    fix_criteria_ptr->preferred_operation_mode = op_mode;
402bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
403bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    fix_criteria_ptr->min_interval = fixCriteria->min_interval;
404bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    fix_criteria_ptr->valid_mask |= RPC_LOC_FIX_CRIT_VALID_MIN_INTERVAL;
405bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
406bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (fixCriteria->preferred_accuracy > 0) {
407bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        fix_criteria_ptr->preferred_accuracy = fixCriteria->preferred_accuracy;
408bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        fix_criteria_ptr->valid_mask |= RPC_LOC_FIX_CRIT_VALID_PREFERRED_ACCURACY;
409bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
410bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (fixCriteria->preferred_time > 0) {
411bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        fix_criteria_ptr->preferred_response_time = fixCriteria->preferred_time;
412bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        fix_criteria_ptr->valid_mask |= RPC_LOC_FIX_CRIT_VALID_PREFERRED_RESPONSE_TIME;
413bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
414bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
415bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    switch (fixCriteria->recurrence) {
416bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case GPS_POSITION_RECURRENCE_SINGLE:
417bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        fix_criteria_ptr->recurrence_type = RPC_LOC_SINGLE_FIX;
418bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
419bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case GPS_POSITION_RECURRENCE_PERIODIC:
420bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    default:
421bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        fix_criteria_ptr->recurrence_type = RPC_LOC_PERIODIC_FIX;
422bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
423bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
424bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ioctl_data.disc = ioctl_type;
425bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
426bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ret_val = loc_eng_ioctl (client_handle,
427bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             ioctl_type,
428bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             &ioctl_data,
429bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             LOC_IOCTL_DEFAULT_TIMEOUT,
430bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             NULL /* No output information is expected*/);
431bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
432bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return convertErr(ret_val);
433bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
434bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
435bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
436bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::setTime(GpsUtcTime time, int64_t timeReference, int uncertainty)
437bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
438bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_data_u_type        ioctl_data;
439bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_assist_data_time_s_type *time_info_ptr;
440bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_e_type             ioctl_type = RPC_LOC_IOCTL_INJECT_UTC_TIME;
441bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    int                              ret_val;
442bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
443bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_LOGD ("loc_eng_inject_time, uncertainty = %d\n", uncertainty);
444bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
445bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    time_info_ptr = &ioctl_data.rpc_loc_ioctl_data_u_type_u.assistance_data_time;
446bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    time_info_ptr->time_utc = time;
447bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    time_info_ptr->time_utc += (int64_t)(ELAPSED_MILLIS_SINCE_BOOT_PLATFORM_LIB_ABSTRACTION - timeReference);
448bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    time_info_ptr->uncertainty = uncertainty; // Uncertainty in ms
449bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
450bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ioctl_data.disc = ioctl_type;
451bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
452bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ret_val = loc_eng_ioctl (client_handle,
453bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             ioctl_type,
454bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             &ioctl_data,
455bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             LOC_IOCTL_DEFAULT_TIMEOUT,
456bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             NULL /* No output information is expected*/);
457bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
458bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return convertErr(ret_val);
459bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
460bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
461bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
462bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::injectPosition(double latitude, double longitude, float accuracy)
463bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
464bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    /* IOCTL data */
465bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_data_u_type ioctl_data;
466bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_assist_data_pos_s_type *assistance_data_position =
467bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        &ioctl_data.rpc_loc_ioctl_data_u_type_u.assistance_data_position;
468bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    int                          ret_val;
469bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
470bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    /************************************************
471bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo     * Fill in latitude, longitude & accuracy
472bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo     ************************************************/
473bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
474bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    /* This combo is required */
475bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    assistance_data_position->valid_mask =
476bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        RPC_LOC_ASSIST_POS_VALID_LATITUDE |
477bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        RPC_LOC_ASSIST_POS_VALID_LONGITUDE |
478bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        RPC_LOC_ASSIST_POS_VALID_HOR_UNC_CIRCULAR |
479bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        RPC_LOC_ASSIST_POS_VALID_CONFIDENCE_HORIZONTAL;
480bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
481bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    assistance_data_position->latitude = latitude;
482bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    assistance_data_position->longitude = longitude;
483bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    assistance_data_position->hor_unc_circular = accuracy; /* Meters assumed */
484bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    assistance_data_position->confidence_horizontal = 63;  /* 63% (1 std dev) assumed */
485bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
486bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    /* Log */
487bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_LOGD("Inject coarse position Lat=%lf, Lon=%lf, Acc=%.2lf\n",
488bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo             (double) assistance_data_position->latitude,
489bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo             (double) assistance_data_position->longitude,
490bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo             (double) assistance_data_position->hor_unc_circular);
491bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
492bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ret_val = loc_eng_ioctl( client_handle,
493bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             RPC_LOC_IOCTL_INJECT_POSITION,
494bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             &ioctl_data,
495bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             LOC_IOCTL_DEFAULT_TIMEOUT,
496bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             NULL /* No output information is expected*/);
497bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return convertErr(ret_val);
498bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
499bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
500bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
501bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::informNiResponse(GpsUserResponseType userResponse,
502bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                   const void* passThroughData)
503bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
504bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_data_u_type data;
505bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_callback_s_type callback_payload;
506bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
507bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    memcpy(&data.rpc_loc_ioctl_data_u_type_u.user_verify_resp.ni_event_pass_back,
508bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo           passThroughData, sizeof (rpc_loc_ni_event_s_type));
509bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
510bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ni_user_resp_e_type resp;
511bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    switch (userResponse)
512bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
513bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case GPS_NI_RESPONSE_ACCEPT:
514bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        data.rpc_loc_ioctl_data_u_type_u.user_verify_resp.user_resp =
515bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            RPC_LOC_NI_LCS_NOTIFY_VERIFY_ACCEPT;
516bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
517bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case GPS_NI_RESPONSE_DENY:
518bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        data.rpc_loc_ioctl_data_u_type_u.user_verify_resp.user_resp =
519bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            RPC_LOC_NI_LCS_NOTIFY_VERIFY_DENY;
520bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
521bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case GPS_NI_RESPONSE_NORESP:
522bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    default:
523bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        data.rpc_loc_ioctl_data_u_type_u.user_verify_resp.user_resp =
524bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            RPC_LOC_NI_LCS_NOTIFY_VERIFY_NORESP;
525bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
526bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
527bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
528bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return convertErr(
529bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        loc_eng_ioctl(client_handle,
530bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      RPC_LOC_IOCTL_INFORM_NI_USER_RESPONSE,
531bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      &data,
532bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      LOC_IOCTL_DEFAULT_TIMEOUT,
533bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      &callback_payload)
534bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        );
535bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
536bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
537bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
538bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::setAPN(char* apn, int len, boolean force)
539bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
540bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    enum loc_api_adapter_err rtv = LOC_API_ADAPTER_ERR_SUCCESS;
541bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    int size = sizeof(apnLastSet);
542bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (force || memcmp(apnLastSet, apn, size)) {
543bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (len < size) {
544bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            // size will be not larger than its original value
545bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            size = len + 1;
546bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
547bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        memcpy(apnLastSet, apn, size);
548bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
549bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (!isInSession()) {
550bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            rpc_loc_ioctl_data_u_type ioctl_data = {RPC_LOC_IOCTL_SET_LBS_APN_PROFILE, {0}};
551bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            ioctl_data.rpc_loc_ioctl_data_u_type_u.apn_profiles[0].srv_system_type = LOC_APN_PROFILE_SRV_SYS_MAX;
552bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            ioctl_data.rpc_loc_ioctl_data_u_type_u.apn_profiles[0].pdp_type = LOC_APN_PROFILE_PDN_TYPE_IPV4;
553bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            memcpy(&(ioctl_data.rpc_loc_ioctl_data_u_type_u.apn_profiles[0].apn_name), apn, size);
554bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
555bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            rtv = convertErr(
556bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                loc_eng_ioctl (client_handle,
557bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                               RPC_LOC_IOCTL_SET_LBS_APN_PROFILE,
558bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                               &ioctl_data,
559bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                               LOC_IOCTL_DEFAULT_TIMEOUT,
560bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                               NULL)
561bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                );
562bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
563bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
564bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return rtv;
565bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
566bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
567bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russovoid LocApiRpc::setInSession(bool inSession)
568bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
569bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (!inSession) {
570bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        enableData(dataEnableLastSet, true);
571bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        setAPN(apnLastSet, sizeof(apnLastSet)-1, true);
572bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
573bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
574bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
575bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
576bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::setServer(const char* url, int len)
577bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
578bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_data_u_type         ioctl_data;
579bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_server_info_s_type       *server_info_ptr;
580bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_e_type              ioctl_cmd;
581bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
582bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ioctl_cmd = RPC_LOC_IOCTL_SET_UMTS_SLP_SERVER_ADDR;
583bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ioctl_data.disc = ioctl_cmd;
584bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    server_info_ptr = &ioctl_data.rpc_loc_ioctl_data_u_type_u.server_addr;
585bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    server_info_ptr->addr_type = RPC_LOC_SERVER_ADDR_URL;
586bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    server_info_ptr->addr_info.disc = server_info_ptr->addr_type;
587bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.url.length = len;
588bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#if (AMSS_VERSION==3200)
589bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.url.addr.addr_val = (char*) url;
590bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.url.addr.addr_len= len;
591bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#else
592bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    strlcpy(server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.url.addr, url,
593bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            sizeof server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.url.addr);
594bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#endif /* #if (AMSS_VERSION==3200) */
595bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_LOGD ("loc_eng_set_server, addr = %s\n", url);
596bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
597bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return convertErr(
598bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        loc_eng_ioctl (client_handle,
599bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                       ioctl_cmd,
600bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                       &ioctl_data,
601bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                       LOC_IOCTL_DEFAULT_TIMEOUT,
602bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                       NULL /* No output information is expected*/)
603bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        );
604bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
605bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
606bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
607bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::setServer(unsigned int ip, int port, LocServerType type)
608bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
609bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_data_u_type         ioctl_data;
610bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_server_info_s_type       *server_info_ptr;
611bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_e_type              ioctl_cmd;
612bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
613bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    switch (type) {
614bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case LOC_AGPS_MPC_SERVER:
615bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        ioctl_cmd = RPC_LOC_IOCTL_SET_CDMA_MPC_SERVER_ADDR;
616bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
617bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case LOC_AGPS_CUSTOM_PDE_SERVER:
618bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        ioctl_cmd = RPC_LOC_IOCTL_SET_CUSTOM_PDE_SERVER_ADDR;
619bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
620bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    default:
621bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        ioctl_cmd = RPC_LOC_IOCTL_SET_CDMA_PDE_SERVER_ADDR;
622bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
623bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
624bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ioctl_data.disc = ioctl_cmd;
625bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    server_info_ptr = &ioctl_data.rpc_loc_ioctl_data_u_type_u.server_addr;
626bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    server_info_ptr->addr_type = RPC_LOC_SERVER_ADDR_IPV4;
627bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    server_info_ptr->addr_info.disc = server_info_ptr->addr_type;
628bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.ipv4.addr = ip;
629bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    server_info_ptr->addr_info.rpc_loc_server_addr_u_type_u.ipv4.port = port;
630bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_LOGD ("setServer, addr = %X:%d\n", (unsigned int) ip, (unsigned int) port);
631bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
632bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return convertErr(
633bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        loc_eng_ioctl (client_handle,
634bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                       ioctl_cmd,
635bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                       &ioctl_data,
636bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                       LOC_IOCTL_DEFAULT_TIMEOUT,
637bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                       NULL /* No output information is expected*/)
638bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        );
639bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
640bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
641bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
642bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::enableData(int enable, boolean force)
643bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
644bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    enum loc_api_adapter_err rtv = LOC_API_ADAPTER_ERR_SUCCESS;
645bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (force || dataEnableLastSet != enable) {
646bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        dataEnableLastSet = enable;
647bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
648bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (!isInSession()) {
649bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            rpc_loc_ioctl_data_u_type ioctl_data = {RPC_LOC_IOCTL_SET_DATA_ENABLE, {0}};
650bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
651bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            ioctl_data.rpc_loc_ioctl_data_u_type_u.data_enable = enable;
652bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            rtv =  convertErr(
653bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                loc_eng_ioctl (client_handle,
654bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                               RPC_LOC_IOCTL_SET_DATA_ENABLE,
655bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                               &ioctl_data,
656bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                               LOC_IOCTL_DEFAULT_TIMEOUT,
657bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                               NULL)
658bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                );
659bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
660bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
661bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return rtv;
662bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
663bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
664bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
665bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::deleteAidingData(GpsAidingData bits)
666bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
667bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_data_u_type ioctl_data = {RPC_LOC_IOCTL_DELETE_ASSIST_DATA, {0}};
668bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ioctl_data.rpc_loc_ioctl_data_u_type_u.assist_data_delete.type = bits;
669bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
670bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return convertErr(
671bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        loc_eng_ioctl (client_handle,
672bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                       RPC_LOC_IOCTL_DELETE_ASSIST_DATA,
673bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                       &ioctl_data,
674bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                       LOC_IOCTL_DEFAULT_TIMEOUT,
675bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                       NULL)
676bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        );
677bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
678bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
679bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russovoid LocApiRpc::reportPosition(const rpc_loc_parsed_position_s_type *location_report_ptr)
680bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
681bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LocPosTechMask tech_Mask = LOC_POS_TECH_MASK_DEFAULT;
682bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
683bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    UlpLocation location = {0};
684bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    GpsLocationExtended locationExtended = {0};
685bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
686bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    location.size = sizeof(location);
687bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    locationExtended.size = sizeof(locationExtended);
688bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_SESSION_STATUS)
689bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
690bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        // Process the position from final and intermediate reports
691bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (location_report_ptr->session_status == RPC_LOC_SESS_STATUS_SUCCESS ||
692bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            location_report_ptr->session_status == RPC_LOC_SESS_STATUS_IN_PROGESS)
693bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
694bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            // Latitude & Longitude
695bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            if ((location_report_ptr->valid_mask & RPC_LOC_POS_VALID_LATITUDE) &&
696bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_LONGITUDE) &&
697bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                (location_report_ptr->latitude != 0 ||
698bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                 location_report_ptr->longitude != 0))
699bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            {
700bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                location.gpsLocation.flags    |= GPS_LOCATION_HAS_LAT_LONG;
701bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                location.gpsLocation.latitude  = location_report_ptr->latitude;
702bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                location.gpsLocation.longitude = location_report_ptr->longitude;
703bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
704bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                // Time stamp (UTC)
705bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                if (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_TIMESTAMP_UTC)
706bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                {
707bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    location.gpsLocation.timestamp = location_report_ptr->timestamp_utc;
708bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                }
709bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
710bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                // Altitude
711bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                if (location_report_ptr->valid_mask &  RPC_LOC_POS_VALID_ALTITUDE_WRT_ELLIPSOID )
712bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                {
713bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    location.gpsLocation.flags    |= GPS_LOCATION_HAS_ALTITUDE;
714bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    location.gpsLocation.altitude = location_report_ptr->altitude_wrt_ellipsoid;
715bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                }
716bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
717bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                // Speed
718bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                if ((location_report_ptr->valid_mask & RPC_LOC_POS_VALID_SPEED_HORIZONTAL) &&
719bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_SPEED_VERTICAL))
720bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                {
721bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    location.gpsLocation.flags    |= GPS_LOCATION_HAS_SPEED;
722bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    location.gpsLocation.speed = sqrt(location_report_ptr->speed_horizontal * location_report_ptr->speed_horizontal +
723bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                          location_report_ptr->speed_vertical * location_report_ptr->speed_vertical);
724bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                }
725bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
726bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                // Heading
727bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                if (location_report_ptr->valid_mask &  RPC_LOC_POS_VALID_HEADING)
728bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                {
729bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    location.gpsLocation.flags    |= GPS_LOCATION_HAS_BEARING;
730bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    location.gpsLocation.bearing = location_report_ptr->heading;
731bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                }
732bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
733bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                // Uncertainty (circular)
734bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                if ( (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_HOR_UNC_CIRCULAR) )
735bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                {
736bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    location.gpsLocation.flags    |= GPS_LOCATION_HAS_ACCURACY;
737bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    location.gpsLocation.accuracy = location_report_ptr->hor_unc_circular;
738bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                }
739bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
740bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                // Technology Mask
741bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
742bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                tech_Mask  |= location_report_ptr->technology_mask;
743bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                //Mark the location source as from GNSS
744bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                location.gpsLocation.flags |= LOCATION_HAS_SOURCE_INFO;
745bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                location.position_source = ULP_LOCATION_IS_FROM_GNSS;
746bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                if (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_ALTITUDE_WRT_MEAN_SEA_LEVEL)
747bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                {
748bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    locationExtended.flags |= GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL;
749bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    locationExtended.altitudeMeanSeaLevel = location_report_ptr->altitude_wrt_mean_sea_level;
750bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                }
751bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
752bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                if (location_report_ptr->valid_mask &  RPC_LOC_POS_VALID_MAGNETIC_VARIATION )
753bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                {
754bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    locationExtended.flags |= GPS_LOCATION_EXTENDED_HAS_MAG_DEV;
755bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    locationExtended.magneticDeviation = location_report_ptr->magnetic_deviation;
756bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                }
757bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
758bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                if (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_VERTICAL_UNC)
759bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                {
760bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                   locationExtended.flags |= GPS_LOCATION_EXTENDED_HAS_VERT_UNC;
761bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                   locationExtended.vert_unc = location_report_ptr->vert_unc;
762bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                }
763bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
764bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                if (location_report_ptr->valid_mask & RPC_LOC_POS_VALID_SPEED_UNC)
765bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                {
766bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                   locationExtended.flags |= GPS_LOCATION_EXTENDED_HAS_SPEED_UNC;
767bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                   locationExtended.speed_unc = location_report_ptr->speed_unc;
768bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                }
769bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
770bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                LOC_LOGV("reportPosition: fire callback\n");
771bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                enum loc_sess_status fixStatus =
772bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    (location_report_ptr->session_status
773bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     == RPC_LOC_SESS_STATUS_IN_PROGESS ?
774bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     LOC_SESS_INTERMEDIATE : LOC_SESS_SUCCESS);
775bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                LocApiBase::reportPosition(location,
776bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                           locationExtended,
777bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                           (void*)location_report_ptr,
778bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                           fixStatus,
779bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                           tech_Mask);
780bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            }
781bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
782bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        else
783bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
784bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            LocApiBase::reportPosition(location,
785bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                       locationExtended,
786bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                       NULL,
787bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                       LOC_SESS_FAILURE);
788bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            LOC_LOGV("loc_eng_report_position: ignore position report "
789bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     "when session status = %d\n",
790bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     location_report_ptr->session_status);
791bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
792bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
793bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    else
794bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
795bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGV("loc_eng_report_position: ignore position report "
796bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                 "when session status is not set\n");
797bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
798bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
799bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
800bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russovoid LocApiRpc::reportSv(const rpc_loc_gnss_info_s_type *gnss_report_ptr)
801bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
802bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    GpsSvStatus     SvStatus = {0};
803bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    GpsLocationExtended locationExtended = {0};
804bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    locationExtended.size = sizeof(locationExtended);
805bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    int             num_svs_max = 0;
806bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    const rpc_loc_sv_info_s_type *sv_info_ptr;
807bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
808bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (gnss_report_ptr->valid_mask & RPC_LOC_GNSS_INFO_VALID_SV_COUNT)
809bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
810bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        num_svs_max = gnss_report_ptr->sv_count;
811bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (num_svs_max > GPS_MAX_SVS)
812bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
813bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            num_svs_max = GPS_MAX_SVS;
814bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
815bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
816bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
817bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (gnss_report_ptr->valid_mask & RPC_LOC_GNSS_INFO_VALID_SV_LIST)
818bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
819bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        SvStatus.num_svs = 0;
820bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
821bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        for (int i = 0; i < num_svs_max; i++)
822bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
823bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            sv_info_ptr = &(gnss_report_ptr->sv_list.sv_list_val[i]);
824bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            if (sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_SYSTEM)
825bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            {
826bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                if (sv_info_ptr->system == RPC_LOC_SV_SYSTEM_GPS)
827bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                {
828bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    SvStatus.sv_list[SvStatus.num_svs].size = sizeof(GpsSvStatus);
829bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    SvStatus.sv_list[SvStatus.num_svs].prn = sv_info_ptr->prn;
830bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
831bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    // We only have the data field to report gps eph and alm mask
832bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    if ((sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_HAS_EPH) &&
833bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                        (sv_info_ptr->has_eph == 1))
834bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    {
835bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                        SvStatus.ephemeris_mask |= (1 << (sv_info_ptr->prn-1));
836bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    }
837bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
838bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    if ((sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_HAS_ALM) &&
839bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                        (sv_info_ptr->has_alm == 1))
840bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    {
841bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                        SvStatus.almanac_mask |= (1 << (sv_info_ptr->prn-1));
842bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    }
843bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
844bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    if ((sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_PROCESS_STATUS) &&
845bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                        (sv_info_ptr->process_status == RPC_LOC_SV_STATUS_TRACK))
846bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    {
847bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                        SvStatus.used_in_fix_mask |= (1 << (sv_info_ptr->prn-1));
848bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    }
849bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                }
850bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                // SBAS: GPS RPN: 120-151,
851bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                // In exteneded measurement report, we follow nmea standard, which is from 33-64.
852bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                else if (sv_info_ptr->system == RPC_LOC_SV_SYSTEM_SBAS)
853bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                {
854bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    SvStatus.sv_list[SvStatus.num_svs].prn = sv_info_ptr->prn + 33 - 120;
855bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                }
856bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                // Gloness: Slot id: 1-32
857bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                // In extended measurement report, we follow nmea standard, which is 65-96
858bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                else if (sv_info_ptr->system == RPC_LOC_SV_SYSTEM_GLONASS)
859bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                {
860bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    SvStatus.sv_list[SvStatus.num_svs].prn = sv_info_ptr->prn + (65-1);
861bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                }
862bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                // Unsupported SV system
863bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                else
864bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                {
865bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    continue;
866bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                }
867bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            }
868bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
869bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            if (sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_SNR)
870bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            {
871bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                SvStatus.sv_list[SvStatus.num_svs].snr = sv_info_ptr->snr;
872bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            }
873bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
874bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            if (sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_ELEVATION)
875bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            {
876bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                SvStatus.sv_list[SvStatus.num_svs].elevation = sv_info_ptr->elevation;
877bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            }
878bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
879bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            if (sv_info_ptr->valid_mask & RPC_LOC_SV_INFO_VALID_AZIMUTH)
880bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            {
881bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                SvStatus.sv_list[SvStatus.num_svs].azimuth = sv_info_ptr->azimuth;
882bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            }
883bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
884bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            SvStatus.num_svs++;
885bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
886bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
887bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
888bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if ((gnss_report_ptr->valid_mask & RPC_LOC_GNSS_INFO_VALID_POS_DOP) &&
889bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        (gnss_report_ptr->valid_mask & RPC_LOC_GNSS_INFO_VALID_HOR_DOP) &&
890bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        (gnss_report_ptr->valid_mask & RPC_LOC_GNSS_INFO_VALID_VERT_DOP))
891bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
892bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        locationExtended.flags |= GPS_LOCATION_EXTENDED_HAS_DOP;
893bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        locationExtended.pdop = gnss_report_ptr->position_dop;
894bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        locationExtended.hdop = gnss_report_ptr->horizontal_dop;
895bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        locationExtended.vdop = gnss_report_ptr->vertical_dop;
896bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
897bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
898bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (SvStatus.num_svs >= 0)
899bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
900bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LocApiBase::reportSv(SvStatus,
901bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             locationExtended,
902bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                             (void*)gnss_report_ptr);
903bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
904bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
905bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
906bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russovoid LocApiRpc::reportStatus(const rpc_loc_status_event_s_type *status_report_ptr)
907bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
908bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
909bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (status_report_ptr->event == RPC_LOC_STATUS_EVENT_ENGINE_STATE) {
910bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (status_report_ptr->payload.rpc_loc_status_event_payload_u_type_u.engine_state == RPC_LOC_ENGINE_STATE_ON)
911bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
912bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            LocApiBase::reportStatus(GPS_STATUS_ENGINE_ON);
913bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            LocApiBase::reportStatus(GPS_STATUS_SESSION_BEGIN);
914bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
915bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        else if (status_report_ptr->payload.rpc_loc_status_event_payload_u_type_u.engine_state == RPC_LOC_ENGINE_STATE_OFF)
916bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
917bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            LocApiBase::reportStatus(GPS_STATUS_SESSION_END);
918bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            LocApiBase::reportStatus(GPS_STATUS_ENGINE_OFF);
919bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
920bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        else
921bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
922bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            LocApiBase::reportStatus(GPS_STATUS_NONE);
923bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
924bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
925bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
926bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
927bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
928bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russovoid LocApiRpc::reportNmea(const rpc_loc_nmea_report_s_type *nmea_report_ptr)
929bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
930bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
931bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#if (AMSS_VERSION==3200)
932bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LocApiBase::reportNmea(nmea_report_ptr->nmea_sentences.nmea_sentences_val,
933bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                           nmea_report_ptr->nmea_sentences.nmea_sentences_len);
934bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#else
935bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LocApiBase::reportNmea(nmea_report_ptr->nmea_sentences,
936bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                           nmea_report_ptr->length);
937bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_LOGD("loc_eng_report_nmea: $%c%c%c\n",
938bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo             nmea_report_ptr->nmea_sentences[3],
939bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo             nmea_report_ptr->nmea_sentences[4],
940bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo             nmea_report_ptr->nmea_sentences[5]);
941bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#endif /* #if (AMSS_VERSION==3200) */
942bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
943bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
944bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
945bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::setXtraData(char* data, int length)
946bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
947bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    int     rpc_ret_val = RPC_LOC_API_GENERAL_FAILURE;
948bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    int     total_parts;
949bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    uint8   part;
950bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    uint16  part_len;
951bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    uint16  len_injected;
952bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_data_u_type            ioctl_data;
953bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_e_type                 ioctl_type = RPC_LOC_IOCTL_INJECT_PREDICTED_ORBITS_DATA;
954bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_predicted_orbits_data_s_type *predicted_orbits_data_ptr;
955bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
956bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_LOGD("qct_loc_eng_inject_xtra_data, xtra size = %d, data ptr = 0x%lx\n", length, (long) data);
957bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
958bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    predicted_orbits_data_ptr = &ioctl_data.rpc_loc_ioctl_data_u_type_u.predicted_orbits_data;
959bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    predicted_orbits_data_ptr->format_type = RPC_LOC_PREDICTED_ORBITS_XTRA;
960bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    predicted_orbits_data_ptr->total_size = length;
961bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    total_parts = (length - 1) / XTRA_BLOCK_SIZE + 1;
962bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    predicted_orbits_data_ptr->total_parts = total_parts;
963bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
964bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    len_injected = 0; // O bytes injected
965bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ioctl_data.disc = ioctl_type;
966bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
967bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // XTRA injection starts with part 1
968bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    for (part = 1; part <= total_parts; part++)
969bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
970bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        predicted_orbits_data_ptr->part = part;
971bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        predicted_orbits_data_ptr->part_len = XTRA_BLOCK_SIZE;
972bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (XTRA_BLOCK_SIZE > (length - len_injected))
973bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
974bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            predicted_orbits_data_ptr->part_len = length - len_injected;
975bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
976bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        predicted_orbits_data_ptr->data_ptr.data_ptr_len = predicted_orbits_data_ptr->part_len;
977bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        predicted_orbits_data_ptr->data_ptr.data_ptr_val = data + len_injected;
978bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
979bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGD("qct_loc_eng_inject_xtra_data, part %d/%d, len = %d, total = %d\n",
980bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                 predicted_orbits_data_ptr->part,
981bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                 total_parts,
982bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                 predicted_orbits_data_ptr->part_len,
983bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                 len_injected);
984bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
985bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (part < total_parts)
986bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
987bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            // No callback in this case
988bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            rpc_ret_val = loc_ioctl (client_handle,
989bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                     ioctl_type,
990bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                     &ioctl_data);
991bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
992bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            if (rpc_ret_val != RPC_LOC_API_SUCCESS)
993bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            {
994bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                LOC_LOGE("loc_ioctl for xtra error: %s\n", loc_get_ioctl_status_name(rpc_ret_val));
995bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                break;
996bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            }
997bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            //Add a delay of 10 ms so that repeated RPC calls dont starve the modem processor
998bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            usleep(10 * 1000);
999bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
1000bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        else // part == total_parts
1001bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
1002bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            // Last part injection, will need to wait for callback
1003bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            if (!loc_eng_ioctl(client_handle,
1004bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                               ioctl_type,
1005bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                               &ioctl_data,
1006bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                               LOC_XTRA_INJECT_DEFAULT_TIMEOUT,
1007bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                               NULL))
1008bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            {
1009bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                rpc_ret_val = RPC_LOC_API_GENERAL_FAILURE;
1010bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            }
1011bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            break; // done with injection
1012bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
1013bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1014bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        len_injected += predicted_orbits_data_ptr->part_len;
1015bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGD("loc_ioctl XTRA injected length: %d\n", len_injected);
1016bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
1017bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1018bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return convertErr(rpc_ret_val);
1019bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
1020bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1021bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo/* Request the Xtra Server Url from the modem */
1022bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
1023bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::requestXtraServer()
1024bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
1025bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    loc_api_adapter_err           err;
1026bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_data_u_type     data;
1027bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_callback_s_type callback_data;
1028bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1029bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    err = convertErr(loc_eng_ioctl(client_handle,
1030bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                   RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE,
1031bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                   &data,
1032bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                   LOC_IOCTL_DEFAULT_TIMEOUT,
1033bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                   &callback_data));
1034bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1035bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (LOC_API_ADAPTER_ERR_SUCCESS != err)
1036bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
1037bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGE("RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE failed!: err=%d\n", err);
1038bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return err;
1039bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
1040bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    else if (RPC_LOC_SESS_STATUS_SUCCESS != callback_data.status)
1041bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
1042bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGE("RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE failed!: status=%ld\n", callback_data.status);
1043bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_GENERAL_FAILURE;
1044bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
1045bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    else if (RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE != callback_data.type)
1046bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
1047bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGE("RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE is not the type expected! type=%d\n", callback_data.type);
1048bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_GENERAL_FAILURE;
1049bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
1050bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    else if (RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE != callback_data.data.disc)
1051bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
1052bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGE("RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE is not the disc expected! disc=%d\n", callback_data.data.disc);
1053bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return LOC_API_ADAPTER_ERR_GENERAL_FAILURE;
1054bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
1055bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1056bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    reportXtraServer(callback_data.data.rpc_loc_ioctl_callback_data_u_type_u.
1057bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     predicted_orbits_data_source.servers[0],
1058bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     callback_data.data.rpc_loc_ioctl_callback_data_u_type_u.
1059bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     predicted_orbits_data_source.servers[1],
1060bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     callback_data.data.rpc_loc_ioctl_callback_data_u_type_u.
1061bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     predicted_orbits_data_source.servers[2],
1062bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                     255);
1063bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1064bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return LOC_API_ADAPTER_ERR_SUCCESS;
1065bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
1066bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1067bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
1068bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bearer, AGpsType agpsType)
1069bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
1070bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_server_open_status_e_type open_status = is_succ ? RPC_LOC_SERVER_OPEN_SUCCESS : RPC_LOC_SERVER_OPEN_FAIL;
1071bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   rpc_loc_ioctl_data_u_type           ioctl_data;
1072bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1073bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if (AGPS_TYPE_INVALID == agpsType) {
1074bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        rpc_loc_server_open_status_s_type  *conn_open_status_ptr =
1075bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            &ioctl_data.rpc_loc_ioctl_data_u_type_u.conn_open_status;
1076bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1077bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        // Fill in data
1078bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        ioctl_data.disc = RPC_LOC_IOCTL_INFORM_SERVER_OPEN_STATUS;
1079bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        conn_open_status_ptr->conn_handle = handle;
1080bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        conn_open_status_ptr->open_status = open_status;
1081bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#if (AMSS_VERSION==3200)
1082bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        conn_open_status_ptr->apn_name = apn; /* requires APN */
1083bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#else
1084bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (is_succ) {
1085bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            strlcpy(conn_open_status_ptr->apn_name, apn,
1086bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    sizeof conn_open_status_ptr->apn_name);
1087bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        } else {
1088bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            conn_open_status_ptr->apn_name[0] = 0;
1089bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
1090bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#endif /* #if (AMSS_VERSION==3200) */
1091bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1092bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGD("ATL RPC_LOC_IOCTL_INFORM_SERVER_OPEN_STATUS open %s, APN name = [%s]\n",
1093bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                 log_succ_fail_string(is_succ),
1094bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                 apn);
1095bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    } else {
1096bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        rpc_loc_server_multi_open_status_s_type  *conn_multi_open_status_ptr =
1097bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            &ioctl_data.rpc_loc_ioctl_data_u_type_u.multi_conn_open_status;
1098bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1099bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        // Fill in data
1100bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        ioctl_data.disc = RPC_LOC_IOCTL_INFORM_SERVER_MULTI_OPEN_STATUS;
1101bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        conn_multi_open_status_ptr->conn_handle = handle;
1102bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        conn_multi_open_status_ptr->open_status = open_status;
1103bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (is_succ) {
1104bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            strlcpy(conn_multi_open_status_ptr->apn_name, apn,
1105bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    sizeof conn_multi_open_status_ptr->apn_name);
1106bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        } else {
1107bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            conn_multi_open_status_ptr->apn_name[0] = 0;
1108bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
1109bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1110bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        switch(bearer)
1111bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
1112bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        case AGPS_APN_BEARER_IPV4:
1113bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            conn_multi_open_status_ptr->pdp_type = RPC_LOC_SERVER_PDP_IP;
1114bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            break;
1115bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        case AGPS_APN_BEARER_IPV6:
1116bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            conn_multi_open_status_ptr->pdp_type = RPC_LOC_SERVER_PDP_IPV6;
1117bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            break;
1118bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        case AGPS_APN_BEARER_IPV4V6:
1119bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            conn_multi_open_status_ptr->pdp_type = RPC_LOC_SERVER_PDP_IPV4V6;
1120bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            break;
1121bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        default:
1122bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            conn_multi_open_status_ptr->pdp_type = RPC_LOC_SERVER_PDP_PPP;
1123bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
1124bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1125bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGD("ATL RPC_LOC_IOCTL_INFORM_SERVER_MULTI_OPEN_STATUS open %s, APN name = [%s], pdp_type = %d\n",
1126bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                 log_succ_fail_string(is_succ),
1127bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                 apn,
1128bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                 conn_multi_open_status_ptr->pdp_type);
1129bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
1130bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1131bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // Make the IOCTL call
1132bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return convertErr(
1133bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        loc_eng_ioctl(client_handle,
1134bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      ioctl_data.disc,
1135bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      &ioctl_data,
1136bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      LOC_IOCTL_DEFAULT_TIMEOUT,
1137bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      NULL)
1138bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        );
1139bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
1140bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1141bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
1142bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::atlCloseStatus(int handle, int is_succ)
1143bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
1144bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_data_u_type           ioctl_data;
1145bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ioctl_data.disc = RPC_LOC_IOCTL_INFORM_SERVER_CLOSE_STATUS;
1146bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1147bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_server_close_status_s_type *conn_close_status_ptr =
1148bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        &ioctl_data.rpc_loc_ioctl_data_u_type_u.conn_close_status;
1149bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    conn_close_status_ptr->conn_handle = handle;
1150bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    conn_close_status_ptr->close_status = is_succ ? RPC_LOC_SERVER_CLOSE_SUCCESS : RPC_LOC_SERVER_CLOSE_FAIL;
1151bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1152bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // Make the IOCTL call
1153bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return convertErr(
1154bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        loc_eng_ioctl(client_handle,
1155bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      ioctl_data.disc,
1156bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      &ioctl_data,
1157bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      LOC_IOCTL_DEFAULT_TIMEOUT,
1158bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      NULL)
1159bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        );
1160bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
1161bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1162bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russovoid LocApiRpc::ATLEvent(const rpc_loc_server_request_s_type *server_request_ptr)
1163bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
1164bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    int connHandle;
1165bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    AGpsType agps_type;
1166bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1167bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_LOGV("RPC_LOC_EVENT_ASSISTANCE_DATA_REQUEST event %s)",
1168bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo             loc_get_event_atl_open_name(server_request_ptr->event));
1169bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    switch (server_request_ptr->event)
1170bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
1171bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_SERVER_REQUEST_MULTI_OPEN:
1172bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        connHandle = server_request_ptr->payload.rpc_loc_server_request_u_type_u.multi_open_req.conn_handle;
1173bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (server_request_ptr->payload.rpc_loc_server_request_u_type_u.multi_open_req.connection_type
1174bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            == RPC_LOC_SERVER_CONNECTION_LBS) {
1175bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            agps_type = AGPS_TYPE_SUPL;
1176bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            LOC_LOGV("ATLEvent: event - RPC_LOC_SERVER_REQUEST_MULTI_OPEN\n            type - AGPS_TYPE_SUPL\n            handle - %d", connHandle);
1177bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        } else {
1178bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            agps_type = AGPS_TYPE_WWAN_ANY;
1179bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            LOC_LOGV("ATLEvent: event - RPC_LOC_SERVER_REQUEST_MULTI_OPEN\n            type - AGPS_TYPE_WWAN_ANY\n            handle - %d", connHandle);
1180bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
1181bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        requestATL(connHandle, agps_type);
1182bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
1183bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_SERVER_REQUEST_OPEN:
1184bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        connHandle = server_request_ptr->payload.rpc_loc_server_request_u_type_u.open_req.conn_handle;
1185bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGV("ATLEvent: event - RPC_LOC_SERVER_REQUEST_OPEN\n            handle - %d", connHandle);
1186bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        requestATL(connHandle, AGPS_TYPE_INVALID);
1187bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
1188bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_SERVER_REQUEST_CLOSE:
1189bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        connHandle = server_request_ptr->payload.rpc_loc_server_request_u_type_u.close_req.conn_handle;
1190bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGV("ATLEvent: event - RPC_LOC_SERVER_REQUEST_CLOSE\n            handle - %d", connHandle);
1191bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        releaseATL(connHandle);
1192bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
1193bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    default:
1194bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGE("ATLEvent: event type %d invalid", server_request_ptr->event);
1195bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   }
1196bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
1197bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1198bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russovoid LocApiRpc::NIEvent(const rpc_loc_ni_event_s_type *ni_req)
1199bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
1200bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    GpsNiNotification notif = {0};
1201bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1202bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    switch (ni_req->event)
1203bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
1204bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_NI_EVENT_VX_NOTIFY_VERIFY_REQ:
1205bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
1206bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        const rpc_loc_ni_vx_notify_verify_req_s_type *vx_req =
1207bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            &ni_req->payload.rpc_loc_ni_event_payload_u_type_u.vx_req;
1208bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGI("VX Notification");
1209bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        notif.ni_type = GPS_NI_TYPE_VOICE;
1210bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        // Requestor ID
1211bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        hexcode(notif.requestor_id, sizeof notif.requestor_id,
1212bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                vx_req->requester_id.requester_id,
1213bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                vx_req->requester_id.requester_id_length);
1214bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        notif.text_encoding = 0; // No text and no encoding
1215bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        notif.requestor_id_encoding = convertNiEncodingType(vx_req->encoding_scheme);
1216bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        NIEventFillVerfiyType(notif, vx_req->notification_priv_type);
1217bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
1218bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
1219bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1220bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_NI_EVENT_UMTS_CP_NOTIFY_VERIFY_REQ:
1221bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
1222bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        const rpc_loc_ni_umts_cp_notify_verify_req_s_type *umts_cp_req =
1223bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            &ni_req->payload.rpc_loc_ni_event_payload_u_type_u.umts_cp_req;
1224bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGI("UMTS CP Notification\n");
1225bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        notif.ni_type= GPS_NI_TYPE_UMTS_CTRL_PLANE;         // Stores notification text
1226bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#if (AMSS_VERSION==3200)
1227bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        hexcode(notif.text, sizeof notif.text,
1228bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                umts_cp_req->notification_text.notification_text_val,
1229bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                umts_cp_req->notification_length);
1230bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        hexcode(notif.requestor_id, sizeof notif.requestor_id,
1231bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                umts_cp_req->requestor_id.requestor_id_string.requestor_id_string_val,
1232bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                umts_cp_req->requestor_id.string_len);
1233bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#else
1234bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        hexcode(notif.text, sizeof notif.text,
1235bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                umts_cp_req->notification_text,
1236bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                umts_cp_req->notification_length);
1237bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        hexcode(notif.requestor_id, sizeof notif.requestor_id,
1238bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                umts_cp_req->requestor_id.requestor_id_string,
1239bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                umts_cp_req->requestor_id.string_len);
1240bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#endif
1241bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        notif.text_encoding = convertNiEncodingType(umts_cp_req->datacoding_scheme);
1242bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        notif.requestor_id_encoding = notif.text_encoding;
1243bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        NIEventFillVerfiyType(notif, umts_cp_req->notification_priv_type);
1244bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1245bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        // LCS address (using extras field)
1246bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (umts_cp_req->ext_client_address_data.ext_client_address_len != 0)
1247bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
1248bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            // Copy LCS Address into notif.extras in the format: Address = 012345
1249bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            strlcat(notif.extras, LOC_NI_NOTIF_KEY_ADDRESS, sizeof notif.extras);
1250bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            strlcat(notif.extras, " = ", sizeof notif.extras);
1251bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            int addr_len = 0;
1252bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            const char *address_source = NULL;
1253bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1254bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#if (AMSS_VERSION==3200)
1255bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            address_source = umts_cp_req->ext_client_address_data.ext_client_address.ext_client_address_val;
1256bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#else
1257bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            address_source = umts_cp_req->ext_client_address_data.ext_client_address;
1258bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#endif /* #if (AMSS_VERSION==3200) */
1259bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1260bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            char lcs_addr[32]; // Decoded LCS address for UMTS CP NI
1261bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            addr_len = decodeAddress(lcs_addr, sizeof lcs_addr, address_source,
1262bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                     umts_cp_req->ext_client_address_data.ext_client_address_len);
1263bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1264bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            // The address is ASCII string
1265bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            if (addr_len)
1266bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            {
1267bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                strlcat(notif.extras, lcs_addr, sizeof notif.extras);
1268bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            }
1269bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
1270bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
1271bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
1272bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1273bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    case RPC_LOC_NI_EVENT_SUPL_NOTIFY_VERIFY_REQ:
1274bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    {
1275bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        const rpc_loc_ni_supl_notify_verify_req_s_type *supl_req =
1276bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            &ni_req->payload.rpc_loc_ni_event_payload_u_type_u.supl_req;
1277bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGI("SUPL Notification\n");
1278bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        notif.ni_type = GPS_NI_TYPE_UMTS_SUPL;
1279bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1280bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (supl_req->flags & RPC_LOC_NI_CLIENT_NAME_PRESENT)
1281bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
1282bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#if (AMSS_VERSION==3200)
1283bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            hexcode(notif.text, sizeof notif.text,
1284bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    supl_req->client_name.client_name_string.client_name_string_val,   /* buffer */
1285bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    supl_req->client_name.string_len                                   /* length */
1286bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            );
1287bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#else
1288bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            hexcode(notif.text, sizeof notif.text,
1289bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                            supl_req->client_name.client_name_string,   /* buffer */
1290bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                            supl_req->client_name.string_len            /* length */
1291bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            );
1292bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#endif /* #if (AMSS_VERSION==3200) */
1293bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            LOC_LOGV("SUPL NI: client_name: %s len=%d", notif.text, supl_req->client_name.string_len);
1294bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
1295bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        else {
1296bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            LOC_LOGV("SUPL NI: client_name not present.");
1297bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
1298bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1299bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        // Requestor ID
1300bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (supl_req->flags & RPC_LOC_NI_REQUESTOR_ID_PRESENT)
1301bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
1302bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#if (AMSS_VERSION==3200)
1303bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            hexcode(notif.requestor_id, sizeof notif.requestor_id,
1304bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    supl_req->requestor_id.requestor_id_string.requestor_id_string_val,  /* buffer */
1305bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    supl_req->requestor_id.string_len                                    /* length */
1306bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                );
1307bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#else
1308bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            hexcode(notif.requestor_id, sizeof notif.requestor_id,
1309bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    supl_req->requestor_id.requestor_id_string,  /* buffer */
1310bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                    supl_req->requestor_id.string_len            /* length */
1311bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                );
1312bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#endif /* #if (AMSS_VERSION==3200) */
1313bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            LOC_LOGV("SUPL NI: requestor_id: %s len=%d", notif.requestor_id, supl_req->requestor_id.string_len);
1314bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
1315bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        else {
1316bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            LOC_LOGV("SUPL NI: requestor_id not present.");
1317bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
1318bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1319bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        // Encoding type
1320bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        if (supl_req->flags & RPC_LOC_NI_ENCODING_TYPE_PRESENT)
1321bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        {
1322bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            notif.text_encoding = convertNiEncodingType(supl_req->datacoding_scheme);
1323bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            notif.requestor_id_encoding = notif.text_encoding;
1324bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
1325bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        else {
1326bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo            notif.text_encoding = notif.requestor_id_encoding = GPS_ENC_UNKNOWN;
1327bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        }
1328bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1329bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        NIEventFillVerfiyType(notif, ni_req->payload.rpc_loc_ni_event_payload_u_type_u.supl_req.notification_priv_type);
1330bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
1331bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        break;
1332bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1333bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    default:
1334bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGE("Unknown NI event: %x\n", (int) ni_req->event);
1335bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        return;
1336bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
1337bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1338bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    // this copy will get freed in loc_eng_ni when loc_ni_respond() is called
1339bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ni_event_s_type *copy = (rpc_loc_ni_event_s_type *)malloc(sizeof(*copy));
1340bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    memcpy(copy, ni_req, sizeof(*copy));
1341bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    requestNiNotify(notif, (const void*)copy);
1342bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
1343bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1344bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoint LocApiRpc::NIEventFillVerfiyType(GpsNiNotification &notif,
1345bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                                rpc_loc_ni_notify_verify_e_type notif_priv)
1346bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
1347bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   switch (notif_priv)
1348bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   {
1349bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   case RPC_LOC_NI_USER_NO_NOTIFY_NO_VERIFY:
1350bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       notif.notify_flags = 0;
1351bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       notif.default_response = GPS_NI_RESPONSE_NORESP;
1352bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       return 1;
1353bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   case RPC_LOC_NI_USER_NOTIFY_ONLY:
1354bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       notif.notify_flags = GPS_NI_NEED_NOTIFY;
1355bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       notif.default_response = GPS_NI_RESPONSE_NORESP;
1356bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       return 1;
1357bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   case RPC_LOC_NI_USER_NOTIFY_VERIFY_ALLOW_NO_RESP:
1358bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       notif.notify_flags = GPS_NI_NEED_NOTIFY | GPS_NI_NEED_VERIFY;
1359bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       notif.default_response = GPS_NI_RESPONSE_ACCEPT;
1360bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       return 1;
1361bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   case RPC_LOC_NI_USER_NOTIFY_VERIFY_NOT_ALLOW_NO_RESP:
1362bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       notif.notify_flags = GPS_NI_NEED_NOTIFY | GPS_NI_NEED_VERIFY;
1363bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       notif.default_response = GPS_NI_RESPONSE_DENY;
1364bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       return 1;
1365bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   case RPC_LOC_NI_USER_PRIVACY_OVERRIDE:
1366bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       notif.notify_flags = GPS_NI_PRIVACY_OVERRIDE;
1367bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       notif.default_response = GPS_NI_RESPONSE_NORESP;
1368bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       return 1;
1369bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   default:
1370bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo      return 0;
1371bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   }
1372bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
1373bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1374bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoenum loc_api_adapter_err
1375bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiRpc::setSUPLVersion(uint32_t version)
1376bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
1377bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   rpc_loc_ioctl_data_u_type ioctl_data = {RPC_LOC_IOCTL_SET_SUPL_VERSION, {0}};
1378bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   ioctl_data.rpc_loc_ioctl_data_u_type_u.supl_version = (int)version;
1379bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   return convertErr(
1380bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       loc_eng_ioctl (client_handle,
1381bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      RPC_LOC_IOCTL_SET_SUPL_VERSION,
1382bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      &ioctl_data,
1383bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      LOC_IOCTL_DEFAULT_TIMEOUT,
1384bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      NULL)
1385bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       );
1386bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
1387bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1388bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoGpsNiEncodingType LocApiRpc::convertNiEncodingType(int loc_encoding)
1389bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
1390bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   switch (loc_encoding)
1391bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   {
1392bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   case RPC_LOC_NI_SUPL_UTF8:
1393bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       return GPS_ENC_SUPL_UTF8;
1394bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   case RPC_LOC_NI_SUPL_UCS2:
1395bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       return GPS_ENC_SUPL_UCS2;
1396bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   case RPC_LOC_NI_SUPL_GSM_DEFAULT:
1397bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo      return GPS_ENC_SUPL_GSM_DEFAULT;
1398bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   case RPC_LOC_NI_SS_LANGUAGE_UNSPEC:
1399bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo      return GPS_ENC_SUPL_GSM_DEFAULT; // SS_LANGUAGE_UNSPEC = GSM
1400bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   default:
1401bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo       return GPS_ENC_UNKNOWN;
1402bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo   }
1403bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
1404bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1405bfff6343845ad9ff062c5fd97bb3b9be1053340eDante RussoLocApiBase* getLocApi(const MsgTask* msgTask,
1406bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      LOC_API_ADAPTER_EVENT_MASK_T exMask,
1407bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                      ContextBase *context) {
1408bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return new LocApiRpc(msgTask, exMask, context);
1409bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
1410bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1411bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo/*Values for lock
1412bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  1 = Do not lock any position sessions
1413bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  2 = Lock MI position sessions
1414bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  3 = Lock MT position sessions
1415bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  4 = Lock all position sessions
1416bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo*/
1417bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoint LocApiRpc::setGpsLock(LOC_GPS_LOCK_MASK lockMask)
1418bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
1419bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_data_u_type    ioctl_data;
1420bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    boolean ret_val;
1421bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_LOGD("%s:%d]: lock: %x\n", __func__, __LINE__, lockMask);
1422bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ioctl_data.rpc_loc_ioctl_data_u_type_u.engine_lock = convertGpsLockMask(lockMask);
1423bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ioctl_data.disc = RPC_LOC_IOCTL_SET_ENGINE_LOCK;
1424bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ret_val = loc_eng_ioctl (loc_eng_data.client_handle,
1425bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                            RPC_LOC_IOCTL_SET_ENGINE_LOCK,
1426bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                            &ioctl_data,
1427bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                            LOC_IOCTL_DEFAULT_TIMEOUT,
1428bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                            NULL /* No output information is expected*/);
1429bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1430bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_LOGD("%s:%d]: ret_val: %d\n", __func__, __LINE__, (int)ret_val);
1431bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return (ret_val == TRUE ? 0 : -1);
1432bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
1433bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
1434bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo/*
1435bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  Returns
1436bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  Current value of GPS lock on success
1437bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  -1 on failure
1438bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo*/
1439bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoint LocApiRpc :: getGpsLock()
1440bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{
1441bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_data_u_type    ioctl_data;
1442bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    rpc_loc_ioctl_callback_s_type callback_payload;
1443bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    boolean ret_val;
1444bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    int ret=0;
1445bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_LOGD("%s:%d]: Enter\n", __func__, __LINE__);
1446bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    ret_val = loc_eng_ioctl (loc_eng_data.client_handle,
1447bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                            RPC_LOC_IOCTL_GET_ENGINE_LOCK,
1448bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                            &ioctl_data,
1449bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                            LOC_IOCTL_DEFAULT_TIMEOUT,
1450bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo                            &callback_payload);
1451bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    if(ret_val == TRUE) {
1452bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        ret = (int)callback_payload.data.engine_lock;
1453bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGD("%s:%d]: Lock type: %d\n", __func__, __LINE__, ret);
1454bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
1455bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    else {
1456bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        LOC_LOGE("%s:%d]: Ioctl failed", __func__, __LINE__);
1457bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo        ret = -1;
1458bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    }
1459bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    LOC_LOGD("%s:%d]: Exit\n", __func__, __LINE__);
1460bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo    return ret;
1461bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
1462