Remove unused code under libloc_api

This folder of sources is no longer
used and is removed

Change-Id: I0b02f56e27346f20f890bc8105e77995e63c0350
CRs-fixed: 566508
This commit is contained in:
Tushar Janefalkar 2013-12-11 15:38:42 -08:00
parent 50a76390ba
commit 4996c5e955
10 changed files with 0 additions and 3069 deletions

View file

@ -1,40 +0,0 @@
#Compile the old library version from Google push for Passion builds with old modem image
ifneq ($(BOARD_VENDOR_QCOM_GPS_LOC_API_AMSS_VERSION),50001)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := gps.$(BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE)
LOCAL_MODULE_OWNER := qcom
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_LIBRARIES:= \
libloc_api-rpc
LOCAL_SHARED_LIBRARIES := \
librpc \
libutils \
libcutils
LOCAL_SRC_FILES += \
loc_eng.cpp \
loc_eng_ioctl.cpp \
loc_eng_xtra.cpp \
loc_eng_ni.cpp \
gps.c
LOCAL_CFLAGS += \
-fno-short-enums \
-DAMSS_VERSION=$(BOARD_VENDOR_QCOM_GPS_LOC_API_AMSS_VERSION)
LOCAL_C_INCLUDES:= \
$(TARGET_OUT_HEADERS)/libloc_api-rpc \
$(TARGET_OUT_HEADERS)/libloc_api-rpc/inc \
$(TARGET_OUT_HEADERS)/libcommondefs-rpc/inc \
$(TARGET_OUT_HEADERS)/librpc
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
include $(BUILD_SHARED_LIBRARY)
endif #BOARD_VENDOR_QCOM_GPS_LOC_API_AMSS_VERSION = 50001

View file

@ -1,68 +0,0 @@
/* Copyright (c) 2009,2011 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <hardware/gps.h>
#include <stdlib.h>
extern const GpsInterface* get_gps_interface();
const GpsInterface* gps__get_gps_interface(struct gps_device_t* dev)
{
return get_gps_interface();
}
static int open_gps(const struct hw_module_t* module, char const* name,
struct hw_device_t** device)
{
struct gps_device_t *dev = malloc(sizeof(struct gps_device_t));
memset(dev, 0, sizeof(*dev));
dev->common.tag = HARDWARE_DEVICE_TAG;
dev->common.version = 0;
dev->common.module = (struct hw_module_t*)module;
dev->get_gps_interface = gps__get_gps_interface;
*device = (struct hw_device_t*)dev;
return 0;
}
static struct hw_module_methods_t gps_module_methods = {
.open = open_gps
};
const struct hw_module_t HAL_MODULE_INFO_SYM = {
.tag = HARDWARE_MODULE_TAG,
.version_major = 1,
.version_minor = 0,
.id = GPS_HARDWARE_MODULE_ID,
.name = "loc_api GPS Module",
.author = "Qualcomm USA, Inc.",
.methods = &gps_module_methods,
};

File diff suppressed because it is too large Load diff

View file

@ -1,115 +0,0 @@
/* Copyright (c) 2009,2011 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef LOC_ENG_H
#define LOC_ENG_H
// Define boolean type to be used by libgps on loc api module
typedef unsigned char boolean;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#include <loc_eng_ioctl.h>
#include <loc_eng_xtra.h>
#include <hardware/gps.h>
#define LOC_IOCTL_DEFAULT_TIMEOUT 1000 // 1000 milli-seconds
enum {
DEFERRED_ACTION_EVENT = 0x01,
DEFERRED_ACTION_DELETE_AIDING = 0x02,
DEFERRED_ACTION_AGPS_STATUS = 0x04,
DEFERRED_ACTION_AGPS_DATA_SUCCESS = 0x08,
DEFERRED_ACTION_AGPS_DATA_CLOSED = 0x10,
DEFERRED_ACTION_AGPS_DATA_FAILED = 0x20,
DEFERRED_ACTION_QUIT = 0x40,
};
// Module data
typedef struct
{
rpc_loc_client_handle_type client_handle;
gps_location_callback location_cb;
gps_status_callback status_cb;
gps_sv_status_callback sv_status_cb;
agps_status_callback agps_status_cb;
gps_nmea_callback nmea_cb;
gps_ni_notify_callback ni_notify_cb;
gps_acquire_wakelock acquire_wakelock_cb;
gps_release_wakelock release_wakelock_cb;
int agps_status;
// used to defer stopping the GPS engine until AGPS data calls are done
boolean agps_request_pending;
boolean stop_request_pending;
pthread_mutex_t deferred_stop_mutex;
loc_eng_xtra_data_s_type xtra_module_data;
loc_eng_ioctl_data_s_type ioctl_data;
// data from loc_event_cb
rpc_loc_event_mask_type loc_event;
rpc_loc_event_payload_u_type loc_event_payload;
// TBD:
char agps_server_host[256];
int agps_server_port;
uint32 agps_server_address;
char apn_name[100];
int position_mode;
rpc_loc_server_connection_handle conn_handle;
// GPS engine status
GpsStatusValue engine_status;
// Aiding data information to be deleted, aiding data can only be deleted when GPS engine is off
GpsAidingData aiding_data_for_deletion;
// Data variables used by deferred action thread
pthread_t deferred_action_thread;
// Mutex used by deferred action thread
pthread_mutex_t deferred_action_mutex;
// Condition variable used by deferred action thread
pthread_cond_t deferred_action_cond;
// flags for pending events for deferred action thread
int deferred_action_flags;
} loc_eng_data_s_type;
extern loc_eng_data_s_type loc_eng_data;
#endif // LOC_ENG_H

View file

@ -1,354 +0,0 @@
/* Copyright (c) 2009,2011 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_NDDEBUG 0
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <ctype.h>
#include <math.h>
#include <pthread.h>
#include <rpc/rpc.h>
#include <loc_api_rpc_glue.h>
#include <hardware/gps.h>
#include <loc_eng.h>
#define LOG_TAG "lib_locapi"
#include <utils/Log.h>
// comment this out to enable logging
// #undef LOGD
// #define LOGD(...) {}
// Function declarations
static boolean loc_eng_ioctl_setup_cb(
rpc_loc_client_handle_type handle,
rpc_loc_ioctl_e_type ioctl_type
);
static boolean loc_eng_ioctl_wait_cb(
int timeout_msec, // Timeout in this number of msec
rpc_loc_ioctl_callback_s_type *cb_data_ptr // Output parameter for IOCTL calls
);
/*===========================================================================
FUNCTION loc_eng_ioctl
DESCRIPTION
This function calls loc_ioctl and waits for the callback result before
returning back to the user.
DEPENDENCIES
N/A
RETURN VALUE
TRUE if successful
FALSE if failed
SIDE EFFECTS
N/A
===========================================================================*/
boolean loc_eng_ioctl(
rpc_loc_client_handle_type handle,
rpc_loc_ioctl_e_type ioctl_type,
rpc_loc_ioctl_data_u_type* ioctl_data_ptr,
uint32 timeout_msec,
rpc_loc_ioctl_callback_s_type *cb_data_ptr
)
{
boolean ret_val;
int rpc_ret_val;
loc_eng_ioctl_data_s_type *ioctl_cb_data_ptr;
LOGV ("loc_eng_ioctl: client = %d, ioctl_type = %d, cb_data =0x%x\n", (int32) handle, ioctl_type, (uint32) cb_data_ptr);
ioctl_cb_data_ptr = &(loc_eng_data.ioctl_data);
// Select the callback we are waiting for
ret_val = loc_eng_ioctl_setup_cb (handle, ioctl_type);
if (ret_val == TRUE)
{
rpc_ret_val = loc_ioctl (handle,
ioctl_type,
ioctl_data_ptr);
LOGV ("loc_eng_ioctl: loc_ioctl returned %d \n", rpc_ret_val);
if (rpc_ret_val == RPC_LOC_API_SUCCESS)
{
// Wait for the callback of loc_ioctl
ret_val = loc_eng_ioctl_wait_cb (timeout_msec, cb_data_ptr);
}
else
{
ret_val = FALSE;
}
}
// Reset the state when we are done
pthread_mutex_lock(&ioctl_cb_data_ptr->cb_data_mutex);
ioctl_cb_data_ptr->cb_is_selected = FALSE;
ioctl_cb_data_ptr->cb_is_waiting = FALSE;
ioctl_cb_data_ptr->cb_has_arrived = FALSE;
pthread_mutex_unlock(&ioctl_cb_data_ptr->cb_data_mutex);
return ret_val;
}
/*===========================================================================
FUNCTION loc_eng_ioctl_setup_cb
DESCRIPTION
Selects which callback is going to be waited for
DEPENDENCIES
N/A
RETURN VALUE
TRUE if successful
FALSE if failed
SIDE EFFECTS
N/A
===========================================================================*/
static boolean loc_eng_ioctl_setup_cb(
rpc_loc_client_handle_type handle,
rpc_loc_ioctl_e_type ioctl_type
)
{
boolean ret_val;
loc_eng_ioctl_data_s_type *ioctl_cb_data_ptr;
ioctl_cb_data_ptr = &(loc_eng_data.ioctl_data);
pthread_mutex_lock(&ioctl_cb_data_ptr->cb_data_mutex);
if (ioctl_cb_data_ptr->cb_is_selected == TRUE)
{
LOGD ("loc_eng_ioctl_setup_cb: ERROR, another ioctl in progress \n");
ret_val = FALSE;
}
else
{
ioctl_cb_data_ptr->cb_is_selected = TRUE;
ioctl_cb_data_ptr->cb_is_waiting = FALSE;
ioctl_cb_data_ptr->cb_has_arrived = FALSE;
ioctl_cb_data_ptr->client_handle = handle;
ioctl_cb_data_ptr->ioctl_type = ioctl_type;
memset (&(ioctl_cb_data_ptr->cb_payload), 0, sizeof (rpc_loc_ioctl_callback_s_type));
ret_val = TRUE;
}
pthread_mutex_unlock(&ioctl_cb_data_ptr->cb_data_mutex);
return ret_val;
}
/*===========================================================================
FUNCTION loc_eng_ioctl_wait_cb
DESCRIPTION
Waits for a selected callback. The wait expires in timeout_msec.
If the function is called before an existing wait has finished, it will
immediately return EBUSY.
DEPENDENCIES
N/A
RETURN VALUE
TRUE if successful
FALSE if failed
SIDE EFFECTS
N/A
===========================================================================*/
boolean loc_eng_ioctl_wait_cb(
int timeout_msec, // Timeout in this number of msec
rpc_loc_ioctl_callback_s_type *cb_data_ptr
)
{
boolean ret_val = FALSE; // the return value of this function
int rc; // return code from pthread calls
struct timeval present_time;
struct timespec expire_time;
loc_eng_ioctl_data_s_type *ioctl_cb_data_ptr;
ioctl_cb_data_ptr = &(loc_eng_data.ioctl_data);
pthread_mutex_lock(&ioctl_cb_data_ptr->cb_data_mutex);
do {
if (ioctl_cb_data_ptr->cb_is_selected == FALSE)
{
LOGD ("loc_eng_ioctl_wait_cb: ERROR called when cb_is_waiting is set to FALSE \n");
ret_val = FALSE;
break;
}
// Calculate absolute expire time
gettimeofday(&present_time, NULL);
expire_time.tv_sec = present_time.tv_sec;
expire_time.tv_sec += timeout_msec / 1000;
if ((present_time.tv_usec + timeout_msec) >= 1000)
{
expire_time.tv_sec += 1;
}
expire_time.tv_nsec = (present_time.tv_usec + timeout_msec) % 1000 * 1000;
// Special case where callback is issued before loc_ioctl ever returns
if (ioctl_cb_data_ptr->cb_has_arrived == TRUE)
{
LOGD ("loc_eng_ioctl_wait_cb: cb has arrived without waiting \n");
ret_val = TRUE;
break;
}
ioctl_cb_data_ptr->cb_is_waiting = TRUE;
// Wait for the callback until timeout expires
rc = pthread_cond_timedwait(&ioctl_cb_data_ptr->cb_arrived_cond,
&ioctl_cb_data_ptr->cb_data_mutex,
&expire_time);
if (rc == 0)
{
ret_val = TRUE;
}
else
{
ret_val = FALSE;
}
LOGV ("loc_eng_ioctl_wait_cb: pthread_cond_timedwait returned %d\n", rc);
} while (0);
// Process the ioctl callback data when IOCTL is successful
if (ret_val == TRUE)
{
ioctl_cb_data_ptr = &(loc_eng_data.ioctl_data);
if (ioctl_cb_data_ptr->cb_payload.status == RPC_LOC_API_SUCCESS)
{
ret_val = TRUE;
if (cb_data_ptr != NULL)
{
memcpy (cb_data_ptr,
&(ioctl_cb_data_ptr->cb_payload),
sizeof (rpc_loc_ioctl_callback_s_type));
}
}
else
{
ret_val = FALSE;
}
}
pthread_mutex_unlock(&ioctl_cb_data_ptr->cb_data_mutex);
LOGV ("loc_eng_ioctl_wait_cb: returned %d\n", ret_val);
return ret_val;
}
/*===========================================================================
FUNCTION loc_eng_ioctl_process_cb
DESCRIPTION
This function process the IOCTL callback, parameter specifies the client
that receives the IOCTL callback.
DEPENDENCIES
N/A
RETURN VALUE
TRUE if successful
FALSE if failed
SIDE EFFECTS
N/A
===========================================================================*/
boolean loc_eng_ioctl_process_cb (
rpc_loc_client_handle_type client_handle,
const rpc_loc_ioctl_callback_s_type *cb_data_ptr
)
{
boolean ret_val = FALSE; // the return value of this function
loc_eng_ioctl_data_s_type *ioctl_cb_data_ptr;
ioctl_cb_data_ptr = &(loc_eng_data.ioctl_data);
pthread_mutex_lock(&ioctl_cb_data_ptr->cb_data_mutex);
if (client_handle != ioctl_cb_data_ptr->client_handle)
{
LOGD ("loc_eng_ioctl_process_cb: client handle mismatch, received = %d, expected = %d \n",
(int32) client_handle, (int32) ioctl_cb_data_ptr->client_handle);
ret_val = FALSE;
}
else if (cb_data_ptr->type != ioctl_cb_data_ptr->ioctl_type)
{
LOGD ("loc_eng_ioctl_process_cb: ioctl type mismatch, received = %d, expected = %d \n",
cb_data_ptr->type, ioctl_cb_data_ptr->ioctl_type);
ret_val = FALSE;
}
else // both matches
{
memcpy (&(ioctl_cb_data_ptr->cb_payload),
cb_data_ptr,
sizeof (rpc_loc_ioctl_callback_s_type));
ioctl_cb_data_ptr->cb_has_arrived = TRUE;
LOGV ("loc_eng_ioctl_process_cb: callback arrived for client = %d, ioctl = %d, status = %d\n",
(int32) ioctl_cb_data_ptr->client_handle, ioctl_cb_data_ptr->ioctl_type,
(int32) ioctl_cb_data_ptr->cb_payload.status);
ret_val = TRUE;
}
pthread_mutex_unlock(&ioctl_cb_data_ptr->cb_data_mutex);
// Signal the waiting thread that callback has arrived
if (ret_val == TRUE)
{
pthread_cond_signal (&ioctl_cb_data_ptr->cb_arrived_cond);
}
return ret_val;
}

View file

@ -1,69 +0,0 @@
/* Copyright (c) 2009,2011 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef LOC_ENG_IOCTL_H
#define LOC_ENG_IOCTL_H
// Module data
typedef struct loc_eng_ioctl_data_s_type
{
// We are waiting for an ioctl callback
boolean cb_is_selected;
// The thread has been put in a wait state for an ioctl callback
boolean cb_is_waiting;
// Loc client handle that is waiting for the callback
rpc_loc_client_handle_type client_handle;
// IOCTL type that the loc client is waiting for
rpc_loc_ioctl_e_type ioctl_type;
// The IOCLT report has arrived for the waiting client
boolean cb_has_arrived;
// The payload for the RPC_LOC_EVENT_IOCTL_REPORT
rpc_loc_ioctl_callback_s_type cb_payload;
// Mutex to access this data structure
pthread_mutex_t cb_data_mutex;
// LOC ioctl callback arrived mutex
pthread_cond_t cb_arrived_cond;
} loc_eng_ioctl_data_s_type;
extern boolean loc_eng_ioctl
(
rpc_loc_client_handle_type handle,
rpc_loc_ioctl_e_type ioctl_type,
rpc_loc_ioctl_data_u_type* ioctl_data_ptr,
uint32 timeout_msec,
rpc_loc_ioctl_callback_s_type *cb_data_ptr
);
extern boolean loc_eng_ioctl_process_cb
(
rpc_loc_client_handle_type client_handle,
const rpc_loc_ioctl_callback_s_type *cb_data_ptr
);
#endif // LOC_ENG_IOCTL_H

View file

@ -1,609 +0,0 @@
/* Copyright (c) 2009,2011 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_NDDEBUG 0
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <time.h>
#include <rpc/rpc.h>
#include <loc_api_rpc_glue.h>
#include <loc_eng.h>
#include <loc_eng_ni.h>
#define LOG_TAG "lib_locapi"
#include <utils/Log.h>
// comment this out to enable logging
// #undef LOGD
// #define LOGD(...) {}
/*=============================================================================
*
* DATA DECLARATION
*
*============================================================================*/
const GpsNiInterface sLocEngNiInterface =
{
sizeof(GpsNiInterface),
loc_eng_ni_init,
loc_eng_ni_respond,
};
boolean loc_eng_ni_data_init = FALSE;
loc_eng_ni_data_s_type loc_eng_ni_data;
extern loc_eng_data_s_type loc_eng_data;
/*=============================================================================
*
* FUNCTION DECLARATIONS
*
*============================================================================*/
/*===========================================================================
FUNCTION respond_from_enum
DESCRIPTION
Returns the name of the response
RETURN VALUE
response name string
===========================================================================*/
static const char* respond_from_enum(rpc_loc_ni_user_resp_e_type resp)
{
switch (resp)
{
case RPC_LOC_NI_LCS_NOTIFY_VERIFY_ACCEPT:
return "accept";
case RPC_LOC_NI_LCS_NOTIFY_VERIFY_DENY:
return "deny";
case RPC_LOC_NI_LCS_NOTIFY_VERIFY_NORESP:
return "no response";
default:
return NULL;
}
}
/*===========================================================================
FUNCTION loc_ni_respond
DESCRIPTION
Displays the NI request and awaits user input. If a previous request is
in session, the new one is handled using sys.ni_default_response (if exists);
otherwise, it is denied.
DEPENDENCY
Do not lock the data by mutex loc_ni_lock
RETURN VALUE
none
===========================================================================*/
static void loc_ni_respond(rpc_loc_ni_user_resp_e_type resp,
const rpc_loc_ni_event_s_type *request_pass_back
)
{
LOGD("Sending NI response: %s\n", respond_from_enum(resp));
rpc_loc_ioctl_data_u_type data;
rpc_loc_ioctl_callback_s_type callback_payload;
memcpy(&data.rpc_loc_ioctl_data_u_type_u.user_verify_resp.ni_event_pass_back,
request_pass_back, sizeof (rpc_loc_ni_event_s_type));
data.rpc_loc_ioctl_data_u_type_u.user_verify_resp.user_resp = resp;
loc_eng_ioctl(
loc_eng_data.client_handle,
RPC_LOC_IOCTL_INFORM_NI_USER_RESPONSE,
&data,
LOC_IOCTL_DEFAULT_TIMEOUT,
&callback_payload
);
}
/*===========================================================================
FUNCTION loc_ni_fill_notif_verify_type
DESCRIPTION
Fills need_notify, need_verify, etc.
RETURN VALUE
none
===========================================================================*/
static boolean loc_ni_fill_notif_verify_type(GpsNiNotification *notif,
rpc_loc_ni_notify_verify_e_type notif_priv)
{
notif->notify_flags = 0;
notif->default_response = GPS_NI_RESPONSE_NORESP;
switch (notif_priv)
{
case RPC_LOC_NI_USER_NO_NOTIFY_NO_VERIFY:
notif->notify_flags = 0;
break;
case RPC_LOC_NI_USER_NOTIFY_ONLY:
notif->notify_flags = GPS_NI_NEED_NOTIFY;
break;
case RPC_LOC_NI_USER_NOTIFY_VERIFY_ALLOW_NO_RESP:
notif->notify_flags = GPS_NI_NEED_NOTIFY | GPS_NI_NEED_VERIFY;
notif->default_response = GPS_NI_RESPONSE_ACCEPT;
break;
case RPC_LOC_NI_USER_NOTIFY_VERIFY_NOT_ALLOW_NO_RESP:
notif->notify_flags = GPS_NI_NEED_NOTIFY | GPS_NI_NEED_VERIFY;
notif->default_response = GPS_NI_RESPONSE_DENY;
break;
case RPC_LOC_NI_USER_PRIVACY_OVERRIDE:
notif->notify_flags = GPS_NI_PRIVACY_OVERRIDE;
break;
default:
return FALSE;
}
return TRUE;
}
/*===========================================================================
FUNCTION hexcode
DESCRIPTION
Converts a binary array into a Hex string. E.g., 1F 00 3F --> "1F003F"
RETURN VALUE
bytes encoded
===========================================================================*/
static int hexcode(char *hexstring, int string_size, const char *data, int data_size)
{
int i;
for (i = 0; i < data_size; i++)
{
char ch = data[i];
if (i*2 + 3 <= string_size)
{
snprintf(&hexstring[i*2], 3, "%02X", ch);
}
else {
break;
}
}
return i;
}
static GpsNiEncodingType convert_encoding_type(int loc_encoding)
{
GpsNiEncodingType enc = GPS_ENC_UNKNOWN;
switch (loc_encoding)
{
case RPC_LOC_NI_SUPL_UTF8:
enc = GPS_ENC_SUPL_UTF8;
break;
case RPC_LOC_NI_SUPL_UCS2:
enc = GPS_ENC_SUPL_UCS2;
break;
case RPC_LOC_NI_SUPL_GSM_DEFAULT:
enc = GPS_ENC_SUPL_GSM_DEFAULT;
break;
default:
break;
}
return enc;
}
/*===========================================================================
FUNCTION loc_ni_request_handler
DESCRIPTION
Displays the NI request and awaits user input. If a previous request is
in session, it is ignored.
RETURN VALUE
none
===========================================================================*/
static void loc_ni_request_handler(const char *msg, const rpc_loc_ni_event_s_type *ni_req)
{
GpsNiNotification notif;
notif.size = sizeof(notif);
strlcpy(notif.text, "[text]", sizeof notif.text); // defaults
strlcpy(notif.requestor_id, "[requestor id]", sizeof notif.requestor_id);
/* If busy, use default or deny */
if (loc_eng_ni_data.notif_in_progress)
{
#if 0
/* Cannot be here because the current thread is in RPC client */
/* XXX Consider adding an event queue to process overlapped NI requests */
loc_ni_user_resp_e_type response =
sys.ni_default_resp == 1 /* accept */ ?
LOC_NI_LCS_NOTIFY_VERIFY_ACCEPT :
LOC_NI_LCS_NOTIFY_VERIFY_DENY;
loc_ni_respond(response, ni_req); */
#endif
LOGW("loc_ni_request_handler, notification in progress, new NI request ignored, type: %d",
ni_req->event);
}
else {
/* Print notification */
LOGD("NI Notification: %s, event: %d", msg, ni_req->event);
pthread_mutex_lock(&loc_eng_ni_data.loc_ni_lock);
/* Save request */
memcpy(&loc_eng_ni_data.loc_ni_request, ni_req, sizeof loc_eng_ni_data.loc_ni_request);
/* Set up NI response waiting */
loc_eng_ni_data.notif_in_progress = TRUE;
loc_eng_ni_data.current_notif_id = abs(rand());
/* Fill in notification */
notif.notification_id = loc_eng_ni_data.current_notif_id;
const rpc_loc_ni_vx_notify_verify_req_s_type *vx_req;
const rpc_loc_ni_supl_notify_verify_req_s_type *supl_req;
const rpc_loc_ni_umts_cp_notify_verify_req_s_type *umts_cp_req;
switch (ni_req->event)
{
case RPC_LOC_NI_EVENT_VX_NOTIFY_VERIFY_REQ:
vx_req = &ni_req->payload.rpc_loc_ni_event_payload_u_type_u.vx_req;
notif.ni_type = GPS_NI_TYPE_VOICE;
notif.timeout = LOC_NI_NO_RESPONSE_TIME; // vx_req->user_resp_timer_val;
memset(notif.extras, 0, sizeof notif.extras);
memset(notif.text, 0, sizeof notif.text);
memset(notif.requestor_id, 0, sizeof notif.requestor_id);
// Requestor ID
hexcode(notif.requestor_id, sizeof notif.requestor_id,
vx_req->requester_id.requester_id,
vx_req->requester_id.requester_id_length);
notif.text_encoding = 0; // No text and no encoding
notif.requestor_id_encoding = convert_encoding_type(vx_req->encoding_scheme);
// Set default_response & notify_flags
loc_ni_fill_notif_verify_type(&notif, vx_req->notification_priv_type);
break;
case RPC_LOC_NI_EVENT_UMTS_CP_NOTIFY_VERIFY_REQ:
umts_cp_req = &ni_req->payload.rpc_loc_ni_event_payload_u_type_u.umts_cp_req;
notif.ni_type = GPS_NI_TYPE_UMTS_CTRL_PLANE;
notif.timeout = LOC_NI_NO_RESPONSE_TIME; // umts_cp_req->user_response_timer;
memset(notif.extras, 0, sizeof notif.extras);
memset(notif.text, 0, sizeof notif.text);
memset(notif.requestor_id, 0, sizeof notif.requestor_id);
// Stores notification text
hexcode(notif.text, sizeof notif.text,
#if (AMSS_VERSION==3200)
umts_cp_req->notification_text.notification_text_val,
#else
umts_cp_req->notification_text,
#endif
umts_cp_req->notification_length);
// Stores requestor ID
hexcode(notif.requestor_id, sizeof notif.requestor_id,
#if (AMSS_VERSION==3200)
umts_cp_req->requestor_id.requestor_id_string.requestor_id_string_val,
#else
umts_cp_req->requestor_id.requestor_id_string,
#endif
umts_cp_req->requestor_id.string_len);
notif.text_encoding = convert_encoding_type(umts_cp_req->datacoding_scheme);
notif.requestor_id_encoding = convert_encoding_type(umts_cp_req->datacoding_scheme);
// Set default_response & notify_flags
loc_ni_fill_notif_verify_type(&notif, umts_cp_req->notification_priv_type);
break;
case RPC_LOC_NI_EVENT_SUPL_NOTIFY_VERIFY_REQ:
supl_req = &ni_req->payload.rpc_loc_ni_event_payload_u_type_u.supl_req;
notif.ni_type = GPS_NI_TYPE_UMTS_SUPL;
notif.timeout = LOC_NI_NO_RESPONSE_TIME; // supl_req->user_response_timer;
memset(notif.extras, 0, sizeof notif.extras);
memset(notif.text, 0, sizeof notif.text);
memset(notif.requestor_id, 0, sizeof notif.requestor_id);
// Client name
if (supl_req->flags & RPC_LOC_NI_CLIENT_NAME_PRESENT)
{
hexcode(notif.text, sizeof notif.text,
#if (AMSS_VERSION==3200)
supl_req->client_name.client_name_string.client_name_string_val, /* buffer */
#else
supl_req->client_name.client_name_string, /* buffer */
#endif
supl_req->client_name.string_len /* length */
);
LOGD("SUPL NI: client_name: %s len=%d", notif.text, supl_req->client_name.string_len);
} else {
LOGD("SUPL NI: client_name not present.");
}
// Requestor ID
if (supl_req->flags & RPC_LOC_NI_REQUESTOR_ID_PRESENT)
{
hexcode(notif.requestor_id, sizeof notif.requestor_id,
#if (AMSS_VERSION==3200)
supl_req->requestor_id.requestor_id_string.requestor_id_string_val, /* buffer */
#else
supl_req->requestor_id.requestor_id_string, /* buffer */
#endif
supl_req->requestor_id.string_len /* length */
);
LOGD("SUPL NI: requestor_id: %s len=%d", notif.requestor_id, supl_req->requestor_id.string_len);
} else {
LOGD("SUPL NI: requestor_id not present.");
}
// Encoding type
if (supl_req->flags & RPC_LOC_NI_ENCODING_TYPE_PRESENT)
{
notif.text_encoding = convert_encoding_type(supl_req->datacoding_scheme);
notif.requestor_id_encoding = convert_encoding_type(supl_req->datacoding_scheme);
} else {
notif.text_encoding = notif.requestor_id_encoding = GPS_ENC_UNKNOWN;
}
// Set default_response & notify_flags
loc_ni_fill_notif_verify_type(&notif, ni_req->payload.rpc_loc_ni_event_payload_u_type_u.supl_req.notification_priv_type);
break;
default:
LOGE("loc_ni_request_handler, unknown request event: %d", ni_req->event);
return;
}
/* Log requestor ID and text for debugging */
LOGI("Notification: notif_type: %d, timeout: %d, default_resp: %d", notif.ni_type, notif.timeout, notif.default_response);
LOGI(" requestor_id: %s (encoding: %d)", notif.requestor_id, notif.requestor_id_encoding);
LOGI(" text: %s text (encoding: %d)", notif.text, notif.text_encoding);
/* For robustness, always sets a timeout to clear up the notification status, even though
* the OEM layer in java does not do so.
**/
loc_eng_ni_data.response_time_left = 5 + (notif.timeout != 0 ? notif.timeout : LOC_NI_NO_RESPONSE_TIME);
LOGI("Automatically sends 'no response' in %d seconds (to clear status)\n", loc_eng_ni_data.response_time_left);
pthread_mutex_unlock(&loc_eng_ni_data.loc_ni_lock);
/* Notify callback */
if (loc_eng_data.ni_notify_cb != NULL)
{
loc_eng_data.ni_notify_cb(&notif);
}
}
}
/*===========================================================================
FUNCTION loc_ni_process_user_response
DESCRIPTION
Handles user input from the UI
RETURN VALUE
error code (0 for successful, -1 for error)
===========================================================================*/
int loc_ni_process_user_response(GpsUserResponseType userResponse)
{
LOGD("NI response from UI: %d", userResponse);
rpc_loc_ni_user_resp_e_type resp;
switch (userResponse)
{
case GPS_NI_RESPONSE_ACCEPT:
resp = RPC_LOC_NI_LCS_NOTIFY_VERIFY_ACCEPT;
break;
case GPS_NI_RESPONSE_DENY:
resp = RPC_LOC_NI_LCS_NOTIFY_VERIFY_DENY;
break;
case GPS_NI_RESPONSE_NORESP:
resp = RPC_LOC_NI_LCS_NOTIFY_VERIFY_NORESP;
break;
default:
return -1;
}
loc_ni_respond(resp, &loc_eng_ni_data.loc_ni_request);
/* Make the NI respond */
pthread_mutex_lock(&loc_eng_ni_data.loc_ni_lock);
loc_eng_ni_data.notif_in_progress = FALSE;
loc_eng_ni_data.response_time_left = 0;
loc_eng_ni_data.current_notif_id = -1;
pthread_mutex_unlock(&loc_eng_ni_data.loc_ni_lock);
return 0;
}
/*===========================================================================
FUNCTION loc_eng_ni_callback
DESCRIPTION
Loc API callback handler
RETURN VALUE
error code (0 for success)
===========================================================================*/
int loc_eng_ni_callback (
rpc_loc_event_mask_type loc_event, /* event mask */
const rpc_loc_event_payload_u_type* loc_event_payload /* payload */
)
{
int rc = 0;
const rpc_loc_ni_event_s_type *ni_req = &loc_event_payload->rpc_loc_event_payload_u_type_u.ni_request;
if (loc_event == RPC_LOC_EVENT_NI_NOTIFY_VERIFY_REQUEST)
{
switch (ni_req->event)
{
case RPC_LOC_NI_EVENT_VX_NOTIFY_VERIFY_REQ:
LOGI("VX Notification");
loc_ni_request_handler("VX Notify", ni_req);
break;
case RPC_LOC_NI_EVENT_UMTS_CP_NOTIFY_VERIFY_REQ:
LOGI("UMTS CP Notification\n");
loc_ni_request_handler("UMTS CP Notify", ni_req);
break;
case RPC_LOC_NI_EVENT_SUPL_NOTIFY_VERIFY_REQ:
LOGI("SUPL Notification\n");
loc_ni_request_handler("SUPL Notify", ni_req);
break;
default:
LOGE("Unknown NI event: %x\n", (int) ni_req->event);
break;
}
}
return rc;
}
/*===========================================================================
FUNCTION loc_ni_thread_proc
===========================================================================*/
static void loc_ni_thread_proc(void *unused)
{
LOGI("Starting Loc NI thread...\n");
while (1)
{
/* wakes up every second to check timed out requests */
sleep(1);
pthread_mutex_lock(&loc_eng_ni_data.loc_ni_lock);
if (loc_eng_ni_data.notif_in_progress && loc_eng_ni_data.response_time_left > 0)
{
loc_eng_ni_data.response_time_left--;
if (loc_eng_ni_data.response_time_left <= 0)
{
loc_ni_respond(RPC_LOC_NI_LCS_NOTIFY_VERIFY_NORESP, &loc_eng_ni_data.loc_ni_request);
loc_eng_ni_data.notif_in_progress = FALSE;
}
}
pthread_mutex_unlock(&loc_eng_ni_data.loc_ni_lock);
} /* while (1) */
}
/*===========================================================================
FUNCTION loc_eng_ni_init
DESCRIPTION
This function initializes the NI interface
DEPENDENCIES
NONE
RETURN VALUE
None
SIDE EFFECTS
N/A
===========================================================================*/
void loc_eng_ni_init(GpsNiCallbacks *callbacks)
{
LOGD("loc_eng_ni_init: entered.");
if (!loc_eng_ni_data_init)
{
pthread_mutex_init(&loc_eng_ni_data.loc_ni_lock, NULL);
callbacks->create_thread_cb("loc_api_ni", loc_ni_thread_proc, NULL);
loc_eng_ni_data_init = TRUE;
}
loc_eng_ni_data.notif_in_progress = FALSE;
loc_eng_ni_data.current_notif_id = -1;
loc_eng_ni_data.response_time_left = 0;
srand(time(NULL));
loc_eng_data.ni_notify_cb = callbacks->notify_cb;
}
/*===========================================================================
FUNCTION loc_eng_ni_respond
DESCRIPTION
This function sends an NI respond to the modem processor
DEPENDENCIES
NONE
RETURN VALUE
None
SIDE EFFECTS
N/A
===========================================================================*/
void loc_eng_ni_respond(int notif_id, GpsUserResponseType user_response)
{
if (notif_id == loc_eng_ni_data.current_notif_id && loc_eng_ni_data.notif_in_progress)
{
LOGI("loc_eng_ni_respond: send user response %d for notif %d", user_response, notif_id);
loc_ni_process_user_response(user_response);
} else {
LOGE("loc_eng_ni_respond: notif_id %d mismatch or notification not in progress, response: %d",
notif_id, user_response);
}
}

View file

@ -1,56 +0,0 @@
/* Copyright (c) 2009,2011 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef LOC_ENG_NI_H
#define LOC_ENG_NI_H
#include <hardware/gps.h>
#define LOC_NI_NO_RESPONSE_TIME 20 /* secs */
extern const GpsNiInterface sLocEngNiInterface;
typedef struct {
pthread_mutex_t loc_ni_lock;
int response_time_left; /* examine time for NI response */
boolean notif_in_progress; /* NI notification/verification in progress */
rpc_loc_ni_event_s_type loc_ni_request;
int current_notif_id; /* ID to check against response */
} loc_eng_ni_data_s_type;
// Functions for sLocEngNiInterface
extern void loc_eng_ni_init(GpsNiCallbacks *callbacks);
extern void loc_eng_ni_respond(int notif_id, GpsUserResponseType user_response);
extern int loc_eng_ni_callback (
rpc_loc_event_mask_type loc_event, /* event mask */
const rpc_loc_event_payload_u_type* loc_event_payload /* payload */
);
#endif /* LOC_ENG_NI_H */

View file

@ -1,180 +0,0 @@
/* Copyright (c) 2009,2011 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_NDDEBUG 0
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <math.h>
#include <pthread.h>
#include <rpc/rpc.h>
#include <loc_api_rpc_glue.h>
#include <loc_eng.h>
#define LOG_TAG "lib_locapi"
#include <utils/Log.h>
// comment this out to enable logging
// #undef LOGD
// #define LOGD(...) {}
#define LOC_XTRA_INJECT_DEFAULT_TIMEOUT (3100)
#define XTRA_BLOCK_SIZE (400)
static int qct_loc_eng_xtra_init (GpsXtraCallbacks* callbacks);
static int qct_loc_eng_inject_xtra_data(char* data, int length);
const GpsXtraInterface sLocEngXTRAInterface =
{
sizeof(GpsXtraInterface),
qct_loc_eng_xtra_init,
qct_loc_eng_inject_xtra_data,
};
/*===========================================================================
FUNCTION qct_loc_eng_xtra_init
DESCRIPTION
Initialize XTRA module.
DEPENDENCIES
N/A
RETURN VALUE
0: success
SIDE EFFECTS
N/A
===========================================================================*/
static int qct_loc_eng_xtra_init (GpsXtraCallbacks* callbacks)
{
rpc_loc_event_mask_type event;
loc_eng_xtra_data_s_type *xtra_module_data_ptr;
xtra_module_data_ptr = &(loc_eng_data.xtra_module_data);
xtra_module_data_ptr->download_request_cb = callbacks->download_request_cb;
return 0;
}
/*===========================================================================
FUNCTION qct_loc_eng_inject_xtra_data
DESCRIPTION
Injects XTRA file into the engine.
DEPENDENCIES
N/A
RETURN VALUE
0: success
>0: failure
SIDE EFFECTS
N/A
===========================================================================*/
static int qct_loc_eng_inject_xtra_data(char* data, int length)
{
int rpc_ret_val = RPC_LOC_API_GENERAL_FAILURE;
boolean ret_val = 0;
int total_parts;
uint8 part;
uint16 part_len;
uint16 len_injected;
rpc_loc_ioctl_data_u_type ioctl_data;
rpc_loc_predicted_orbits_data_s_type *predicted_orbits_data_ptr;
LOGV ("qct_loc_eng_inject_xtra_data, xtra size = %d, data ptr = 0x%x\n", length, (int) data);
ioctl_data.disc = RPC_LOC_IOCTL_INJECT_PREDICTED_ORBITS_DATA;
predicted_orbits_data_ptr = &(ioctl_data.rpc_loc_ioctl_data_u_type_u.predicted_orbits_data);
predicted_orbits_data_ptr->format_type = RPC_LOC_PREDICTED_ORBITS_XTRA;
predicted_orbits_data_ptr->total_size = length;
total_parts = (length / XTRA_BLOCK_SIZE);
if ((total_parts % XTRA_BLOCK_SIZE) != 0)
{
total_parts += 1;
}
predicted_orbits_data_ptr->total_parts = total_parts;
len_injected = 0; // O bytes injected
// XTRA injection starts with part 1
for (part = 1; part <= total_parts; part++)
{
predicted_orbits_data_ptr->part = part;
predicted_orbits_data_ptr->part_len = XTRA_BLOCK_SIZE;
if (XTRA_BLOCK_SIZE > (length - len_injected))
{
predicted_orbits_data_ptr->part_len = length - len_injected;
}
predicted_orbits_data_ptr->data_ptr.data_ptr_len = predicted_orbits_data_ptr->part_len;
predicted_orbits_data_ptr->data_ptr.data_ptr_val = data + len_injected;
LOGV ("qct_loc_eng_inject_xtra_data, inject part = %d, len = %d, len = %d\n", predicted_orbits_data_ptr->part, predicted_orbits_data_ptr->part_len, predicted_orbits_data_ptr->data_ptr.data_ptr_len);
LOGV ("qct_loc_eng_inject_xtra_data, total part = %d, len = %d \n", predicted_orbits_data_ptr->part, predicted_orbits_data_ptr->part_len);
if (part < total_parts)
{
// No callback in this case
rpc_ret_val = loc_ioctl (loc_eng_data.client_handle,
RPC_LOC_IOCTL_INJECT_PREDICTED_ORBITS_DATA,
&ioctl_data);
if (rpc_ret_val != RPC_LOC_API_SUCCESS)
{
LOGE ("loc_ioctl for xtra returned %d \n", rpc_ret_val);
ret_val = EINVAL; // return error
break;
}
}
else // part == total_parts
{
// Last part injection, will need to wait for callback
ret_val = loc_eng_ioctl (loc_eng_data.client_handle,
RPC_LOC_IOCTL_INJECT_PREDICTED_ORBITS_DATA,
&ioctl_data,
LOC_XTRA_INJECT_DEFAULT_TIMEOUT,
NULL /* No output information is expected*/);
break; // done with injection
}
len_injected += predicted_orbits_data_ptr->part_len;
LOGV ("loc_ioctl for xtra len injected %d \n", len_injected);
}
return ret_val;
}

View file

@ -1,45 +0,0 @@
/* Copyright (c) 2009,2011 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef LOC_ENG_XTRA_H
#define LOC_ENG_XTRA_H
#include <hardware/gps.h>
extern const GpsXtraInterface sLocEngXTRAInterface;
// Module data
typedef struct
{
// loc_eng_ioctl_cb_data_s_type ioctl_cb_data;
gps_xtra_download_request download_request_cb;
} loc_eng_xtra_data_s_type;
#endif // LOC_ENG_XTRA_H