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