1 /* Copyright (c) 2009-2013,2016, 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 #define LOG_NDDEBUG 0 31 #define LOG_TAG "LocSvc_eng" 32 33 #include <loc_eng.h> 34 #include <MsgTask.h> 35 #include "log_util.h" 36 #include "platform_lib_includes.h" 37 38 using namespace loc_core; 39 40 struct LocEngRequestXtraServer : public LocMsg { 41 LocEngAdapter* mAdapter; 42 inline LocEngRequestXtraServer(LocEngAdapter* adapter) : 43 LocMsg(), mAdapter(adapter) 44 { 45 locallog(); 46 } 47 inline virtual void proc() const { 48 mAdapter->requestXtraServer(); 49 } 50 inline void locallog() const { 51 LOC_LOGV("LocEngRequestXtraServer"); 52 } 53 inline virtual void log() const { 54 locallog(); 55 } 56 }; 57 58 struct LocEngInjectXtraData : public LocMsg { 59 LocEngAdapter* mAdapter; 60 char* mData; 61 const int mLen; 62 inline LocEngInjectXtraData(LocEngAdapter* adapter, 63 char* data, int len): 64 LocMsg(), mAdapter(adapter), 65 mData(new char[len]), mLen(len) 66 { 67 memcpy((void*)mData, (void*)data, len); 68 locallog(); 69 } 70 inline ~LocEngInjectXtraData() 71 { 72 delete[] mData; 73 } 74 inline virtual void proc() const { 75 mAdapter->setXtraData(mData, mLen); 76 } 77 inline void locallog() const { 78 LOC_LOGV("length: %d\n data: %p", mLen, mData); 79 } 80 inline virtual void log() const { 81 locallog(); 82 } 83 }; 84 85 struct LocEngSetXtraVersionCheck : public LocMsg { 86 LocEngAdapter *mAdapter; 87 int mCheck; 88 inline LocEngSetXtraVersionCheck(LocEngAdapter* adapter, 89 int check): 90 mAdapter(adapter), mCheck(check) {} 91 inline virtual void proc() const { 92 locallog(); 93 mAdapter->setXtraVersionCheck(mCheck); 94 } 95 inline void locallog() const { 96 LOC_LOGD("%s:%d]: mCheck: %d", 97 __func__, __LINE__, mCheck); 98 } 99 inline virtual void log() const { 100 locallog(); 101 } 102 }; 103 104 /*=========================================================================== 105 FUNCTION loc_eng_xtra_init 106 107 DESCRIPTION 108 Initialize XTRA module. 109 110 DEPENDENCIES 111 N/A 112 113 RETURN VALUE 114 0: success 115 116 SIDE EFFECTS 117 N/A 118 119 ===========================================================================*/ 120 int loc_eng_xtra_init (loc_eng_data_s_type &loc_eng_data, 121 GpsXtraExtCallbacks* callbacks) 122 { 123 int ret_val = -1; 124 loc_eng_xtra_data_s_type *xtra_module_data_ptr; 125 ENTRY_LOG(); 126 127 if(!loc_eng_data.adapter->mSupportsTimeInjection 128 || loc_eng_data.adapter->hasNativeXtraClient()) { 129 LOC_LOGD("XTRA is already supported. disable it here.\n"); 130 EXIT_LOG(%d, 1); // return 1 denote failure 131 return 1; 132 } 133 134 if(callbacks == NULL) { 135 LOC_LOGE("loc_eng_xtra_init: failed, cb is NULL"); 136 } else { 137 xtra_module_data_ptr = &loc_eng_data.xtra_module_data; 138 xtra_module_data_ptr->download_request_cb = callbacks->download_request_cb; 139 xtra_module_data_ptr->report_xtra_server_cb = callbacks->report_xtra_server_cb; 140 141 ret_val = 0; 142 } 143 EXIT_LOG(%d, ret_val); 144 return ret_val; 145 } 146 147 /*=========================================================================== 148 FUNCTION loc_eng_xtra_inject_data 149 150 DESCRIPTION 151 Injects XTRA file into the engine but buffers the data if engine is busy. 152 153 DEPENDENCIES 154 N/A 155 156 RETURN VALUE 157 0 158 159 SIDE EFFECTS 160 N/A 161 162 ===========================================================================*/ 163 int loc_eng_xtra_inject_data(loc_eng_data_s_type &loc_eng_data, 164 char* data, int length) 165 { 166 ENTRY_LOG(); 167 LocEngAdapter* adapter = loc_eng_data.adapter; 168 adapter->sendMsg(new LocEngInjectXtraData(adapter, data, length)); 169 EXIT_LOG(%d, 0); 170 return 0; 171 } 172 /*=========================================================================== 173 FUNCTION loc_eng_xtra_request_server 174 175 DESCRIPTION 176 Request the Xtra server url from the modem 177 178 DEPENDENCIES 179 N/A 180 181 RETURN VALUE 182 0 183 184 SIDE EFFECTS 185 N/A 186 187 ===========================================================================*/ 188 int loc_eng_xtra_request_server(loc_eng_data_s_type &loc_eng_data) 189 { 190 ENTRY_LOG(); 191 LocEngAdapter* adapter = loc_eng_data.adapter; 192 adapter->sendMsg(new LocEngRequestXtraServer(adapter)); 193 EXIT_LOG(%d, 0); 194 return 0; 195 } 196 /*=========================================================================== 197 FUNCTION loc_eng_xtra_version_check 198 199 DESCRIPTION 200 Injects the enable/disable value for checking XTRA version 201 that is specified in gps.conf 202 203 DEPENDENCIES 204 N/A 205 206 RETURN VALUE 207 none 208 209 SIDE EFFECTS 210 N/A 211 212 ===========================================================================*/ 213 void loc_eng_xtra_version_check(loc_eng_data_s_type &loc_eng_data, 214 int check) 215 { 216 ENTRY_LOG(); 217 LocEngAdapter *adapter = loc_eng_data.adapter; 218 adapter->sendMsg(new LocEngSetXtraVersionCheck(adapter, check)); 219 EXIT_LOG(%d, 0); 220 } 221