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 <string.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <errno.h>
37 #include <hardware/gps.h>
38 #include <cutils/properties.h>
39 #include "loc_target.h"
40 #include "loc_log.h"
41 #include "log_util.h"
42
43 #define APQ8064_ID_1 "109"
44 #define APQ8064_ID_2 "153"
45 #define MPQ8064_ID_1 "130"
46 #define MSM8930_ID_1 "142"
47 #define MSM8930_ID_2 "116"
48 #define APQ8030_ID_1 "157"
49 #define APQ8074_ID_1 "184"
50
51 #define LINE_LEN 100
52 #define STR_LIQUID "Liquid"
53 #define STR_SURF "Surf"
54 #define STR_MTP "MTP"
55 #define STR_APQ "apq"
56 #define IS_STR_END(c) ((c) == '\0' || (c) == '\n' || (c) == '\r')
57 #define LENGTH(s) (sizeof(s) - 1)
58 #define GPS_CHECK_NO_ERROR 0
59 #define GPS_CHECK_NO_GPS_HW 1
60
61 static int gss_fd = 0;
62
read_a_line(const char * file_path,char * line,int line_size)63 static int read_a_line(const char * file_path, char * line, int line_size)
64 {
65 FILE *fp;
66 int result = 0;
67
68 * line = '\0';
69 fp = fopen(file_path, "r" );
70 if( fp == NULL ) {
71 LOC_LOGE("open failed: %s: %s\n", file_path, strerror(errno));
72 result = -1;
73 } else {
74 int len;
75 fgets(line, line_size, fp);
76 len = strlen(line);
77 len = len < line_size - 1? len : line_size - 1;
78 line[len] = '\0';
79 LOC_LOGD("cat %s: %s", file_path, line);
80 fclose(fp);
81 }
82 return result;
83 }
84
get_target(void)85 unsigned int get_target(void)
86 {
87 unsigned int target = TARGET_DEFAULT;
88
89 char hw_platform[] = "/sys/devices/system/soc/soc0/hw_platform";
90 char id[] = "/sys/devices/system/soc/soc0/id";
91 char mdm[] = "/dev/mdm"; // No such file or directory
92
93 char rd_hw_platform[LINE_LEN];
94 char rd_id[LINE_LEN];
95 char rd_mdm[LINE_LEN];
96 char baseband[LINE_LEN];
97
98 property_get("ro.baseband", baseband, "");
99 read_a_line(hw_platform, rd_hw_platform, LINE_LEN);
100 read_a_line( id, rd_id, LINE_LEN);
101
102 if( !memcmp(baseband, STR_APQ, LENGTH(STR_APQ)) ){
103 if( !memcmp(rd_id, MPQ8064_ID_1, LENGTH(MPQ8064_ID_1))
104 && IS_STR_END(rd_id[LENGTH(MPQ8064_ID_1)]) )
105 target = TARGET_MPQ;
106 else
107 target = TARGET_APQ_SA;
108 }
109 else {
110 if( (!memcmp(rd_hw_platform, STR_LIQUID, LENGTH(STR_LIQUID))
111 && IS_STR_END(rd_hw_platform[LENGTH(STR_LIQUID)])) ||
112 (!memcmp(rd_hw_platform, STR_SURF, LENGTH(STR_SURF))
113 && IS_STR_END(rd_hw_platform[LENGTH(STR_SURF)])) ||
114 (!memcmp(rd_hw_platform, STR_MTP, LENGTH(STR_MTP))
115 && IS_STR_END(rd_hw_platform[LENGTH(STR_MTP)]))) {
116
117 if (!read_a_line( mdm, rd_mdm, LINE_LEN))
118 target = TARGET_MDM;
119 }
120 else if( (!memcmp(rd_id, MSM8930_ID_1, LENGTH(MSM8930_ID_1))
121 && IS_STR_END(rd_id[LENGTH(MSM8930_ID_1)])) ||
122 (!memcmp(rd_id, MSM8930_ID_2, LENGTH(MSM8930_ID_2))
123 && IS_STR_END(rd_id[LENGTH(MSM8930_ID_2)])) )
124 target = TARGET_MSM_NO_SSC;
125 }
126 return target;
127 }
128