blob: 04b0951084c575e46c8fc002c29fb46f2777639e [file] [log] [blame]
/*-----------------------------------------------------------------------------------------------*/
/**
@file ql_ecall.c
@brief Ecall APIs
*/
/*-------------------------------------------------------------------------------------------------
Copyright (c) 2019 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
Quectel Wireless Solution Proprietary and Confidential.
-------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------
EDIT HISTORY
This section contains comments describing changes made to the file.
Notice that changes are listed in reverse chronological order.
$Header: $
when who what, where, why
-------- --- ----------------------------------------------------------
202306xx Lyndsay.Xie Created .
-------------------------------------------------------------------------------------------------*/
#ifndef __ECALL_H__
#define __ECALL_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>
#include "ql_asn1Msd.h"
#include "ql_ms_voice.h"
#include "ql_type.h"
// #include "ql_voice.h"
#define ASSERT(condition) \
if (!(condition)) { LOGE("Assert Failed: '%s'", #condition);}
//--------------------------------------------------------------------------------------------------
/**
* Unlimited dial attempts for eCall session (used for PAN-European system)
*/
//--------------------------------------------------------------------------------------------------
#define UNLIMITED_DIAL_ATTEMPTS UINT32_MAX
#define QL_VOICE_MAX_ECALL_MSD (140)
typedef enum
{
QL_ECALL_TX_MODE_PULL = 0, /**< Pull mode (modem/host waits for MSD request from PSAP to send MSD). */
QL_ECALL_TX_MODE_PUSH = 1 /**< Push mode (modem/host sends MSD to PSAP right after eCall is connected). */
} QL_ECALL_MSD_TX_MODE_E;
typedef enum
{
QL_ECALL_RESET_SESSION_NONE = 0,
QL_ECALL_RESET_SESSION_AUTOANSWER= 1, /**< Reset the ecall session to allow automatic answering of calls
* It can only be enabled once after calling ql_ecall_init() == OK*/
QL_ECALL_RESET_SESSION_MAX = 0xff
} QL_ECALL_RESET_SESSION_MODE_E;
typedef struct
{
uint8_t t5_timeout_ms_valid;
uint16_t t5_timeout_ms;
uint8_t t6_timeout_ms_valid;
uint16_t t6_timeout_ms;
uint8_t t7_timeout_ms_valid;
uint16_t t7_timeout_ms;
uint8_t autoAnswer_timeout_ms_valid; // callback
uint32_t autoAnswer_timeout_ms; // default 3600000 ms (1 hour)
uint8_t dialDurationTimer_timout_ms_valid; // dial
uint32_t dialDurationTimer_timout_ms;
uint8_t maxDialAttempts_valid; // redialcnt
uint32_t maxDialAttempts;
uint8_t intervalBetweenAttempts_valid;
uint16_t intervalBetweenAttempts;
uint8_t resetEcallSessionMode_valid;
uint8_t resetEcallSessionMode;
} ql_ecall_config_t;
typedef void (*ql_ecall_user_ind_f)(int ind, void *userdata);
typedef enum{
QL_ECALL_MAKE_ECALL_TYPE_TEST = 0,
QL_ECALL_MAKE_ECALL_TYPE_RECONFIG = 1,
QL_ECALL_MAKE_ECALL_TYPE_MANUAL = 2,
QL_ECALL_MAKE_ECALL_TYPE_AUTOMATIC = 3,
}QL_ECALL_MAKE_ECALL_TYPE;
/** eCall mode */
typedef enum {
QL_ECALL_MODE_NORMAL = 0, /**< eCall enabled normal mode. */
QL_ECALL_MODE_ONLY = 1, /**< eCall-only mode. */
QL_ECALL_MODE_DEFAULT = 2,
} QL_ECALL_MODE_E;
typedef enum
{
QL_ECALL_EVENT_SENDING_START = 1,
QL_ECALL_EVENT_SENDING_MSD = 2,
QL_ECALL_EVENT_LLACK_RECEIVED = 3,
QL_ECALL_EVENT_ALLACK_POSITIVE_RECEIVED = 4,
QL_ECALL_EVENT_ALLACK_CLEARDOWN_RECEIVED = 5,
QL_ECALL_EVENT_ACTIVE = 11,
QL_ECALL_EVENT_DISCONNECTED = 12,
QL_ECALL_EVENT_ABNORMAL_HANGUP = 15,
// QL_ECALL_EVENT_IMS_MSD_ACK = 0x0014,
// QL_ECALL_EVENT_IMS_UPDATE_MSD,
QL_ECALL_EVENT_ONLY_DEREGISTRATION = 31,
QL_ECALL_EVENT_MAY_DEREGISTRATION = 32,
QL_ECALL_EVENT_PSAP_CALLBACK_START = 40,
QL_ECALL_EVENT_ECALL_STARTED = 260,
QL_ECALL_EVENT_INCOMING_CALL = 261,
QL_ECALL_EVENT_T2_TIMEOUT = 262,
QL_ECALL_EVENT_T5_TIMEOUT = 263,
QL_ECALL_EVENT_T6_TIMEOUT = 264,
QL_ECALL_EVENT_T7_TIMEOUT = 265,
QL_ECALL_EVENT_DIAL_DURATION_TIMEOUT = 266,
QL_ECALL_EVENT_INTERVAL_TIMEOUT = 267,
QL_ECALL_EVENT_AUTO_ANSWER_TIMEOUT = 268,
// TO DO - add customer app events
} QL_ECALL_EVENT_E;
// TODO: Will be used potentially. If not remove it!
// QL_ERR_MSD_RESULT_E QL_Set_MsdMessageData(msd_Message_t *pMsdMsg);
// QL_ERR_MSD_RESULT_E QL_Set_EraGlonassData(msd_EraGlonassData_t *pEraGlonassData);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Set the system standard.
@param[in] system_std system standard which can be set to PAN-European or ERA-GLONASS.
@return Whether the system standard was set successfully.
@retval QL_ERR_OK successful.
@retval QL_ERR_INVALID_ARG unsupported value.
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_set_system_std(ECALL_SYSTEM_STD_E system_std);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Get the system standard.
@param[out] system_std pointer to system standard which can be PAN-European or ERA-GLONASS.
*/
/*-----------------------------------------------------------------------------------------------*/
void ql_ecall_get_system_std(ECALL_SYSTEM_STD_E* system_std);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Set the MSD version.
@param[in] msd_version MSD version which can be set to ASN1_ECALL_MSD_VERSION_1 or ASN1_ECALL_MSD_VERSION_2
@return Whether the MSD version was set successfully.
@retval QL_ERR_MSD_SUCCESS successful.
@retval QL_ERR_MSD_VERSION unsupported value.
*/
/*-----------------------------------------------------------------------------------------------*/
QL_ERR_MSD_RESULT_E ql_ecall_set_msd_version(uint8_t msd_version);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Get the MSD version.
@param[out] msd_version pointer to MSD version.
@return Whether the MSD version was get successfully.
@retval QL_ERR_MSD_SUCCESS successful.
@retval QL_ERR_MSD_VERSION unsupported value.
*/
/*-----------------------------------------------------------------------------------------------*/
QL_ERR_MSD_RESULT_E ql_ecall_get_msd_version(uint8_t* msdVersionPtr);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Sets MSD's testCall field.
@param[in] testCall MSD call type: true = Test call false = Emergency
*/
/*-----------------------------------------------------------------------------------------------*/
void ql_ecall_set_msd_call_type(bool testCall);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Gets MSD's testCall field.
@param[out] testCall pointer to MSD call type: true = Test call false = Emergency
*/
/*-----------------------------------------------------------------------------------------------*/
void ql_ecall_get_msd_call_type(bool* testCall);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Sets VehicleType.
@param[in] vehicleType vehicle type
@return Whether the vehicleType was set successfully.
@retval QL_ERR_MSD_SUCCESS successful.
@retval QL_ERR_MSD_BADPARM unsupported value.
*/
/*-----------------------------------------------------------------------------------------------*/
QL_ERR_MSD_RESULT_E ql_ecall_set_msd_vehicle_type(uint8_t vehicleType);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Gets VehicleType.
@param[out] vehicleType pointer to vehicle type
@return Whether the vehicleType was get successfully.
@retval QL_ERR_MSD_SUCCESS successful.
@retval QL_ERR_MSD_BADPARM unsupported value.
*/
/*-----------------------------------------------------------------------------------------------*/
QL_ERR_MSD_RESULT_E ql_ecall_get_msd_vehicle_type(uint8_t* vehicleType);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Sets Vehicle Identification Number
@param[in] vin vehicle identification number
@return Whether the vehicle identification number was set successfully.
@retval QL_ERR_MSD_SUCCESS successful.
@retval QL_ERR_MSD_VEH_IDENTIFI_NUMBER unsupported value.
*/
/*-----------------------------------------------------------------------------------------------*/
QL_ERR_MSD_RESULT_E ql_ecall_set_msd_vin(msd_Vin_t vin);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Gets Vehicle Identification Number
@param[out] vin pointer to vehicle identification number
@return Whether the vehicle identification number was get successfully.
@retval QL_ERR_MSD_SUCCESS successful.
@retval QL_ERR_MSD_VEH_IDENTIFI_NUMBER unsupported value.
*/
/*-----------------------------------------------------------------------------------------------*/
QL_ERR_MSD_RESULT_E ql_ecall_get_msd_vin(msd_Vin_t* vin);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Sets Propulsion Type.
@param[in] PropulsionType propulsion type.
*/
/*-----------------------------------------------------------------------------------------------*/
void ql_ecall_set_msd_propulsion_type(uint8_t PropulsionType);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Gets Propulsion Type.
@param[out] PropulsionType pointer to propulsion type.
*/
/*-----------------------------------------------------------------------------------------------*/
void ql_ecall_get_msd_propulsion_type(uint8_t* PropulsionType);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Sets number of passangers.
@param[in] numberOfPassengers number of passangers.
*/
/*-----------------------------------------------------------------------------------------------*/
void ql_ecall_set_msd_passengers_count(uint8_t numberOfPassengers);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Sets vehicle location.
@param[in] isTrusted true if the position can be trusted, false otherwise.
@param[in] latitude latitude of vehicle's location.
@param[in] longitude longitude of vehicle's location.
@param[in] direction direction of vehicle's location.
@return Whether the vehicle location was set successfully.
@retval QL_ERR_MSD_SUCCESS successful.
@retval QL_ERR_MSD_LATITUDE latitude unsupported value.
@retval QL_ERR_MSD_LONGITUDE longitude unsupported value.
@retval QL_ERR_MSD_VEH_DIRECTION direction unsupported value.
*/
/*-----------------------------------------------------------------------------------------------*/
QL_ERR_MSD_RESULT_E ql_ecall_set_msd_position(bool isTrusted, int32_t latitude, int32_t longitude, int32_t direction);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Set the position Delta N-1 from position set in ql_ecall_set_msd_position() transmitted by the MSD.
@param[in] latitudeN2 latitude delta from position set in ql_ecall_set_msd_position().
@param[in] longitudeN2 longitude delta from position set in ql_ecall_set_msd_position().
@return Whether the vehicle location delta was set successfully.
@retval QL_ERR_MSD_SUCCESS successful.
@retval QL_ERR_MSD_LATITUDE delta latitude unsupported value.
@retval QL_ERR_MSD_LONGITUDE delta longitude unsupported value.
*/
/*-----------------------------------------------------------------------------------------------*/
QL_ERR_MSD_RESULT_E ql_ecall_set_msd_position_n1(int32_t latitudeDeltaN1, int32_t longitudeDeltaN1);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Set the position Delta N-2 from position set in ql_ecall_set_msd_position() transmitted by the MSD.
@param[in] latitudeN2 latitude delta from position set in ql_ecall_set_msd_position_n1().
@param[in] longitudeN2 longitude delta from position set in ql_ecall_set_msd_position_n1().
@return Whether the vehicle location delta was set successfully.
@retval QL_ERR_MSD_SUCCESS successful.
@retval QL_ERR_MSD_LATITUDE delta latitude unsupported value.
@retval QL_ERR_MSD_LONGITUDE delta longitude unsupported value.
*/
/*-----------------------------------------------------------------------------------------------*/
QL_ERR_MSD_RESULT_E ql_ecall_set_msd_position_n2(int32_t latitudeDeltaN2, int32_t longitudeDeltaN2);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Set MSD TX Mode.
@param[in] tx_mode Transmission MSD mode, 0 - PULL, 1 - PUSH.
@return Whether the transmission MSD mode was set successfully.
@retval QL_ERR_MSD_SUCCESS successful.
@retval QL_ERR_MSD_BADPARM unsupported value.
*/
/*-----------------------------------------------------------------------------------------------*/
QL_ERR_MSD_RESULT_E ql_ecall_set_msd_tx_mode(QL_ECALL_MSD_TX_MODE_E tx_mode);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Get MSD TX Mode.
@param[out] tx_mode Pointer to transmission MSD mode, 0 - PULL, 1 - PUSH.
*/
/*-----------------------------------------------------------------------------------------------*/
void ql_ecall_get_msd_tx_mode(QL_ECALL_MSD_TX_MODE_E* tx_mode);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Set the minimum interval value between dial attempts. Available for both manual and test modes.
@param[in] pause the minimum interval value in seconds.
@retval ql_type.h
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_set_interval_between_dial_attempts(uint16_t pause);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Get the minimum interval value between dial attempts.
@param[out] pause pointer to the minimum interval value in seconds.
*/
/*-----------------------------------------------------------------------------------------------*/
void ql_ecall_get_interval_between_dial_attempts(uint16_t* pause);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Initialize MSD to default values.
*/
/*-----------------------------------------------------------------------------------------------*/
void ql_ecall_msd_init(void);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Start a test eCall session.
@return Whether the test ecall was started successfully.
@retval QL_ERR_MSD_SUCCESS successful.
@retval QL_ERR_MSD_BADPARM unsupported value.
@retval QL_ERR_OK successful.
@retval QL_ERR_INVALID_ARG invalid argument.
@retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
@retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
@retval Other error code defined by ql_type.h.
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_start_test(int sim_id);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Start a manual eCall session.
@return Whether the manually triggered ecall was started successfully.
@retval QL_ERR_MSD_SUCCESS successful.
@retval QL_ERR_MSD_BADPARM unsupported value.
@retval Other MSD error code defined by QL_ERR_MSD_RESULT_E.
@retval QL_ERR_OK successful.
@retval QL_ERR_INVALID_ARG invalid argument.
@retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
@retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
@retval Other error code defined by ql_type.h.
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_start_manual(int sim_id);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Start an automatic eCall session.
@return Whether the automatically triggered ecall was started successfully.
@retval QL_ERR_MSD_SUCCESS successful.
@retval QL_ERR_MSD_BADPARM unsupported value.
@retval Other MSD error code defined by QL_ERR_MSD_RESULT_E.
@retval QL_ERR_OK successful.
@retval QL_ERR_INVALID_ARG invalid argument.
@retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
@retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
@retval Other error code defined by ql_type.h.
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_start_automatic(int sim_id);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Initializes ecall service.
@return Whether the ecall service was initialized successfully.
@retval QL_ERR_OK successful.
@retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
@retval Other error code defined by ql_type.h.
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_init(void);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Deinitializes ecall service.
@return Whether the ecall service was deinitialized successfully.
@retval QL_ERR_OK successful.
@retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
@retval Other error code defined by ql_type.h.
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_deinit(void);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Sets ecall User indication callback.
@param[in] cb call back handler.
@param[in] userdata user data.
@return void
*/
/*-----------------------------------------------------------------------------------------------*/
void ql_ecall_set_user_ind_cb(ql_ecall_user_ind_f cb, void *userdata);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Dials eCall.
@param[in] sim_id sim id.
@param[in] p_info eCall info.
@param[out] p_id call id.
@return Whether a eCall was successfully dialed.
@retval QL_ERR_OK successful.
@retval QL_ERR_INVALID_ARG invalid argument.
@retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
@retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
@retval Other error code defined by ql_type.h.
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_dial(int sim_id, const ql_voice_ecall_info_t* const p_info, uint32_t* const p_id);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Hangs up eCall.
@return Whether the eCall was successfully hung up.
@retval QL_ERR_OK successful.
@retval QL_ERR_INVALID_ARG invalid argument.
@retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
@retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
@retval Other error code defined by ql_type.h.
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_hangup(void);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Updates eCall MSD with raw data.
@param[in] msd Minimum Set of Data.
@param[in] msd_len Length of Minimum Set of Data.
@return Whether the eCall MSD was successfully updated.
@retval QL_ERR_OK successful.
@retval QL_ERR_INVALID_ARG invalid argument.
@retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
@retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
@retval Other error code defined by ql_type.h.
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_update_msd_raw(const uint8_t* msd, uint32_t msd_len);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Updates eCall MSD.
@return Whether the eCall MSD was successfully updated.
@retval QL_ERR_OK successful.
@retval QL_ERR_INVALID_ARG invalid argument.
@retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
@retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
@retval Other error code defined by ql_type.h.
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_update_msd(void);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Pushes eCall MSD.
@param[out] state eCall state.
@return Whether the eCall MSD was successfully pushed.
@retval QL_ERR_OK successful.
@retval QL_ERR_INVALID_ARG invalid argument.
@retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
@retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
@retval Other error code defined by ql_type.h.
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_push_msd(void);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Setting ecall test number. Number will be saved on the modem side.
@param[in] number test number
@return
QL_ERR_OK - successful
Other - error code defined by ql_type.h
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_set_test_number(int sim_id, const char* number);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Setting ecall test number. Number will be saved on the modem side.
@param[in] number test number
@return
QL_ERR_OK - successful
Other - error code defined by ql_type.h
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_reset_test_number(int sim_id, const char* number);
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Reset IVS during ecall session and switch to voice.
@return
QL_ERR_OK - successful
Other - error code defined by ql_type.h
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_reset_ivs(int sim_id);
#if 0
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Starts ecall session.
@return
QL_ERR_OK - successful
Other - error code defined by ql_type.h
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_make_ecall(int sim_id, QL_ECALL_MAKE_ECALL_TYPE ecall_type);
#endif
/*-----------------------------------------------------------------------------------------------*/
/**
@brief Deregister from Network.
@return Whether a request was executed.
@retval QL_ERR_OK successful.
@retval Other error code defined by ql_type.h.
*/
/*-----------------------------------------------------------------------------------------------*/
int ql_ecall_terminate_nw_registration(void);
void ql_ecall_set_config_info(ql_ecall_config_t ecall_context_info);
void ql_ecall_get_config_info(ql_ecall_config_t* ecall_context_info);
int ql_ecall_set_ecall_only_mode(bool ecall_only_value);
#ifdef __cplusplus
}
#endif
#endif /* __ECALL_H__ */