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  namespace OHOS {
23  namespace HDI {
24  namespace Location {
25  
26  #define SATELLITE_NUM_MAXIMUM 128
27  #define APN_LENGTH_MAXIMUM 64
28  #define GNSS_NI_SUPPLICANT_INFO_LENGTH_MAXIMUM 256
29  #define GNSS_NI_NOTIFICATION_TEXT_LENGTH_MAXIMUM 2048
30  
31  enum class GnssLocationValidity {
32      GNSS_LOCATION_LAT_VALID = (1 << 0),
33      GNSS_LOCATION_LONG_VALID = (1 << 1),
34      GNSS_LOCATION_ALTITUDE_VALID = (1 << 2),
35      GNSS_LOCATION_SPEED_VALID = (1 << 3),
36      GNSS_LOCATION_BEARING_VALID = (1 << 4),
37      GNSS_LOCATION_HORIZONTAL_ACCURACY_VALID = (1 << 5),
38      GNSS_LOCATION_VERTICAL_ACCURACY_VALID = (1 << 6),
39      GNSS_LOCATION_SPEED_ACCURACY_VALID = (1 << 7),
40      GNSS_LOCATION_BEARING_ACCURACY_VALID = (1 << 8),
41      GNSS_LOCATION_TIME_VALID = (1 << 9),
42      GNSS_LOCATION_TIME_SINCE_BOOT_VALID = (1 << 10),
43      GNSS_LOCATION_TIME_UNCERTAINTY_VALID = (1 << 11),
44  };
45  
46  enum class AgnssSetidCategory {
47      AGNSS_SETID_CATEGORY_NULL = 0,
48      AGNSS_SETID_CATEGORY_IMSI = 1,
49      AGNSS_SETID_CATEGORY_MSISDN = 2,
50  };
51  
52  enum class AgnssRefInfoCategory {
53      AGNSS_REF_INFO_CATEGORY_CELLID = 1,
54      AGNSS_REF_INFO_CATEGORY_MAC = 2,
55  };
56  
57  enum class GnssStartCategory {
58      GNSS_START_CATEGORY_NORMAL = 1,
59      GNSS_START_CATEGORY_GNSS_CACHE = 2,
60  };
61  
62  enum class CellIdCategory {
63      CELLID_CATEGORY_GSM = 1,
64      CELLID_CATEGORY_UMTS = 2,
65      CELLID_CATEGORY_LTE = 3,
66      CELLID_CATEGORY_NR = 4,
67  };
68  
69  enum class AgnssDataConnectionSetUpCategory {
70      ESTABLISH_DATA_CONNECTION = 1,
71      RELEASE_DATA_CONNECTION = 2
72  };
73  
74  enum class DataConnectionState {
75      DATA_CONNECTION_DISCONNECTED = 1,
76      DATA_CONNECTION_CONNECTED = 2,
77  };
78  
79  enum class AgnssCategory {
80      AGNSS_CATEGORY_SUPL = 1,
81      AGNSS_CATEGORY_C2K = 2
82  };
83  
84  enum class ApnIpCategory {
85      APN_CATEGORY_INVALID = 0,
86      APN_CATEGORY_IPV4 = 1,
87      APN_CATEGORY_IPV6 = 2,
88      APN_CATEGORY_IPV4V6 = 3
89  };
90  
91  enum class ConstellationCategory {
92      CONSTELLATION_CATEGORY_UNKNOWN = 0,
93      CONSTELLATION_CATEGORY_GPS = 1,
94      CONSTELLATION_CATEGORY_SBAS = 2,
95      CONSTELLATION_CATEGORY_GLONASS = 3,
96      CONSTELLATION_CATEGORY_QZSS = 4,
97      CONSTELLATION_CATEGORY_BEIDOU = 5,
98      CONSTELLATION_CATEGORY_GALILEO = 6,
99      CONSTELLATION_CATEGORY_IRNSS = 7,
100      CONSTELLATION_CATEGORY_MAXIMUM = 8,
101  };
102  
103  enum class GnssWorkingStatus {
104      GNSS_WORKING_STATUS_NULL = 0,
105      GNSS_WORKING_STATUS_NAVIGATING_BEGIN = 1,
106      GNSS_WORKING_STATUS_NAVIGATING_END = 2,
107      GNSS_WORKING_STATUS_POWER_ON = 3,
108      GNSS_WORKING_STATUS_POWER_OFF = 4
109  };
110  
111  enum class GnssCapabilities {
112      GNSS_CAP_SUPPORT_MSB = (1 << 0),
113      GNSS_CAP_SUPPORT_MSA = (1 << 1),
114      GNSS_CAP_SUPPORT_GEOFENCING = (1 << 2),
115      GNSS_CAP_SUPPORT_MEASUREMENTS = (1 << 3),
116      GNSS_CAP_SUPPORT_NAV_MESSAGES = (1 << 4),
117      GNSS_CAP_SUPPORT_GNSS_CACHE = (1 << 5),
118  };
119  
120  enum class SatelliteAdditionalInfo {
121      SATELLITES_ADDITIONAL_INFO_NULL = 0,
122      SATELLITES_ADDITIONAL_INFO_EPHEMERIS_DATA_EXIST = (1 << 0),
123      SATELLITES_ADDITIONAL_INFO_ALMANAC_DATA_EXIST = (1 << 1),
124      SATELLITES_ADDITIONAL_INFO_USED_IN_FIX = (1 << 2),
125      SATELLITES_ADDITIONAL_INFO_CARRIER_FREQUENCY_EXIST = (1 << 3),
126  };
127  
128  enum class GnssWorkingMode {
129      GNSS_WORKING_MODE_STANDALONE = 1,
130      GNSS_WORKING_MODE_MS_BASED = 2,
131      GNSS_WORKING_MODE_MS_ASSISTED = 3
132  };
133  
134  enum class GnssRefInfoCategory {
135      GNSS_REF_INFO_CATEGORY_TIME = 1,
136      GNSS_REF_INFO_CATEGORY_GNSS_LOCATION = 2,
137      GNSS_REF_INFO_CATEGORY_BEST_LOCATION = 3,
138      GNSS_REF_INFO_CATEGORY_GNSS_LOCATION_EMERGENCY = 4,
139      GNSS_REF_INFO_CATEGORY_BEST_LOCATION_EMERGENCY = 5,
140  };
141  
142  enum class GnssAuxiliaryDataCategory {
143      GNSS_AUXILIARY_DATA_CATEGORY_EPHEMERIS = (1 << 0),
144      GNSS_AUXILIARY_DATA_CATEGORY_ALMANAC = (1 << 1),
145      GNSS_AUXILIARY_DATA_CATEGORY_POSITION = (1 << 2),
146      GNSS_AUXILIARY_DATA_CATEGORY_TIME = (1 << 3),
147      GNSS_AUXILIARY_DATA_CATEGORY_IONO = (1 << 4),
148      GNSS_AUXILIARY_DATA_CATEGORY_UTC = (1 << 5),
149      GNSS_AUXILIARY_DATA_CATEGORY_HEALTH = (1 << 6),
150      GNSS_AUXILIARY_DATA_CATEGORY_SVDIR = (1 << 7),
151      GNSS_AUXILIARY_DATA_CATEGORY_SVSTEER = (1 << 8),
152      GNSS_AUXILIARY_DATA_CATEGORY_SADATA = (1 << 9),
153      GNSS_AUXILIARY_DATA_CATEGORY_RTI = (1 << 10),
154      GNSS_AUXILIARY_DATA_CATEGORY_CELLDB_INFO = (1 << 11),
155      GNSS_AUXILIARY_DATA_CATEGORY_ALL = 0xFFFF,
156  };
157  
158  enum class GnssModuleIfaceCategory {
159      AGNSS_MODULE_INTERFACE = 1,
160      GNSS_GEOFENCING_MODULE_INTERFACE = 2,
161      GNSS_NET_INITIATED_MODULE_INTERFACE = 3,
162      GNSS_MEASUREMENT_MODULE_INTERFACE = 4,
163  };
164  
165  enum class GeofenceEvent {
166      GEOFENCE_EVENT_UNCERTAIN = (1 << 0),
167      GEOFENCE_EVENT_ENTERED = (1 << 1),
168      GEOFENCE_EVENT_EXITED = (1 << 2),
169  };
170  
171  enum class GeofenceOperateCategory {
172      GEOFENCE_ADD = 1,
173      GEOFENCE_DELETE = 2,
174  };
175  
176  enum class GeofenceOperateResult {
177      GEOFENCE_OPERATION_SUCCESS = 0,
178      GEOFENCE_OPERATION_ERROR_UNKNOWN = -1,
179      GEOFENCE_OPERATION_ERROR_TOO_MANY_GEOFENCES = -2,
180      GEOFENCE_OPERATION_ERROR_GEOFENCE_ID_EXISTS = -3,
181      GEOFENCE_OPERATION_ERROR_PARAMS_INVALID = -4,
182  };
183  
184  enum class GnssClockValidity {
185      GNSS_CLOCK_FLAG_LEAP_SECOND_VALID = (1 << 0),
186      GNSS_CLOCK_FLAG_TIME_UNCERTAINTY_VALID = (1 << 1),
187      GNSS_CLOCK_FLAG_FULL_BIAS_VALID = (1 << 2),
188      GNSS_CLOCK_FLAG_BIAS_VALID = (1 << 3),
189      GNSS_CLOCK_FLAG_BIAS_UNCERTAINTY_VALID = (1 << 4),
190      GNSS_CLOCK_FLAG_DRIFT_VALID = (1 << 5),
191      GNSS_CLOCK_FLAG_DRIFT_UNCERTAINTY_VALID = (1 << 6),
192      GNSS_CLOCK_FLAG_CLOCK_JUMP_VALID = (1 << 7),
193      GNSS_CLOCK_FLAG_CLOCK_FREQ_BIAS_VALID = (1 << 8),
194      GNSS_CLOCK_FLAG_CLOCK_FREQ_DRIFT_VALID = (1 << 9),
195  };
196  
197  enum class GnssMeasurementValidity {
198      GNSS_MEASUREMENT_SNR_VALID = (1 << 0),
199      GNSS_MEASUREMENT_CARRIER_FREQUENCY_VALID = (1 << 1),
200      GNSS_MEASUREMENT_CARRIER_CYCLES_VALID = (1 << 2),
201      GNSS_MEASUREMENT_CARRIER_PHASE_VALID = (1 << 3),
202      GNSS_MEASUREMENT_CARRIER_PHASE_UNCERTAINTY_VALID = (1 << 4),
203      GNSS_MEASUREMENT_AUTOMATIC_GAIN_CONTROL_VALID = (1 << 5),
204      GNSS_MEASUREMENT_IONO_CORRECT_VALID = (1 << 6),
205      GNSS_MEASUREMENT_TROP_CORRECT_VALID = (1 << 7),
206      GNSS_MEASUREMENT_SVCLOCK_BIAS_VALID = (1 << 8),
207      GNSS_MEASUREMENT_SVCLOCK_DRIFT_VALID = (1 << 9),
208  };
209  
210  enum class SatelliteSyncState {
211      SATELLITE_SYNC_STATE_UNKNOWN = 0,
212      SATELLITE_SYNC_STATE_CODE_LOCK = (1 << 0),
213      SATELLITE_SYNC_STATE_BIT_SYNC = (1 << 1),
214      SATELLITE_SYNC_STATE_SUBFRAME_SYNC = (1 << 2),
215      SATELLITE_SYNC_STATE_TOW_DECODED = (1 << 3),
216      SATELLITE_SYNC_STATE_MSEC_AMBIGUOUS = (1 << 4),
217      SATELLITE_SYNC_STATE_SYMBOL_SYNC = (1 << 5),
218      SATELLITE_SYNC_STATE_GLO_STRING_SYNC = (1 << 6),
219      SATELLITE_SYNC_STATE_GLO_TOD_DECODED = (1 << 7),
220      SATELLITE_SYNC_STATE_BDS_D2_BIT_SYNC = (1 << 8),
221      SATELLITE_SYNC_STATE_BDS_D2_SUBFRAME_SYNC = (1 << 9),
222      SATELLITE_SYNC_STATE_GAL_E1BC_CODE_LOCK = (1 << 10),
223      SATELLITE_SYNC_STATE_GAL_E1C_2ND_CODE_LOCK = (1 << 11),
224      SATELLITE_SYNC_STATE_GAL_E1B_PAGE_SYNC = (1 << 12),
225      SATELLITE_SYNC_STATE_SBAS_SYNC = (1 << 13),
226      SATELLITE_SYNC_STATE_TOW_KNOWN = (1 << 14),
227      SATELLITE_SYNC_STATE_GLO_TOD_KNOWN = (1 << 15),
228      SATELLITE_SYNC_STATE_2ND_CODE_LOCK = (1 << 16),
229  };
230  
231  enum class GnssMeasurementTrackedCodeCategory {
232      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_UNKNOWN = 0,
233      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_A = 1,
234      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_B = 2,
235      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_C = 3,
236      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_I = 4,
237      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_L = 5,
238      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_M = 6,
239      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_N = 7,
240      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_P = 8,
241      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_Q = 9,
242      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_S = 10,
243      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_W = 11,
244      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_X = 12,
245      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_Y = 13,
246      GNSS_MEASUREMENT_TRACKED_CODE_CATEGORY_Z = 14,
247  };
248  
249  enum class GnssAccumulatedDeltaRangeFlag {
250      GNSS_ADR_FLAG_UNKNOWN = 0,
251      GNSS_ADR_FLAG_VALID = (1 << 0),
252      GNSS_ADR_FLAG_RESET = (1 << 1),
253      GNSS_ADR_FLAG_CYCLE_SLIP = (1 << 2),
254      GNSS_ADR_FLAG_HALF_CYCLE_RESOLVED = (1 << 3),
255  };
256  
257  enum class GnssMultipathFlag {
258      GNSS_MULTIPATH_FLAG_UNKNOWN = 0,
259      GNSS_MULTIPATH_FLAG_PRESENT = 1,
260      GNSS_MULTIPATH_FLAG_NOT_PRESENT = 2,
261  };
262  
263  enum class GnssNiRequestCategory {
264      GNSS_NI_REQUEST_CATEGORY_EMERGENCY_SUPL = 1,
265      GNSS_NI_REQUEST_CATEGORY_VOICE = 2,
266      GNSS_NI_REQUEST_CATEGORY_UMTS_CONTROL_PLANE = 3,
267      GNSS_NI_REQUEST_CATEGORY_UMTS_SUPL = 4,
268  };
269  
270  enum class GnssNiResponseCmd {
271      GNSS_NI_RESPONSE_CMD_ACCEPT = 1,
272      GNSS_NI_RESPONSE_CMD_NO_RESPONSE = 2,
273      GNSS_NI_RESPONSE_CMD_REJECT = 3,
274  };
275  
276  enum class GnssNiNotificationCategory {
277      GNSS_NI_NOTIFICATION_REQUIRE_NOTIFY = (1 << 0),
278      GNSS_NI_NOTIFICATION_REQUIRE_VERIFY = (1 << 1),
279      GNSS_NI_NOTIFICATION_REQUIRE_PRIVACY_OVERRIDE = (1 << 2),
280  };
281  
282  enum class GnssNiRequestEncodingFormat {
283      GNSS_NI_ENCODING_FORMAT_NULL = 1,
284      GNSS_NI_ENCODING_FORMAT_SUPL_GSM_DEFAULT = 2,
285      GNSS_NI_ENCODING_FORMAT_SUPL_UCS2 = 3,
286      GNSS_NI_ENCODING_FORMAT_SUPL_UTF8 = 4,
287  };
288  
289  enum class ClockHWFreBiasState {
290      UNKNOWN = 0,
291      NORMAL = 1,
292      ABNORMAL = 2,
293  };
294  
295  enum class ClockHWFreDriftState {
296      UNKNOWN = 0,
297      NORMAL = 1,
298      ABNORMAL = 2,
299  };
300  
301  /*
302   * Definition of Cell ID structure.
303   */
304  typedef struct {
305      size_t size;
306  
307      /* See CellIdCategory for the definition of category. */
308      uint16_t category;
309  
310      /* Mobile Country Code. */
311      uint16_t mcc;
312  
313      /* Mobile Network Code. */
314      uint16_t mnc;
315  
316      /* Location Area Code. */
317      uint16_t lac;
318  
319      /* 2G:Cell id. 3G:Utran Cell id. LTE:Cell Global Id EUTRA. */
320      uint32_t cid;
321  
322      /* Tracking Area Code. */
323      uint16_t tac;
324  
325      /* Physical Cell id. */
326      uint16_t pcid;
327  
328      /* NR cell id */
329      uint64_t nci;
330  } CellId;
331  
332  /*
333   * WiFi MAC information.
334   */
335  typedef struct {
336      size_t size;
337      uint8_t mac[6];
338  } MacInfo;
339  
340  /*
341   * AGNSS reference information.
342   */
343  typedef struct {
344      size_t size;
345  
346      /* See AgnssRefInfoCategory for the definition of category. */
347      uint32_t category;
348  
349      union {
350          CellId cellId;
351          MacInfo mac;
352      } u;
353  } AgnssReferenceInfo;
354  
355  /*
356   * Data service network state.
357   */
358  typedef struct {
359      size_t size;
360  
361      uint32_t netId;
362  
363      /* See ApnIpCategory for the definition of state. */
364      uint32_t apnIpCategory;
365  
366      char apn[APN_LENGTH_MAXIMUM];
367  
368      /* See DataConnectionState for the definition of state. */
369      uint8_t state;
370  } NetworkState;
371  
372  /*
373   * GNSS location structure.
374   */
375  typedef struct {
376      size_t size;
377  
378      /* See GnssLocationValidity for the definition of fieldValidity. */
379      uint32_t fieldValidity;
380  
381      double latitude;
382  
383      double longitude;
384  
385      /* Altitude in meters. */
386      double altitude;
387  
388      /* Speed in meters per second. */
389      float speed;
390  
391      /* Heading in degrees. */
392      float bearing;
393  
394      /* Horizontal position accuracy in meters. */
395      float horizontalAccuracy;
396  
397      /* Vertical position accuracy in meters. */
398      float verticalAccuracy;
399  
400      /* Speed accuracy in meter per seconds. */
401      float speedAccuracy;
402  
403      /* Bearing accuracy in degrees. */
404      float bearingAccuracy;
405  
406      /* Timestamp for the location fix. Number of milliseconds since January 1, 1970. */
407      int64_t timeForFix;
408  
409      /* Time since the system was booted, and include deep sleep. The unit is nanosecond. */
410      uint64_t timeSinceBoot;
411  
412      /* Time uncertainty in nanosecond. */
413      uint64_t timeUncertainty;
414  } GnssLocation;
415  
416  /*
417   * Configuration of the GNSS caching function.
418   */
419  typedef struct {
420      size_t size;
421  
422      /* Minimus interval between locations in millisecond. */
423      uint32_t interval;
424  
425      /*
426       * If the value is true, the cached locations
427       * are reported and the AP is woken up after the FIFO is full.
428       */
429      bool fifoFullNotify;
430  } GnssCachingConfig;
431  
432  /*
433   * Status information of a single satellite.
434   */
435  typedef struct {
436      size_t size;
437  
438      /* Satellite ID number for the satellite. */
439      int16_t satelliteId;
440  
441      /*
442       * Defines the constellation category.
443       * See ConstellationCategory for the definition of constellationCategory.
444       */
445      uint8_t constellationCategory;
446  
447      /* Carrier-to-noise density in dB-Hz. */
448      float cn0;
449  
450      /* Elevation of satellite in degrees. */
451      float elevation;
452  
453      /* Azimuth of satellite in degrees. */
454      float azimuth;
455  
456      /* Carrier frequency of the signal tracked. The unit is Hz. */
457      float carrierFrequency;
458  
459      /* See SatelliteAdditionalInfo for the definition of satelliteAdditionalInfo. */
460      uint32_t satelliteAdditionalInfo;
461  } SatelliteStatusInfo;
462  
463  /*
464   * Status informations of all satellites.
465   */
466  typedef struct {
467      size_t size;
468  
469      /* Number of all satellites that can be viewed. */
470      uint32_t satellitesNum;
471  
472      /* Array of all satellites information. */
473      SatelliteStatusInfo satellitesList[SATELLITE_NUM_MAXIMUM];
474  } GnssSatelliteStatus;
475  
476  /*
477   * Callback for location reporting.
478   */
479  typedef void (*OnLocationChange)(GnssLocation* location);
480  
481  /*
482   * Callback for GNSS working status reporting.
483   * Parameters:
484   *    status  - Working status of GNSS chip.
485   *              See GnssWorkingStatus for the definition of status.
486   */
487  typedef void (*OnGnssWorkingStatusChange)(uint16_t* status);
488  
489  /*
490   * Callback for satellite status reporting.
491   */
492  typedef void (*OnSatelliteStatusChange)(GnssSatelliteStatus* status);
493  
494  /*
495   * Callback for NMEA info reporting.
496   * Parameters:
497   *    time   - Timestamp when the nmea was reported. Milliseconds since January 1, 1970.
498   *    nmea  - NMEA string.
499   *    length  - Length of NMEA string.
500   */
501  typedef void (*OnGnssNmeaChange)(int64_t time, const char* nmea, int length);
502  
503  /*
504   * Callback for GNSS capabilities reporting.
505   * Parameters:
506   *    capabilities   - GNSS capabilities. See GnssCapabilities for the definition of capabilities.
507   */
508  typedef void (*OnCapabilitiesChange)(uint32_t capabilities);
509  
510  /*
511   * Request to delivery GNSS reference information.
512   * Parameters:
513   *    category   - Category of GNSS reference information, See GnssRefInfoCategory for the definition of category.
514   */
515  typedef void (*RequestGnssReferenceInfo)(int category);
516  
517  /*
518   * GNSS basic config structure.
519   */
520  typedef struct {
521      size_t size;
522  
523      /* Minimus interval between locations in ms */
524      uint32_t minInterval;
525  
526      /* See GnssWorkingMode for the definition of gnssMode */
527      int gnssMode;
528  } GnssBasicConfigPara;
529  
530  /*
531   * GNSS config structure.
532   */
533  typedef struct {
534      size_t size;
535  
536      /*
537       * Indicates the method of location reporting,
538       * whether to report immediately or after caching for a
539       * period of time. See GnssStartCategory for the definition of startCategory.
540       */
541      uint32_t startCategory;
542  
543      union {
544          GnssBasicConfigPara gnssBasicConfig;
545          GnssCachingConfig gnssCacheConfig;
546      } u;
547  } GnssConfigParameter;
548  
549  /*
550   * GNSS reference time.
551   */
552  typedef struct {
553      size_t size;
554  
555      /* UTC time received from the NTP server, Milliseconds since January 1, 1970. */
556      int64_t time;
557  
558      /* Time since the system was booted, and include deep sleep. The unit is milliseconds. */
559      int64_t elapsedRealtime;
560  
561      /* This is uncertainty of time. The unit is milliseconds. */
562      int uncertaintyOfTime;
563  } GnssRefTime;
564  
565  /*
566   * GNSS reference information structure.
567   */
568  typedef struct {
569      size_t size;
570  
571      /*
572       * Category of GNSS reference information,
573       * See GnssRefInfoCategory for the definition of category.
574       */
575      int category;
576  
577      union {
578          GnssRefTime time;
579          GnssLocation gnssLocation;
580          GnssLocation bestLocation;
581      } u;
582  } GnssReferenceInfo;
583  
584  /*
585   * Request the client to download extended ephemeris data.
586   */
587  typedef void (*RequestExtendedEphemeris)(void);
588  
589  /*
590   * Callback for GNSS cache location information reporting.
591   */
592  typedef void (*OnCachedLocationsChange)(const GnssLocation** locationArray, size_t arrayLength);
593  
594  /*
595   * GNSS basic callback functions.
596   */
597  typedef struct {
598      size_t size;
599      OnLocationChange locationUpdate;
600      OnGnssWorkingStatusChange gnssWorkingStatusUpdate;
601      OnSatelliteStatusChange satelliteStatusUpdate;
602      OnGnssNmeaChange nmeaUpdate;
603      OnCapabilitiesChange capabilitiesUpdate;
604      RequestGnssReferenceInfo requestRefInfo;
605      RequestExtendedEphemeris requestExtendedEphemeris;
606  } GnssBasicCallbackIfaces;
607  
608  /*
609   * GNSS cached location callback functions.
610   */
611  typedef struct {
612      size_t size;
613      OnCachedLocationsChange cachedLocationUpdate;
614  } GnssCacheCallbackIfaces;
615  
616  /*
617   * GNSS callback structure.
618   */
619  typedef struct {
620      size_t size;
621      GnssBasicCallbackIfaces gnssCallback;
622      GnssCacheCallbackIfaces gnssCacheCallback;
623  } GnssCallbackStruct;
624  
625  /*
626   * GNSS vendor interface definition.
627   */
628  typedef struct {
629      size_t size;
630  
631      /* Enable the GNSS function. Initializing the GNSS Chip. */
632      int (*enableGnss)(GnssCallbackStruct* callbacks);
633  
634      /* Disables the GNSS function. */
635      int (*disableGnss)(void);
636  
637      /* Start navigating. See GnssStartCategory for the definition of category. */
638      int (*startGnss)(uint32_t category);
639  
640      /* Stops navigating. See GnssStartCategory for the definition of category. */
641      int (*stopGnss)(uint32_t category);
642  
643      /* Inject reference information into the GNSS chip.
644       * See GnssRefInfoCategory for the definition of category. */
645      int (*injectsGnssReferenceInfo)(int category, GnssReferenceInfo* info);
646  
647      /* Set GNSS configuration parameters. */
648      int (*setGnssConfigPara)(GnssConfigParameter* para);
649  
650      /*
651       * This function is used to delete the assistance data,
652       * which will not be used in the next GNSS positioning.
653       * See GnssAuxiliaryDataCategory for the definition of flags.
654       */
655      void (*removeAuxiliaryData)(uint16_t flags);
656  
657      /* Injects extended ephemeris data into the GNSS. */
658      int (*injectExtendedEphemeris)(char* data, int length);
659  
660      /* Return the cached locations size. */
661      int (*getCachedLocationsSize)();
662  
663      /* Retrieve all cached locations currently stored and clear the buffer. */
664      void (*flushCachedGnssLocations)();
665  
666      /* Get a pointer to GNSS module interface. See GnssModuleIfaceCategory for the definition of iface. */
667      const void* (*getGnssModuleIface)(int iface);
668  } GnssVendorInterface;
669  
670  /*
671   * GNSS vendor device definition.
672   */
673  struct GnssVendorDevice {
674      size_t size;
675      const GnssVendorInterface* (*getGnssInterface)();
676  };
677  
678  /*
679   * Defines the structure of the request for operating the AGNSS data link.
680   */
681  typedef struct {
682      size_t size;
683  
684      /* See AgnssCategory for the definition of agnssCategory */
685      uint16_t agnssCategory;
686  
687      /* See AgnssDataConnectionSetUpCategory for the definition of requestCategory. */
688      uint16_t requestCategory;
689  
690      /* IPv4 address. */
691      uint32_t ipaddr;
692  
693      /* IPv6 address. */
694      struct sockaddr_storage sockAddr;
695  } AgnssDataConnectionRequest;
696  
697  /*
698   * Request to setup the AGNSS data link.
699   */
700  typedef void (*RequestSetupAgnssDataConnection)(const AgnssDataConnectionRequest* request);
701  
702  /*
703   * Callback function for requesting setid.
704   * Parameters:
705   *    category   - Category of setid, See enum class AgnssSetidCategory for the definition of setidCategory.
706   */
707  typedef void (*RequestDeliverySetid)(uint16_t setidCategory);
708  
709  /*
710   * Callback function for requesting AGNSS reference information.
711   * Parameters:
712   *    category   - Category of AGNSS reference information,
713   *                 See enum class AgnssRefInfoCategory for the definition of category.
714   */
715  typedef void (*RequestDeliveryReferenceInfo)(uint32_t category);
716  
717  /*
718   * Definition of the AGNSS callback interfaces.
719   */
720  typedef struct {
721      size_t size;
722      RequestSetupAgnssDataConnection requestSetupDataLink;
723      RequestDeliverySetid requestSetid;
724      RequestDeliveryReferenceInfo requestRefInfo;
725  } AgnssCallbackIfaces;
726  
727  /*
728   * Interface for AGNSS functions.
729   */
730  typedef struct {
731      size_t size;
732  
733      /* Set AGNSS callback interfaces. */
734      bool (*setAgnssCallback)(AgnssCallbackIfaces* callbacks);
735  
736      /* Sets the AGNSS reference information. */
737      bool (*setAgnssReferenceInfo)(const AgnssReferenceInfo* refInfo);
738  
739      /*
740       * Set the set ID.
741       * Parameters:
742       *    category  - Category of setid, See enum class AgnssSetidCategory for the definition of category.
743       *    setid     - Setid string.
744       *    length    - Length of setid string.
745       */
746      bool (*setSetid)(uint16_t category, const char* setid, size_t length);
747  
748      /*
749       * Set the AGNSS Server Information.
750       * Parameters:
751       *    category - Category of AGNSS. See AgnssCategory for the definition of category.
752       *    server   - AGNSS server information.
753       *    length   - Length of server string.
754       *    port     - Port of AGNSS server.
755       */
756      bool (*setAgnssServer)(uint16_t category, const char* server, size_t length, int32_t port);
757  
758      /* Used to receive network state changes. */
759      void (*onNetworkStateChange)(const NetworkState* state);
760  } AgnssModuleInterface;
761  
762  /*
763   * Callback for geofence event reporting.
764   * Parameters:
765   *    geofenceId - The id of geofence.
766   *    location   - The current GNSS location.
767   *    event      - Current geofencing event. See GeofenceEvent for the definition of event.
768   *    timestamp  - Timestamp when the transition was detected. Milliseconds since January 1, 1970.
769   */
770  typedef void (*OnGeofenceEventChange)(int32_t geofenceId,  GnssLocation* location,
771      int32_t event, int64_t timestamp);
772  
773  /*
774   * Callback function that indicates whether the geofence service is available.
775   *
776   * Parameters:
777   *    isAvailable is true when GNSS geofence service is available.
778   */
779  typedef void (*OnGeofenceAvailabilityChange)(bool isAvailable);
780  
781  /*
782   * Callback function indicating the result of the geofence operation.
783   *
784   *    geofenceId      - Id of the geofence.
785   *    operateCategory - Geofence operate category.
786                            See GeofenceOperateCategory for the definition of operateCategory.
787   *    result          - Operation result. See GeofenceOperateResult for the definition of result.
788   */
789  typedef void (*OnGeofenceOperateResultChange)(int32_t geofenceId, int32_t operateCategory,
790      int32_t result);
791  
792  /*
793   * Callbacks for geofence informations reporting.
794   */
795  typedef struct {
796      size_t size;
797      OnGeofenceAvailabilityChange geofenceAvailabilityUpdate;
798      OnGeofenceEventChange geofenceEventUpdate;
799      OnGeofenceOperateResultChange geofenceOperateResultUpdate;
800  } GeofenceCallbackIfaces;
801  
802  /*
803   * Interface for GNSS Geofence.
804   */
805  typedef struct {
806      size_t size;
807  
808      /*
809       * Set the geofence callback interfaces.
810       */
811      bool (*setCallback)(GeofenceCallbackIfaces* callbacks);
812  
813      /*
814       * Add a GNSS geofence.
815       * Parameters:
816       *    geofenceId           - The id of the geofence.
817       *    latitude, longtitude - Center of a circular geofence.
818       *    radius               - Radius of a circular geofence.
819       *    monitorEvent         - Which geofence event to monitor.
820       *                           See GeofenceEvent for the definition of monitorEvent.
821       */
822      bool (*addGnssGeofence)(int32_t geofenceId, double latitude, double longitude,
823         double radius, int32_t monitorEvent);
824  
825      /*
826       * Delete a GNSS geofence.
827       *    geofenceId - The id of the geofence.
828       */
829      bool (*deleteGnssGeofence)(int32_t geofenceId);
830  } GeofenceModuleInterface;
831  
832  /*
833   * Definition of the GNSS clock information structure.
834   */
835  typedef struct {
836      size_t size;
837  
838      /*
839       * Identifies which field is valid.
840       * See GnssClockValidity for the definition of fieldValidFlags.
841       */
842      uint16_t fieldValidFlags;
843  
844      /*
845       * Leap second data.
846       */
847      int16_t leapSecond;
848  
849      /*
850       * Indicates the clock time of the GNSS receiver, the unit is nanosecond.
851       * This is a mandatory value.
852       */
853      int64_t receiverClockTime;
854  
855      /*
856       * Uncertainty of the receiverClockTime, the unit is nanosecond.
857       */
858      double timeUncertainty;
859  
860      /*
861       * The difference between receiverClockTime and the true GPS time since 0000Z, January 6, 1980.
862       * the unit is nanosecond.
863       */
864      int64_t rcvClockFullBias;
865  
866      /*
867       * Sub-nanosecond bias of receiverClockTime.
868       */
869      double rcvClockSubBias;
870  
871      /*
872       * Uncertainty of the local estimate of GPS time (clock bias 'rcvClockFullBias' and 'rcvClockSubBias' feild)
873       * in nanoseconds.
874       */
875      double biasUncertainty;
876  
877      /*
878       * The clock's drift of receiver clock. the unit is nanosecond (per second).
879       */
880      double clockDrift;
881  
882      /*
883       * The uncertainty of clockDrift. the unit is nanosecond (per second).
884       */
885      double clockDriftUncertainty;
886  
887      /*
888       * Indicates hardware clock discontinuity count.
889       * This is a mandatory value.
890       */
891      uint32_t clockInterruptCnt;
892  
893      /*
894       * Indicates clockJump threshold of hardware clock. the unit is nanosecond.
895       * the clock bias ('rcvClockFullBias' + 'rcvClockSubBias' should be less than clockJumpThreshold)
896       */
897      double clockJumpThreshold;
898  
899      /*
900       * Indicates clockHWFreBias event, If the crystal oscillator(XO) has a frequency offset exception event,
901       * this enumeration field reports the state.
902       * If this field is frequently reported, check the environment or hardware status of the XO.
903       * See ClockHWFreBiasState for the definition of clockHWFreBiasIndicator.
904       */
905      uint32_t clockHWFreBiasIndicator;
906  
907      /*
908       * Indicates clockHWFreDrift event, If the crystal oscillator(XO) has a frequency drift exception event,
909       * this enumeration field reports the state.
910       * If this field is frequently reported, check the environment or hardware status of the XO.
911       * See clockHWFreDriftState for the definition of clockHWFreDriftIndicator.
912       */
913      uint32_t clockHWFreDriftIndicator;
914  } GnssClockInfo;
915  
916  /*
917   * Definition of the GNSS measurement information.
918   */
919  typedef struct {
920      size_t size;
921  
922      /*
923       * Identifies which field is valid.
924       * See GnssMeasurementValidity for the definition of fieldValidFlags.
925       */
926      uint32_t fieldValidflags;
927  
928      /*
929       * Satellite ID number.
930       * This is a mandatory value.
931       */
932      int16_t satelliteId;
933  
934      /*
935       * Defines the constellation category.
936       * See ConstellationCategory for the definition of constellationCategory.
937       */
938      int16_t constellationCategory;
939  
940      /*
941       * Measurement generation time offset in nanoseconds.
942       * This is a mandatory value.
943       * The formula for calculating the measurement time is as follows:
944       *     measurement time = GnssClockInfo::receiverClockTime + timeOffset
945       */
946      double timeOffset;
947  
948      /*
949       * Satellite sync state. See SatelliteSyncState for the definition of syncState.
950       * This is a mandatory value.
951       */
952      uint32_t syncState;
953  
954      /*
955       * The received satellite Time-of-Week in nanoseconds.
956       */
957      int64_t receivedSatelliteTime;
958  
959      /*
960       * Uncertainty of the received satellite Time-of-Week in nanoseconds.
961       */
962      int64_t receivedSatelliteTimeUncertainty;
963  
964      /*
965       * Carrier-to-noise density. The unit is dB-Hz.
966       * This is a mandatory value.
967       */
968      double cn0;
969  
970      /*
971       * Pseudorange rate. The unit is m/s.
972       */
973      double pseudorangeRate;
974  
975      /*
976       * Uncertainty of the pseudorangeRate. The unit is m/s.
977       * This is a mandatory value.
978       */
979      double pseudorangeRateUncertainty;
980  
981      /*
982       * Accumulated delta range's state.
983       * See GnssAccumulatedDeltaRangeFlag for the definition.
984       * This is a mandatory value.
985       */
986      uint32_t accumulatedDeltaRangeFlag;
987  
988      /*
989       * Accumulated delta range since the last channel reset. The unit is meters.
990       */
991      double accumulatedDeltaRange;
992  
993      /*
994       * Uncertainty of the accumulated delta range. The unit is meters.
995       */
996      double accumulatedDeltaRangeUncertainty;
997  
998      /*
999       * Carrier frequency at which codes and messages are modulated. The unit is Hz.
1000       */
1001      float carrierFrequency;
1002  
1003      /*
1004       * The count of carrier cycles between satellite and receiver.
1005       */
1006      int64_t carrierCyclesCount;
1007  
1008      /*
1009       * Carrier phase, in the range [0.0, 1.0].
1010       */
1011      double carrierPhase;
1012  
1013      /*
1014       * Uncertainty of the carrierPhase.
1015       */
1016      double carrierPhaseUncertainty;
1017  
1018      /*
1019       * Indicates the 'multipath' flag.
1020       * See GnssMultipathFlag for the definition of multipathFlag.
1021       */
1022      uint32_t multipathFlag;
1023  
1024      /*
1025       * Automatic gain control (AGC) level in dB.
1026       */
1027      double agcGain;
1028  
1029      /*
1030       * The category of code that is currently being tracked in the GNSS measurement.
1031       * See GnssMeasurementTrackedCodeCategory for the definition of codeCategory.
1032       */
1033      uint32_t codeCategory;
1034  
1035      /*
1036       * Iono-correct value in meters.
1037       */
1038      double ionoCorrect;
1039  
1040      /*
1041       * Trop-correct value in meters.
1042       */
1043      double tropCorrect;
1044  
1045      /*
1046       * Satellite clock bias value in meters.
1047       */
1048      double satelliteClockBias;
1049  
1050      /*
1051       * Satellite clock drift bias value in meters.
1052       */
1053      double satelliteClockDriftBias;
1054  } GnssMeasurement;
1055  
1056  /*
1057   * Definition of the GNSS measurement informations.
1058   */
1059  typedef struct {
1060      size_t size;
1061  
1062      GnssClockInfo gnssClock;
1063  
1064      /* Time since the system was booted, and include deep sleep. The unit is nanoseconds. */
1065      uint64_t elapsedRealtime;
1066  
1067      /* This is uncertainty of elapsedRealtime. The unit is nanoseconds. */
1068      uint64_t uncertainty;
1069  
1070      /* Number of measurements. */
1071      size_t measurementCount;
1072  
1073      /* The array of measurements. */
1074      GnssMeasurement measurements[SATELLITE_NUM_MAXIMUM];
1075  } GnssMeasurementInfo;
1076  
1077  /*
1078   * Callback for reporting the GNSS measurement informations.
1079   */
1080  typedef void (*OnGnssMeasurementChange)(GnssMeasurementInfo* data);
1081  
1082  /*
1083   * Definition of the GNSS measurement callback interface.
1084   */
1085  typedef struct {
1086      size_t size;
1087      OnGnssMeasurementChange gnssMeasurementUpdate;
1088  } GnssMeasurementCallbackIfaces;
1089  
1090  /*
1091   * Definition of the GNSS measurement interface.
1092   */
1093  typedef struct {
1094      size_t size;
1095  
1096      /*
1097       * Enable measurement information reporting and register callback.
1098       */
1099      bool (*enable)(GnssMeasurementCallbackIfaces* callbacks);
1100  
1101      /*
1102       * Disable measurement information reporting and unregister callback.
1103       */
1104      void (*disable)();
1105  } GnssMeasurementInterface;
1106  
1107  /*
1108   * Definition of the GNSS NI notification request structure.
1109   */
1110  typedef struct {
1111      size_t size;
1112  
1113      /*
1114       * An ID of GNSS NI notifications.
1115       */
1116      int16_t gnssNiNotificationId;
1117  
1118      /*
1119       * Category of GNSS NI Request. See GnssNiRequestCategory for the definition of gnssNiRequestCategory.
1120       */
1121      int16_t gnssNiRequestCategory;
1122  
1123      /*
1124       * Category of notification. See GnssNiNotificationCategory for the definition of gnssNiCategory.
1125       */
1126      int32_t notificationCategory;
1127  
1128      /*
1129       * Timeout to wait for user response. The unit is seconds.
1130       */
1131      int32_t requestTimeout;
1132  
1133      /*
1134       * Default response command when timeout.
1135       */
1136      int32_t defaultResponseCmd;
1137  
1138      /*
1139       * Supplicant information.
1140       */
1141      char supplicantInfo[GNSS_NI_SUPPLICANT_INFO_LENGTH_MAXIMUM];
1142  
1143      /*
1144       * Notification message text.
1145       */
1146      char notificationText[GNSS_NI_NOTIFICATION_TEXT_LENGTH_MAXIMUM];
1147  
1148      /*
1149       * See GnssNiRequestEncodingFormat for the definition of supplicantInfoEncoding.
1150       */
1151      int16_t supplicantInfoEncoding;
1152  
1153      /*
1154       * See GnssNiRequestEncodingFormat for the definition of notificationTextEncoding.
1155       */
1156      int16_t notificationTextEncoding;
1157  } GnssNiNotificationRequest;
1158  
1159  /*
1160   * Callback for GNSS NI notification reporting.
1161   */
1162  typedef void (*OnGnssNiNotificationChange)(GnssNiNotificationRequest *notification);
1163  
1164  /*
1165   * Definition of GNSS NI callback structure.
1166   */
1167  typedef struct {
1168      OnGnssNiNotificationChange reportNiNotification;
1169  } GnssNetInitiatedCallbacks;
1170  
1171  /*
1172   * Definition of GNSS NI interface.
1173   */
1174  typedef struct {
1175      size_t size;
1176  
1177      /* Set callbacks. */
1178      void (*setCallback)(GnssNetInitiatedCallbacks *callbacks);
1179  
1180      /*
1181       * Sends user response command.
1182       * Parameters:
1183       *    gnssNiNotificationId - The id of GNSS NI notifications.
1184       *    userResponse         - User reponse command.
1185       *                           See GnssNiResponseCmd for the definition of userResponse.
1186       */
1187      void (*sendUserResponse)(int32_t gnssNiNotificationId, int32_t userResponse);
1188  
1189      /*
1190       * Send network initiated message.
1191       */
1192      void (*sendNetworkInitiatedMsg)(uint8_t *msg, size_t length);
1193  } GnssNetInitiatedInterface;
1194  } // namespace Location
1195  } // namespace HDI
1196  } // namespace OHOS
1197  
1198  #endif /* OHOS_HDI_LOCATION_LOCATION_VENDOR_LIB_H */
1199