1 /* Copyright (c) 2012, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <errno.h>
36 #include <hardware/gps.h>
37 #include <cutils/properties.h>
38 #include "loc_target.h"
39 #include "loc_log.h"
40 #include "log_util.h"
41
42 #define APQ8064_ID_1 "109"
43 #define APQ8064_ID_2 "153"
44 #define MPQ8064_ID_1 "130"
45 #define MSM8930_ID_1 "142"
46 #define MSM8930_ID_2 "116"
47 #define APQ8030_ID_1 "157"
48 #define APQ8074_ID_1 "184"
49
50 #define LINE_LEN 100
51 #define STR_LIQUID "Liquid"
52 #define STR_SURF "Surf"
53 #define STR_MTP "MTP"
54 #define STR_APQ "apq"
55 #define IS_STR_END(c) ((c) == '\0' || (c) == '\n' || (c) == '\r')
56 #define LENGTH(s) (sizeof(s) - 1)
57 #define GPS_CHECK_NO_ERROR 0
58 #define GPS_CHECK_NO_GPS_HW 1
59
60 static int gss_fd = 0;
61
read_a_line(const char * file_path,char * line,int line_size)62 static int read_a_line(const char * file_path, char * line, int line_size)
63 {
64 FILE *fp;
65 int result = 0;
66
67 * line = '\0';
68 fp = fopen(file_path, "r" );
69 if( fp == NULL ) {
70 LOC_LOGE("open failed: %s: %s\n", file_path, strerror(errno));
71 result = -1;
72 } else {
73 int len;
74 fgets(line, line_size, fp);
75 len = strlen(line);
76 len = len < line_size - 1? len : line_size - 1;
77 line[len] = '\0';
78 LOC_LOGD("cat %s: %s", file_path, line);
79 fclose(fp);
80 }
81 return result;
82 }
83
get_target(void)84 unsigned int get_target(void)
85 {
86 unsigned int target = TARGET_DEFAULT;
87
88 char hw_platform[] = "/sys/devices/system/soc/soc0/hw_platform";
89 char id[] = "/sys/devices/system/soc/soc0/id";
90 char mdm[] = "/dev/mdm"; // No such file or directory
91
92 char rd_hw_platform[LINE_LEN];
93 char rd_id[LINE_LEN];
94 char rd_mdm[LINE_LEN];
95 char baseband[LINE_LEN];
96
97 property_get("ro.baseband", baseband, "");
98 read_a_line(hw_platform, rd_hw_platform, LINE_LEN);
99 read_a_line( id, rd_id, LINE_LEN);
100
101 if( !memcmp(baseband, STR_APQ, LENGTH(STR_APQ)) ){
102 if( !memcmp(rd_id, MPQ8064_ID_1, LENGTH(MPQ8064_ID_1))
103 && IS_STR_END(rd_id[LENGTH(MPQ8064_ID_1)]) )
104 target = TARGET_MPQ;
105 else
106 target = TARGET_APQ_SA;
107 }
108 else {
109 if( (!memcmp(rd_hw_platform, STR_LIQUID, LENGTH(STR_LIQUID))
110 && IS_STR_END(rd_hw_platform[LENGTH(STR_LIQUID)])) ||
111 (!memcmp(rd_hw_platform, STR_SURF, LENGTH(STR_SURF))
112 && IS_STR_END(rd_hw_platform[LENGTH(STR_SURF)])) ||
113 (!memcmp(rd_hw_platform, STR_MTP, LENGTH(STR_MTP))
114 && IS_STR_END(rd_hw_platform[LENGTH(STR_MTP)]))) {
115
116 if (!read_a_line( mdm, rd_mdm, LINE_LEN))
117 target = TARGET_MDM;
118 }
119 else if( (!memcmp(rd_id, MSM8930_ID_1, LENGTH(MSM8930_ID_1))
120 && IS_STR_END(rd_id[LENGTH(MSM8930_ID_1)])) ||
121 (!memcmp(rd_id, MSM8930_ID_2, LENGTH(MSM8930_ID_2))
122 && IS_STR_END(rd_id[LENGTH(MSM8930_ID_2)])) )
123 target = TARGET_MSM_NO_SSC;
124 }
125 return target;
126 }
127