1 /* Copyright (c) 2011-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_afw"
32
33 #include <hardware/gps.h>
34 #include <gps_extended.h>
35 #include <loc_eng.h>
36 #include <loc_target.h>
37 #include <loc_log.h>
38 #include <fcntl.h>
39 #include <errno.h>
40 #include <dlfcn.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <fcntl.h>
44 #include <errno.h>
45 #include <LocDualContext.h>
46 #include <cutils/properties.h>
47 #include <sys/socket.h>
48 #include <sys/un.h>
49 #include <sstream>
50 #include <string>
51 #include <unistd.h>
52
53 using namespace loc_core;
54
55 #define LOC_PM_CLIENT_NAME "GPS"
56
57 //Globals defns
58 static gps_location_callback gps_loc_cb = NULL;
59 static gps_sv_status_callback gps_sv_cb = NULL;
60
61 static void local_loc_cb(UlpLocation* location, void* locExt);
62 static void local_sv_cb(GpsSvStatus* sv_status, void* svExt);
63
64 static const GpsGeofencingInterface* get_geofence_interface(void);
65
66 // Function declarations for sLocEngInterface
67 static int loc_init(GpsCallbacks* callbacks);
68 static int loc_start();
69 static int loc_stop();
70 static void loc_cleanup();
71 static int loc_inject_time(GpsUtcTime time, int64_t timeReference, int uncertainty);
72 static int loc_inject_location(double latitude, double longitude, float accuracy);
73 static void loc_delete_aiding_data(GpsAidingData f);
74 static int loc_set_position_mode(GpsPositionMode mode, GpsPositionRecurrence recurrence,
75 uint32_t min_interval, uint32_t preferred_accuracy,
76 uint32_t preferred_time);
77 static const void* loc_get_extension(const char* name);
78 // Defines the GpsInterface in gps.h
79 static const GpsInterface sLocEngInterface =
80 {
81 sizeof(GpsInterface),
82 loc_init,
83 loc_start,
84 loc_stop,
85 loc_cleanup,
86 loc_inject_time,
87 loc_inject_location,
88 loc_delete_aiding_data,
89 loc_set_position_mode,
90 loc_get_extension
91 };
92
93 // Function declarations for sLocEngAGpsInterface
94 static void loc_agps_init(AGpsCallbacks* callbacks);
95 static int loc_agps_open(const char* apn);
96 static int loc_agps_closed();
97 static int loc_agps_open_failed();
98 static int loc_agps_set_server(AGpsType type, const char *hostname, int port);
99 static int loc_agps_open_with_apniptype( const char* apn, ApnIpType apnIpType);
100
101 static const AGpsInterface sLocEngAGpsInterface =
102 {
103 sizeof(AGpsInterface),
104 loc_agps_init,
105 loc_agps_open,
106 loc_agps_closed,
107 loc_agps_open_failed,
108 loc_agps_set_server,
109 loc_agps_open_with_apniptype
110 };
111
112 static int loc_xtra_init(GpsXtraCallbacks* callbacks);
113 static int loc_xtra_inject_data(char* data, int length);
114
115 static const GpsXtraInterface sLocEngXTRAInterface =
116 {
117 sizeof(GpsXtraInterface),
118 loc_xtra_init,
119 loc_xtra_inject_data
120 };
121
122 static void loc_ni_init(GpsNiCallbacks *callbacks);
123 static void loc_ni_respond(int notif_id, GpsUserResponseType user_response);
124
125 static const GpsNiInterface sLocEngNiInterface =
126 {
127 sizeof(GpsNiInterface),
128 loc_ni_init,
129 loc_ni_respond,
130 };
131
132 static int loc_gps_measurement_init(GpsMeasurementCallbacks* callbacks);
133 static void loc_gps_measurement_close();
134
135 static const GpsMeasurementInterface sLocEngGpsMeasurementInterface =
136 {
137 sizeof(GpsMeasurementInterface),
138 loc_gps_measurement_init,
139 loc_gps_measurement_close
140 };
141
142 // for XTRA
createSocket()143 static inline int createSocket() {
144 int socketFd = -1;
145
146 if ((socketFd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
147 LOC_LOGe("create socket error. reason:%s", strerror(errno));
148
149 } else {
150 const char* socketPath = "/data/misc/location/xtra/socket_hal_xtra";
151 struct sockaddr_un addr = { .sun_family = AF_UNIX };
152 snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socketPath);
153
154 if (::connect(socketFd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
155 LOC_LOGe("cannot connect to XTRA. reason:%s", strerror(errno));
156 if (::close(socketFd)) {
157 LOC_LOGe("close socket error. reason:%s", strerror(errno));
158 }
159 socketFd = -1;
160 }
161 }
162
163 return socketFd;
164 }
165
closeSocket(const int socketFd)166 static inline void closeSocket(const int socketFd) {
167 if (socketFd >= 0) {
168 if(::close(socketFd)) {
169 LOC_LOGe("close socket error. reason:%s", strerror(errno));
170 }
171 }
172 }
173
sendConnectionEvent(const bool connected,const int8_t type)174 static inline bool sendConnectionEvent(const bool connected, const int8_t type) {
175 int socketFd = createSocket();
176 if (socketFd < 0) {
177 LOC_LOGe("XTRA unreachable. sending failed.");
178 return false;
179 }
180
181 std::stringstream ss;
182 ss << "connection";
183 ss << " " << (connected ? "1" : "0");
184 ss << " " << (int)type;
185 ss << "\n"; // append seperator
186
187 const std::string& data = ss.str();
188 int remain = data.length();
189 ssize_t sent = 0;
190
191 while (remain > 0 &&
192 (sent = ::send(socketFd, data.c_str() + (data.length() - remain),
193 remain, MSG_NOSIGNAL)) > 0) {
194 remain -= sent;
195 }
196
197 if (sent < 0) {
198 LOC_LOGe("sending error. reason:%s", strerror(errno));
199 }
200
201 closeSocket(socketFd);
202
203 return (remain == 0);
204 }
205
206 static void loc_agps_ril_init( AGpsRilCallbacks* callbacks );
207 static void loc_agps_ril_set_ref_location(const AGpsRefLocation *agps_reflocation, size_t sz_struct);
208 static void loc_agps_ril_set_set_id(AGpsSetIDType type, const char* setid);
209 static void loc_agps_ril_ni_message(uint8_t *msg, size_t len);
210 static void loc_agps_ril_update_network_state(int connected, int type, int roaming, const char* extra_info);
211 static void loc_agps_ril_update_network_availability(int avaiable, const char* apn);
212
213 static const AGpsRilInterface sLocEngAGpsRilInterface =
214 {
215 sizeof(AGpsRilInterface),
216 loc_agps_ril_init,
217 loc_agps_ril_set_ref_location,
218 loc_agps_ril_set_set_id,
219 loc_agps_ril_ni_message,
220 loc_agps_ril_update_network_state,
221 loc_agps_ril_update_network_availability
222 };
223
224 static int loc_agps_install_certificates(const DerEncodedCertificate* certificates,
225 size_t length);
226 static int loc_agps_revoke_certificates(const Sha1CertificateFingerprint* fingerprints,
227 size_t length);
228
229 static const SuplCertificateInterface sLocEngAGpsCertInterface =
230 {
231 sizeof(SuplCertificateInterface),
232 loc_agps_install_certificates,
233 loc_agps_revoke_certificates
234 };
235
236 static void loc_configuration_update(const char* config_data, int32_t length);
237
238 static const GnssConfigurationInterface sLocEngConfigInterface =
239 {
240 sizeof(GnssConfigurationInterface),
241 loc_configuration_update
242 };
243
244 static loc_eng_data_s_type loc_afw_data;
245 static int gss_fd = -1;
246 static int sGnssType = GNSS_UNKNOWN;
247 /*===========================================================================
248 FUNCTION gps_get_hardware_interface
249
250 DESCRIPTION
251 Returns the GPS hardware interaface based on LOC API
252 if GPS is enabled.
253
254 DEPENDENCIES
255 None
256
257 RETURN VALUE
258 0: success
259
260 SIDE EFFECTS
261 N/A
262
263 ===========================================================================*/
gps_get_hardware_interface()264 const GpsInterface* gps_get_hardware_interface ()
265 {
266 ENTRY_LOG_CALLFLOW();
267 const GpsInterface* ret_val;
268
269 char propBuf[PROPERTY_VALUE_MAX];
270
271 loc_eng_read_config();
272
273 // check to see if GPS should be disabled
274 property_get("gps.disable", propBuf, "");
275 if (propBuf[0] == '1')
276 {
277 LOC_LOGD("gps_get_interface returning NULL because gps.disable=1\n");
278 ret_val = NULL;
279 } else {
280 ret_val = &sLocEngInterface;
281 }
282
283 loc_eng_read_config();
284
285 EXIT_LOG(%p, ret_val);
286 return ret_val;
287 }
288
289 // for gps.c
get_gps_interface()290 extern "C" const GpsInterface* get_gps_interface()
291 {
292 unsigned int target = TARGET_DEFAULT;
293 loc_eng_read_config();
294
295 target = loc_get_target();
296 LOC_LOGD("Target name check returned %s", loc_get_target_name(target));
297
298 sGnssType = getTargetGnssType(target);
299 switch (sGnssType)
300 {
301 case GNSS_GSS:
302 case GNSS_AUTO:
303 //APQ8064
304 gps_conf.CAPABILITIES &= ~(GPS_CAPABILITY_MSA | GPS_CAPABILITY_MSB);
305 gss_fd = open("/dev/gss", O_RDONLY);
306 if (gss_fd < 0) {
307 LOC_LOGE("GSS open failed: %s\n", strerror(errno));
308 }
309 else {
310 LOC_LOGD("GSS open success! CAPABILITIES %0lx\n",
311 gps_conf.CAPABILITIES);
312 }
313 break;
314 case GNSS_NONE:
315 //MPQ8064
316 LOC_LOGE("No GPS HW on this target. Not returning interface.");
317 return NULL;
318 case GNSS_QCA1530:
319 // qca1530 chip is present
320 gps_conf.CAPABILITIES &= ~(GPS_CAPABILITY_MSA | GPS_CAPABILITY_MSB);
321 LOC_LOGD("qca1530 present: CAPABILITIES %0lx\n", gps_conf.CAPABILITIES);
322 break;
323 }
324 return &sLocEngInterface;
325 }
326
327 /*===========================================================================
328 FUNCTION loc_init
329
330 DESCRIPTION
331 Initialize the location engine, this include setting up global datas
332 and registers location engien with loc api service.
333
334 DEPENDENCIES
335 None
336
337 RETURN VALUE
338 0: success
339
340 SIDE EFFECTS
341 N/Ax
342
343 ===========================================================================*/
loc_init(GpsCallbacks * callbacks)344 static int loc_init(GpsCallbacks* callbacks)
345 {
346 int retVal = -1;
347 ENTRY_LOG();
348 LOC_API_ADAPTER_EVENT_MASK_T event;
349
350 if (NULL == callbacks) {
351 LOC_LOGE("loc_init failed. cb = NULL\n");
352 EXIT_LOG(%d, retVal);
353 return retVal;
354 }
355
356 event = LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT |
357 LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT |
358 LOC_API_ADAPTER_BIT_SATELLITE_REPORT |
359 LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST |
360 LOC_API_ADAPTER_BIT_ASSISTANCE_DATA_REQUEST |
361 LOC_API_ADAPTER_BIT_IOCTL_REPORT |
362 LOC_API_ADAPTER_BIT_STATUS_REPORT |
363 LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT |
364 LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST;
365
366 LocCallbacks clientCallbacks = {local_loc_cb, /* location_cb */
367 callbacks->status_cb, /* status_cb */
368 local_sv_cb, /* sv_status_cb */
369 callbacks->nmea_cb, /* nmea_cb */
370 callbacks->set_capabilities_cb, /* set_capabilities_cb */
371 callbacks->acquire_wakelock_cb, /* acquire_wakelock_cb */
372 callbacks->release_wakelock_cb, /* release_wakelock_cb */
373 callbacks->create_thread_cb, /* create_thread_cb */
374 NULL, /* location_ext_parser */
375 NULL, /* sv_ext_parser */
376 callbacks->request_utc_time_cb, /* request_utc_time_cb */
377 callbacks->set_system_info_cb, /* set_system_info_cb */
378 callbacks->gnss_sv_status_cb, /* gnss_sv_status_cb */
379 };
380
381 gps_loc_cb = callbacks->location_cb;
382 gps_sv_cb = callbacks->sv_status_cb;
383
384 retVal = loc_eng_init(loc_afw_data, &clientCallbacks, event, NULL);
385 loc_afw_data.adapter->mSupportsAgpsRequests = !loc_afw_data.adapter->hasAgpsExtendedCapabilities();
386 loc_afw_data.adapter->mSupportsPositionInjection = !loc_afw_data.adapter->hasCPIExtendedCapabilities();
387 loc_afw_data.adapter->mSupportsTimeInjection = !loc_afw_data.adapter->hasCPIExtendedCapabilities();
388 loc_afw_data.adapter->setGpsLockMsg(0);
389 loc_afw_data.adapter->requestUlp(ContextBase::getCarrierCapabilities());
390
391 if(retVal) {
392 LOC_LOGE("loc_eng_init() fail!");
393 goto err;
394 }
395
396 loc_afw_data.adapter->setPowerVoteRight(loc_get_target() == TARGET_QCA1530);
397 loc_afw_data.adapter->setPowerVote(true);
398
399 LOC_LOGD("loc_eng_init() success!");
400
401 err:
402 EXIT_LOG(%d, retVal);
403 return retVal;
404 }
405
406 /*===========================================================================
407 FUNCTION loc_cleanup
408
409 DESCRIPTION
410 Cleans location engine. The location client handle will be released.
411
412 DEPENDENCIES
413 None
414
415 RETURN VALUE
416 None
417
418 SIDE EFFECTS
419 N/A
420
421 ===========================================================================*/
loc_cleanup()422 static void loc_cleanup()
423 {
424 ENTRY_LOG();
425
426 loc_afw_data.adapter->setPowerVote(false);
427 loc_afw_data.adapter->setGpsLockMsg(gps_conf.GPS_LOCK);
428
429 loc_eng_cleanup(loc_afw_data);
430 gps_loc_cb = NULL;
431 gps_sv_cb = NULL;
432
433 EXIT_LOG(%s, VOID_RET);
434 }
435
436 /*===========================================================================
437 FUNCTION loc_start
438
439 DESCRIPTION
440 Starts the tracking session
441
442 DEPENDENCIES
443 None
444
445 RETURN VALUE
446 0: success
447
448 SIDE EFFECTS
449 N/A
450
451 ===========================================================================*/
loc_start()452 static int loc_start()
453 {
454 ENTRY_LOG();
455 int ret_val = loc_eng_start(loc_afw_data);
456
457 EXIT_LOG(%d, ret_val);
458 return ret_val;
459 }
460
461 /*===========================================================================
462 FUNCTION loc_stop
463
464 DESCRIPTION
465 Stops the tracking session
466
467 DEPENDENCIES
468 None
469
470 RETURN VALUE
471 0: success
472
473 SIDE EFFECTS
474 N/A
475
476 ===========================================================================*/
loc_stop()477 static int loc_stop()
478 {
479 ENTRY_LOG();
480 int ret_val = -1;
481 ret_val = loc_eng_stop(loc_afw_data);
482
483 EXIT_LOG(%d, ret_val);
484 return ret_val;
485 }
486
487 /*===========================================================================
488 FUNCTION loc_set_position_mode
489
490 DESCRIPTION
491 Sets the mode and fix frequency for the tracking session.
492
493 DEPENDENCIES
494 None
495
496 RETURN VALUE
497 0: success
498
499 SIDE EFFECTS
500 N/A
501
502 ===========================================================================*/
loc_set_position_mode(GpsPositionMode mode,GpsPositionRecurrence recurrence,uint32_t min_interval,uint32_t preferred_accuracy,uint32_t preferred_time)503 static int loc_set_position_mode(GpsPositionMode mode,
504 GpsPositionRecurrence recurrence,
505 uint32_t min_interval,
506 uint32_t preferred_accuracy,
507 uint32_t preferred_time)
508 {
509 ENTRY_LOG();
510 int ret_val = -1;
511 LocPositionMode locMode;
512 switch (mode) {
513 case GPS_POSITION_MODE_MS_BASED:
514 locMode = LOC_POSITION_MODE_MS_BASED;
515 break;
516 case GPS_POSITION_MODE_MS_ASSISTED:
517 locMode = LOC_POSITION_MODE_MS_ASSISTED;
518 break;
519 default:
520 locMode = LOC_POSITION_MODE_STANDALONE;
521 break;
522 }
523
524 LocPosMode params(locMode, recurrence, min_interval,
525 preferred_accuracy, preferred_time, NULL, NULL);
526 ret_val = loc_eng_set_position_mode(loc_afw_data, params);
527
528 EXIT_LOG(%d, ret_val);
529 return ret_val;
530 }
531
532 /*===========================================================================
533 FUNCTION loc_inject_time
534
535 DESCRIPTION
536 This is used by Java native function to do time injection.
537
538 DEPENDENCIES
539 None
540
541 RETURN VALUE
542 0
543
544 SIDE EFFECTS
545 N/A
546
547 ===========================================================================*/
loc_inject_time(GpsUtcTime time,int64_t timeReference,int uncertainty)548 static int loc_inject_time(GpsUtcTime time, int64_t timeReference, int uncertainty)
549 {
550 ENTRY_LOG();
551 int ret_val = 0;
552
553 ret_val = loc_eng_inject_time(loc_afw_data, time,
554 timeReference, uncertainty);
555
556 EXIT_LOG(%d, ret_val);
557 return ret_val;
558 }
559
560
561 /*===========================================================================
562 FUNCTION loc_inject_location
563
564 DESCRIPTION
565 This is used by Java native function to do location injection.
566
567 DEPENDENCIES
568 None
569
570 RETURN VALUE
571 0 : Successful
572 error code : Failure
573
574 SIDE EFFECTS
575 N/A
576 ===========================================================================*/
loc_inject_location(double latitude,double longitude,float accuracy)577 static int loc_inject_location(double latitude, double longitude, float accuracy)
578 {
579 ENTRY_LOG();
580
581 int ret_val = 0;
582 ret_val = loc_eng_inject_location(loc_afw_data, latitude, longitude, accuracy);
583
584 EXIT_LOG(%d, ret_val);
585 return ret_val;
586 }
587
588
589 /*===========================================================================
590 FUNCTION loc_delete_aiding_data
591
592 DESCRIPTION
593 This is used by Java native function to delete the aiding data. The function
594 updates the global variable for the aiding data to be deleted. If the GPS
595 engine is off, the aiding data will be deleted. Otherwise, the actual action
596 will happen when gps engine is turned off.
597
598 DEPENDENCIES
599 Assumes the aiding data type specified in GpsAidingData matches with
600 LOC API specification.
601
602 RETURN VALUE
603 None
604
605 SIDE EFFECTS
606 N/A
607
608 ===========================================================================*/
loc_delete_aiding_data(GpsAidingData f)609 static void loc_delete_aiding_data(GpsAidingData f)
610 {
611 ENTRY_LOG();
612
613 loc_eng_delete_aiding_data(loc_afw_data, f);
614
615 EXIT_LOG(%s, VOID_RET);
616 }
617
get_geofence_interface(void)618 const GpsGeofencingInterface* get_geofence_interface(void)
619 {
620 ENTRY_LOG();
621 void *handle;
622 const char *error;
623 typedef const GpsGeofencingInterface* (*get_gps_geofence_interface_function) (void);
624 get_gps_geofence_interface_function get_gps_geofence_interface;
625 static const GpsGeofencingInterface* geofence_interface = NULL;
626
627 dlerror(); /* Clear any existing error */
628
629 handle = dlopen ("libgeofence.so", RTLD_NOW);
630
631 if (!handle)
632 {
633 if ((error = dlerror()) != NULL) {
634 LOC_LOGE ("%s, dlopen for libgeofence.so failed, error = %s\n", __func__, error);
635 }
636 goto exit;
637 }
638 dlerror(); /* Clear any existing error */
639 get_gps_geofence_interface = (get_gps_geofence_interface_function)dlsym(handle, "gps_geofence_get_interface");
640 if ((error = dlerror()) != NULL || NULL == get_gps_geofence_interface) {
641 LOC_LOGE ("%s, dlsym for get_gps_geofence_interface failed, error = %s\n", __func__, error);
642 goto exit;
643 }
644
645 geofence_interface = get_gps_geofence_interface();
646
647 exit:
648 EXIT_LOG(%d, geofence_interface == NULL);
649 return geofence_interface;
650 }
651 /*===========================================================================
652 FUNCTION loc_get_extension
653
654 DESCRIPTION
655 Get the gps extension to support XTRA.
656
657 DEPENDENCIES
658 N/A
659
660 RETURN VALUE
661 The GPS extension interface.
662
663 SIDE EFFECTS
664 N/A
665
666 ===========================================================================*/
loc_get_extension(const char * name)667 const void* loc_get_extension(const char* name)
668 {
669 ENTRY_LOG();
670 const void* ret_val = NULL;
671
672 LOC_LOGD("%s:%d] For Interface = %s\n",__func__, __LINE__, name);
673 if (strcmp(name, GPS_XTRA_INTERFACE) == 0)
674 {
675 ret_val = &sLocEngXTRAInterface;
676 }
677 else if (strcmp(name, AGPS_INTERFACE) == 0)
678 {
679 ret_val = &sLocEngAGpsInterface;
680 }
681 else if (strcmp(name, GPS_NI_INTERFACE) == 0)
682 {
683 ret_val = &sLocEngNiInterface;
684 }
685 else if (strcmp(name, AGPS_RIL_INTERFACE) == 0)
686 {
687 ret_val = &sLocEngAGpsRilInterface;
688 }
689 else if (strcmp(name, GPS_GEOFENCING_INTERFACE) == 0)
690 {
691 if ((gps_conf.CAPABILITIES | GPS_CAPABILITY_GEOFENCING) == gps_conf.CAPABILITIES ){
692 ret_val = get_geofence_interface();
693 }
694 }
695 else if (strcmp(name, SUPL_CERTIFICATE_INTERFACE) == 0)
696 {
697 ret_val = &sLocEngAGpsCertInterface;
698 }
699 else if (strcmp(name, GNSS_CONFIGURATION_INTERFACE) == 0)
700 {
701 ret_val = &sLocEngConfigInterface;
702 }
703 else if (strcmp(name, GPS_MEASUREMENT_INTERFACE) == 0)
704 {
705 ret_val = &sLocEngGpsMeasurementInterface;
706 }
707 else
708 {
709 LOC_LOGE ("get_extension: Invalid interface passed in\n");
710 }
711 EXIT_LOG(%p, ret_val);
712 return ret_val;
713 }
714
715 /*===========================================================================
716 FUNCTION loc_agps_init
717
718 DESCRIPTION
719 Initialize the AGps interface.
720
721 DEPENDENCIES
722 NONE
723
724 RETURN VALUE
725 0
726
727 SIDE EFFECTS
728 N/A
729
730 ===========================================================================*/
loc_agps_init(AGpsCallbacks * callbacks)731 static void loc_agps_init(AGpsCallbacks* callbacks)
732 {
733 ENTRY_LOG();
734 loc_eng_agps_init(loc_afw_data, (AGpsExtCallbacks*)callbacks);
735 EXIT_LOG(%s, VOID_RET);
736 }
737
738 /*===========================================================================
739 FUNCTION loc_agps_open
740
741 DESCRIPTION
742 This function is called when on-demand data connection opening is successful.
743 It should inform ARM 9 about the data open result.
744
745 DEPENDENCIES
746 NONE
747
748 RETURN VALUE
749 0
750
751 SIDE EFFECTS
752 N/A
753
754 ===========================================================================*/
loc_agps_open(const char * apn)755 static int loc_agps_open(const char* apn)
756 {
757 ENTRY_LOG();
758 AGpsType agpsType = AGPS_TYPE_SUPL;
759 AGpsBearerType bearerType = AGPS_APN_BEARER_IPV4;
760 int ret_val = loc_eng_agps_open(loc_afw_data, agpsType, apn, bearerType);
761
762 EXIT_LOG(%d, ret_val);
763 return ret_val;
764 }
765
766 /*===========================================================================
767 FUNCTION loc_agps_open_with_apniptype
768
769 DESCRIPTION
770 This function is called when on-demand data connection opening is successful.
771 It should inform ARM 9 about the data open result.
772
773 DEPENDENCIES
774 NONE
775
776 RETURN VALUE
777 0
778
779 SIDE EFFECTS
780 N/A
781
782 ===========================================================================*/
loc_agps_open_with_apniptype(const char * apn,ApnIpType apnIpType)783 static int loc_agps_open_with_apniptype(const char* apn, ApnIpType apnIpType)
784 {
785 ENTRY_LOG();
786 AGpsType agpsType = AGPS_TYPE_SUPL;
787 AGpsBearerType bearerType;
788
789 switch (apnIpType) {
790 case APN_IP_IPV4:
791 bearerType = AGPS_APN_BEARER_IPV4;
792 break;
793 case APN_IP_IPV6:
794 bearerType = AGPS_APN_BEARER_IPV6;
795 break;
796 case APN_IP_IPV4V6:
797 bearerType = AGPS_APN_BEARER_IPV4V6;
798 break;
799 default:
800 bearerType = AGPS_APN_BEARER_IPV4;
801 break;
802 }
803
804 int ret_val = loc_eng_agps_open(loc_afw_data, agpsType, apn, bearerType);
805
806 EXIT_LOG(%d, ret_val);
807 return ret_val;
808 }
809
810 /*===========================================================================
811 FUNCTION loc_agps_closed
812
813 DESCRIPTION
814 This function is called when on-demand data connection closing is done.
815 It should inform ARM 9 about the data close result.
816
817 DEPENDENCIES
818 NONE
819
820 RETURN VALUE
821 0
822
823 SIDE EFFECTS
824 N/A
825
826 ===========================================================================*/
loc_agps_closed()827 static int loc_agps_closed()
828 {
829 ENTRY_LOG();
830 AGpsType agpsType = AGPS_TYPE_SUPL;
831 int ret_val = loc_eng_agps_closed(loc_afw_data, agpsType);
832
833 EXIT_LOG(%d, ret_val);
834 return ret_val;
835 }
836
837 /*===========================================================================
838 FUNCTION loc_agps_open_failed
839
840 DESCRIPTION
841 This function is called when on-demand data connection opening has failed.
842 It should inform ARM 9 about the data open result.
843
844 DEPENDENCIES
845 NONE
846
847 RETURN VALUE
848 0
849
850 SIDE EFFECTS
851 N/A
852
853 ===========================================================================*/
loc_agps_open_failed()854 int loc_agps_open_failed()
855 {
856 ENTRY_LOG();
857 AGpsType agpsType = AGPS_TYPE_SUPL;
858 int ret_val = loc_eng_agps_open_failed(loc_afw_data, agpsType);
859
860 EXIT_LOG(%d, ret_val);
861 return ret_val;
862 }
863
864 /*===========================================================================
865 FUNCTION loc_agps_set_server
866
867 DESCRIPTION
868 If loc_eng_set_server is called before loc_eng_init, it doesn't work. This
869 proxy buffers server settings and calls loc_eng_set_server when the client is
870 open.
871
872 DEPENDENCIES
873 NONE
874
875 RETURN VALUE
876 0
877
878 SIDE EFFECTS
879 N/A
880
881 ===========================================================================*/
loc_agps_set_server(AGpsType type,const char * hostname,int port)882 static int loc_agps_set_server(AGpsType type, const char* hostname, int port)
883 {
884 ENTRY_LOG();
885 LocServerType serverType;
886 switch (type) {
887 case AGPS_TYPE_SUPL:
888 serverType = LOC_AGPS_SUPL_SERVER;
889 break;
890 case AGPS_TYPE_C2K:
891 serverType = LOC_AGPS_CDMA_PDE_SERVER;
892 break;
893 default:
894 serverType = LOC_AGPS_SUPL_SERVER;
895 }
896 int ret_val = loc_eng_set_server_proxy(loc_afw_data, serverType, hostname, port);
897
898 EXIT_LOG(%d, ret_val);
899 return ret_val;
900 }
901
902 /*===========================================================================
903 FUNCTIONf571
904 loc_xtra_init
905
906 DESCRIPTION
907 Initialize XTRA module.
908
909 DEPENDENCIES
910 None
911
912 RETURN VALUE
913 0: success
914
915 SIDE EFFECTS
916 N/A
917
918 ===========================================================================*/
loc_xtra_init(GpsXtraCallbacks * callbacks)919 static int loc_xtra_init(GpsXtraCallbacks* callbacks)
920 {
921 ENTRY_LOG();
922 GpsXtraExtCallbacks extCallbacks;
923 memset(&extCallbacks, 0, sizeof(extCallbacks));
924 extCallbacks.download_request_cb = callbacks->download_request_cb;
925 int ret_val = loc_eng_xtra_init(loc_afw_data, &extCallbacks);
926
927 EXIT_LOG(%d, ret_val);
928 return ret_val;
929 }
930
931
932 /*===========================================================================
933 FUNCTION loc_xtra_inject_data
934
935 DESCRIPTION
936 Initialize XTRA module.
937
938 DEPENDENCIES
939 None
940
941 RETURN VALUE
942 0: success
943
944 SIDE EFFECTS
945 N/A
946
947 ===========================================================================*/
loc_xtra_inject_data(char * data,int length)948 static int loc_xtra_inject_data(char* data, int length)
949 {
950 ENTRY_LOG();
951 int ret_val = -1;
952 if( (data != NULL) && ((unsigned int)length <= XTRA_DATA_MAX_SIZE))
953 ret_val = loc_eng_xtra_inject_data(loc_afw_data, data, length);
954 else
955 LOC_LOGE("%s, Could not inject XTRA data. Buffer address: %p, length: %d",
956 __func__, data, length);
957 EXIT_LOG(%d, ret_val);
958 return ret_val;
959 }
960
961 /*===========================================================================
962 FUNCTION loc_gps_measurement_init
963
964 DESCRIPTION
965 This function initializes the gps measurement interface
966
967 DEPENDENCIES
968 NONE
969
970 RETURN VALUE
971 None
972
973 SIDE EFFECTS
974 N/A
975
976 ===========================================================================*/
loc_gps_measurement_init(GpsMeasurementCallbacks * callbacks)977 static int loc_gps_measurement_init(GpsMeasurementCallbacks* callbacks)
978 {
979 ENTRY_LOG();
980 int ret_val = loc_eng_gps_measurement_init(loc_afw_data,
981 callbacks);
982
983 EXIT_LOG(%d, ret_val);
984 return ret_val;
985 }
986
987 /*===========================================================================
988 FUNCTION loc_gps_measurement_close
989
990 DESCRIPTION
991 This function closes the gps measurement interface
992
993 DEPENDENCIES
994 NONE
995
996 RETURN VALUE
997 None
998
999 SIDE EFFECTS
1000 N/A
1001
1002 ===========================================================================*/
loc_gps_measurement_close()1003 static void loc_gps_measurement_close()
1004 {
1005 ENTRY_LOG();
1006 loc_eng_gps_measurement_close(loc_afw_data);
1007
1008 EXIT_LOG(%s, VOID_RET);
1009 }
1010
1011 /*===========================================================================
1012 FUNCTION loc_ni_init
1013
1014 DESCRIPTION
1015 This function initializes the NI interface
1016
1017 DEPENDENCIES
1018 NONE
1019
1020 RETURN VALUE
1021 None
1022
1023 SIDE EFFECTS
1024 N/A
1025
1026 ===========================================================================*/
loc_ni_init(GpsNiCallbacks * callbacks)1027 void loc_ni_init(GpsNiCallbacks *callbacks)
1028 {
1029 ENTRY_LOG();
1030 loc_eng_ni_init(loc_afw_data,(GpsNiExtCallbacks*) callbacks);
1031 EXIT_LOG(%s, VOID_RET);
1032 }
1033
1034 /*===========================================================================
1035 FUNCTION loc_ni_respond
1036
1037 DESCRIPTION
1038 This function sends an NI respond to the modem processor
1039
1040 DEPENDENCIES
1041 NONE
1042
1043 RETURN VALUE
1044 None
1045
1046 SIDE EFFECTS
1047 N/A
1048
1049 ===========================================================================*/
loc_ni_respond(int notif_id,GpsUserResponseType user_response)1050 void loc_ni_respond(int notif_id, GpsUserResponseType user_response)
1051 {
1052 ENTRY_LOG();
1053 loc_eng_ni_respond(loc_afw_data, notif_id, user_response);
1054 EXIT_LOG(%s, VOID_RET);
1055 }
1056
1057 // Below stub functions are members of sLocEngAGpsRilInterface
loc_agps_ril_init(AGpsRilCallbacks * callbacks)1058 static void loc_agps_ril_init( AGpsRilCallbacks* callbacks ) {}
loc_agps_ril_set_ref_location(const AGpsRefLocation * agps_reflocation,size_t sz_struct)1059 static void loc_agps_ril_set_ref_location(const AGpsRefLocation *agps_reflocation, size_t sz_struct) {}
loc_agps_ril_set_set_id(AGpsSetIDType type,const char * setid)1060 static void loc_agps_ril_set_set_id(AGpsSetIDType type, const char* setid) {}
loc_agps_ril_ni_message(uint8_t * msg,size_t len)1061 static void loc_agps_ril_ni_message(uint8_t *msg, size_t len) {}
loc_agps_ril_update_network_state(int connected,int type,int roaming,const char * extra_info)1062 static void loc_agps_ril_update_network_state(int connected, int type, int roaming, const char* extra_info) {
1063 ENTRY_LOG();
1064 // for XTRA
1065 sendConnectionEvent((connected != 0) ? true : false, type);
1066
1067 EXIT_LOG(%s, VOID_RET);
1068 }
1069
1070 /*===========================================================================
1071 FUNCTION loc_agps_ril_update_network_availability
1072
1073 DESCRIPTION
1074 Sets data call allow vs disallow flag to modem
1075 This is the only member of sLocEngAGpsRilInterface implemented.
1076
1077 DEPENDENCIES
1078 None
1079
1080 RETURN VALUE
1081 0: success
1082
1083 SIDE EFFECTS
1084 N/A
1085
1086 ===========================================================================*/
loc_agps_ril_update_network_availability(int available,const char * apn)1087 static void loc_agps_ril_update_network_availability(int available, const char* apn)
1088 {
1089 ENTRY_LOG();
1090 char baseband[PROPERTY_VALUE_MAX];
1091 property_get("ro.baseband", baseband, "msm");
1092 if (strcmp(baseband, "csfb") == 0)
1093 {
1094 loc_eng_agps_ril_update_network_availability(loc_afw_data, available, apn);
1095 }
1096 EXIT_LOG(%s, VOID_RET);
1097 }
1098
loc_agps_install_certificates(const DerEncodedCertificate * certificates,size_t length)1099 static int loc_agps_install_certificates(const DerEncodedCertificate* certificates,
1100 size_t length)
1101 {
1102 ENTRY_LOG();
1103 int ret_val = loc_eng_agps_install_certificates(loc_afw_data, certificates, length);
1104 EXIT_LOG(%d, ret_val);
1105 return ret_val;
1106 }
loc_agps_revoke_certificates(const Sha1CertificateFingerprint * fingerprints,size_t length)1107 static int loc_agps_revoke_certificates(const Sha1CertificateFingerprint* fingerprints,
1108 size_t length)
1109 {
1110 ENTRY_LOG();
1111 LOC_LOGE("%s:%d]: agps_revoke_certificates not supported");
1112 int ret_val = AGPS_CERTIFICATE_ERROR_GENERIC;
1113 EXIT_LOG(%d, ret_val);
1114 return ret_val;
1115 }
1116
loc_configuration_update(const char * config_data,int32_t length)1117 static void loc_configuration_update(const char* config_data, int32_t length)
1118 {
1119 ENTRY_LOG();
1120 loc_eng_configuration_update(loc_afw_data, config_data, length);
1121 switch (sGnssType)
1122 {
1123 case GNSS_GSS:
1124 case GNSS_AUTO:
1125 case GNSS_QCA1530:
1126 //APQ
1127 gps_conf.CAPABILITIES &= ~(GPS_CAPABILITY_MSA | GPS_CAPABILITY_MSB);
1128 break;
1129 }
1130 EXIT_LOG(%s, VOID_RET);
1131 }
1132
local_loc_cb(UlpLocation * location,void * locExt)1133 static void local_loc_cb(UlpLocation* location, void* locExt)
1134 {
1135 ENTRY_LOG();
1136 if (NULL != location) {
1137 CALLBACK_LOG_CALLFLOW("location_cb - from", %d, location->position_source);
1138
1139 if (NULL != gps_loc_cb) {
1140 gps_loc_cb(&location->gpsLocation);
1141 }
1142 }
1143 EXIT_LOG(%s, VOID_RET);
1144 }
1145
local_sv_cb(GpsSvStatus * sv_status,void * svExt)1146 static void local_sv_cb(GpsSvStatus* sv_status, void* svExt)
1147 {
1148 ENTRY_LOG();
1149 if (NULL != gps_sv_cb) {
1150 CALLBACK_LOG_CALLFLOW("sv_status_cb -", %d, sv_status->num_svs);
1151 gps_sv_cb(sv_status);
1152 }
1153 EXIT_LOG(%s, VOID_RET);
1154 }
1155
1156