summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTushar Janefalkar <tusharj@codeaurora.org>2012-11-08 11:41:43 -0800
committerGerrit - the friendly Code Review server <code-review@localhost>2013-03-18 15:49:52 -0700
commit5049a4779793ac7c8eeed87114805fd63bf16ac9 (patch)
treec9d5fb6b5d37367872b49a13afaa7847812f3be1
parentdc72922169d42765ba420c79fe9e3f7fc4082d3e (diff)
downloadgps-5049a4779793ac7c8eeed87114805fd63bf16ac9.tar.gz
Utility to identify target HW
Earlier this identification was done in loc.cpp This change moves that to a separate utility. Also included is a change to not return a handle to the GPS interface if the target is found to be MPQ8064. This change is a re-cherry-pick from change id - I98d5619d2e6e63711a9b56f0af2b3ddd27372871 Change-Id: I058d206c37245b44f1cf74d6065e7ce46f50baf7 CRs-Fixed: 418009
-rw-r--r--loc_api/libloc_api_50001/loc.cpp81
-rw-r--r--utils/Android.mk6
-rw-r--r--utils/loc_log.cpp30
-rw-r--r--utils/loc_log.h2
-rw-r--r--utils/loc_target.cpp109
-rw-r--r--utils/loc_target.h51
6 files changed, 210 insertions, 69 deletions
diff --git a/loc_api/libloc_api_50001/loc.cpp b/loc_api/libloc_api_50001/loc.cpp
index 6592cc5..fc6a216 100644
--- a/loc_api/libloc_api_50001/loc.cpp
+++ b/loc_api/libloc_api_50001/loc.cpp
@@ -33,10 +33,10 @@
#include <hardware/gps.h>
#include <loc_ulp.h>
#include <loc_eng.h>
+#include <loc_target.h>
#include <loc_log.h>
#include <msg_q.h>
#include <dlfcn.h>
-
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -190,65 +190,6 @@ static const UlpPhoneContextInterface sLocEngUlpPhoneContextInterface =
static loc_eng_data_s_type loc_afw_data;
static int gss_fd = 0;
-#define TARGET_NAME_OTHER 0
-#define TARGET_NAME_APQ8064_STANDALONE 1
-#define TARGET_NAME_APQ8064_FUSION3 2
-
-static int read_a_line(const char * file_path, char * line, int line_size)
-{
- FILE *fp;
- int result = 0;
-
- * line = '\0';
- fp = fopen(file_path, "r" );
- if( fp == NULL ) {
- LOC_LOGE("open failed: %s: %s\n", file_path, strerror(errno));
- result = -1;
- } else {
- int len;
- fgets(line, line_size, fp);
- len = strlen(line);
- len = len < line_size - 1? len : line_size - 1;
- line[len] = '\0';
- LOC_LOGD("cat %s: %s", file_path, line);
- fclose(fp);
- }
- return result;
-}
-
-#define LINE_LEN 100
-#define STR_LIQUID "Liquid"
-#define STR_SURF "Surf"
-#define STRLEN_LIQUID (sizeof(STR_LIQUID) - 1)
-#define STRLEN_SURF (sizeof(STR_SURF) - 1)
-#define IS_STR_END(c) ((c) == '\0' || (c) == '\n' || (c) == '\r')
-
-static int get_target_name(void)
-{
- int target_name = TARGET_NAME_OTHER;
-
- char hw_platform[] = "/sys/devices/system/soc/soc0/hw_platform"; // "Liquid" or "Surf"
- char id[] = "/sys/devices/system/soc/soc0/id"; //109
- char mdm[] = "/dev/mdm"; // No such file or directory
-
- char line[LINE_LEN];
-
- read_a_line( hw_platform, line, LINE_LEN);
- if(( !memcmp(line, STR_LIQUID, STRLEN_LIQUID) && IS_STR_END(line[STRLEN_LIQUID]) ) ||
- ( !memcmp(line, STR_SURF, STRLEN_SURF) && IS_STR_END(line[STRLEN_SURF]) )
- ) {
- if (!read_a_line( mdm, line, LINE_LEN)) {
- target_name = TARGET_NAME_APQ8064_FUSION3;
- } else {
- read_a_line( id, line, LINE_LEN);
- if(!strncmp(line, "109", strlen("109")) || !strncmp(line, "153", strlen("153"))) {
- target_name = TARGET_NAME_APQ8064_STANDALONE;
- }
- }
- }
- return target_name;
-}
-
/*===========================================================================
FUNCTION gps_get_hardware_interface
@@ -290,6 +231,7 @@ const GpsInterface* gps_get_hardware_interface ()
// for gps.c
extern "C" const GpsInterface* get_gps_interface()
{
+ targetEnumType target = TARGET_OTHER;
loc_eng_read_config();
//We load up libulp module at this point itself if ULP configured to be On
@@ -297,16 +239,23 @@ extern "C" const GpsInterface* get_gps_interface()
loc_eng_ulp_inf = loc_eng_get_ulp_inf();
}
- if (get_target_name() == TARGET_NAME_APQ8064_STANDALONE)
- {
+ target = get_target();
+ LOC_LOGD("Target name check returned %s", loc_get_target_name(target));
+ //APQ8064
+ if(target == TARGET_APQ8064_STANDALONE) {
gps_conf.CAPABILITIES &= ~(GPS_CAPABILITY_MSA | GPS_CAPABILITY_MSB);
gss_fd = open("/dev/gss", O_RDONLY);
- if (gss_fd < 0) {
+ if (gss_fd < 0)
LOC_LOGE("GSS open failed: %s\n", strerror(errno));
+ else {
+ LOC_LOGD("GSS open success! CAPABILITIES %0lx\n", gps_conf.CAPABILITIES);
}
- LOC_LOGD("GSS open success! CAPABILITIES %0x\n", gps_conf.CAPABILITIES);
}
-
+ //MPQ8064
+ else if(target == TARGET_MPQ8064) {
+ LOC_LOGE("No GPS HW on this target (MPQ8064). Not returning interface");
+ return NULL;
+ }
return &sLocEngInterface;
}
@@ -410,7 +359,7 @@ static void loc_cleanup()
gps_sv_cb = NULL;
/*
- * if (get_target_name() == TARGET_NAME_APQ8064_STANDALONE)
+ * if (get_target() == TARGET_NAME_APQ8064_STANDALONE)
* {
* close(gss_fd);
* LOC_LOGD("GSS shutdown.\n");
diff --git a/utils/Android.mk b/utils/Android.mk
index 4bf0401..7dc1799 100644
--- a/utils/Android.mk
+++ b/utils/Android.mk
@@ -15,7 +15,8 @@ LOCAL_SRC_FILES += \
loc_log.cpp \
loc_cfg.cpp \
msg_q.c \
- linked_list.c
+ linked_list.c \
+ loc_target.cpp
LOCAL_CFLAGS += \
-fno-short-enums \
@@ -32,7 +33,8 @@ LOCAL_COPY_HEADERS:= \
loc_cfg.h \
log_util.h \
linked_list.h \
- msg_q.h
+ msg_q.h \
+ loc_target.h
LOCAL_MODULE := libgps.utils
diff --git a/utils/loc_log.cpp b/utils/loc_log.cpp
index 8b064ec..f39667c 100644
--- a/utils/loc_log.cpp
+++ b/utils/loc_log.cpp
@@ -34,7 +34,6 @@
#include <sys/time.h>
#include "loc_log.h"
#include "msg_q.h"
-
#include "log_util.h"
// Logging Improvements
@@ -100,6 +99,35 @@ const char* log_succ_fail_string(int is_succ)
return is_succ? "successful" : "failed";
}
+//Target names
+loc_name_val_s_type target_name[] =
+{
+ NAME_VAL(TARGET_OTHER),
+ NAME_VAL(TARGET_APQ8064_STANDALONE),
+ NAME_VAL(TARGET_APQ8064_FUSION3),
+ NAME_VAL(TARGET_MPQ8064),
+ NAME_VAL(TARGET_MSM8930)
+};
+
+static int target_name_num = sizeof(target_name)/sizeof(loc_name_val_s_type);
+
+/*===========================================================================
+
+FUNCTION loc_get_target_name
+
+DESCRIPTION
+ Returns pointer to a string that contains name of the target
+
+ XX:XX:XX.000\0
+
+RETURN VALUE
+ The target name string
+
+===========================================================================*/
+const char *loc_get_target_name(targetEnumType target)
+{
+ return loc_get_name_from_val(target_name, target_name_num, (long)target);
+}
/*===========================================================================
diff --git a/utils/loc_log.h b/utils/loc_log.h
index 63236de..abe29b7 100644
--- a/utils/loc_log.h
+++ b/utils/loc_log.h
@@ -36,6 +36,7 @@ extern "C"
#endif
#include <ctype.h>
+#include "loc_target.h"
typedef struct
{
@@ -54,6 +55,7 @@ typedef struct
const char* loc_get_name_from_mask(loc_name_val_s_type table[], int table_size, long mask);
const char* loc_get_name_from_val(loc_name_val_s_type table[], int table_size, long value);
const char* loc_get_msg_q_status(int status);
+const char* loc_get_target_name(targetEnumType target);
extern const char* log_succ_fail_string(int is_succ);
diff --git a/utils/loc_target.cpp b/utils/loc_target.cpp
new file mode 100644
index 0000000..10b508c
--- /dev/null
+++ b/utils/loc_target.cpp
@@ -0,0 +1,109 @@
+/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <hardware/gps.h>
+#include <cutils/properties.h>
+#include "loc_target.h"
+#include "loc_log.h"
+#include "log_util.h"
+
+#define APQ8064_ID_1 "109"
+#define APQ8064_ID_2 "153"
+#define MPQ8064_ID_1 "130"
+#define MSM8930_ID_1 "142"
+#define MSM8930_ID_2 "116"
+
+#define LINE_LEN 100
+#define STR_LIQUID "Liquid"
+#define STR_SURF "Surf"
+#define IS_STR_END(c) ((c) == '\0' || (c) == '\n' || (c) == '\r')
+#define LENGTH(s) (sizeof(s) - 1)
+#define GPS_CHECK_NO_ERROR 0
+#define GPS_CHECK_NO_GPS_HW 1
+
+static int gss_fd = 0;
+
+static int read_a_line(const char * file_path, char * line, int line_size)
+{
+ FILE *fp;
+ int result = 0;
+
+ * line = '\0';
+ fp = fopen(file_path, "r" );
+ if( fp == NULL ) {
+ LOC_LOGE("open failed: %s: %s\n", file_path, strerror(errno));
+ result = -1;
+ } else {
+ int len;
+ fgets(line, line_size, fp);
+ len = strlen(line);
+ len = len < line_size - 1? len : line_size - 1;
+ line[len] = '\0';
+ LOC_LOGD("cat %s: %s", file_path, line);
+ fclose(fp);
+ }
+ return result;
+}
+
+targetEnumType get_target(void)
+{
+ targetEnumType target = TARGET_OTHER;
+
+ char hw_platform[] = "/sys/devices/system/soc/soc0/hw_platform";
+ char id[] = "/sys/devices/system/soc/soc0/id";
+ char mdm[] = "/dev/mdm"; // No such file or directory
+
+ char rd_hw_platform[LINE_LEN];
+ char rd_id[LINE_LEN];
+ char rd_mdm[LINE_LEN];
+
+ read_a_line(hw_platform, rd_hw_platform, LINE_LEN);
+ read_a_line( id, rd_id, LINE_LEN);
+
+ if( (!memcmp(rd_hw_platform, STR_LIQUID, LENGTH(STR_LIQUID)) && IS_STR_END(rd_hw_platform[LENGTH(STR_LIQUID)])) ||
+ (!memcmp(rd_hw_platform, STR_SURF, LENGTH(STR_SURF)) && IS_STR_END(rd_hw_platform[LENGTH(STR_SURF)])) ) {
+ if (!read_a_line( mdm, rd_mdm, LINE_LEN))
+ target = TARGET_APQ8064_FUSION3;
+ else if( (!memcmp(rd_id, APQ8064_ID_1, LENGTH(APQ8064_ID_1)) && IS_STR_END(rd_id[LENGTH(APQ8064_ID_1)])) ||
+ (!memcmp(rd_id, APQ8064_ID_2, LENGTH(APQ8064_ID_2)) && IS_STR_END(rd_id[LENGTH(APQ8064_ID_2)])) )
+ target = TARGET_APQ8064_STANDALONE;
+ }
+ else if( !memcmp(rd_id, MPQ8064_ID_1, LENGTH(MPQ8064_ID_1)) && IS_STR_END(rd_id[LENGTH(MPQ8064_ID_1)]) )
+ target = TARGET_MPQ8064;
+ else if( (!memcmp(rd_id, MSM8930_ID_1, LENGTH(MSM8930_ID_1)) && IS_STR_END(rd_id[LENGTH(MSM8930_ID_1)])) ||
+ (!memcmp(rd_id, MSM8930_ID_2, LENGTH(MSM8930_ID_2)) && IS_STR_END(rd_id[LENGTH(MSM8930_ID_2)])) )
+ target = TARGET_MSM8930;
+ return target;
+}
diff --git a/utils/loc_target.h b/utils/loc_target.h
new file mode 100644
index 0000000..489aadd
--- /dev/null
+++ b/utils/loc_target.h
@@ -0,0 +1,51 @@
+/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef LOC_TARGET_H
+#define LOC_TARGET_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef enum {
+ TARGET_OTHER = 0,
+ TARGET_APQ8064_STANDALONE,
+ TARGET_APQ8064_FUSION3,
+ TARGET_MPQ8064,
+ TARGET_MSM8930
+}targetEnumType;
+
+targetEnumType get_target(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*LOC_TARGET_H*/