• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_HDI_LOCATION_LOCATION_VENDOR_LIB_H
17 #define OHOS_HDI_LOCATION_LOCATION_VENDOR_LIB_H
18 
19 #include <cstdint>
20 #include <sys/socket.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define SV_NUM_MAX 64
27 
28 enum class AgnssSetIdClass {
29     AGNSS_SETID_CLASS_NONE = 0,
30     AGNSS_SETID_CLASS_IMSI = 1,
31     AGNSS_SETID_CLASS_MSISDM = 2,
32 };
33 
34 enum class AgnssRefLocClass {
35     AGNSS_REF_LOC_CLASS_CELLID = 1,
36     AGNSS_REF_LOC_CLASS_MAC = 2,
37 };
38 
39 enum class GnssStartClass {
40     GNSS_START_CLASS_NORMAL = 1,
41     GNSS_START_CLASS_GNSS_CACHE = 2,
42 };
43 
44 enum class CellIdClass {
45     GSM_CELLID = 1,
46     UMTS_CELLID = 2,
47     LTE_CELLID = 3,
48     NR_CELLID = 4,
49 };
50 
51 enum class ApnIpClass {
52     APN_CLASS_INVALID = 0,
53     APN_CLASS_IPV4 = 1,
54     APN_CLASS_IPV6 = 2,
55     APN_CLASS_IPV4V6 = 3
56 };
57 
58 enum class AgnssDataConnStatus {
59     /* AGNSS data connecting. */
60     AGNSS_DATA_CONN_CONNECTING = 1,
61     /* AGNSS data connection initiated. */
62     AGNSS_DATA_CONN_CONNECTED = 2,
63     /* AGNSS data disconnecting. */
64     AGNSS_DATA_CONN_DISCONNECTING = 3,
65     /* AGNSS data disconnected. */
66     AGNSS_DATA_CONN_DISCONNECTED = 4
67 };
68 
69 enum class AgnssClass {
70     AGNSS_CLASS_SUPL = 1,
71     AGNSS_CLASS_C2K = 2
72 };
73 
74 /*
75  * Constellation class
76  */
77 enum class ConstellationClass {
78     GNSS_CONSTELLATION_UNKNOWN = 0,
79     /* Global Positioning System. */
80     GNSS_CONSTELLATION_GPS = 1,
81     /* Satellite-Based Augmentation System. */
82     GNSS_CONSTELLATION_SBAS = 2,
83     /* Global Navigation Satellite System. */
84     GNSS_CONSTELLATION_GLONASS = 3,
85     /* Quasi-Zenith Satellite System. */
86     GNSS_CONSTELLATION_QZSS = 4,
87     /* BeiDou Navigation Satellite System. */
88     GNSS_CONSTELLATION_BEIDOU = 5,
89     /* Galileo Navigation Satellite System. */
90     GNSS_CONSTELLATION_GALILEO = 6,
91     /* Indian Regional Navigation Satellite System. */
92     GNSS_CONSTELLATION_IRNSS = 7,
93 };
94 
95 /* GNSS working status values. */
96 enum class GnssWorkingStatus {
97     /* GNSS status unknown. */
98     GNSS_STATUS_NONE = 0,
99     /* GNSS has begun navigating. */
100     GNSS_STATUS_SESSION_BEGIN = 1,
101     /* GNSS has stopped navigating. */
102     GNSS_STATUS_SESSION_END = 2,
103     /* GNSS has powered on but is not navigating. */
104     GNSS_STATUS_ENGINE_ON = 3,
105     /* GNSS is powered off. */
106     GNSS_STATUS_ENGINE_OFF = 4
107 };
108 
109 enum class GnssCapabilities {
110     /* GNSS supports MS-Based AGNSS mode */
111     GNSS_CAP_SUPPORT_MSB = (1 << 0),
112     /* GNSS supports MS-Assisted AGNSS mode */
113     GNSS_CAP_SUPPORT_MSA = (1 << 1),
114     /* GNSS supports Geofencing  */
115     GNSS_CAP_SUPPORT_GEOFENCING = (1 << 2),
116     /* GNSS supports Measurements for at least GPS. */
117     GNSS_CAP_SUPPORT_MEASUREMENTS = (1 << 3),
118     /* GNSS supports Navigation Messages */
119     GNSS_CAP_SUPPORT_NAV_MESSAGES = (1 << 4),
120     /* GNSS supports location caching */
121     GNSS_CAP_SUPPORT_GNSS_CACHE = (1 << 5),
122 };
123 
124 enum class SatellitesStatusFlag {
125     SATELLITES_STATUS_NONE = 0,
126     SATELLITES_STATUS_HAS_EPHEMERIS_DATA = 1 << 0,
127     SATELLITES_STATUS_HAS_ALMANAC_DATA = 1 << 1,
128     SATELLITES_STATUS_USED_IN_FIX = 1 << 2,
129     SATELLITES_STATUS_HAS_CARRIER_FREQUENCY = 1 << 3
130 };
131 
132 enum class GnssWorkingMode {
133     GNSS_WORKING_MODE_STANDALONE = 1, /* GNSS standalone (no assistance) */
134     GNSS_WORKING_MODE_MS_BASED = 2, /* AGNSS MS-Based mode */
135     GNSS_WORKING_MODE_MS_ASSISTED = 3 /* AGPS MS-Assisted mode */
136 };
137 
138 enum class GnssRefInfoClass {
139     GNSS_REF_INFO_TIME = 1,
140     GNSS_REF_INFO_LOCATION = 2,
141     GNSS_REF_INFO_BEST_LOCATION = 3,
142 };
143 
144 enum class GnssAuxiliaryDataClass {
145     GNSS_AUXILIARY_DATA_CLASS_EPHEMERIS = 0x0001,
146     GNSS_AUXILIARY_DATA_CLASS_ALMANAC = 0x0002,
147     GNSS_AUXILIARY_DATA_CLASS_POSITION = 0x0004,
148     GNSS_AUXILIARY_DATA_CLASS_TIME = 0x0008,
149     GNSS_AUXILIARY_DATA_CLASS_IONO = 0x0010,
150     GNSS_AUXILIARY_DATA_CLASS_UTC = 0x0020,
151     GNSS_AUXILIARY_DATA_CLASS_HEALTH = 0x0040,
152     GNSS_AUXILIARY_DATA_CLASS_SVDIR = 0x0080,
153     GNSS_AUXILIARY_DATA_CLASS_SVSTEER = 0x0100,
154     GNSS_AUXILIARY_DATA_CLASS_SADATA = 0x0200,
155     GNSS_AUXILIARY_DATA_CLASS_RTI = 0x0400,
156     GNSS_AUXILIARY_DATA_CLASS_CELLDB_INFO = 0x8000,
157     GNSS_AUXILIARY_DATA_CLASS_ALL = 0xFFFF
158 };
159 
160 enum class GnssModuleIfaceClass {
161     AGPS_INTERFACE = 1,
162     GNSS_GEOFENCING_INTERFACE = 2,
163     GNSS_CACHE_INTERFACE = 3,
164 };
165 
166 enum class GeofenceEvent {
167     GEOFENCE_EVENT_UNCERTAIN = (1 << 0),
168     GEOFENCE_EVENT_ENTERED = (1 << 1),
169     GEOFENCE_EVENT_EXITED = (1 << 2),
170 };
171 
172 enum class GeofenceOperateClass {
173     GEOFENCE_ADD = 1,
174     GEOFENCE_DELETE = 2,
175 };
176 
177 enum class GeofenceOperateResult {
178     GEOFENCE_OPERATION_SUCCESS = 0,
179     GEOFENCE_OPERATION_ERROR_UNKNOWN = -100,
180     GEOFENCE_OPERATION_ERROR_TOO_MANY_GEOFENCES = -101,
181     GEOFENCE_OPERATION_ERROR_GEOFENCE_ID_EXISTS = -102,
182     GEOFENCE_OPERATION_ERROR_PARAMS_INVALID = -103,
183 };
184 
185 /* CellID info struct. */
186 typedef struct {
187     size_t size;
188     /* See CellIdClass for the definition of type. */
189     uint16_t type;
190     /* Mobile Country Code. */
191     uint16_t mcc;
192     /* Mobile Network Code. */
193     uint16_t mnc;
194     /* Location Area Code in 2G, 3G and LTE. */
195     uint16_t lac;
196     /* 2G:Cell id. 3G:Utran Cell id. LTE:Cell Global Id EUTRA. */
197     uint32_t cid;
198     /* Tracking Area Code in LTE. */
199     uint16_t tac;
200     /* Physical Cell id in LTE. */
201     uint16_t pcid;
202 } AGnssRefInfoCellId;
203 
204 typedef struct {
205     size_t size;
206     uint8_t mac[6];
207 } AGnssRefInfoMac;
208 
209 /* Agnss reference location information structure */
210 typedef struct {
211     size_t size;
212     /* See AgnssRefLocClass for the definition of type. */
213     uint32_t type;
214     union {
215         AGnssRefInfoCellId cellId;
216         AGnssRefInfoMac mac;
217     } u;
218 } AGnssRefLocInfo;
219 
220 /* GNSS position structure. */
221 typedef struct {
222     size_t size;
223     uint32_t flags;
224     double latitude;
225     double longitude;
226     /* Altitude in meters. */
227     double altitude;
228     /* Speed in meters per second. */
229     float speed;
230     /* Heading in degrees. */
231     float bearing;
232     /*
233      * Represents expected horizontal position accuracy, radial, in meters
234      * (68% confidence).
235      */
236     float horizontalAccuracy;
237     /*
238      * Represents expected vertical position accuracy in meters
239      * (68% confidence).
240      */
241     float verticalAccuracy;
242     /*
243      * Represents expected speed accuracy in meter per seconds
244      * (68% confidence).
245      */
246     float speedAccuracy;
247     /*
248      * Represents expected bearing accuracy in degrees
249      * (68% confidence).
250      */
251     float bearingAccuracy;
252     /* Timestamp for the location fix.Milliseconds since January 1, 1970. */
253     int64_t timestamp;
254     /* Timestamp since boot.Milliseconds since January 1, 1970. */
255     int64_t timestampSinceBoot;
256 } GnssLocation;
257 
258 typedef struct {
259     size_t size;
260     /* min interval between locations in ms. */
261     uint32_t interval;
262     /* If the value is true, the cached locations
263      *  are reported and the AP is woken up after the FIFO is full.
264      */
265     bool fifoFullNotify;
266 } GnssCachingConfig;
267 
268 /*
269  * Represents Satellite Statu info.
270  */
271 typedef struct {
272     size_t size;
273     /*
274      * Pseudo-random or satellite ID number for the satellite, a.k.a. Space Vehicle (SV), or
275      * FCN/OSN number for Glonass. The distinction is made by looking at constellation field.
276      * Values must be in the range of:
277      *
278      * - GNSS:    1-32
279      * - SBAS:    120-151, 183-192
280      * - GLONASS: 1-24, the orbital slot number (OSN), if known.  Or, if not:
281      *            93-106, the frequency channel number (FCN) (-7 to +6) offset by
282      *            + 100
283      *            i.e. report an FCN of -7 as 93, FCN of 0 as 100, and FCN of +6
284      *            as 106.
285      * - QZSS:    193-200
286      * - Galileo: 1-36
287      * - Beidou:  1-37
288      * - IRNSS:   1-14
289      */
290     int16_t satelliteId;
291 
292     /* Defines the constellation type.
293      * See ConstellationClass for the definition of constellationType */
294     uint8_t constellationType;
295 
296     /* Carrier-to-noise density in dB-Hz */
297     float cn0;
298 
299     /* Elevation of SV in degrees. */
300     float elevation;
301 
302     /* Azimuth of SV in degrees. */
303     float azimuth;
304 
305     /* Carrier frequency of the signal tracked. */
306     float carrierFrequencie;
307 
308     /* See SatellitesStatusFlag for the definition of flag. */
309     uint32_t flag;
310 } SatelliteStatusInfo;
311 
312 /*
313  * Represents all satellite status info.
314  */
315 typedef struct {
316     /* set to sizeof(GnssSatelliteStatus) */
317     size_t size;
318 
319     /* Number of GNSS SVs currently visible. */
320     uint32_t satellitesNum;
321 
322     /* Pointer to an array of SVs information for all GNSS constellations. */
323     SatelliteStatusInfo satellitesList[SV_NUM_MAX];
324 } GnssSatelliteStatus;
325 
326 /*  Callback with location information. */
327 typedef void (* on_location_change)(GnssLocation* location);
328 
329 /*
330  * Callback with gnss working status information.
331  * Parameters:
332  *      status  - Working status of GNSS chip.
333  *                See GnssWorkingStatus for the definition of status.
334  */
335 typedef void (* on_gnss_status_change)(uint16_t* status);
336 
337 /* Callback with satellite status information. */
338 typedef void (* on_sv_status_change)(GnssSatelliteStatus* status);
339 
340 /*
341  * Callback for reporting NMEA info.
342  * Parameters:
343  *      timestamp   - Timestamp when the nmea was reported. Milliseconds since January 1, 1970.
344  *      nmea  - NMEA string.
345  *      length  - length of NMEA string.
346  */
347 typedef void (* on_gnss_nmea_change)(int64_t timestamp, const char* nmea, int length);
348 
349 /*
350  * Callback to reporting the GNSS capabilities.
351  * Parameters:
352  *      capabilities   - GNSS capabilities,See GnssCapabilities for the definition of capabilities.
353  */
354 typedef void (* on_capabilities_change)(uint32_t capabilities);
355 
356 /*
357  * Request Delivery Reference Information.
358  * Parameters:
359  *      type   - Type of GNSS reference information,See GnssRefInfoClass for the definition of type.
360  */
361 typedef void (* request_reference_information)(int type);
362 
363 /* Gnss basic config structure. */
364 typedef struct {
365     size_t size;
366     uint32_t minInterval; /* min interval between locations in ms */
367     int gnssMode; /* See GnssWorkingMode for the definition of gnssMode */
368 } GnssBasicConfigPara;
369 
370 /* GNSS config structure. */
371 typedef struct {
372     size_t size;
373     /*
374      * Indicates the method of location reporting,
375      * whether to report immediately or after caching for a
376      * period of time. See GnssStartClass for the definition of type.
377      */
378     uint32_t type;
379     union {
380         GnssBasicConfigPara gnssBasicConfig;
381         GnssCachingConfig gnssCacheConfig;
382     } u;
383 } GnssConfigPara;
384 
385 /* Gnss reference time. */
386 typedef struct {
387     size_t size;
388     int64_t time; /* Milliseconds since January 1, 1970. */
389     int64_t timeReference; /* Milliseconds since January 1, 1970. */
390     int uncertainty;
391 } GnssRefTime;
392 
393 /* Gnss reference position. */
394 typedef struct {
395     size_t size;
396     double latitude;
397     double longitude;
398     float accuracy;
399 } GnssRefLocation;
400 
401 /* Gnss reference information structure. */
402 typedef struct {
403     size_t size;
404     /*
405      * Type of GNSS reference information,
406      * See GnssRefInfoClass for the definition of type.
407      */
408     int type;
409     union {
410         GnssRefTime time;
411         GnssRefLocation location;
412         GnssLocation bestLocation;
413     } u;
414 } GnssRefInfo;
415 
416 /* Callback to request the client to download XTRA data. */
417 typedef void (* extended_ephemeris_download_request)(void);
418 
419 /* GNSS cache location information reporting. */
420 typedef void (* on_cached_locations_change)(const GnssLocation** locationArray, size_t len);
421 
422 /* GNSS basic callback functions. */
423 typedef struct {
424     size_t size;
425     on_location_change locationUpdate;
426     on_gnss_status_change statusUpdate;
427     on_sv_status_change svStatusUpdate;
428     on_gnss_nmea_change nmeaUpdate;
429     on_capabilities_change capabilitiesUpdate;
430     request_reference_information refInfoRequest;
431     extended_ephemeris_download_request downloadRequestCb;
432 } GnssBasicCallbackIfaces;
433 
434 /* GNSS cache callback functions. */
435 typedef struct {
436     size_t size;
437     on_cached_locations_change cachedLocationCb;
438 } GnssCacheCallbackIfaces;
439 
440 /* GNSS callback structure. */
441 typedef struct {
442     size_t size;
443     GnssBasicCallbackIfaces gnssCb;
444     GnssCacheCallbackIfaces gnssCacheCb;
445 } GnssCallbackStruct;
446 
447 /* GNSS vendor interface definition. */
448 typedef struct {
449     size_t size;
450 
451     /* Enable the GNSS function.Initializing the GNSS Chip. */
452     int (* enable_gnss)(GnssCallbackStruct* callbacks);
453 
454     /* Disables the GNSS function. */
455     int (* disable_gnss)(void);
456 
457     /* start navigating.See GnssStartClass for the definition of type. */
458     int (* start_gnss)(uint32_t type);
459 
460     /* Stops navigating.See GnssStartClass for the definition of type. */
461     int (* stop_gnss)(uint32_t type);
462 
463     /* Inject reference information into the GNSS chip.
464      * See GnssRefInfoClass for the definition of type. */
465     int (* injects_reference_information)(int type, GnssRefInfo* info);
466 
467     /* Set gnss configuration parameters. */
468     int (* set_gnss_config_para)(GnssConfigPara* para);
469 
470     /*
471      * Specifies that the next call to start will not use the
472      * information defined in the flags.
473      * See GnssAuxiliaryDataClass for the definition of flags.
474      */
475     void (* remove_auxiliary_data)(uint16_t flags);
476 
477     /* Injects XTRA data into the GNSS. */
478     int (* inject_extended_ephemeris)(char* data, int length);
479 
480     /* Return the cached locations size. */
481     int (* get_cached_locations_size)();
482 
483     /* Retrieve all cached locations currently stored and clear the buffer. */
484     void (* flush_cached_gnss_locations)();
485 
486     /* Get a pointer to gnss module interface.See GnssModuleIfaceClass for the definition of iface. */
487     const void* (* get_gnss_module_iface)(int iface);
488 } GnssVendorInterface;
489 
490 struct GnssVendorDevice {
491     size_t size;
492     const GnssVendorInterface* (*get_gnss_interface)();
493 };
494 
495 /* Status of AGNSS. */
496 typedef struct {
497     size_t size;
498     /* See AgnssClass for the definition of agnss_type */
499     uint16_t agnssType;
500     /* See AgnssDataConnStatus for the definition of conn_status. */
501     uint16_t connStatus;
502     /* IPv4 address. */
503     uint32_t ipaddr;
504     /* Contain the IPv4 (AF_INET) or IPv6 (AF_INET6) address to report. */
505     struct sockaddr_storage sockAddr;
506 } AGnssStatusInfo;
507 
508 typedef void (* on_agnss_status_change)(const AGnssStatusInfo* status);
509 
510 /*
511  * Callback function for requesting setid.
512  * Parameters:
513  *      type   - Type of setid,See enum class agnssetidclass for the definition of type.
514  */
515 typedef void (* get_setid_cb)(uint16_t type);
516 
517 /*
518  * Callback function for requesting setid.
519  * Parameters:
520  *      type   - Type of Type of reference location,See enum class AgnssRefLocClass for the definition of type.
521  */
522 typedef void (* get_ref_location_cb)(uint32_t type);
523 
524 typedef struct {
525     size_t size;
526     on_agnss_status_change agnssStatusChange;
527     get_setid_cb getSetid;
528     get_ref_location_cb getRefLoc;
529 } AGnssCallbackIfaces;
530 
531 /* interface for AGNSS support */
532 typedef struct {
533     size_t size;
534 
535     /*
536      * Opens the AGNSS interface and provides the callback interfaces
537      */
538     bool (* set_agnss_callback)(AGnssCallbackIfaces* callbacks);
539 
540     /*
541      * Sets the reference cell id.
542      */
543     bool (* set_ref_location)(const AGnssRefLocInfo* refLoc);
544 
545     /*
546      * Sets the set ID.
547      * Parameters:
548      *      type   - Type of setid,See enum class agnssetidclass for the definition of type.
549      *      setid  - String to hold setid.
550      *      len    - length of setid.
551      */
552     bool (* set_setid)(uint16_t type, const char* setid, size_t len);
553 
554     /*
555      * Setting the Agnss Server Information.
556      * Parameters:
557      * type    - type of agnss.See AgnssClass for the definition of type.
558      * server  - agnss server.
559      * len     - length of server string.
560      * port    - port of agnss server.
561      */
562     bool (* set_agnss_server)(uint16_t type, const char* server, size_t len, int32_t port);
563 } AGnssModuleInterface;
564 
565 /*
566  * The callback associated with the geofence.
567  * Parameters:
568  *      geofence_id - The id associated with the add_gnss_geofence.
569  *      location    - The current GNSS location.
570  *      event  - Can be one of GEOFENCE_EVENT_UNCERTAIN, GEOFENCE_EVENT_ENTERED,
571  *                    GEOFENCE_EVENT_EXITED.
572  *      timestamp   - Timestamp when the transition was detected. Milliseconds since January 1, 1970.
573  */
574 typedef void (* geofence_event_callback)(int32_t geofenceId,  GnssLocation* location,
575     int32_t event, int64_t timestamp);
576 
577 /*
578  * Callback function that indicates whether the geofence service is available.
579  *
580  * Parameters:
581  *  is_available is true when gnss geofence service is available.
582  */
583 typedef void (* geofence_availability_callback)(bool isAvailable);
584 
585 /*
586  * Callback function indicating the result of the geofence operation
587  *
588  * geofence_id - Id of the geofence.
589  * operate_type - geofence operate type.
590  * result - GEOFENCE_OPERATION_SUCCESS
591  *          GEOFENCE_OPERATION_ERROR_TOO_MANY_GEOFENCES  - geofence limit has been reached.
592  *          GEOFENCE_OPERATION_ERROR_GEOFENCE_ID_EXISTS  - geofence with id already exists
593  *          GEOFENCE_OPERATION_ERROR_PARAMS_INVALID - input params are invalid.
594  */
595 typedef void (* geofence_operate_result_callback)(int32_t geofenceId, int32_t operateType,
596     int32_t result);
597 
598 typedef struct {
599     size_t size;
600     geofence_availability_callback on_geofence_availability_change;
601     geofence_event_callback geofence_event_notify;
602     geofence_operate_result_callback geofence_operate_result_cb;
603 } GeofenceCallbackIfaces;
604 
605 /* Interface for GNSS Geofence */
606 typedef struct {
607     size_t size;
608 
609     /*
610      * Opens the geofence interface and provides the callback interfaces.
611      */
612     bool (* set_callback)(GeofenceCallbackIfaces* callbacks);
613 
614     /*
615      * Add a geofence area. This api currently supports circular geofences.
616      * Parameters:
617      *    geofence_id - The id for the geofence.
618      *    latitude, longtitude, radius_meters - The lat, long and radius
619      *       (in meters) for the geofence
620      *    monitor_event - Which transitions to monitor. Bitwise OR of
621      *       GEOFENCE_EVENT_UNCERTAIN, GEOFENCE_EVENT_ENTERED and
622      *       GEOFENCE_EVENT_EXITED.
623      */
624     bool (* add_gnss_geofence)(int32_t geofenceId, double latitude, double longitude,
625        double radius, int32_t monitorEvent);
626 
627     /*
628      * Remove a gnss geofence.
629      * geofence_id - The id for the geofence.
630      * Return true if delete successful.
631      */
632     bool (* delete_gnss_geofence)(int32_t geofenceId);
633 } GeofenceModuleInterface;
634 
635 #ifdef __cplusplus
636 }
637 #endif
638 
639 #endif /* OHOS_HDI_LOCATION_LOCATION_VENDOR_LIB_H */
640