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