From 5049a4779793ac7c8eeed87114805fd63bf16ac9 Mon Sep 17 00:00:00 2001 From: Tushar Janefalkar Date: Thu, 8 Nov 2012 11:41:43 -0800 Subject: 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 --- utils/Android.mk | 6 ++- utils/loc_log.cpp | 30 +++++++++++++- utils/loc_log.h | 2 + utils/loc_target.cpp | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++ utils/loc_target.h | 51 ++++++++++++++++++++++++ 5 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 utils/loc_target.cpp create mode 100644 utils/loc_target.h (limited to 'utils') 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 #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 +#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 +#include +#include +#include +#include +#include +#include +#include +#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*/ -- cgit v1.2.3