blob: 9ead23aebbc51f6989467c03d3079bb015d4509b [file] [log] [blame]
/*------------------------------------------------------------
(C) Copyright [2006-2014] Marvell International Ltd.
All Rights Reserved
------------------------------------------------------------*/
#ifndef __CM_SERVICE_H__
#define __CM_SERVICE_H__
//////////////////////////////////////////////////////////////////////
// INCLUDE FILES FOR MODULE
//////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <libubus.h>
#include <libubox/blob.h>
#include <libubox/usock.h>
#include <uci.h>
#include <telephony/cm.h>
#include <telephony/ril.h>
#include "cm_def.h"
#include "utilities.h"
#include <cutils/properties.h>
#include "eeh_assert_notify.h"
#include <ril.h>
#include <rilutil.h>
#include "profile_management.h"
#include "cm_toe.h"
//////////////////////////////////////////////////////////////////////
// Global definitions
//////////////////////////////////////////////////////////////////////
#define WAN_PACKAGE_NAME "wan"
#define WAN_SECTION_PDP_CONFIG "pdp-conf-list"
#define WAN_SECTION_WAN_CONFIG "wan-config"
#define WAN_SECTION_WAN_CONNECT_WITCH "connect-switch"
#define WAN_SECTION_AUTO_SWITCH "auto-switch"
#define WAN_SECTION_TYPE_ENG_MODE "eng-mode"
#define WAN_SECTION_NAME_ENG_MODE "eng_mode"
#define WAN_ENG_MODE_OPTION "mode"
#define GETELCOM_CONFIG "GETELCOM"
#define SEC_MCCMNC "mccmnc"
#define OPT_NULLAPN "NULLAttachAPN"
#define SEC_GETELCOM "getelcom"
#define MAX_SIM_INFO_STR_LEN 32
#define RIL_MAX_RETRIES 20
#define RULE_SHOW_PLMN 0x01
#define RULE_SHOW_SPN 0x02
#define NETWORK_NAME_TYPE 0
#define ROAMING_NETWORK_NAME_TYPE 1
#define MAX_NWACTIVITY_ARRAYNUM 10
#define CM_INNER_CONN_SOCKET "/tmp/cm_socket.sock"
#define CM_URSP_CONN_SOCKET "/tmp/ursp_socket.sock"
#define CM_CONN_SOCKET "/tmp/cm_conn.sock"
#define CM_FIFO_NAME "/tmp/cm_connfifo"
#define QUERY_ENG_INFO_TIMEOUT 60000 // ms
#ifdef CONFIG_DEFAULT_CID_5
#define CM_DEFAULT_ATTACH_CID 5
#else
#define CM_DEFAULT_ATTACH_CID 1
#endif
#ifdef SYS_EXIST_CP
#undef SYS_EXIST_CP
#define SYS_EXIST_CP "ro.sys.exist.cp"
#endif
#define INVALID_CID 0xFF
//////////////////////////////////////////////////////////////////////
// Structs
//////////////////////////////////////////////////////////////////////
typedef struct {
int dis_cond;
int spn_exist;
char spn_name[MAX_SIM_INFO_STR_LEN];
} s_spn_info;
typedef struct {
char ons[MAX_SIM_INFO_STR_LEN];
char plmn[7];
} s_ons_info;
typedef rilDevLteEngScellInfo s_lte_svc_info;
typedef rilDevUmtsServingCellInfo s_umts_svc_info;
typedef struct _cellular_info {
char IMEI[MAX_SIM_INFO_STR_LEN];
char IMEI_SV[MAX_SIM_INFO_STR_LEN];
char MSISDN[MAX_SIM_INFO_STR_LEN];
char IMSI[MAX_SIM_INFO_STR_LEN];
int rssi;
int roaming;
s_ons_info ons_info;
int sys_mode;
int data_mode;
s_spn_info spn_info;
s_lte_svc_info lte_info;
s_umts_svc_info umts_info;
int status;
int etiflag;
int ims_state;
} s_cellular_info;
extern s_cellular_info g_cell_basic_info;
//redial message type
typedef enum {
REDIAL_IMMED,
REDIAL_NEWAPN,
REDIAL_NEWAPN_CLEARETIF,
REDIAL_NWCHANGE,
REDIAL_ROAMCHANGE,
REDIAL_REJECT,
REDIAL_SINGLE_STACK,
REDIAL_DEFAULT_DATACALL,
REDIAL_NEXT_RSD,
REDIAL_NEXT_TD,
} redialmsg_type;
enum {
_MODE_INIT,
MODE_LTE,
MODE_UMTS,
MODE_TD,
MODE_GSM
};
typedef struct {
// extend msg here
unsigned int id;
int connectionNum;
redialmsg_type msgtype;
} msg_hdr;
typedef struct {
int connect_status; //0-disconnect, 1-connected;
int cid;
int iptype; //0-IPV4V6, 1-IPV4, 2-IPV6
int current_duration_time;
int duration_time;
int notify_ticks;
} network_activity_msg;
typedef struct {
int cid;
int connect_status;
int connect_ticks;
int current_duration_time;
int duration_time;
}network_duration_s;
typedef struct {
char PDP_name[64];
int cid;
int index;
char start_tim[32];
char end_tim[32];
int iptype;
int ipv4addr;
int ipv6addr[4];
int connect_ticks;
int current_duration_time;
int duration_time;
} network_activity_array;
typedef struct {
int connect_num;
int cause;
} s_cause_msg;
typedef RIL_SignalStrength_v6 s_signal_quality;
typedef enum
{
CM_SIM_SWITCH_INIT,
CM_SIM_SWITCH_START,
CM_SIM_SWITCH_PRESIM_PDP_DOWN,
CM_SIM_SWITCH_PRESIM_IMS_DOWN,
CM_SIM_SWITCH_PRESIM_PSDC_DOWN,
CM_SIM_SWITCH_CURRSIM_PDP_UP,
CM_SIM_SWITCH_CURRSIM_CFUN0,
CM_SIM_SWITCH_CURRSIM_IMS_UP,
CM_SIM_SWITCH_CURRSIM_PSDC_UP,
CM_SIM_SWITCH_ERROR
}CMSimSwitchState;
typedef void (*SwitchSimDoneCb)(UINT8);
typedef struct {
CMSimID currSim;
UINT8 state;
UINT8 waitDone;
SwitchSimDoneCb switchDone;
} SimSwitchCtx;
enum {
NW_MODE,
PREFER_MODE,
PREFER_LTE_TYPE
};
enum {
CM_ID,
CM_MSG1,
CM_MSG2,
CM_MAX
};
enum {
PDP0_CN,
PDP0_NAME,
PDP1,
PDP2,
PDP3,
PDP4,
PDP5,
PDP6,
PDP7,
PDP8,
PDP9,
PDP10,
PDP_MAX
};
enum {
TFT1,
TFT2,
TFT3_MIN,
TFT3_MAX,
TFT4_MIN,
TFT4_MAX,
TFT5,
TFT6,
TFT7,
TFT8,
TFT9,
TFT_MAX
};
enum {
NWACTIVITY_DEL_INDEX,
NWACTIVITY_DEL_FLAG,
NWACTIVITY_MAX,
};
enum {
E_MCC,
E_MNC,
E_MCC_MNC_MAX
};
enum sys_mode_ {
E_NO_SERVICE,
E_2G_3G,
E_LTE,
E_LTEP,
E_5G
};
enum {
NW_CONNECT_STATUS,
NW_CID,
NW_IPTYPE
};
enum {
CM_NW_STATUS_23G,
CM_NW_STATUS_LTE,
CM_NW_STATUS_5G,
CM_NW_STATUS_NOT_REGISTERED = 3,
};
//////////////////////////////////////////////////////////////////////
// Prototypes
//////////////////////////////////////////////////////////////////////
void spn_info_request_cb(struct ubus_request *req, int type, struct blob_attr *msg);
void rssi_info_request_cb(struct ubus_request *req, int type, struct blob_attr *msg);
void sim_info_request_cb(struct ubus_request *req, int type, struct blob_attr *msg);
void plmn_operator_request_cb(struct ubus_request *req, int type, struct blob_attr *msg);
void CheckDataCallRegisterStatus_data_cb(struct ubus_request *req, int type, struct blob_attr *msg);
void CheckDataCallRegisterStatus_IndCall_data_cb(struct ubus_request *req, int type, struct blob_attr *msg);
void CheckDataCallRegisterStatus_complete_cb(struct ubus_request *req, int ret);
void cm_nwactivity_notify_complete_cb(struct ubus_request *req, int ret);
void CheckDataCallRegisterStatus();
void CheckDataCallRegisterStatus_IndCallback();
char *ucs2_to_utf8(unsigned char *ucs2);
int get_network_display_rule(s_cellular_info * info);
int get_register_plmn();
char *get_network_name(int type);
struct uci_context *uci_wan_ctx_get(void);
void free_wan_uci_ctx(void);
void CM_disable_pdplist_touci(CM_Connection_Context * ConInfo);
void CM_add_pdplist_touci(CM_Connection_Context * ConInfo);
void CM_modify_pdplist_touci(CM_Connection_Context * ConInfo, char match_type);
void sim_info_request_cb(struct ubus_request *req, int type, struct blob_attr *msg);
void send_dialmsg_to_mainthread(int connectionNum, redialmsg_type msgtype);
void send_redialmsg_to_redialthread(int connectionNum, redialmsg_type msgtype);
void nwactivity_arrary_init(void);
int cm_nwactivity_notify(network_activity_msg * msg, bool sync);
int cm_find_nwarrayindex(int cid);
void cm_record_nwactivity(CM_Connection_Context * coninfo, bool sync);
int set_default_data_call(void);
int pdp_info_parse(struct blob_attr *msg, Apn_Info * info);
int create_connection(void);
int destroy_connection(int connection_num, int delete_all);
bool cm_allow_datalink(void);
void save_imsi_into_tmp_file(char *imsi);
int is_pdp_auto_mode(Mnc_Apn * work_apn, char *apn_type);
int cm_get_zroam_iptype();
void cm_notify_dial_failure(int connect_num, int status, int cause);
int is_pdp_auto_apn(Mnc_Apn * work_apn, char *apn_type);
void init_zgdcont_pdp_info(void);
void init_zgdcont_default_pdp_info(void);
void cm_set_atcmd_apn_state(int cid, int state);
int cm_get_atcmd_apn_state(int cid);
void cm_process_mtu_msg(fifo_msg_mtu_s *msg);
void cm_process_switchsim_msg(fifo_msg_switchsim_s *msg);
int cm_get_config_mtu(int cid);
int cm_get_netmask_last_oct(void);
void cm_toe_tft_param_init(void);
void cm_toe_tft_param_update(void *data, int len);
void cm_toe_tuple_send(void);
char *cm_get_cellular_imsi(void);
#ifdef CM_CONFIG_TOE
int cm_trigger_tft_query(bool force);
bool cm_ctx_toe_tuple_match(int cid, struct toe_tuple_list *tuple);
void cm_toe_tft_pf_prepare(PacketFilterInfo *data, int data_len);
void cm_toe_tft_pf_update(TftExtendInfo *data, int data_len);
void cm_toe_tft_pf_delete(int p_cid, int cid);
void cm_toe_tft_pf_list_clear(void);
#endif
int cm_get_nw_status_cache();
void cm_reset_nw_last_param(void);
int cm_save_default_apn(char *apn, char *lte_apn);
int get_etiflag();
void cm_process_switchsim_msg(fifo_msg_switchsim_s *msg);
int getMasterSimID(void);
void setMasterSimID(int simID);
bool isMasterSim0(void);
int cm_query_admindata(void);
int cm_get_mnc_length(void);
#endif