From: Prasanth Kammampati Date: Tue, 4 Sep 2012 13:10:13 +0000 (+0530) Subject: Fixed code formatting issues and end of line(LF) to UNIX style X-Git-Tag: 2.0_alpha~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b4cbb18e340f07d3e0d27479f625a152803c464b;p=framework%2Ftelephony%2Ftel-plugin-imc.git Fixed code formatting issues and end of line(LF) to UNIX style Change-Id: Ie322a5c80a6ebabd8e86a29b653e7c4d51c02faf --- diff --git a/include/common/TelErr.h b/include/common/TelErr.h index d27f39b..4097fc5 100755 --- a/include/common/TelErr.h +++ b/include/common/TelErr.h @@ -1,190 +1,186 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Hayoon Ko - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @open - * @ingroup TelephonyAPI - * @addtogroup COMMON_TAPI COMMON - * @{ - * These error codes are used by Applications. - */ - - -#ifndef _TEL_ERR_H_ -#define _TEL_ERR_H_ -/*================================================================================================== - INCLUDE FILES -==================================================================================================*/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -/*================================================================================================== - CONSTANTS -==================================================================================================*/ - - -/*================================================================================================== - MACROS -==================================================================================================*/ - - -/*================================================================================================== - ENUMS -==================================================================================================*/ - -/************************************************************ -** Errors defined in "+CME ERROR" , -** - see 3GPP TS 27.007 -** - ranges are 0x00 ~ 0x7FFF -************************************************************/ -/** - Error codes sent by the modem in response to the above operations. -*/ -typedef enum -{ - /* GENERAL ERRORS */ - TAPI_OP_GEN_ERR_PHONE_FAILURE = 0, /* 0 */ - TAPI_OP_GEN_ERR_NO_CONNECTION_TO_PHONE, /* 1 */ - TAPI_OP_GEN_ERR_PHONE_ADAPTOR_LINK_RESERVED, /* 2 */ - TAPI_OP_GEN_ERR_OPER_NOT_ALLOWED, /* 3 */ - TAPI_OP_GEN_ERR_OPER_NOT_SUPPORTED, /* 4 */ - TAPI_OP_GEN_ERR_PH_SIM_PIN_REQU, /* 5 */ - TAPI_OP_GEN_ERR_PH_FSIM_PIN_REQU, /* 6 */ - TAPI_OP_GEN_ERR_PH_FSIM_PUK_REQU, /* 7 */ - TAPI_OP_GEN_ERR_SIM_NOT_INSERTED =10, /* 10 */ - TAPI_OP_GEN_ERR_SIM_PIN_REQU, /* 11 */ - TAPI_OP_GEN_ERR_SIM_PUK_REQU, /* 12 */ - TAPI_OP_GEN_ERR_SIM_FAILURE, /* 13 */ - TAPI_OP_GEN_ERR_SIM_BUSY, /* 14 */ - TAPI_OP_GEN_ERR_SIM_WRONG, /* 15 */ - TAPI_OP_GEN_ERR_INCORRECT_PW, /* 16 */ - TAPI_OP_GEN_ERR_SIM_PIN2_REQU, /* 17 */ - TAPI_OP_GEN_ERR_SIM_PUK2_REQU, /* 18 */ - TAPI_OP_GEN_ERR_MEM_FULL = 20, /* 20 */ - TAPI_OP_GEN_ERR_INVALID_INDEX, /* 21 */ - TAPI_OP_GEN_ERR_NOT_FOUND, /* 22 */ - TAPI_OP_GEN_ERR_MEM_FAILURE, /* 23 */ - TAPI_OP_GEN_ERR_TEXT_STR_TOO_LONG, /* 24 */ - TAPI_OP_GEN_ERR_INVALID_CHARACTERS_IN_TEXT_STR, /* 25 */ - TAPI_OP_GEN_ERR_DIAL_STR_TOO_LONG, /* 26 */ - TAPI_OP_GEN_ERR_INVALID_CHARACTERS_IN_DIAL_STR, /* 27 */ - TAPI_OP_GEN_ERR_NO_NET_SVC = 30, /* 30 */ - TAPI_OP_GEN_ERR_NET_TIMEOUT, /* 31 */ - TAPI_OP_GEN_ERR_NET_NOT_ALLOWED_EMERGENCY_CALLS_ONLY, /* 32 */ - TAPI_OP_GEN_ERR_NET_PERS_PIN_REQU = 40, /* 40 */ - TAPI_OP_GEN_ERR_NET_PERS_PUK_REQU, /* 41 */ - TAPI_OP_GEN_ERR_NET_SUBSET_PERS_PIN_REQU, /* 42 */ - TAPI_OP_GEN_ERR_NET_SUBSET_PERS_PUK_REQU, /* 43 */ - TAPI_OP_GEN_ERR_SVC_PROVIDER_PERS_PIN_REQU, /* 44 */ - TAPI_OP_GEN_ERR_SVC_PROVIDER_PERS_PUK_REQU, /* 45 */ - TAPI_OP_GEN_ERR_CORPORATE_PERS_PIN_REQU, /* 46 */ - TAPI_OP_GEN_ERR_CORPORATE_PERS_PUK_REQU, /* 47 */ - TAPI_OP_GEN_ERR_HIDDEN_KEY_REQU, /* 48 */ - TAPI_OP_GEN_ERR_UNKNOWN = 100, /* 100 */ - - /* Errors related to a failure to perform an Attach */ - TAPI_OP_GEN_ERR_ILLEGAL_MS = 103, /* 103 */ - TAPI_OP_GEN_ERR_ILLEGAL_ME = 106, /* 106 */ - TAPI_OP_GEN_ERR_GPRS_SVC_NOT_ALLOWED, /* 107 */ - TAPI_OP_GEN_ERR_PLMN_NOT_ALLOWED = 111, /* 111 */ - TAPI_OP_GEN_ERR_LOCATION_AREA_NOT_ALLOWED, /* 112 */ - TAPI_OP_GEN_ERR_ROAMING_NOT_ALLOWED_IN_THIS_LOCATION_AREA,/* 113 */ - - /* Errors related to a failure to Activate a Context */ - TAPI_OP_GEN_ERR_SVC_OPT_NOT_SUPPORTED = 132, /* 132 */ - TAPI_OP_GEN_ERR_REQ_SVC_OPT_NOT_SUBSCRIBED, /* 133 */ - TAPI_OP_GEN_ERR_SVC_OPT_TEMPORARILY_OUT_OF_ORDER, /* 134 */ - TAPI_OP_GEN_ERR_UNSPECIFIED_GPRS_ERR = 148, /* 148 */ - TAPI_OP_GEN_ERR_PDP_AUTHENTICATION_FAILURE, /* 149 */ - TAPI_OP_GEN_ERR_INVALID_MOBILE_CLASS, /* 150 */ - - /* VBS / VGCS and eMLPP -related errors */ - TAPI_OP_GEN_ERR_VBS_VGCS_NOT_SUPPORTED_BY_THE_NET = 151, /* 151 */ - TAPI_OP_GEN_ERR_NO_SVC_SUBSCRIPTION_ON_SIM, /* 152 */ - TAPI_OP_GEN_ERR_NO_SUBSCRIPTION_FOR_GROUP_ID, /* 153 */ - TAPI_OP_GEN_ERR_GROUP_ID_NOT_ACTIVATED_ON_SIM, /* 154 */ - TAPI_OP_GEN_ERR_NO_MATCHING_NOTI = 155, /* 155 */ - TAPI_OP_GEN_ERR_VBS_VGCS_CALL_ALREADY_PRESENT, /* 156 */ - TAPI_OP_GEN_ERR_CONGESTION, /* 157 */ - TAPI_OP_GEN_ERR_NET_FAILURE, /* 158 */ - TAPI_OP_GEN_ERR_UPLINK_BUSY, /* 159 */ - TAPI_OP_GEN_ERR_NO_ACCESS_RIGHTS_FOR_SIM_FILE = 160, /* 160 */ - TAPI_OP_GEN_ERR_NO_SUBSCRIPTION_FOR_PRIORITY, /* 161 */ - TAPI_OP_GEN_ERR_OPER_NOT_APPLICABLE_OR_NOT_POSSIBLE, /* 162 */ - - - /************************************************************ - ** SAMSUNG ADDED ERRORS - ************************************************************/ - TAPI_OP_GEN_ERR_NONE = 0x8000, /* 0x8000 : No Errors */ - - /* General Common Errors : 0x8000 - 0x80FF */ - TAPI_OP_GEN_ERR_INVALID_FORMAT, /* 0x8001 : Invalid Parameter or Format */ - TAPI_OP_GEN_ERR_PHONE_OFFLINE, /* 0x8002 : */ - TAPI_OP_GEN_ERR_CMD_NOT_ALLOWED, /* 0x8003 : */ - TAPI_OP_GEN_ERR_PHONE_IS_INUSE, /* 0x8004 : */ - TAPI_OP_GEN_ERR_INVALID_STATE = 0x8005, /* 0x8005 : */ - - TAPI_OP_GEN_ERR_NO_BUFFER, /* 0x8006 : No internal free buffers */ - TAPI_OP_GEN_ERR_OPER_REJ, /* 0x8007 : Operation Rejected */ - TAPI_OP_GEN_ERR_INSUFFICIENT_RESOURCE, /* 0x8008 : insufficient resource */ - TAPI_OP_GEN_ERR_NET_NOT_RESPOND, /* 0x8009 : Network not responding */ - TAPI_OP_GEN_ERR_SIM_PIN_ENABLE_REQ = 0x800A, /* 0x800A : SIM Pin Enable Required */ - TAPI_OP_GEN_ERR_SIM_PERM_BLOCKED, /* 0x800B : SIM Permanent Blocked */ - TAPI_OP_GEN_ERR_SIM_PHONEBOOK_RESTRICTED, /*0x800C: SIM Phonebook Restricted*/ - TAPI_OP_GEM_ERR_FIXED_DIALING_NUMBER_ONLY, /*0x800D: Restricted By FDN Mode */ - - /* Reserved : 0x800E ~ 0x80FF */ - TAPI_OP_GEN_ERR_800E_RESERVED_START = 0x800E, /* 0x800E */ - - TAPI_OP_GEN_ERR_80FF_RESERVED_END = 0x80ff, /* 0x80FF */ - - /* the other errors */ - TAPI_OP_GEN_ERR_OTHERS = 0xFFFE, /* 0xFFFE */ - - TAPI_OP_GEN_ERR_MAX = 0xFFFF - -}tapi_phone_err_t; - - -/*================================================================================================== - STRUCTURES AND OTHER TYPEDEFS -==================================================================================================*/ - - -/*================================================================================================== - FUNCTION PROTOTYPES -==================================================================================================*/ - - -#ifdef __cplusplus -} -#endif - -#endif // _TEL_ERR_H_ - -/** -* @} -*/ - +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hayoon Ko + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @open + * @ingroup TelephonyAPI + * @addtogroup COMMON_TAPI COMMON + * @{ + * These error codes are used by Applications. + */ + + +#ifndef _TEL_ERR_H_ +#define _TEL_ERR_H_ +/*================================================================================================== + INCLUDE FILES +==================================================================================================*/ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/*================================================================================================== + CONSTANTS +==================================================================================================*/ + + +/*================================================================================================== + MACROS +==================================================================================================*/ + + +/*================================================================================================== + ENUMS +==================================================================================================*/ + +/************************************************************ +** Errors defined in "+CME ERROR" , +** - see 3GPP TS 27.007 +** - ranges are 0x00 ~ 0x7FFF +************************************************************/ +/** + Error codes sent by the modem in response to the above operations. +*/ +typedef enum { + /* GENERAL ERRORS */ + TAPI_OP_GEN_ERR_PHONE_FAILURE = 0, /* 0 */ + TAPI_OP_GEN_ERR_NO_CONNECTION_TO_PHONE, /* 1 */ + TAPI_OP_GEN_ERR_PHONE_ADAPTOR_LINK_RESERVED, /* 2 */ + TAPI_OP_GEN_ERR_OPER_NOT_ALLOWED, /* 3 */ + TAPI_OP_GEN_ERR_OPER_NOT_SUPPORTED, /* 4 */ + TAPI_OP_GEN_ERR_PH_SIM_PIN_REQU, /* 5 */ + TAPI_OP_GEN_ERR_PH_FSIM_PIN_REQU, /* 6 */ + TAPI_OP_GEN_ERR_PH_FSIM_PUK_REQU, /* 7 */ + TAPI_OP_GEN_ERR_SIM_NOT_INSERTED = 10, /* 10 */ + TAPI_OP_GEN_ERR_SIM_PIN_REQU, /* 11 */ + TAPI_OP_GEN_ERR_SIM_PUK_REQU, /* 12 */ + TAPI_OP_GEN_ERR_SIM_FAILURE, /* 13 */ + TAPI_OP_GEN_ERR_SIM_BUSY, /* 14 */ + TAPI_OP_GEN_ERR_SIM_WRONG, /* 15 */ + TAPI_OP_GEN_ERR_INCORRECT_PW, /* 16 */ + TAPI_OP_GEN_ERR_SIM_PIN2_REQU, /* 17 */ + TAPI_OP_GEN_ERR_SIM_PUK2_REQU, /* 18 */ + TAPI_OP_GEN_ERR_MEM_FULL = 20, /* 20 */ + TAPI_OP_GEN_ERR_INVALID_INDEX, /* 21 */ + TAPI_OP_GEN_ERR_NOT_FOUND, /* 22 */ + TAPI_OP_GEN_ERR_MEM_FAILURE, /* 23 */ + TAPI_OP_GEN_ERR_TEXT_STR_TOO_LONG, /* 24 */ + TAPI_OP_GEN_ERR_INVALID_CHARACTERS_IN_TEXT_STR, /* 25 */ + TAPI_OP_GEN_ERR_DIAL_STR_TOO_LONG, /* 26 */ + TAPI_OP_GEN_ERR_INVALID_CHARACTERS_IN_DIAL_STR, /* 27 */ + TAPI_OP_GEN_ERR_NO_NET_SVC = 30, /* 30 */ + TAPI_OP_GEN_ERR_NET_TIMEOUT, /* 31 */ + TAPI_OP_GEN_ERR_NET_NOT_ALLOWED_EMERGENCY_CALLS_ONLY, /* 32 */ + TAPI_OP_GEN_ERR_NET_PERS_PIN_REQU = 40, /* 40 */ + TAPI_OP_GEN_ERR_NET_PERS_PUK_REQU, /* 41 */ + TAPI_OP_GEN_ERR_NET_SUBSET_PERS_PIN_REQU, /* 42 */ + TAPI_OP_GEN_ERR_NET_SUBSET_PERS_PUK_REQU, /* 43 */ + TAPI_OP_GEN_ERR_SVC_PROVIDER_PERS_PIN_REQU, /* 44 */ + TAPI_OP_GEN_ERR_SVC_PROVIDER_PERS_PUK_REQU, /* 45 */ + TAPI_OP_GEN_ERR_CORPORATE_PERS_PIN_REQU, /* 46 */ + TAPI_OP_GEN_ERR_CORPORATE_PERS_PUK_REQU, /* 47 */ + TAPI_OP_GEN_ERR_HIDDEN_KEY_REQU, /* 48 */ + TAPI_OP_GEN_ERR_UNKNOWN = 100, /* 100 */ + + /* Errors related to a failure to perform an Attach */ + TAPI_OP_GEN_ERR_ILLEGAL_MS = 103, /* 103 */ + TAPI_OP_GEN_ERR_ILLEGAL_ME = 106, /* 106 */ + TAPI_OP_GEN_ERR_GPRS_SVC_NOT_ALLOWED, /* 107 */ + TAPI_OP_GEN_ERR_PLMN_NOT_ALLOWED = 111, /* 111 */ + TAPI_OP_GEN_ERR_LOCATION_AREA_NOT_ALLOWED, /* 112 */ + TAPI_OP_GEN_ERR_ROAMING_NOT_ALLOWED_IN_THIS_LOCATION_AREA, /* 113 */ + + /* Errors related to a failure to Activate a Context */ + TAPI_OP_GEN_ERR_SVC_OPT_NOT_SUPPORTED = 132, /* 132 */ + TAPI_OP_GEN_ERR_REQ_SVC_OPT_NOT_SUBSCRIBED, /* 133 */ + TAPI_OP_GEN_ERR_SVC_OPT_TEMPORARILY_OUT_OF_ORDER, /* 134 */ + TAPI_OP_GEN_ERR_UNSPECIFIED_GPRS_ERR = 148, /* 148 */ + TAPI_OP_GEN_ERR_PDP_AUTHENTICATION_FAILURE, /* 149 */ + TAPI_OP_GEN_ERR_INVALID_MOBILE_CLASS, /* 150 */ + + /* VBS / VGCS and eMLPP -related errors */ + TAPI_OP_GEN_ERR_VBS_VGCS_NOT_SUPPORTED_BY_THE_NET = 151, /* 151 */ + TAPI_OP_GEN_ERR_NO_SVC_SUBSCRIPTION_ON_SIM, /* 152 */ + TAPI_OP_GEN_ERR_NO_SUBSCRIPTION_FOR_GROUP_ID, /* 153 */ + TAPI_OP_GEN_ERR_GROUP_ID_NOT_ACTIVATED_ON_SIM, /* 154 */ + TAPI_OP_GEN_ERR_NO_MATCHING_NOTI = 155, /* 155 */ + TAPI_OP_GEN_ERR_VBS_VGCS_CALL_ALREADY_PRESENT, /* 156 */ + TAPI_OP_GEN_ERR_CONGESTION, /* 157 */ + TAPI_OP_GEN_ERR_NET_FAILURE, /* 158 */ + TAPI_OP_GEN_ERR_UPLINK_BUSY, /* 159 */ + TAPI_OP_GEN_ERR_NO_ACCESS_RIGHTS_FOR_SIM_FILE = 160, /* 160 */ + TAPI_OP_GEN_ERR_NO_SUBSCRIPTION_FOR_PRIORITY, /* 161 */ + TAPI_OP_GEN_ERR_OPER_NOT_APPLICABLE_OR_NOT_POSSIBLE, /* 162 */ + + + /************************************************************ + ** SAMSUNG ADDED ERRORS + ************************************************************/ + TAPI_OP_GEN_ERR_NONE = 0x8000, /* 0x8000 : No Errors */ + + /* General Common Errors : 0x8000 - 0x80FF */ + TAPI_OP_GEN_ERR_INVALID_FORMAT, /* 0x8001 : Invalid Parameter or Format */ + TAPI_OP_GEN_ERR_PHONE_OFFLINE, /* 0x8002 : */ + TAPI_OP_GEN_ERR_CMD_NOT_ALLOWED, /* 0x8003 : */ + TAPI_OP_GEN_ERR_PHONE_IS_INUSE, /* 0x8004 : */ + TAPI_OP_GEN_ERR_INVALID_STATE = 0x8005, /* 0x8005 : */ + + TAPI_OP_GEN_ERR_NO_BUFFER, /* 0x8006 : No internal free buffers */ + TAPI_OP_GEN_ERR_OPER_REJ, /* 0x8007 : Operation Rejected */ + TAPI_OP_GEN_ERR_INSUFFICIENT_RESOURCE, /* 0x8008 : insufficient resource */ + TAPI_OP_GEN_ERR_NET_NOT_RESPOND, /* 0x8009 : Network not responding */ + TAPI_OP_GEN_ERR_SIM_PIN_ENABLE_REQ = 0x800A, /* 0x800A : SIM Pin Enable Required */ + TAPI_OP_GEN_ERR_SIM_PERM_BLOCKED, /* 0x800B : SIM Permanent Blocked */ + TAPI_OP_GEN_ERR_SIM_PHONEBOOK_RESTRICTED, /*0x800C: SIM Phonebook Restricted*/ + TAPI_OP_GEM_ERR_FIXED_DIALING_NUMBER_ONLY, /*0x800D: Restricted By FDN Mode */ + + /* Reserved : 0x800E ~ 0x80FF */ + TAPI_OP_GEN_ERR_800E_RESERVED_START = 0x800E, /* 0x800E */ + + TAPI_OP_GEN_ERR_80FF_RESERVED_END = 0x80ff, /* 0x80FF */ + + /* the other errors */ + TAPI_OP_GEN_ERR_OTHERS = 0xFFFE, /* 0xFFFE */ + + TAPI_OP_GEN_ERR_MAX = 0xFFFF +} tapi_phone_err_t; + + +/*================================================================================================== + STRUCTURES AND OTHER TYPEDEFS +==================================================================================================*/ + + +/*================================================================================================== + FUNCTION PROTOTYPES +==================================================================================================*/ + + +#ifdef __cplusplus +} +#endif + +#endif // _TEL_ERR_H_ + +/** +* @} +*/ diff --git a/include/s_call.h b/include/s_call.h index b7148dd..32e869c 100755 --- a/include/s_call.h +++ b/include/s_call.h @@ -1,28 +1,27 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Sharanayya Mathapati - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __S_CALL_H__ -#define __S_CALL_H__ - -gboolean s_call_init(TcorePlugin *p, TcoreHal *h); -void s_call_exit(TcorePlugin *p); - -#endif - +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Sharanayya Mathapati + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __S_CALL_H__ +#define __S_CALL_H__ + +gboolean s_call_init(TcorePlugin *p, TcoreHal *h); +void s_call_exit(TcorePlugin *p); + +#endif diff --git a/include/s_common.h b/include/s_common.h index a19581c..cb03d61 100755 --- a/include/s_common.h +++ b/include/s_common.h @@ -1,113 +1,111 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Hayoon Ko - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __S_COMMON_H__ -#define __S_COMMON_H__ - -#include -#include -#include - - -#define EVENT_SYS_NOTI_MODEM_POWER "system_power" -#define EVENT_NOTI_MODEM_POWER "modem_power" -#define EVENT_NOTI_MODEM_PHONE_STATE "modem_phone_state" -#define EVENT_NOTI_MODEM_PIN_CTRL "ps_pin_control" - -#define EVENT_NOTI_CALL_STATUS "call_status" -#define EVENT_NOTI_CALL_INCOMING "call_incoming" -#define EVENT_NOTI_CALL_WAITING "call_waiting" -#define EVENT_NOTI_CALL_SOUND_WBAMR_REPORT "call_sound_wbamr_report" -#define EVENT_NOTI_CALL_SOUND_TWO_MIC "call_sound_two_mic" -#define EVENT_NOTI_CALL_SOUND_DHA "call_sound_dha" - -#define EVENT_NOTI_SS_INFO "ss_info" -#define EVENT_NOTI_SS_USSD "ss_ussd" - -#define EVENT_NOTI_PS_CALL_STATUS "ps_call_status" -#define EVENT_NOTI_PS_DATA_COUNTER "ps_data_counter" -#define EVENT_NOTI_PS_IPCONFIGURATION "ps_ipconfiguration" -#define EVENT_NOTI_PS_HSDPA_STATUS "ps_hsdpa_status" -#define EVENT_NOTI_PS_ATTACH_DETACH "ps_attach_detach" -#define EVENT_NOTI_PS_EXTERNAL_CALL "ps_external_call" - -#define EVENT_NOTI_SAP_STATUS "sap_status" -#define EVENT_NOTI_SAP_DISCONNECT "sap_disconnect" - -#define EVENT_NOTI_SIM_PIN_STATUS "sim_pin_status" - -#define EVENT_NOTI_SAT_ENVELOPE_RESP "sat_envelope_response" -#define EVENT_NOTI_SAT_REFRESH_STATUS "sat_refresh_status" -#define EVENT_NOTI_SAT_PROACTIVE_COMMAND "sat_proactive_command" -#define EVENT_NOTI_SAT_CONTROL_RESULT "sat_control_result" - -#define EVENT_NOTI_NETWORK_REGISTRATION "network_regist" -#define EVENT_NOTI_NETWORK_ICON_INFO "network_icon_info" -#define EVENT_NOTI_NETWORK_TIME_INFO "network_time_info" -#define EVENT_NOTI_NETWORK_IDENTITY "network_identity" - -#define EVENT_NOTI_SMS_INCOM_MSG "sms_incom_msg" -#define EVENT_NOTI_SMS_SEND_ACK "sms_send_ack" -#define EVENT_NOTI_SMS_MEMORY_STATUS "sms_memory_status" -#define EVENT_NOTI_SMS_CB_INCOM_MSG "sms_cb_incom_msg" -#define EVENT_NOTI_SMS_DELETE_MSG_CNF "sms_delete_msg_cnf" -#define EVENT_NOTI_SMS_WRITE_MSG_CNF "sms_write_msg_cnf" -#define EVENT_NOTI_SMS_DELIVERY_RPT_CNF "sms_deliver_rpt_cnf" -#define EVENT_NOTI_SMS_DEVICE_READY "sms_device_ready" - -#define EVENT_NOTI_PHONEBOOK_STATUS "phonebook_status" -#define EVENT_NOTI_PHONEBOOK_FIRST_INDEX "phonebook_first_index" - -#define EVENT_NOTI_GPS_ASSIST_DATA "gps_assist_data" -#define EVENT_IND_GPS_MEASURE_POSITION "gps_measure_position" -#define EVENT_NOTI_RESET_ASSIST_DATA "gps_reset_assist_data" - -enum direction_e { - RX, - TX -}; - -struct global_data { - unsigned int msg_auto_id_current; - unsigned int msg_auto_id_start; - unsigned int msg_auto_id_end; - - TcoreHal *hal; -}; - -struct work_queue_data { - unsigned int id; - UserRequest *ur; -}; - -#define UTIL_ID(hdr) ((hdr).main_cmd << 8 | (hdr).sub_cmd) -#define UTIL_IDP(hdr) ((hdr)->main_cmd << 8 | (hdr)->sub_cmd) - -void hook_hex_dump(enum direction_e d, int size, const void *data); -unsigned int util_assign_message_sequence_id(TcorePlugin *p); -gboolean util_add_waiting_job(GQueue *queue, unsigned int id, UserRequest *ur); -UserRequest* util_pop_waiting_job(GQueue *queue, unsigned int id); -void util_hex_dump(char *pad, int size, const void *data); -unsigned char util_hexCharToInt(char c); -char* util_hexStringToBytes(char * s); -char* util_removeQuotes(void *data); - -#endif +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hayoon Ko + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __S_COMMON_H__ +#define __S_COMMON_H__ + +#include +#include +#include + +#define EVENT_SYS_NOTI_MODEM_POWER "system_power" +#define EVENT_NOTI_MODEM_POWER "modem_power" +#define EVENT_NOTI_MODEM_PHONE_STATE "modem_phone_state" +#define EVENT_NOTI_MODEM_PIN_CTRL "ps_pin_control" + +#define EVENT_NOTI_CALL_STATUS "call_status" +#define EVENT_NOTI_CALL_INCOMING "call_incoming" +#define EVENT_NOTI_CALL_WAITING "call_waiting" +#define EVENT_NOTI_CALL_SOUND_WBAMR_REPORT "call_sound_wbamr_report" +#define EVENT_NOTI_CALL_SOUND_TWO_MIC "call_sound_two_mic" +#define EVENT_NOTI_CALL_SOUND_DHA "call_sound_dha" + +#define EVENT_NOTI_SS_INFO "ss_info" +#define EVENT_NOTI_SS_USSD "ss_ussd" + +#define EVENT_NOTI_PS_CALL_STATUS "ps_call_status" +#define EVENT_NOTI_PS_DATA_COUNTER "ps_data_counter" +#define EVENT_NOTI_PS_IPCONFIGURATION "ps_ipconfiguration" +#define EVENT_NOTI_PS_HSDPA_STATUS "ps_hsdpa_status" +#define EVENT_NOTI_PS_ATTACH_DETACH "ps_attach_detach" +#define EVENT_NOTI_PS_EXTERNAL_CALL "ps_external_call" + +#define EVENT_NOTI_SAP_STATUS "sap_status" +#define EVENT_NOTI_SAP_DISCONNECT "sap_disconnect" + +#define EVENT_NOTI_SIM_PIN_STATUS "sim_pin_status" + +#define EVENT_NOTI_SAT_ENVELOPE_RESP "sat_envelope_response" +#define EVENT_NOTI_SAT_REFRESH_STATUS "sat_refresh_status" +#define EVENT_NOTI_SAT_PROACTIVE_COMMAND "sat_proactive_command" +#define EVENT_NOTI_SAT_CONTROL_RESULT "sat_control_result" + +#define EVENT_NOTI_NETWORK_REGISTRATION "network_regist" +#define EVENT_NOTI_NETWORK_ICON_INFO "network_icon_info" +#define EVENT_NOTI_NETWORK_TIME_INFO "network_time_info" +#define EVENT_NOTI_NETWORK_IDENTITY "network_identity" + +#define EVENT_NOTI_SMS_INCOM_MSG "sms_incom_msg" +#define EVENT_NOTI_SMS_SEND_ACK "sms_send_ack" +#define EVENT_NOTI_SMS_MEMORY_STATUS "sms_memory_status" +#define EVENT_NOTI_SMS_CB_INCOM_MSG "sms_cb_incom_msg" +#define EVENT_NOTI_SMS_DELETE_MSG_CNF "sms_delete_msg_cnf" +#define EVENT_NOTI_SMS_WRITE_MSG_CNF "sms_write_msg_cnf" +#define EVENT_NOTI_SMS_DELIVERY_RPT_CNF "sms_deliver_rpt_cnf" +#define EVENT_NOTI_SMS_DEVICE_READY "sms_device_ready" + +#define EVENT_NOTI_PHONEBOOK_STATUS "phonebook_status" +#define EVENT_NOTI_PHONEBOOK_FIRST_INDEX "phonebook_first_index" + +#define EVENT_NOTI_GPS_ASSIST_DATA "gps_assist_data" +#define EVENT_IND_GPS_MEASURE_POSITION "gps_measure_position" +#define EVENT_NOTI_RESET_ASSIST_DATA "gps_reset_assist_data" + +enum direction_e { + RX, + TX +}; + +struct global_data { + unsigned int msg_auto_id_current; + unsigned int msg_auto_id_start; + unsigned int msg_auto_id_end; + + TcoreHal *hal; +}; + +struct work_queue_data { + unsigned int id; + UserRequest *ur; +}; + +#define UTIL_ID(hdr) ((hdr).main_cmd << 8 | (hdr).sub_cmd) +#define UTIL_IDP(hdr) ((hdr)->main_cmd << 8 | (hdr)->sub_cmd) + +void hook_hex_dump(enum direction_e d, int size, const void *data); +unsigned int util_assign_message_sequence_id(TcorePlugin *p); +gboolean util_add_waiting_job(GQueue *queue, unsigned int id, UserRequest *ur); +UserRequest* util_pop_waiting_job(GQueue *queue, unsigned int id); +void util_hex_dump(char *pad, int size, const void *data); +unsigned char util_hexCharToInt(char c); +char* util_hexStringToBytes(char *s); +char* util_removeQuotes(void *data); + +#endif diff --git a/include/s_dispatch.h b/include/s_dispatch.h index 9a38cdd..5ee2f85 100755 --- a/include/s_dispatch.h +++ b/include/s_dispatch.h @@ -1,28 +1,28 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Ja-young Gu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __S_DISPATCH_H__ -#define __S_DISPATCH_H__ - -void do_factory(TcoreHal *h, const ipc_message_type *ipc); -void do_notification_message(TcorePlugin *p, const ipc_message_type *ipc); -void do_notification_sys_message(TcorePlugin *p, const void *data); - -#endif +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Ja-young Gu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __S_DISPATCH_H__ +#define __S_DISPATCH_H__ + +void do_factory(TcoreHal *h, const ipc_message_type *ipc); +void do_notification_message(TcorePlugin *p, const ipc_message_type *ipc); +void do_notification_sys_message(TcorePlugin *p, const void *data); + +#endif diff --git a/include/s_gps.h b/include/s_gps.h index 6b0da4d..9c1cb1f 100755 --- a/include/s_gps.h +++ b/include/s_gps.h @@ -1,29 +1,27 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Arun Shukla - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __S_GPS_H__ -#define __S_GPS_H__ - - -gboolean s_gps_init(TcorePlugin *p, TcoreHal *h); -void s_gps_exit(TcorePlugin *p); - -#endif +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Arun Shukla + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __S_GPS_H__ +#define __S_GPS_H__ + +gboolean s_gps_init(TcorePlugin *p, TcoreHal *h); +void s_gps_exit(TcorePlugin *p); + +#endif diff --git a/include/s_modem.h b/include/s_modem.h index 6ee9281..2fdd1d8 100755 --- a/include/s_modem.h +++ b/include/s_modem.h @@ -1,31 +1,29 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Hayoon Ko - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __S_MODEM_H__ -#define __S_MODEM_H__ - -gboolean on_event_modem_power(TcoreAT *at, const char *line, TcorePlugin *p); - -gboolean s_modem_init(TcorePlugin *p, TcoreHal *h); -void s_modem_exit(TcorePlugin *p); - -gboolean s_modem_send_poweron(TcorePlugin *p); -#endif +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hayoon Ko + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __S_MODEM_H__ +#define __S_MODEM_H__ + +gboolean on_event_modem_power(TcoreAT *at, const char *line, TcorePlugin *p); +gboolean s_modem_init(TcorePlugin *p, TcoreHal *h); +void s_modem_exit(TcorePlugin *p); +gboolean s_modem_send_poweron(TcorePlugin *p); + +#endif diff --git a/include/s_network.h b/include/s_network.h index 68ab682..43fde4c 100755 --- a/include/s_network.h +++ b/include/s_network.h @@ -1,29 +1,27 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Harish Bishnoi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __S_NETWORK_H__ -#define __S_NETWORK_H__ - - -gboolean s_network_init(TcorePlugin *p, TcoreHal *h); -void s_network_exit(TcorePlugin *p); - -#endif +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Harish Bishnoi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __S_NETWORK_H__ +#define __S_NETWORK_H__ + +gboolean s_network_init(TcorePlugin *p, TcoreHal *h); +void s_network_exit(TcorePlugin *p); + +#endif diff --git a/include/s_phonebook.h b/include/s_phonebook.h index dc1e037..a277ed2 100755 --- a/include/s_phonebook.h +++ b/include/s_phonebook.h @@ -1,28 +1,27 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Ja-young Gu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef S_PHONEBOOK_H_ -#define S_PHONEBOOK_H_ - -gboolean s_phonebook_init(TcorePlugin *p, TcoreHal *h); -void s_phonebook_exit(TcorePlugin *p); - -#endif /* S_PHONEBOOK_H_ */ +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Ja-young Gu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef S_PHONEBOOK_H_ +#define S_PHONEBOOK_H_ + +gboolean s_phonebook_init(TcorePlugin *p, TcoreHal *h); +void s_phonebook_exit(TcorePlugin *p); + +#endif /* S_PHONEBOOK_H_ */ diff --git a/include/s_ps.h b/include/s_ps.h index b70ae52..ee73554 100755 --- a/include/s_ps.h +++ b/include/s_ps.h @@ -1,29 +1,27 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Arun Shukla - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __S_PS_H__ -#define __S_PS_H__ - -gboolean s_ps_init(TcorePlugin *p,TcoreHal *hal); -void s_ps_exit(TcorePlugin *p); - - -#endif/*__S_PS_H__*/ +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Arun Shukla + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __S_PS_H__ +#define __S_PS_H__ + +gboolean s_ps_init(TcorePlugin *p, TcoreHal *hal); +void s_ps_exit(TcorePlugin *p); + +#endif /*__S_PS_H__*/ diff --git a/include/s_sap.h b/include/s_sap.h index e9572bc..8e713cd 100755 --- a/include/s_sap.h +++ b/include/s_sap.h @@ -1,28 +1,27 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Hayoon Ko - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef S_SAP_H_ -#define S_SAP_H_ - -gboolean s_sap_init(TcorePlugin *p, TcoreHal *h); -void s_sap_exit(TcorePlugin *p); - -#endif /* S_SAP_H_ */ +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hayoon Ko + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef S_SAP_H_ +#define S_SAP_H_ + +gboolean s_sap_init(TcorePlugin *p, TcoreHal *h); +void s_sap_exit(TcorePlugin *p); + +#endif /* S_SAP_H_ */ diff --git a/include/s_sat.h b/include/s_sat.h index c282d61..c7cb514 100755 --- a/include/s_sat.h +++ b/include/s_sat.h @@ -1,28 +1,28 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Harish Bishnoi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef S_SAT_H_ -#define S_SAT_H_ - -gboolean s_sat_init(TcorePlugin *p, TcoreHal *h); -void s_sat_exit(TcorePlugin *p); - -#endif /* S_SAT_H_ */ +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Harish Bishnoi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef S_SAT_H_ +#define S_SAT_H_ + +gboolean s_sat_init(TcorePlugin *p, TcoreHal *h); +void s_sat_exit(TcorePlugin *p); + +#endif /* S_SAT_H_ */ diff --git a/include/s_sim.h b/include/s_sim.h index c740152..8f8081d 100755 --- a/include/s_sim.h +++ b/include/s_sim.h @@ -1,28 +1,27 @@ -/** - * tel-plugin-imc - * - * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Ankit Jogi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __S_SIM_H__ -#define __S_SIM_H__ - - -gboolean s_sim_init(TcorePlugin *p, TcoreHal *h); -void s_sim_exit(TcorePlugin *p); - -#endif +/** + * tel-plugin-imc + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Ankit Jogi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __S_SIM_H__ +#define __S_SIM_H__ + +gboolean s_sim_init(TcorePlugin *p, TcoreHal *h); +void s_sim_exit(TcorePlugin *p); + +#endif diff --git a/include/s_sms.h b/include/s_sms.h index 2084f37..9eaad7f 100755 --- a/include/s_sms.h +++ b/include/s_sms.h @@ -1,28 +1,27 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Madhavi Akella - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Madhavi Akella + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef S_SMS_H_ #define S_SMS_H_ - -gboolean s_sms_init(TcorePlugin *p, TcoreHal *h); -void s_sms_exit(TcorePlugin *p); - -#endif //S_SMS_H_ \ No newline at end of file + +gboolean s_sms_init(TcorePlugin *p, TcoreHal *h); +void s_sms_exit(TcorePlugin *p); + +#endif // S_SMS_H_ diff --git a/include/s_ss.h b/include/s_ss.h index 68f6a0a..7eeb2e9 100755 --- a/include/s_ss.h +++ b/include/s_ss.h @@ -1,31 +1,27 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Sharanayya Mathapati - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __S_SS_H__ -#define __S_SS_H__ - - -gboolean s_ss_init(TcorePlugin *p, TcoreHal *h); -void s_ss_exit(TcorePlugin *p); - - - -#endif +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Sharanayya Mathapati + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __S_SS_H__ +#define __S_SS_H__ + +gboolean s_ss_init(TcorePlugin *p, TcoreHal *h); +void s_ss_exit(TcorePlugin *p); + +#endif diff --git a/res/convert_to_sql.c b/res/convert_to_sql.c index e22f3cf..5b1b1ba 100755 --- a/res/convert_to_sql.c +++ b/res/convert_to_sql.c @@ -24,7 +24,7 @@ #define TABLE_NAME "mcc_mnc_oper_list" #define TABLE_SCHEMA "create table " TABLE_NAME " (id integer primary key, country char(3), mcc integer, mnc char(3), oper char(45));" -#define dbg(fmt,args...) fprintf(stderr, fmt, ##args); +#define dbg(fmt, args ...) fprintf(stderr, fmt, ## args) int main(int argc, char *argv[]) { @@ -54,52 +54,52 @@ int main(int argc, char *argv[]) printf("BEGIN;\n"); while (1) { - fgets (buf, 255, fp_in); + fgets(buf, 255, fp_in); - if (feof(fp_in)) { + if (feof(fp_in)) { break; } // remove '\n' - buf[strlen(buf)-1] = '\0'; + buf[strlen(buf) - 1] = '\0'; dbg("\n%s\n", buf); - pos1 = strchr (buf, ','); - memset (country, 0, 10); - memcpy(country, buf, pos1-buf); + pos1 = strchr(buf, ','); + memset(country, 0, 10); + memcpy(country, buf, pos1 - buf); dbg("country=[%s]\n", country); - sscanf (pos1+1, "%d", &mcc); + sscanf(pos1 + 1, "%d", &mcc); dbg("mcc=[%d]\n", mcc); // get mnc - pos1 = strchr (pos1+1, ','); - pos2 = strchr (pos1+1, ','); + pos1 = strchr(pos1 + 1, ','); + pos2 = strchr(pos1 + 1, ','); - dbg("mnc=[%s]\n", pos1+1); + dbg("mnc=[%s]\n", pos1 + 1); - memset (mnc, 0, 10); - strncpy (mnc, pos1+1, pos2-pos1-1); + memset(mnc, 0, 10); + strncpy(mnc, pos1 + 1, pos2 - pos1 - 1); // get brand pos1 = pos2; - pos2 = strchr (pos1+1, ','); + pos2 = strchr(pos1 + 1, ','); - dbg("brand=[%s]\n", pos1+1); + dbg("brand=[%s]\n", pos1 + 1); - memset (brand, 0, 255); - strncpy (brand, pos1+1, pos2-pos1-1); + memset(brand, 0, 255); + strncpy(brand, pos1 + 1, pos2 - pos1 - 1); // get oper pos1 = pos2; - pos2 = strchr (pos1+1, ','); + pos2 = strchr(pos1 + 1, ','); - dbg("oper=[%s]\n", pos1+1); + dbg("oper=[%s]\n", pos1 + 1); - memset (oper, 0, 255); - strcpy (oper, pos1+1); + memset(oper, 0, 255); + strcpy(oper, pos1 + 1); oper_select = brand; if (strlen(brand) == 0) @@ -107,15 +107,15 @@ int main(int argc, char *argv[]) if (oper_select[0] == '\"') { memset(buf, 0, 255); - snprintf(buf, strlen(oper_select)-2, "%s", oper_select+1); + snprintf(buf, strlen(oper_select) - 2, "%s", oper_select + 1); snprintf(oper_select, 255, "%s", buf); } snprintf(buf, 255, "insert into %s " - " (country, mcc, mnc, oper) " - " values (\"%s\", %d, \"%s\", \"%s\");", - TABLE_NAME, country, mcc, mnc, oper_select); - printf("%s\n",buf); + " (country, mcc, mnc, oper) " + " values (\"%s\", %d, \"%s\", \"%s\");", + TABLE_NAME, country, mcc, mnc, oper_select); + printf("%s\n", buf); } printf("COMMIT;\n"); diff --git a/src/desc.c b/src/desc.c index 9261732..97e3cef 100755 --- a/src/desc.c +++ b/src/desc.c @@ -1,219 +1,220 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Hayoon Ko - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include "s_common.h" -#include "s_network.h" -#include "s_modem.h" -#include "s_sim.h" -#include "s_sap.h" -#include "s_ps.h" -#include "s_call.h" -#include "s_ss.h" -#include "s_sms.h" -#include "s_sat.h" -#include "s_phonebook.h" -#include "s_gps.h" - -static char *cp_name; - -static enum tcore_hook_return on_hal_send(TcoreHal *hal, unsigned int data_len, void *data, void *user_data) -{ - hook_hex_dump(TX, data_len, data); - return TCORE_HOOK_RETURN_CONTINUE; -} - -static void on_hal_recv(TcoreHal *hal, unsigned int data_len, const void *data, void *user_data) -{ - msg("=== RX data DUMP ====="); - util_hex_dump(" ", data_len, data); - msg("=== RX data DUMP ====="); -} - -static gboolean on_load() -{ - dbg("i'm load!"); - - return TRUE; -} - -static int _get_cp_name(char** name) -{ - struct utsname u; - - char *svnet1_models[] = { "F1", "S1", "M2", "H2", "H2_SDK", - "CRESPO", "STEALTHV", "SLP45", "Kessler", "P1P2", - "U1SLP", "U1HD", "SLP7_C210", "SLP10_C210", NULL }; - - char *svnet2_models[] = { "SMDK4410", "SMDK4212", "SLP_PQ", "SLP_PQ_LTE", "SLP_NAPLES", "REDWOOD", "TRATS", NULL }; - - char* tty_models[] = {"QCT MSM8X55 SURF" , "QCT MSM7x27a FFA", NULL }; - - int i=0; - - if (*name) { - dbg("[ error ] name is not empty"); - return FALSE; - } - - memset(&u, '\0', sizeof(struct utsname)); - - uname(&u); - - dbg("u.nodename : [ %s ]", u.nodename); - - for(i=0; svnet1_models[i]; i++) { - if (!strcmp(u.nodename, svnet1_models[i])) { - *name = g_new0(char, 5); - strcpy(*name, "6260"); - return 5; - } - } - - for(i=0; svnet2_models[i]; i++) { - if (!strcmp(u.nodename, svnet2_models[i])) { - *name = g_new0(char, 5); - strcpy(*name, "6262"); - return 5; - } - } - - for(i=0; tty_models[i]; i++) { - if (!strcmp(u.nodename, tty_models[i])) { - *name = g_new0(char, 6); - strcpy(*name, "dpram"); - return 6; - } - } - - dbg("[ error ] unknown model : (%s)", u.nodename); - - return 0; -} - -static gboolean on_init(TcorePlugin *p) -{ - TcoreHal *h; - struct global_data *gd; - //char *cp_name = 0; - int len = 0; - - if (!p) - return FALSE; - - gd = calloc(sizeof(struct global_data), 1); - if (!gd) - return FALSE; - - dbg("i'm init!"); - - gd->msg_auto_id_current = 0; - gd->msg_auto_id_start = 1; - gd->msg_auto_id_end = 255; - - len = _get_cp_name(&cp_name); - if (!len) { - dbg("[ error ] unsupport cp (name : %s)", cp_name); - free(gd); - return FALSE; - } - - /* FIXME: HAL will reside in Co-object. - * This HAL is just used as default before MUX setup. - * Each HAL has AT pasre functionality. - */ - h = tcore_server_find_hal(tcore_plugin_ref_server(p), cp_name); - if (!h) { - g_free(cp_name); - free(gd); - return FALSE; - } - - //set physical hal into plugin's userdata - gd->hal = h; - - tcore_plugin_link_user_data(p, gd); - - tcore_hal_add_send_hook(h, on_hal_send, p); - tcore_hal_add_recv_callback(h, on_hal_recv, p); - - dbg("skip _register_unsolicited_messages() - this should be done in each co-object"); - - /* Register Unsolicited msg handler */ - //_register_unsolicited_messages(p); - - s_modem_init(p, h); - s_sim_init(p, h); - s_sat_init(p, h); - s_network_init(p, h); -// s_sap_init(p, h); - s_ps_init(p, h); - s_call_init(p, h); - s_ss_init(p, h); - s_sms_init(p, h); -// s_phonebook_init(p, h); -// s_gps_init(p, h); - - g_free(cp_name); - - tcore_hal_set_power(h, TRUE); - /* SEND CPAS command to invoke modem power on. */ - s_modem_send_poweron(p); - - return TRUE; -} - -static void on_unload(TcorePlugin *p) -{ - struct global_data *gd; - - if (!p) - return; - - dbg("i'm unload"); - - gd = tcore_plugin_ref_user_data(p); - if (gd) { - free(gd); - } -} - -struct tcore_plugin_define_desc plugin_define_desc = -{ - .name = "IMC", - .priority = TCORE_PLUGIN_PRIORITY_MID, - .version = 1, - .load = on_load, - .init = on_init, - .unload = on_unload -}; +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hayoon Ko + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include "s_common.h" +#include "s_network.h" +#include "s_modem.h" +#include "s_sim.h" +#include "s_sap.h" +#include "s_ps.h" +#include "s_call.h" +#include "s_ss.h" +#include "s_sms.h" +#include "s_sat.h" +#include "s_phonebook.h" +#include "s_gps.h" + +static char *cp_name; + +static enum tcore_hook_return on_hal_send(TcoreHal *hal, unsigned int data_len, void *data, void *user_data) +{ + hook_hex_dump(TX, data_len, data); + return TCORE_HOOK_RETURN_CONTINUE; +} + +static void on_hal_recv(TcoreHal *hal, unsigned int data_len, const void *data, void *user_data) +{ + msg("=== RX data DUMP ====="); + util_hex_dump(" ", data_len, data); + msg("=== RX data DUMP ====="); +} + +static gboolean on_load() +{ + dbg("i'm load!"); + + return TRUE; +} + +static int _get_cp_name(char **name) +{ + struct utsname u; + + char *svnet1_models[] = { + "F1", "S1", "M2", "H2", "H2_SDK", + "CRESPO", "STEALTHV", "SLP45", "Kessler", "P1P2", + "U1SLP", "U1HD", "SLP7_C210", "SLP10_C210", NULL + }; + + char *svnet2_models[] = { "SMDK4410", "SMDK4212", "SLP_PQ", "SLP_PQ_LTE", "SLP_NAPLES", "REDWOOD", "TRATS", NULL }; + + char *tty_models[] = { "QCT MSM8X55 SURF", "QCT MSM7x27a FFA", NULL }; + + int i = 0; + + if (*name) { + dbg("[ error ] name is not empty"); + return FALSE; + } + + memset(&u, '\0', sizeof(struct utsname)); + + uname(&u); + + dbg("u.nodename : [ %s ]", u.nodename); + + for (i = 0; svnet1_models[i]; i++) { + if (!strcmp(u.nodename, svnet1_models[i])) { + *name = g_new0(char, 5); + strcpy(*name, "6260"); + return 5; + } + } + + for (i = 0; svnet2_models[i]; i++) { + if (!strcmp(u.nodename, svnet2_models[i])) { + *name = g_new0(char, 5); + strcpy(*name, "6262"); + return 5; + } + } + + for (i = 0; tty_models[i]; i++) { + if (!strcmp(u.nodename, tty_models[i])) { + *name = g_new0(char, 6); + strcpy(*name, "dpram"); + return 6; + } + } + + dbg("[ error ] unknown model : (%s)", u.nodename); + + return 0; +} + +static gboolean on_init(TcorePlugin *p) +{ + TcoreHal *h; + struct global_data *gd; + // char *cp_name = 0; + int len = 0; + + if (!p) + return FALSE; + + gd = calloc(sizeof(struct global_data), 1); + if (!gd) + return FALSE; + + dbg("i'm init!"); + + gd->msg_auto_id_current = 0; + gd->msg_auto_id_start = 1; + gd->msg_auto_id_end = 255; + + len = _get_cp_name(&cp_name); + if (!len) { + dbg("[ error ] unsupport cp (name : %s)", cp_name); + free(gd); + return FALSE; + } + + /* FIXME: HAL will reside in Co-object. + * This HAL is just used as default before MUX setup. + * Each HAL has AT pasre functionality. + */ + h = tcore_server_find_hal(tcore_plugin_ref_server(p), cp_name); + if (!h) { + g_free(cp_name); + free(gd); + return FALSE; + } + + // set physical hal into plugin's userdata + gd->hal = h; + + tcore_plugin_link_user_data(p, gd); + + tcore_hal_add_send_hook(h, on_hal_send, p); + tcore_hal_add_recv_callback(h, on_hal_recv, p); + + dbg("skip _register_unsolicited_messages() - this should be done in each co-object"); + + /* Register Unsolicited msg handler */ + // _register_unsolicited_messages(p); + + s_modem_init(p, h); + s_sim_init(p, h); + s_sat_init(p, h); + s_network_init(p, h); +// s_sap_init(p, h); + s_ps_init(p, h); + s_call_init(p, h); + s_ss_init(p, h); + s_sms_init(p, h); +// s_phonebook_init(p, h); +// s_gps_init(p, h); + + g_free(cp_name); + + tcore_hal_set_power(h, TRUE); + /* SEND CPAS command to invoke modem power on. */ + s_modem_send_poweron(p); + + return TRUE; +} + +static void on_unload(TcorePlugin *p) +{ + struct global_data *gd; + + if (!p) + return; + + dbg("i'm unload"); + + gd = tcore_plugin_ref_user_data(p); + if (gd) { + free(gd); + } +} + +struct tcore_plugin_define_desc plugin_define_desc = { + .name = "IMC", + .priority = TCORE_PLUGIN_PRIORITY_MID, + .version = 1, + .load = on_load, + .init = on_init, + .unload = on_unload +}; diff --git a/src/s_call.c b/src/s_call.c index ab06a68..1760bcc 100755 --- a/src/s_call.c +++ b/src/s_call.c @@ -1,3961 +1,3903 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: sharanayya mathapati - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "s_common.h" -#include "s_call.h" - - -#define STATUS_INCOMING 4 -#define STATUS_WAITING 5 -#define STATUS_CONNECTED 7 -#define COMMA 0X2c - -static gboolean setsoundpath = FALSE; -static gboolean soundvolume = FALSE; - -// End Cause field - Call state end cause - -typedef enum { - CALL_END_NO_CAUSE, - - // These definitions are taken from GSM 04.08 Table 10.86 - - CC_CAUSE_UNASSIGNED_NUMBER, - CC_CAUSE_NO_ROUTE_TO_DEST, - CC_CAUSE_CHANNEL_UNACCEPTABLE, - CC_CAUSE_OPERATOR_DETERMINED_BARRING, - CC_CAUSE_NORMAL_CALL_CLEARING, - CC_CAUSE_USER_BUSY, - CC_CAUSE_NO_USER_RESPONDING, - CC_CAUSE_USER_ALERTING_NO_ANSWER, - CC_CAUSE_CALL_REJECTED, - CC_CAUSE_NUMBER_CHANGED, - CC_CAUSE_NON_SELECTED_USER_CLEARING, - CC_CAUSE_DESTINATION_OUT_OF_ORDER, - CC_CAUSE_INVALID_NUMBER_FORMAT, - CC_CAUSE_FACILITY_REJECTED, - CC_CAUSE_RESPONSE_TO_STATUS_ENQUIRY, - CC_CAUSE_NORMAL_UNSPECIFIED, - CC_CAUSE_NO_CIRCUIT_CHANNEL_AVAILABLE, - CC_CAUSE_NETWORK_OUT_OF_ORDER, - CC_CAUSE_TEMPORARY_FAILURE, - CC_CAUSE_SWITCHING_EQUIPMENT_CONGESTION, - CC_CAUSE_ACCESS_INFORMATION_DISCARDED, - CC_CAUSE_REQUESTED_CIRCUIT_CHANNEL_NOT_AVAILABLE, - CC_CAUSE_RESOURCES_UNAVAILABLE_UNSPECIFIED, - CC_CAUSE_QUALITY_OF_SERVICE_UNAVAILABLE, - CC_CAUSE_REQUESTED_FACILITY_NOT_SUBSCRIBED, - CC_CAUSE_INCOMING_CALL_BARRED_WITHIN_CUG, - CC_CAUSE_BEARER_CAPABILITY_NOT_AUTHORISED, - CC_CAUSE_BEARER_CAPABILITY_NOT_PRESENTLY_AVAILABLE, - CC_CAUSE_SERVICE_OR_OPTION_NOT_AVAILABLE, - CC_CAUSE_BEARER_SERVICE_NOT_IMPLEMENTED, - CC_CAUSE_ACM_GEQ_ACMMAX, - CC_CAUSE_REQUESTED_FACILITY_NOT_IMPLEMENTED, - CC_CAUSE_ONLY_RESTRICTED_DIGITAL_INFO_BC_AVAILABLE, - CC_CAUSE_SERVICE_OR_OPTION_NOT_IMPLEMENTED, - CC_CAUSE_INVALID_TRANSACTION_ID_VALUE, - CC_CAUSE_USER_NOT_MEMBER_OF_CUG, - CC_CAUSE_INCOMPATIBLE_DESTINATION, - CC_CAUSE_INVALID_TRANSIT_NETWORK_SELECTION, - CC_CAUSE_SEMANTICALLY_INCORRECT_MESSAGE, - CC_CAUSE_INVALID_MANDATORY_INFORMATION, - CC_CAUSE_MESSAGE_TYPE_NON_EXISTENT, - CC_CAUSE_MESSAGE_TYPE_NOT_COMPATIBLE_WITH_PROT_STATE, - CC_CAUSE_IE_NON_EXISTENT_OR_NOT_IMPLEMENTED, - CC_CAUSE_CONDITIONAL_IE_ERROR, - CC_CAUSE_MESSAGE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE, - CC_CAUSE_RECOVERY_ON_TIMER_EXPIRY, - CC_CAUSE_PROTOCOL_ERROR_UNSPECIFIED, - CC_CAUSE_INTERWORKING_UNSPECIFIED, - CC_CAUSE_END = 128, - - // Reject causes - REJECT_CAUSE_IMSI_UNKNOWN_IN_HLR, - REJECT_CAUSE_ILLEGAL_MS, - REJECT_CAUSE_IMSI_UNKNOWN_IN_VLR, - REJECT_CAUSE_IMEI_NOT_ACCEPTED, - REJECT_CAUSE_ILLEGAL_ME, - REJECT_CAUSE_GPRS_SERVICES_NOT_ALLOWED, - REJECT_CAUSE_GPRS_SERVICES_AND_NON_GPRS_SERVICES_NOT_ALLOWED, - REJECT_CAUSE_MS_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK, - REJECT_CAUSE_IMPLICITLY_DETACHED, - REJECT_CAUSE_PLMN_NOT_ALLOWED, - REJECT_CAUSE_LA_NOT_ALLOWED, - REJECT_CAUSE_NATIONAL_ROAMING_NOT_ALLOWED, - REJECT_CAUSE_GPRS_SERVICES_NOT_ALLOWED_IN_THIS_PLMN, - REJECT_CAUSE_NO_SUITABLE_CELLS_IN_LA, - REJECT_CAUSE_MSC_TEMPORARILY_NOT_REACHABLE, - REJECT_CAUSE_NETWORK_FAILURE , - REJECT_CAUSE_MAC_FAILURE, - REJECT_CAUSE_SYNCH_FAILURE, - REJECT_CAUSE_CONGESTTION, - REJECT_CAUSE_GSM_AUTH_UNACCEPTED, - REJECT_CAUSE_SERVICE_OPTION_NOT_SUPPORTED, - REJECT_CAUSE_REQ_SERV_OPT_NOT_SUBSCRIBED, - REJECT_CAUSE_SERVICE_OPT__OUT_OF_ORDER, - REJECT_CAUSE_CALL_CANNOT_BE_IDENTIFIED, - REJECT_CAUSE_NO_PDP_CONTEXT_ACTIVATED, - REJECT_CAUSE_RETRY_UPON_ENTRY_INTO_A_NEW_CELL_MIN_VALUE, - REJECT_CAUSE_RETRY_UPON_ENTRY_INTO_A_NEW_CELL_MAX_VALUE, - REJECT_CAUSE_SEMANTICALLY_INCORRECT_MSG, - REJECT_CAUSE_INVALID_MANDATORY_INFO, - REJECT_CAUSE_MESSAGE_TYPE_NON_EXISTANT, - REJECT_CAUSE_MESSAGE_TYPE_NOT_COMP_PRT_ST, - REJECT_CAUSE_IE_NON_EXISTANT, - REJECT_CAUSE_MSG_NOT_COMPATIBLE_PROTOCOL_STATE, - - - // Connection Management establishment rejection cause - REJECT_CAUSE_REJ_UNSPECIFIED, - - // AS reject causes - REJECT_CAUSE_AS_REJ_RR_REL_IND, - REJECT_CAUSE_AS_REJ_RR_RANDOM_ACCESS_FAILURE, - REJECT_CAUSE_AS_REJ_RRC_REL_IND, - REJECT_CAUSE_AS_REJ_RRC_CLOSE_SESSION_IND, - REJECT_CAUSE_AS_REJ_RRC_OPEN_SESSION_FAILURE, - REJECT_CAUSE_AS_REJ_LOW_LEVEL_FAIL, - REJECT_CAUSE_AS_REJ_LOW_LEVEL_FAIL_REDIAL_NOT_ALLOWED, - REJECT_CAUSE_AS_REJ_LOW_LEVEL_IMMED_RETRY, - - // MM reject causes - REJECT_CAUSE_MM_REJ_INVALID_SIM, - REJECT_CAUSE_MM_REJ_NO_SERVICE, - REJECT_CAUSE_MM_REJ_TIMER_T3230_EXP, - REJECT_CAUSE_MM_REJ_NO_CELL_AVAILABLE, - REJECT_CAUSE_MM_REJ_WRONG_STATE, - REJECT_CAUSE_MM_REJ_ACCESS_CLASS_BLOCKED, - // Definitions for release ind causes between MM and CNM - REJECT_CAUSE_ABORT_MSG_RECEIVED, - REJECT_CAUSE_OTHER_CAUSE, - - // CNM reject causes - REJECT_CAUSE_CNM_REJ_TIMER_T303_EXP, - REJECT_CAUSE_CNM_REJ_NO_RESOURCES, - REJECT_CAUSE_CNM_MM_REL_PENDING, - REJECT_CAUSE_CNM_INVALID_USER_DATA, - CALL_END_CAUSE_MAX = 255 -}call_end_cause_e_type; - - -struct clcc_call_t { - struct call_CLCC_info { - int id; - enum tcore_call_direction direction; - enum tcore_call_status status; - enum tcore_call_type type; - int mpty; - int num_len; - int num_type; - } info; - char number[90]; -}; - -typedef struct { - int network_cause; - int tapi_cause; -}call_end_cause_info; - -/************************************************************************** - * Local Function Prototypes - **************************************************************************/ -/************************* REQUESTS ***************************/ -static void _call_status_idle(TcorePlugin *p, CallObject *co); -static void _call_status_active(TcorePlugin *p, CallObject *co); -static void _call_status_dialing(TcorePlugin *p, CallObject *co); -static void _call_status_alert(TcorePlugin *p, CallObject *co); -static void _call_status_incoming(TcorePlugin *p, CallObject *co); -static void _call_status_waiting(TcorePlugin *p, CallObject *co); -static TReturn _call_list_get(CoreObject *o, gboolean *event_flag); -static TReturn _set_dtmf_tone_duration(CoreObject *o, UserRequest *ur); - -/************************* CONFIRMATION ***************************/ -static void on_confirmation_call_message_send(TcorePending *p, gboolean result, void *user_data); // from Kernel -static void on_confirmation_call_hold(TcorePending *p, int data_len, const void *data, void *user_data); -static void on_confirmation_call_swap(TcorePending *p, int data_len, const void *data, void *user_data); -static void on_confirmation_call_split(TcorePending *p, int data_len, const void *data, void *user_data); -static void on_confirmation_call_hold_and_accept(TcorePending *p, int data_len, const void *data, void *user_data); - -static void _on_confirmation_call_release(TcorePending *p, int data_len, const void *data, void *user_data, int type); -static void _on_confirmation_call(TcorePending *p, int data_len, const void *data, void *user_data, int type); -static void _on_confirmation_dtmf_tone_duration(TcorePending *p, int data_len, const void *data, void *user_data); -static void _on_confirmation_call_end_cause(TcorePending * p, int data_len, const void * data, void * user_data); - -/************************* RESPONSES ***************************/ -static void on_response_call_list_get(TcorePending *p, int data_len, const void *data, void *user_data); - -/************************* NOTIIFICATIONS ***************************/ -static void on_notification_call_waiting(CoreObject *o, const void *data, void *user_data); -static void on_notification_call_incoming(CoreObject *o, const void *data, void *user_data); -static void on_notification_call_status(CoreObject *o, const void *data, void *user_data); -static gboolean on_notification_call_info(CoreObject *o, const void *data, void *user_data); -static gboolean on_notification_call_clip_info(CoreObject *o, const void *data, void *user_data); - - -/************************************************************************** - * Local Utility Function Prototypes - **************************************************************************/ -static gboolean _call_request_message(TcorePending *pending, CoreObject *o, UserRequest* ur, void* on_resp, void* user_data); -static void _call_branch_by_status(TcorePlugin *p, CallObject *co, unsigned int status); -static int _callFromCLCCLine(char *line, struct clcc_call_t *p_call); - -/************************************************************************** - * Local Function Definitions - **************************************************************************/ - -const call_end_cause_info call_end_cause_table[] = { // call end cause table to convert Netwotk cause to TAPI cause - - { 1, CC_CAUSE_UNASSIGNED_NUMBER}, { 3, CC_CAUSE_NO_ROUTE_TO_DEST}, - { 6, CC_CAUSE_CHANNEL_UNACCEPTABLE}, { 8, CC_CAUSE_OPERATOR_DETERMINED_BARRING}, - { 16, CC_CAUSE_NORMAL_CALL_CLEARING}, { 17, CC_CAUSE_USER_BUSY}, - { 18, CC_CAUSE_NO_USER_RESPONDING}, { 19, CC_CAUSE_USER_ALERTING_NO_ANSWER}, - { 21, CC_CAUSE_CALL_REJECTED}, { 22, CC_CAUSE_NUMBER_CHANGED}, - { 26, CC_CAUSE_NON_SELECTED_USER_CLEARING}, { 27, CC_CAUSE_DESTINATION_OUT_OF_ORDER}, - { 28, CC_CAUSE_INVALID_NUMBER_FORMAT}, { 29, CC_CAUSE_FACILITY_REJECTED}, - { 30, CC_CAUSE_RESPONSE_TO_STATUS_ENQUIRY}, { 31, CC_CAUSE_NORMAL_UNSPECIFIED}, - { 34, CC_CAUSE_NO_CIRCUIT_CHANNEL_AVAILABLE},{ 38, CC_CAUSE_NETWORK_OUT_OF_ORDER}, - { 41, CC_CAUSE_TEMPORARY_FAILURE}, { 42, CC_CAUSE_SWITCHING_EQUIPMENT_CONGESTION}, - { 43, CC_CAUSE_ACCESS_INFORMATION_DISCARDED},{ 44, CC_CAUSE_REQUESTED_CIRCUIT_CHANNEL_NOT_AVAILABLE}, - { 47, CC_CAUSE_RESOURCES_UNAVAILABLE_UNSPECIFIED}, { 49, CC_CAUSE_QUALITY_OF_SERVICE_UNAVAILABLE}, - { 50, CC_CAUSE_REQUESTED_FACILITY_NOT_SUBSCRIBED}, { 55, CC_CAUSE_INCOMING_CALL_BARRED_WITHIN_CUG}, - { 57, CC_CAUSE_BEARER_CAPABILITY_NOT_AUTHORISED}, { 58, CC_CAUSE_BEARER_CAPABILITY_NOT_PRESENTLY_AVAILABLE}, - { 63, CC_CAUSE_SERVICE_OR_OPTION_NOT_AVAILABLE}, { 65, CC_CAUSE_BEARER_SERVICE_NOT_IMPLEMENTED}, - { 68, CC_CAUSE_ACM_GEQ_ACMMAX}, { 69, CC_CAUSE_REQUESTED_FACILITY_NOT_IMPLEMENTED}, - { 70, CC_CAUSE_ONLY_RESTRICTED_DIGITAL_INFO_BC_AVAILABLE}, { 79, CC_CAUSE_SERVICE_OR_OPTION_NOT_IMPLEMENTED}, - { 81, CC_CAUSE_INVALID_TRANSACTION_ID_VALUE}, { 87, CC_CAUSE_USER_NOT_MEMBER_OF_CUG}, - { 88, CC_CAUSE_INCOMPATIBLE_DESTINATION}, { 91, CC_CAUSE_INVALID_TRANSIT_NETWORK_SELECTION}, - { 95, CC_CAUSE_SEMANTICALLY_INCORRECT_MESSAGE}, { 96, CC_CAUSE_INVALID_MANDATORY_INFORMATION}, - { 97, CC_CAUSE_MESSAGE_TYPE_NON_EXISTENT}, { 98, CC_CAUSE_MESSAGE_TYPE_NOT_COMPATIBLE_WITH_PROT_STATE}, - { 99, CC_CAUSE_IE_NON_EXISTENT_OR_NOT_IMPLEMENTED}, { 100, CC_CAUSE_CONDITIONAL_IE_ERROR}, - { 101,CC_CAUSE_MESSAGE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE},{ 102, CC_CAUSE_RECOVERY_ON_TIMER_EXPIRY}, - { 111 ,CC_CAUSE_PROTOCOL_ERROR_UNSPECIFIED}, {127, CC_CAUSE_INTERWORKING_UNSPECIFIED}, - -}; - -static enum tcore_call_cli_mode _get_clir_status(char *num) -{ - enum tcore_call_cli_mode clir = CALL_CLI_MODE_DEFAULT; - dbg("Entry"); - - if(!strncmp(num, "*31#", 4)) { - dbg("CLI mode restricted"); - return TCORE_CALL_CLI_MODE_RESTRICT; - } - - if(!strncmp(num, "#31#", 4)) { - dbg("CLI mode allowed"); - return TCORE_CALL_CLI_MODE_PRESENT; - } - - err("Exit"); - return clir; -} - -static enum tcore_call_status _call_status(unsigned int status) -{ - dbg("Entry"); - - switch(status) { - case 0: - return TCORE_CALL_STATUS_ACTIVE; - case 1: - return TCORE_CALL_STATUS_HELD; - case 2: - return TCORE_CALL_STATUS_DIALING; - case 3: - return TCORE_CALL_STATUS_ALERT; - case 4: - return TCORE_CALL_STATUS_INCOMING; - case 5: - return TCORE_CALL_STATUS_WAITING; - case 6: // DISCONNECTED state // FALL THROUGH - default: - return TCORE_CALL_STATUS_IDLE; - } -} - -static gboolean _call_is_in_mpty(int mpty) -{ - dbg("Entry"); - - switch(mpty) { - case 0: - return FALSE; - case 1: - return TRUE; - default: - break; - } - - return FALSE; -} - -static enum tcore_call_type call_type(int type) -{ - dbg("Entry"); - - switch (type) { - case 0: - return TCORE_CALL_TYPE_VOICE; - case 1: - return TCORE_CALL_TYPE_VIDEO; - default: - break; - } - - return TCORE_CALL_TYPE_VOICE; -} - -static int _compare_call_end_cause(int networkcause) -{ - unsigned int count; - for (count = 0; count < sizeof(call_end_cause_table)/sizeof(call_end_cause_info); count++){ - if (call_end_cause_table[count].network_cause == networkcause) - return (call_end_cause_table[count].tapi_cause); - } - return CC_CAUSE_NORMAL_CALL_CLEARING; - dbg("Exit"); -} - -static gboolean on_notification_call_clip_info(CoreObject *o, const void *data, void *user_data) -{ - dbg("Entry"); - - // TODO - - return TRUE; -} - -static gboolean on_notification_call_info(CoreObject *o, const void *data, void *user_data) -{ - GSList *tokens = NULL; - GSList *lines = NULL; - const char *line = NULL; - char *stat; - int status; - - dbg("Entry"); - - lines = (GSList*)data; - if (1 != g_slist_length(lines)) { - err("Unsolicited message, BUT multiple lines present"); - goto OUT; - } - - line = (char*)(lines->data); - tokens = tcore_at_tok_new(line); - - stat = g_slist_nth_data(tokens, 1); - if(!stat) { - dbg("Stat is missing from %XCALLSTAT indiaction"); - } - else { - status = atoi(stat); - - switch(status) { - case STATUS_INCOMING: - dbg("calling on_notification_call_incoming"); - on_notification_call_incoming(o, line, user_data); - break; - case STATUS_WAITING: - dbg("calling on_notification_call_waiting"); - on_notification_call_waiting(o, line, user_data); - break; - case STATUS_CONNECTED: /*igonre Connected state. */ - dbg("Connected state"); - break; - default: - dbg("calling on_notification_call_status"); - on_notification_call_status(o, line, user_data); - break; - } - } - - // Free tokens - tcore_at_tok_free(tokens); - -OUT: - dbg("Exit"); - return TRUE; -} - -static gboolean _call_request_message(TcorePending *pending, - CoreObject *o, - UserRequest *ur, - void* on_resp, - void* user_data) -{ - TcoreHal *hal = NULL; - TReturn ret; - dbg("Entry"); - - tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT); - - if (on_resp) { - tcore_pending_set_response_callback(pending, on_resp, user_data); - } - tcore_pending_set_send_callback(pending, on_confirmation_call_message_send, NULL); - - if (ur) { - tcore_pending_link_user_request(pending, ur); - } - else { - err("User Request is NULL, is this internal request??"); - } - - // HAL - hal = tcore_object_get_hal(o); - // Send request to HAL - ret = tcore_hal_send_request(hal, pending); - if(TCORE_RETURN_SUCCESS != ret) { - err("Request send failed"); - return FALSE; - } - - dbg("Exit"); - return TRUE; -} - -static void _call_status_idle(TcorePlugin *p, CallObject *co) -{ - CoreObject *core_obj = NULL; - char *cmd_str = NULL; - TcorePending *pending = NULL; - TcoreATRequest *req = NULL; - gboolean ret = FALSE; - UserRequest *ur; - - dbg("Entry"); - core_obj = tcore_plugin_ref_core_object(p, "call"); - dbg("Call ID [%d], Call Status [%d]", tcore_call_object_get_id(co), tcore_call_object_get_status(co)); - - if (tcore_call_object_get_status(co) != TCORE_CALL_STATUS_IDLE) { - - //get call end cause. - cmd_str = g_strdup_printf("%s","AT+XCEER"); - dbg("Request command string: %s", cmd_str); - - // Create new Pending request - pending = tcore_pending_new(core_obj, 0); - - // Create new AT-Command request - req = tcore_at_request_new(cmd_str, "+XCEER", TCORE_AT_SINGLELINE); - dbg("Command: %s, prefix(if any): %s, Command length: %d", req->cmd, req->prefix, strlen(req->cmd)); - // Free command string - g_free(cmd_str); - - // Set request data (AT command) to Pending request - tcore_pending_set_request_data(pending, 0, req); - - ur = tcore_user_request_new(NULL, NULL); - // Send request - ret = _call_request_message (pending, core_obj, ur, _on_confirmation_call_end_cause, co); - - if (!ret) { - err("Failed to send AT-Command request"); - return ; - } - - } - else { - err("Call object was not free"); - tcore_call_object_free(core_obj, co); - } - dbg("Exit"); - return; -} - -static void _call_status_dialing(TcorePlugin *p, CallObject *co) -{ - struct tnoti_call_status_dialing data; - dbg("Entry"); - - if (tcore_call_object_get_status(co) != TCORE_CALL_STATUS_DIALING) { - data.type = tcore_call_object_get_type(co); - dbg("data.type : [%d]", data.type); - - data.id = tcore_call_object_get_id(co); - dbg("data.id : [%d]", data.id); - - // Set Status - tcore_call_object_set_status(co, TCORE_CALL_STATUS_DIALING); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(p), - tcore_plugin_ref_core_object(p, "call"), - TNOTI_CALL_STATUS_DIALING, - sizeof(struct tnoti_call_status_dialing), - (void*)&data); - - } - - dbg("Exit"); - return; -} - -static void _call_status_alert(TcorePlugin *p, CallObject *co) -{ - struct tnoti_call_status_alert data; - dbg("Entry"); - - // Alerting has just 1 data 'CALL ID' - if (tcore_call_object_get_status(co) != TCORE_CALL_STATUS_ALERT) { - data.type = tcore_call_object_get_type(co); - dbg("data.type : [%d]", data.type); - - data.id = tcore_call_object_get_id(co); - dbg("data.id : [%d]", data.id); - - // Set Status - tcore_call_object_set_status(co, TCORE_CALL_STATUS_ALERT); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(p), - tcore_plugin_ref_core_object(p, "call"), - TNOTI_CALL_STATUS_ALERT, - sizeof(struct tnoti_call_status_alert), - (void*)&data); - } - - dbg("Exit"); - return; -} - -static void _call_status_active(TcorePlugin *p, CallObject *co) -{ - struct tnoti_call_status_active data; - dbg("Entry"); - - if (tcore_call_object_get_status(co) != TCORE_CALL_STATUS_ACTIVE) { - data.type = tcore_call_object_get_type(co); - dbg("data.type : [%d]", data.type); - - data.id = tcore_call_object_get_id(co); - dbg("data.id : [%d]", data.id); - - // Set Status - tcore_call_object_set_status(co, TCORE_CALL_STATUS_ACTIVE); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(p), - tcore_plugin_ref_core_object(p, "call"), - TNOTI_CALL_STATUS_ACTIVE, - sizeof(struct tnoti_call_status_active), - (void*)&data); - } - - dbg("Exit"); - return; -} - -static void _call_status_held(TcorePlugin *p, CallObject *co) -{ - struct tnoti_call_status_held data; - dbg("Entry"); - - if (tcore_call_object_get_status(co) != TCORE_CALL_STATUS_HELD) { - data.type = tcore_call_object_get_type(co); - dbg("data.type : [%d]", data.type); - - data.id = tcore_call_object_get_id(co); - dbg("data.id : [%d]", data.id); - - // Set Status - tcore_call_object_set_status(co, TCORE_CALL_STATUS_HELD); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(p), - tcore_plugin_ref_core_object(p, "call"), - TNOTI_CALL_STATUS_HELD, - sizeof(struct tnoti_call_status_held), - (void*)&data); - } - - dbg("Exit"); - return; -} - -static void _call_status_incoming(TcorePlugin *p, CallObject *co) -{ - struct tnoti_call_status_incoming data; - dbg("Entry"); - - if (tcore_call_object_get_status(co) != TCORE_CALL_STATUS_INCOMING) { - tcore_call_object_set_status(co, TCORE_CALL_STATUS_INCOMING); - - data.type = tcore_call_object_get_type(co); - dbg("data.type : [%d]", data.type); - - data.id = tcore_call_object_get_id(co); - dbg("data.id : [%d]", data.id); - - data.cli.mode = tcore_call_object_get_cli_mode(co); - dbg("data.cli.mode : [%d]", data.cli.mode); - - tcore_call_object_get_number(co, data.cli.number); - dbg("data.cli.number : [%s]", data.cli.number); - - data.cna.mode = tcore_call_object_get_cna_mode(co); - dbg("data.cna.mode : [%d]", data.cna.mode); - - tcore_call_object_get_name(co, data.cna.name); - dbg("data.cna.name : [%s]", data.cna.name); - - data.forward = FALSE; // this is tmp code - - data.active_line = tcore_call_object_get_active_line(co); - dbg("data.active_line : [%d]", data.active_line); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(p), - tcore_plugin_ref_core_object(p, "call"), - TNOTI_CALL_STATUS_INCOMING, - sizeof(struct tnoti_call_status_incoming), - (void*)&data); - } - - dbg("Exit"); - return; -} - -static void _call_status_waiting(TcorePlugin *p, CallObject *co) -{ - dbg("Entry"); - _call_status_incoming(p, co); - - dbg("Exit"); - return; -} - -static void _call_branch_by_status(TcorePlugin *p, CallObject *co, unsigned int status) -{ - dbg("Entry"); - - dbg("Call Status is %d", status); - switch (status) { - case TCORE_CALL_STATUS_IDLE: - _call_status_idle(p, co); - break; - - case TCORE_CALL_STATUS_ACTIVE: - _call_status_active(p, co); - break; - - case TCORE_CALL_STATUS_HELD: - _call_status_held(p, co); - break; - - case TCORE_CALL_STATUS_DIALING: - _call_status_dialing(p, co); - break; - - case TCORE_CALL_STATUS_ALERT: - _call_status_alert(p, co); - break; - - case TCORE_CALL_STATUS_INCOMING: - _call_status_incoming(p, co); - break; - - case TCORE_CALL_STATUS_WAITING: - _call_status_waiting(p, co); - break; - } - - dbg("Exit"); - return; -} - -static TReturn _call_list_get(CoreObject *o, gboolean *event_flag) -{ - UserRequest* ur = NULL; - TcorePending *pending = NULL; - char *cmd_str = NULL; - TcoreATRequest *req = NULL; - gboolean ret = FALSE; - - dbg("Entry"); - if (!o) { - err("Core Object is NULL"); - return TCORE_RETURN_FAILURE; - } - - // Create new User Request - ur = tcore_user_request_new(NULL, NULL); - - // Command string - cmd_str = g_strdup("AT+CLCC"); - - // Create new Pending Request - pending = tcore_pending_new(o, 0); - req = tcore_at_request_new(cmd_str, "+CLCC", TCORE_AT_MULTILINE); - - g_free(cmd_str); - - dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_request_data(pending, 0, req); - - ret = _call_request_message (pending, o, ur, on_response_call_list_get, event_flag); - if (!ret) { - err("AT request (%s) sending failed", req->cmd); - return TCORE_RETURN_FAILURE; - } - - dbg("AT request sent success"); - return TCORE_RETURN_SUCCESS; -} - -// CONFIRMATION -static void on_confirmation_call_message_send(TcorePending *p, gboolean result, void *user_data) -{ - dbg("Entry"); - - if (result == FALSE) { // Fail - dbg("SEND FAIL"); - } - else { - dbg("SEND OK"); - } - - dbg("Exit"); - return; -} - -static void on_confirmation_call_outgoing(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur = NULL; - GSList *tokens = NULL; - const char *line = NULL; - const TcoreATResponse* response = data; - struct tresp_call_dial resp; - int error; - dbg("Entry"); - - ur = tcore_pending_ref_user_request(p); - if (ur) { - if (response->success > 0) { - dbg("RESPONSE OK"); - resp.err = TCORE_RETURN_SUCCESS; - } - else { - dbg("RESPONSE NOT OK"); - - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - err("Unspecified error cause OR string corrupted"); - resp.err = TCORE_RETURN_3GPP_ERROR; - } - else { - error = atoi(g_slist_nth_data(tokens, 0)); - - // TODO: CMEE error mapping is required. - resp.err = TCORE_RETURN_3GPP_ERROR; - } - - // Free tokens - tcore_at_tok_free(tokens); - } - - // Send Response to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_DIAL, sizeof(struct tresp_call_dial), &resp); - } - else { - err("User Request is NULL"); - } - - dbg("Exit") - return; -} - -static void on_confirmation_call_accept(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur = NULL; - GSList *tokens = NULL; - const char *line = NULL; - const TcoreATResponse* response = data; - struct tresp_call_answer resp; - int error; - dbg("Entry"); - - ur = tcore_pending_ref_user_request(p); - if (ur) { - if (response->success > 0) { - dbg("RESPONSE OK"); - resp.err = TCORE_RETURN_SUCCESS; - } - else { - dbg("RESPONSE NOT OK"); - - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - err("Unspecified error cause OR string corrupted"); - resp.err = TCORE_RETURN_3GPP_ERROR; - } - else { - error = atoi(g_slist_nth_data(tokens, 0)); - - // TODO: CMEE error mapping is required. - resp.err = TCORE_RETURN_3GPP_ERROR; - } - - //Free tokens - tcore_at_tok_free(tokens); - } - - resp.id = tcore_call_object_get_id((CallObject*)user_data); - - // Send Response to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_ANSWER, sizeof(struct tresp_call_answer), &resp); - } - else { - err("User Request is NULL"); - } - - dbg("Exit"); - return; -} - - -static void on_confirmation_call_reject(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur = NULL; - GSList *tokens = NULL; - const char *line = NULL; - const TcoreATResponse* response = data; - struct tresp_call_answer resp; - int error; - - dbg("Entry"); - - ur = tcore_pending_ref_user_request(p); - if (ur) { - if (response->success > 0) { - - dbg("RESPONSE OK"); - resp.err = TCORE_RETURN_SUCCESS; - } - else { - - dbg("RESPONSE NOT OK"); - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - err("Unspecified error cause OR string corrupted"); - resp.err = TCORE_RETURN_3GPP_ERROR; - } - else { - - error = atoi(g_slist_nth_data(tokens, 0)); - // TODO: CMEE error mapping is required. - resp.err = TCORE_RETURN_3GPP_ERROR; - } - - // Free tokens - tcore_at_tok_free(tokens); - } - - resp.id = tcore_call_object_get_id((CallObject*)user_data); - - //Send Response to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_ANSWER, sizeof(struct tresp_call_answer), &resp); - } - else { - err("User Request is NULL"); - } - - dbg("Exit"); - return; -} - -static void on_confirmation_call_replace(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur = NULL; - GSList *tokens = NULL; - const char *line = NULL; - const TcoreATResponse* response = data; - struct tresp_call_answer resp; - int error; - - dbg("Entry"); - ur = tcore_pending_ref_user_request(p); - if (ur) { - if (response->success > 0) { - dbg("RESPONSE OK"); - resp.err = TCORE_RETURN_SUCCESS; - } - else { - - dbg("RESPONSE NOT OK"); - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - err("Unspecified error cause OR string corrupted"); - resp.err = TCORE_RETURN_3GPP_ERROR; - } - else { - error = atoi(g_slist_nth_data(tokens, 0)); - // TODO: CMEE error mapping is required. - resp.err = TCORE_RETURN_3GPP_ERROR; - } - - // Free tokens - tcore_at_tok_free(tokens); - } - resp.id = tcore_call_object_get_id((CallObject*)user_data); - - // Send Response to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_ANSWER, sizeof(struct tresp_call_answer), &resp); - } - else { - dbg("User Request is NULL"); - } - - dbg("Exit"); - return; -} - -static void on_confirmation_call_hold_and_accept(TcorePending *p, int data_len, const void *data, void *user_data) -{ - CoreObject *o = NULL; - UserRequest *ur = NULL; - GSList *tokens = NULL; - const char *line = NULL; - const TcoreATResponse* response = data; - struct tresp_call_answer resp; - int error; - - dbg("Entry"); - - o = tcore_pending_ref_core_object(p); - ur = tcore_pending_ref_user_request(p); - resp.id = tcore_call_object_get_id((CallObject*)user_data); - - if (ur) { - if (response->success > 0) { - dbg("RESPONSE OK"); - resp.err = TCORE_RETURN_SUCCESS; - } - else { - err("RESPONSE NOT OK"); - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - err("Unspecified error cause OR string corrupted"); - resp.err = TCORE_RETURN_3GPP_ERROR; - } - else { - error = atoi(g_slist_nth_data(tokens, 0)); - - // TODO: CMEE error mapping is required. - resp.err = TCORE_RETURN_3GPP_ERROR; - } - - // Free tokens - tcore_at_tok_free(tokens); - } - - // Send response to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_ANSWER, sizeof(struct tresp_call_answer), &resp); - if (!resp.err) { - - GSList *list = 0; - CallObject *co = NULL; - - // Active Call - list = tcore_call_object_find_by_status(o, TCORE_CALL_STATUS_ACTIVE); - if (!list) { - err("Can't find active Call"); - return; - } - - co = (CallObject*)list->data; - if (!co) { - err("Can't get active Call object"); - return; - } - - // Set Call Status - tcore_call_object_set_status(co, TCORE_CALL_STATUS_HELD); - dbg("Call status is set to HELD"); - } - } - else { - err("User Request is NULL"); - } - - dbg("Exit"); - return; -} - -static void _on_confirmation_call_release(TcorePending *p, int data_len, const void *data, void *user_data, int type) -{ - UserRequest *ur = NULL; - struct tresp_call_end resp; - GSList *tokens = NULL; - const char *line = NULL; - int error; - const TcoreATResponse* response = data; - - dbg("Entry"); - ur = tcore_pending_ref_user_request(p); - if (ur) { - if (response->success > 0) { - dbg("RESPONSE OK"); - resp.err = TCORE_RETURN_SUCCESS; - } - else { - err("RESPONSE NOT OK"); - - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - err("Unspecified error cause OR string corrupted"); - resp.err = TCORE_RETURN_3GPP_ERROR; - } - else { - error = atoi(g_slist_nth_data(tokens, 0)); - - // TODO: CMEE error mapping is required. - resp.err = TCORE_RETURN_3GPP_ERROR; - } - tcore_at_tok_free(tokens); - } - - resp.type = type; - resp.id = tcore_call_object_get_id((CallObject*)user_data); - dbg("resp.type = %d resp.id= %d", resp.type,resp.id); - - // Send reponse to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_END, sizeof(struct tresp_call_end), &resp); - } - else { - err("User Request is NULL"); - } - - dbg("Exit"); - return; -} - -// RESPONSE -static void on_confirmation_call_endall(TcorePending *p, int data_len, const void *data, void *user_data) -{ - // skip response handling - actual result will be handled in on_confirmation_call_release_all - const TcoreATResponse* response = data; - dbg("Entry"); - - if (response->success > 0) { - dbg("RESPONSE OK"); - } - else { - err("RESPONSE NOT OK"); - } - - dbg("Exit"); - return; -} - - -static void on_confirmation_call_release_all(TcorePending *p, int data_len, const void *data, void *user_data) -{ - dbg("Entry"); - _on_confirmation_call_release(p, data_len, data, user_data, CALL_END_TYPE_ALL); - - return; -} - - -static void on_confirmation_call_release_specific(TcorePending *p, int data_len, const void *data, void *user_data) -{ - dbg("Entry"); - _on_confirmation_call_release(p, data_len, data, user_data, CALL_END_TYPE_DEFAULT); - - return; -} - -static void on_confirmation_call_release_all_active(TcorePending *p, int data_len, const void *data, void *user_data) -{ - dbg("Entry"); - _on_confirmation_call_release(p, data_len, data, user_data, CALL_END_TYPE_ACTIVE_ALL); - - return; -} - -static void on_confirmation_call_release_all_held(TcorePending *p, int data_len, const void *data, void *user_data) -{ - dbg("Entry"); - _on_confirmation_call_release(p, data_len, data, user_data, CALL_END_TYPE_HOLD_ALL); - - return; -} - -static void _on_confirmation_call(TcorePending *p, int data_len, const void *data, void *user_data, int type) -{ - UserRequest *ur = NULL; - GSList *tokens = NULL; - const char *line = NULL; - const TcoreATResponse *response = NULL; - int error; - - dbg("Entry"); - ur = tcore_pending_ref_user_request(p); - response = (TcoreATResponse *)data; - if (response->success > 0) { - dbg("RESPONSE OK"); - error = TCORE_RETURN_SUCCESS; - } - else { - err("RESPONSE NOT OK"); - - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - err("Unspecified error cause OR string corrupted"); - error = TCORE_RETURN_3GPP_ERROR; - } - else { - error = atoi(g_slist_nth_data(tokens, 0)); - - // TODO: CMEE error mapping is required. - error = TCORE_RETURN_3GPP_ERROR; - } - - // Free tokens - tcore_at_tok_free(tokens); - } - - dbg("Response Call type -%d", type); - switch(type){ - - case TRESP_CALL_HOLD: - { - struct tresp_call_hold resp; - - resp.err = error; - resp.id = tcore_call_object_get_id((CallObject*)user_data); - dbg("call hold response"); - // Send reponse to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_HOLD, sizeof(struct tresp_call_hold), &resp); - } - break; - case TRESP_CALL_ACTIVE: - { - struct tresp_call_active resp; - - resp.err = error; - resp.id = tcore_call_object_get_id((CallObject*)user_data); - dbg("call active response"); - // Send reponse to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_ACTIVE, sizeof(struct tresp_call_active), &resp); - } - break; - case TRESP_CALL_JOIN: - { - struct tresp_call_join resp; - - resp.err = error; - resp.id = tcore_call_object_get_id((CallObject*)user_data); - dbg("call join response"); - - // Send reponse to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_JOIN, sizeof(struct tresp_call_join), &resp); - } - break; - case TRESP_CALL_SPLIT: - { - struct tresp_call_split resp; - - resp.err = error; - resp.id = tcore_call_object_get_id((CallObject*)user_data); - dbg("call split response"); - // Send reponse to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_SPLIT, sizeof(struct tresp_call_split), &resp); - } - break; - case TRESP_CALL_DEFLECT: - { - struct tresp_call_deflect resp; - - resp.err = error; - resp.id = tcore_call_object_get_id((CallObject*)user_data); - dbg("call deflect response"); - // Send reponse to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_DEFLECT, sizeof(struct tresp_call_deflect), &resp); - } - - break; - case TRESP_CALL_TRANSFER: - { - struct tresp_call_transfer resp; - - resp.err = error; - resp.id = tcore_call_object_get_id((CallObject*)user_data); - dbg("call transfer response"); - //Send reponse to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_TRANSFER, sizeof(struct tresp_call_transfer), &resp); - } - break; - case TRESP_CALL_SEND_DTMF: - { - struct tresp_call_dtmf resp; - - resp.err = error; - dbg("call dtmf response"); - // Send reponse to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_SEND_DTMF, sizeof(struct tresp_call_dtmf), &resp); - } - break; - default: - { - dbg("type not supported"); - return; - } - } - - if ((type == TRESP_CALL_HOLD)||(type == TRESP_CALL_ACTIVE)||(type == TRESP_CALL_JOIN) - ||(type == TRESP_CALL_SPLIT)) { - - if (!error) { - CoreObject *core_obj = NULL; - gboolean *eflag = g_new0(gboolean, 1); - - core_obj = tcore_pending_ref_core_object(p); - *eflag = FALSE; - - dbg("Calling _call_list_get"); - _call_list_get(core_obj, eflag); - } - } - - dbg("Exit"); - return; -} - -static void on_confirmation_call_hold(TcorePending *p, int data_len, const void *data, void *user_data) -{ - dbg("Entry"); - _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_HOLD); - - return; -} - -static void on_confirmation_call_active(TcorePending *p, int data_len, const void *data, void *user_data) -{ - dbg("Entry"); - _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_ACTIVE); - - return; -} - -static void on_confirmation_call_join(TcorePending *p, int data_len, const void *data, void *user_data) -{ - dbg("Entry"); - _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_JOIN); - - return; -} - -static void on_confirmation_call_split(TcorePending *p, int data_len, const void *data, void *user_data) -{ - dbg("Entry"); - _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_SPLIT); - - return; -} - -static void on_confirmation_call_deflect(TcorePending *p, int data_len, const void *data, void *user_data) -{ - dbg("Entry"); - _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_DEFLECT); - - return; -} - -static void on_confirmation_call_transfer(TcorePending *p, int data_len, const void *data, void *user_data) -{ - dbg("Entry"); - _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_TRANSFER); - - return; -} - -static void on_confirmation_call_dtmf(TcorePending *p, int data_len, const void *data, void *user_data) -{ - dbg("Entry"); - _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_SEND_DTMF); - - return; -} - -static void _on_confirmation_dtmf_tone_duration(TcorePending * p, int data_len, const void * data, void * user_data) -{ - GSList *tokens = NULL; - const char *line = NULL; - const TcoreATResponse* response = data; - int error; - - dbg("Entry"); - - if (response->success > 0) { - dbg("RESPONSE OK"); - error = TCORE_RETURN_SUCCESS; - } - else { - - err("RESPONSE NOT OK"); - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - if (g_slist_length(tokens) < 1) { - err("err cause not specified or string corrupted"); - error = TCORE_RETURN_3GPP_ERROR; - } - else { - error = atoi(g_slist_nth_data(tokens, 0)); - // TODO: CMEE error mapping is required. - } - - // Free tokens - tcore_at_tok_free(tokens); - } - - dbg("Set dtmf tone duration response - %d", error); - return; -} - -static void on_confirmation_call_swap(TcorePending *p, int data_len, const void *data, void *user_data) -{ - CoreObject *core_obj = NULL; - UserRequest *ur = NULL; - const TcoreATResponse* response = data; - struct tresp_call_swap resp; - GSList *tokens = NULL; - const char *line = NULL; - - dbg("Entry"); - core_obj = tcore_pending_ref_core_object(p); - ur = tcore_pending_ref_user_request(p); - - if (ur) { - if (response->success > 0) { - dbg("RESPONSE OK"); - resp.err = TCORE_RETURN_SUCCESS; - } - else { - - err("RESPONSE NOT OK"); - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - if (g_slist_length(tokens) < 1) { - err("err cause not specified or string corrupted"); - resp.err = TCORE_RETURN_3GPP_ERROR; - } - else { - resp.err = atoi(g_slist_nth_data(tokens, 0)); - - // TODO: CMEE error mapping is required. - resp.err = TCORE_RETURN_3GPP_ERROR; - } - - //Free tokens - tcore_at_tok_free(tokens); - } - - resp.id = tcore_call_object_get_id((CallObject*)user_data); - dbg("resp.id = %d", resp.id); - - // Send response to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_SWAP, sizeof(struct tresp_call_swap), &resp); - - if (!resp.err) { - - GSList *active = NULL; - GSList *held = NULL; - CallObject *co = NULL; - gboolean *eflag = NULL; - - held = tcore_call_object_find_by_status(core_obj, TCORE_CALL_STATUS_HELD); - if (!held) { - err("Can't find held Call"); - return; - } - - active = tcore_call_object_find_by_status(core_obj, TCORE_CALL_STATUS_ACTIVE); - if (!active) { - dbg("Can't find active Call"); - return; - } - - while (held) { - co = (CallObject*)held->data; - if (!co) { - err("Can't get held Call object"); - return; - } - - resp.id = tcore_call_object_get_id(co); - - // Send response to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_ACTIVE, sizeof(struct tresp_call_active), &resp); - - held = g_slist_next(held); - } - - while (active) { - co = (CallObject*)active->data; - if (!co) { - err("[ error ] can't get active call object"); - return; - } - - resp.id = tcore_call_object_get_id(co); - - // Send response to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_HOLD, sizeof(struct tresp_call_hold), &resp); - active = g_slist_next(active); - } - - eflag = g_new0(gboolean, 1); - *eflag = FALSE; - - dbg("calling _call_list_get"); - _call_list_get(core_obj, eflag); - } - } - else { - - err("User Request is NULL"); - } - - dbg("Exit"); - return; -} - -static void on_confirmation_call_set_source_sound_path(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur = NULL; - GSList *tokens = NULL; - const char *line = NULL; - const TcoreATResponse* response = data; - char *resp_str = NULL; - struct tresp_call_sound_set_path resp; - int error; - - dbg("Entry"); - ur = tcore_pending_ref_user_request(p); - - //+XDRV: ,,[,] - if (!response) { - err("Input data is NULL"); - return; - } - - if (response->success > 0) { - dbg("RESPONSE OK"); - - line = (const char*) (((GSList*)response->lines)->data); - tokens = tcore_at_tok_new(line); - - resp_str = g_slist_nth_data(tokens, 0); - if(!g_slist_nth_data(tokens, 0)) { - err("group_id is missing"); - resp.err = TCORE_RETURN_3GPP_ERROR; - goto OUT; - } - - if(!g_slist_nth_data(tokens, 1)) { - err(" function_id is missing"); - resp.err = TCORE_RETURN_3GPP_ERROR; - goto OUT; - } - - resp_str = g_slist_nth_data(tokens, 2); - - if(resp_str) { - error = atoi(resp_str); - if(0 == error) { - dbg("Response is Success"); - resp.err = TCORE_RETURN_SUCCESS; - } - else { - resp.err = TCORE_RETURN_3GPP_ERROR; - } - } -OUT: - // Free tokens - tcore_at_tok_free(tokens); - } - else { - dbg("RESPONSE NOT OK"); - - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - err("err cause not specified or string corrupted"); - resp.err = TCORE_RETURN_3GPP_ERROR; - } - else { - error = atoi(g_slist_nth_data(tokens, 0)); - - // TODO: CMEE error mapping is required. - resp.err = TCORE_RETURN_3GPP_ERROR; - } - - // Free tokens - tcore_at_tok_free(tokens); - } - - if (ur) { - if(resp.err != TCORE_RETURN_SUCCESS) { // Send only failed notification . success notification send when destination device is set. - // Send notification to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_SET_SOUND_PATH, sizeof(struct tresp_call_sound_set_path), &resp); - setsoundpath = TRUE; - } - } - else { - err("User Request is NULL"); - } - - dbg("Exit"); - return; -} - -static void on_confirmation_call_set_destination_sound_path(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur = NULL; - GSList *tokens = NULL; - const char *line = NULL; - char *resp_str = NULL ; - struct tresp_call_sound_set_path resp; - const TcoreATResponse* response = data; - int error; - - dbg("Entry"); - - ur = tcore_pending_ref_user_request(p); - // +XDRV: ,,[,] - - if (!response) { - err("Input data is NULL"); - return; - } - - if (ur) { - if (response->success > 0) { - dbg("RESPONSE OK"); - - line = (const char*) (((GSList*)response->lines)->data); - tokens = tcore_at_tok_new(line); - - resp_str = g_slist_nth_data(tokens, 0); - if(!g_slist_nth_data(tokens, 0)) { - dbg("group_id is missing"); - resp.err = TCORE_RETURN_3GPP_ERROR; - goto OUT; - } - - if(!g_slist_nth_data(tokens, 1)) { - dbg("function_id is missing"); - resp.err = TCORE_RETURN_3GPP_ERROR; - goto OUT; - } - - resp_str = g_slist_nth_data(tokens, 2); - if(resp_str) { - error = atoi(resp_str); - if(0 == error) { - dbg("Response is Success"); - resp.err = TCORE_RETURN_SUCCESS; - } - else { - resp.err = TCORE_RETURN_3GPP_ERROR; - } - } - -OUT: - // Free tokens - tcore_at_tok_free(tokens); - } - else { - dbg("RESPONSE NOT OK"); - - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - err("err cause not specified or string corrupted"); - resp.err = TCORE_RETURN_3GPP_ERROR; - } - else { - error = atoi(g_slist_nth_data(tokens, 0)); - // TODO: CMEE error mapping is required. - resp.err = TCORE_RETURN_3GPP_ERROR; - } - - // Free tokens - tcore_at_tok_free(tokens); - } - - if(setsoundpath == TRUE) { - setsoundpath = FALSE; - } - else { - // Send response to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_SET_SOUND_PATH, sizeof(struct tresp_call_sound_set_path), &resp); - } - } - else { - dbg("User Request is NULL"); - } - - dbg("Exit"); - return; -} - -static void on_confirmation_call_set_source_sound_volume_level(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur = NULL; - GSList *tokens = NULL; - const char *line = NULL; - const TcoreATResponse* response = data; - char *resp_str = NULL; - struct tresp_call_sound_set_volume_level resp; - int error; - - ur = tcore_pending_ref_user_request(p); - dbg("Entry"); - // +XDRV: ,,[,] - if (!response) { - err("Input data is NULL"); - return; - } - - if (response->success > 0) { - dbg("RESPONSE OK"); - - line = (const char*) (((GSList*)response->lines)->data); - tokens = tcore_at_tok_new(line); - - resp_str = g_slist_nth_data(tokens, 0); - if(!g_slist_nth_data(tokens, 0)) { - err("group_id is missing"); - resp.err = TCORE_RETURN_3GPP_ERROR; - goto OUT; - } - - if(!g_slist_nth_data(tokens, 1)) { - err("function_id is missing"); - resp.err = TCORE_RETURN_3GPP_ERROR; - goto OUT; - } - - resp_str = g_slist_nth_data(tokens, 2); - if(resp_str) { - error = atoi(resp_str); - - if(0 == error) { - dbg("Response is Success "); - resp.err = TCORE_RETURN_SUCCESS; - } - else { - resp.err = TCORE_RETURN_3GPP_ERROR; - } - } - -OUT: - // Free tokens - tcore_at_tok_free(tokens); - } - else { - dbg("RESPONSE NOT OK"); - - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - err("err cause not specified or string corrupted"); - resp.err = TCORE_RETURN_3GPP_ERROR; - } - else { - error = atoi(g_slist_nth_data(tokens, 0)); - - // TODO: CMEE error mapping is required. - resp.err = TCORE_RETURN_3GPP_ERROR; - } - - // Free tokens - tcore_at_tok_free(tokens); - } - - if (ur) { - if(resp.err && soundvolume == FALSE) { // Send only failed notification . success notification send when destination device is set. - // Send reposne to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_SET_SOUND_VOLUME_LEVEL, sizeof(struct tresp_call_sound_set_volume_level), &resp); - soundvolume = TRUE; - } - } - else { - err("User Request is NULL"); - } - - dbg("Exit"); - return; -} - - -static void on_confirmation_call_set_destination_sound_volume_level(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur = NULL; - GSList *tokens = NULL; - const char *line = NULL; - char *resp_str = NULL; - const TcoreATResponse* response = data; - struct tresp_call_sound_set_volume_level resp; - int error; - - dbg("Entry"); - - ur = tcore_pending_ref_user_request(p); - - // +XDRV: ,,[,] - if (!response) { - err("Input data is NULL"); - return; - } - - if (ur) { - if (response->success > 0) { - - dbg("RESPONSE OK"); - line = (const char*) (((GSList*)response->lines)->data); - tokens = tcore_at_tok_new(line); - resp_str = g_slist_nth_data(tokens, 0); - - if(!g_slist_nth_data(tokens, 0)) { - err("group_id is missing"); - resp.err = TCORE_RETURN_3GPP_ERROR; - goto OUT; - } - - if(!g_slist_nth_data(tokens, 1)) { - err("function_id is missing"); - resp.err = TCORE_RETURN_3GPP_ERROR; - goto OUT; - } - - resp_str = g_slist_nth_data(tokens, 2); - - if(resp_str) { - error = atoi(resp_str); - - if(0 == error) { - dbg("Response is Success"); - resp.err = TCORE_RETURN_SUCCESS; - } - else { - resp.err = TCORE_RETURN_3GPP_ERROR; - } - } - -OUT: - // Free tokens - tcore_at_tok_free(tokens); - } - else { - dbg("RESPONSE NOT OK"); - - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - err("err cause not specified or string corrupted"); - resp.err = TCORE_RETURN_3GPP_ERROR; - } - else { - error = atoi(g_slist_nth_data(tokens, 0)); - - // TODO: CMEE error mapping is required. - resp.err = TCORE_RETURN_3GPP_ERROR; - } - - tcore_at_tok_free(tokens); - } - - if(soundvolume == TRUE){ - soundvolume = FALSE; - } - else{ - // Send reposne to TAPI - tcore_user_request_send_response(ur, TRESP_CALL_SET_SOUND_VOLUME_LEVEL, sizeof(struct tresp_call_sound_set_volume_level), &resp); - } - } - else { - err("User Request is NULL"); - } - - dbg("Exit"); - return; -} - - -static void on_confirmation_call_mute(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur = NULL; - GSList *tokens = NULL; - const char *line = NULL; - char *resp_str = NULL; - struct tresp_call_mute resp; - const TcoreATResponse* response = data; - int error; - - dbg("Entry"); - - ur = tcore_pending_ref_user_request(p); - - if (!response) { - err("Input data is NULL"); - return; - } - - if (response->success > 0) { - dbg("RESPONSE OK"); - - line = (const char*) (((GSList*)response->lines)->data); - tokens = tcore_at_tok_new(line); - resp_str = g_slist_nth_data(tokens, 0); - - if(!g_slist_nth_data(tokens, 0)) { - err("group_id is missing"); - resp.err = TCORE_RETURN_3GPP_ERROR; - goto OUT; - } - - if(!g_slist_nth_data(tokens, 1)) { - err(" function_id is missing"); - resp.err = TCORE_RETURN_3GPP_ERROR; - goto OUT; - } - - resp_str = g_slist_nth_data(tokens, 2); - - if(resp_str) { - error = atoi(resp_str); - if(0 == error) { - dbg("Response is Success"); - resp.err = TCORE_RETURN_SUCCESS; - } - else { - resp.err = TCORE_RETURN_3GPP_ERROR; - } - } -OUT: - // Free tokens - tcore_at_tok_free(tokens); - } - else { - dbg("RESPONSE NOT OK"); - - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - err("err cause not specified or string corrupted"); - resp.err = TCORE_RETURN_3GPP_ERROR; - } - else { - error = atoi(g_slist_nth_data(tokens, 0)); - - // TODO: CMEE error mapping is required. - resp.err = TCORE_RETURN_3GPP_ERROR; - } - - // Free tokens - tcore_at_tok_free(tokens); - } - - if (ur) { - tcore_user_request_send_response(ur, TRESP_CALL_MUTE, sizeof(struct tresp_call_mute), &resp); - } - else { - err("User Request is NULL"); - } - - dbg("Exit"); - return; -} - -static void on_confirmation_call_unmute(TcorePending *p, int data_len, const void *data, void *user_data) -{ - const TcoreATResponse *response = NULL; - struct tresp_call_unmute resp; - GSList *tokens = NULL; - const char *line = NULL; - UserRequest *ur = NULL; - char *resp_str = NULL; - int error; - - dbg("Entry"); - - response = (TcoreATResponse *)data; - ur = tcore_pending_ref_user_request(p); - - if (!response) { - err("Input data is NULL"); - return; - } - - if (response->success > 0) { - dbg("RESPONSE OK"); - - line = (const char*) (((GSList*)response->lines)->data); - tokens = tcore_at_tok_new(line); - resp_str = g_slist_nth_data(tokens, 0); - - if(!g_slist_nth_data(tokens, 0)) { - err("group_id is missing"); - resp.err = TCORE_RETURN_3GPP_ERROR; - goto OUT; - } - - if(!g_slist_nth_data(tokens, 1)) { - err(" function_id is missing"); - resp.err = TCORE_RETURN_3GPP_ERROR; - goto OUT; - } - - resp_str = g_slist_nth_data(tokens, 2); - - if(resp_str) { - error = atoi(resp_str); - if(0 == error) { - dbg("Response is Success"); - resp.err = TCORE_RETURN_SUCCESS; - } - else { - resp.err = TCORE_RETURN_3GPP_ERROR; - } - } -OUT: - // Free tokens - tcore_at_tok_free(tokens); - } - else { - dbg("RESPONSE NOT OK"); - - line = (const char*)response->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - err("err cause not specified or string corrupted"); - resp.err = TCORE_RETURN_3GPP_ERROR; - } - else { - error = atoi(g_slist_nth_data(tokens, 0)); - - // TODO: CMEE error mapping is required. - resp.err = TCORE_RETURN_3GPP_ERROR; - } - - // Free tokens - tcore_at_tok_free(tokens); - } - - if (ur) { - tcore_user_request_send_response(ur, TRESP_CALL_UNMUTE, sizeof(struct tresp_call_unmute), &resp); - } - else { - err("User Request is NULL"); - } - - dbg("Exit"); - return; -} - -// RESPONSE -static void on_response_call_list_get(TcorePending *p, int data_len, const void *data, void *user_data) -{ - TcorePlugin *plugin = NULL; - CoreObject *core_obj = NULL; - CallObject *co = NULL; - struct clcc_call_t *call_list = NULL; - gboolean *event_flag = (gboolean*)user_data; - const TcoreATResponse *response = data; - GSList *resp_data = NULL; - char *line = NULL; - - int cllc_info = 0, countCalls = 0, countValidCalls = 0; - int error = 0; - dbg("Entry"); - - plugin = tcore_pending_ref_plugin(p); - core_obj = tcore_pending_ref_core_object(p); - - if(response->success > 0) { - dbg("RESPONCE OK"); - if(response->lines) { - resp_data = (GSList*)response->lines; - countCalls = g_slist_length(resp_data); - dbg("Total records : %d",countCalls); - } - - if (0 == countCalls) { - err("Call count is zero"); - return; - } - - call_list = g_new0(struct clcc_call_t, countCalls); - - for (countValidCalls = 0;resp_data != NULL ;resp_data = resp_data->next,countValidCalls++,cllc_info++) { - - line = (char*)(resp_data->data); - - error = _callFromCLCCLine(line, call_list + countValidCalls); - if (0 != error) { - continue; - } - - co = tcore_call_object_find_by_id(core_obj, call_list[cllc_info].info.id); - if (!co) { - co = tcore_call_object_new(core_obj, call_list[cllc_info].info.id); - if (!co) { - err("error : tcore_call_object_new [ id : %d ]", call_list[cllc_info].info.id); - continue; - } - } - - // Call set parameters - tcore_call_object_set_type(co, call_type(call_list[cllc_info].info.type)); - tcore_call_object_set_direction(co, call_list[cllc_info].info.direction); - tcore_call_object_set_multiparty_state(co, _call_is_in_mpty(call_list[cllc_info].info.mpty)); - tcore_call_object_set_cli_info(co, CALL_CLI_MODE_DEFAULT, call_list[cllc_info].number); - tcore_call_object_set_active_line(co, 0); - - if (*event_flag) { - dbg("Call status before calling _call_branch_by_status() : (%d)", call_list[cllc_info].info.status); - _call_branch_by_status(plugin, co, call_list[cllc_info].info.status); - } - else { - // Set Status - tcore_call_object_set_status(co, call_list[cllc_info].info.status); - - dbg("Call id : (%d)", call_list[cllc_info].info.id); - dbg("Call direction : (%d)", call_list[cllc_info].info.direction); - dbg("Call type : (%d)", call_list[cllc_info].info.type); - dbg("Call mpty : (%d)", call_list[cllc_info].info.mpty); - dbg("Call number : (%s)", call_list[cllc_info].number); - dbg("Call status : (%d)", call_list[cllc_info].info.status); - } - } - - // Free Call list - g_free(call_list); - } - - // Free User data - g_free(event_flag); - - dbg("Exit"); - return; -} - -static void _on_confirmation_call_end_cause(TcorePending * p, int data_len, const void * data, void * user_data) -{ - TcorePlugin *plugin = NULL; - CoreObject *core_obj = NULL; - CallObject *co = (CallObject *)user_data; - const TcoreATResponse *response = data; - const char *line = NULL; - struct tnoti_call_status_idle call_status; - GSList *tokens = NULL; - char* resp_str; - int error; - - dbg("Entry"); - plugin = tcore_pending_ref_plugin(p); - core_obj = tcore_pending_ref_core_object(p); - - if (response->success > 0){ - dbg("RESPONSE OK"); - line = (const char*) (((GSList*)response->lines)->data); - tokens = tcore_at_tok_new(line); - resp_str = g_slist_nth_data(tokens, 0); - if(!resp_str){ - err("call end cause - report value missing"); - } - else { - resp_str = g_slist_nth_data(tokens, 1); - if(!resp_str){ - err("call end cause value missing"); - } - error = atoi(resp_str); - dbg("call end cause - %d",error); - call_status.cause =_compare_call_end_cause(error); - dbg("TAPI call end cause - %d",call_status.cause); - } - - //Free tokens - tcore_at_tok_free(tokens); - } - else { - err("RESPONSE NOT OK"); - line = (char*)response->final_response; - tokens = tcore_at_tok_new(line); - if (g_slist_length(tokens) < 1) { - err("err cause not specified or string corrupted"); - } - else { - err(" err cause value: %d",atoi(g_slist_nth_data(tokens, 0))); - } - call_status.cause = CC_CAUSE_NORMAL_CALL_CLEARING; - //Free tokens - tcore_at_tok_free(tokens); - } - - call_status.type = tcore_call_object_get_type(co); - dbg("data.type : [%d]", call_status.type); - - call_status.id = tcore_call_object_get_id(co); - dbg("data.id : [%d]", call_status.id); - - // Set Status - tcore_call_object_set_status(co, TCORE_CALL_STATUS_IDLE); - - // Send Notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - core_obj, - TNOTI_CALL_STATUS_IDLE, - sizeof(struct tnoti_call_status_idle), - (void*)&call_status); - - // Free Call object - tcore_call_object_free(core_obj, co); -} - -static int _callFromCLCCLine(char *line, struct clcc_call_t *p_call) -{ - //+CLCC: 1,0,2,0,0,"18005551212",145 - //[+CLCC: , , , ,[,,[,[,]]] - int state; - int mode; - int isMT; - char *num = NULL; - unsigned int num_type; - GSList *tokens = NULL; - char *resp = NULL; - dbg("Entry"); - - tokens = tcore_at_tok_new(line); - // parse - resp = g_slist_nth_data(tokens, 0); - if(!resp) { - err("InValid ID"); - goto ERROR; - } - p_call->info.id = atoi(resp); - dbg("id : [%d]\n", p_call->info.id); - - //parse - resp = g_slist_nth_data(tokens, 1); - if(!resp) { - err("InValid Dir"); - goto ERROR; - } - isMT = atoi(resp); - if(0 == isMT) { - p_call->info.direction = TCORE_CALL_DIRECTION_OUTGOING; - } - else { - p_call->info.direction = TCORE_CALL_DIRECTION_INCOMING; - } - dbg("Direction : [ %d ]\n", p_call->info.direction); - - // parse - resp = g_slist_nth_data(tokens, 2); - if(!resp) { - err("InValid Stat"); - goto ERROR; - } - state = atoi(resp); - dbg("Call state : %d", state); - switch(state){ - case 0: //active - p_call->info.status = TCORE_CALL_STATUS_ACTIVE; - break; - case 1: - p_call->info.status = TCORE_CALL_STATUS_HELD; - break; - case 2: - p_call->info.status = TCORE_CALL_STATUS_DIALING; - break; - case 3: - p_call->info.status = TCORE_CALL_STATUS_ALERT; - break; - case 4: - p_call->info.status = TCORE_CALL_STATUS_INCOMING; - break; - case 5: - p_call->info.status = TCORE_CALL_STATUS_WAITING; - break; - } - dbg("Status : [%d]\n", p_call->info.status); - - // parse - resp = g_slist_nth_data(tokens, 3); - if(!resp) { - err("InValid Mode"); - goto ERROR; - } - mode = atoi(resp); - switch(mode) - { - case 0: - p_call->info.type = TCORE_CALL_TYPE_VOICE; - break; - case 1: - p_call->info.type = TCORE_CALL_TYPE_VIDEO; - break; - default: // only Voice/VT call is supported in CS. treat other unknown calls as error - dbg("invalid type : [%d]\n", mode); - goto ERROR; - } - dbg("Call type : [%d]\n", p_call->info.type); - - // parse - resp = g_slist_nth_data(tokens, 4); - if(!resp) { - err("InValid Mpty"); - goto ERROR; - } - - p_call->info.mpty = atoi(resp); - dbg("Mpty : [ %d ]\n", p_call->info.mpty); - - // parse - resp = g_slist_nth_data(tokens, 5); - dbg("Incoming number - %s and its len - %d", resp, strlen(resp)); - - // tolerate null here - if (!resp) { - err("Number is NULL"); - goto ERROR; - } - // Strike off double quotes +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: sharanayya mathapati + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "s_common.h" +#include "s_call.h" + + +#define STATUS_INCOMING 4 +#define STATUS_WAITING 5 +#define STATUS_CONNECTED 7 +#define COMMA 0X2c + +static gboolean setsoundpath = FALSE; +static gboolean soundvolume = FALSE; + +// End Cause field - Call state end cause + +typedef enum { + CALL_END_NO_CAUSE, + + // These definitions are taken from GSM 04.08 Table 10.86 + + CC_CAUSE_UNASSIGNED_NUMBER, + CC_CAUSE_NO_ROUTE_TO_DEST, + CC_CAUSE_CHANNEL_UNACCEPTABLE, + CC_CAUSE_OPERATOR_DETERMINED_BARRING, + CC_CAUSE_NORMAL_CALL_CLEARING, + CC_CAUSE_USER_BUSY, + CC_CAUSE_NO_USER_RESPONDING, + CC_CAUSE_USER_ALERTING_NO_ANSWER, + CC_CAUSE_CALL_REJECTED, + CC_CAUSE_NUMBER_CHANGED, + CC_CAUSE_NON_SELECTED_USER_CLEARING, + CC_CAUSE_DESTINATION_OUT_OF_ORDER, + CC_CAUSE_INVALID_NUMBER_FORMAT, + CC_CAUSE_FACILITY_REJECTED, + CC_CAUSE_RESPONSE_TO_STATUS_ENQUIRY, + CC_CAUSE_NORMAL_UNSPECIFIED, + CC_CAUSE_NO_CIRCUIT_CHANNEL_AVAILABLE, + CC_CAUSE_NETWORK_OUT_OF_ORDER, + CC_CAUSE_TEMPORARY_FAILURE, + CC_CAUSE_SWITCHING_EQUIPMENT_CONGESTION, + CC_CAUSE_ACCESS_INFORMATION_DISCARDED, + CC_CAUSE_REQUESTED_CIRCUIT_CHANNEL_NOT_AVAILABLE, + CC_CAUSE_RESOURCES_UNAVAILABLE_UNSPECIFIED, + CC_CAUSE_QUALITY_OF_SERVICE_UNAVAILABLE, + CC_CAUSE_REQUESTED_FACILITY_NOT_SUBSCRIBED, + CC_CAUSE_INCOMING_CALL_BARRED_WITHIN_CUG, + CC_CAUSE_BEARER_CAPABILITY_NOT_AUTHORISED, + CC_CAUSE_BEARER_CAPABILITY_NOT_PRESENTLY_AVAILABLE, + CC_CAUSE_SERVICE_OR_OPTION_NOT_AVAILABLE, + CC_CAUSE_BEARER_SERVICE_NOT_IMPLEMENTED, + CC_CAUSE_ACM_GEQ_ACMMAX, + CC_CAUSE_REQUESTED_FACILITY_NOT_IMPLEMENTED, + CC_CAUSE_ONLY_RESTRICTED_DIGITAL_INFO_BC_AVAILABLE, + CC_CAUSE_SERVICE_OR_OPTION_NOT_IMPLEMENTED, + CC_CAUSE_INVALID_TRANSACTION_ID_VALUE, + CC_CAUSE_USER_NOT_MEMBER_OF_CUG, + CC_CAUSE_INCOMPATIBLE_DESTINATION, + CC_CAUSE_INVALID_TRANSIT_NETWORK_SELECTION, + CC_CAUSE_SEMANTICALLY_INCORRECT_MESSAGE, + CC_CAUSE_INVALID_MANDATORY_INFORMATION, + CC_CAUSE_MESSAGE_TYPE_NON_EXISTENT, + CC_CAUSE_MESSAGE_TYPE_NOT_COMPATIBLE_WITH_PROT_STATE, + CC_CAUSE_IE_NON_EXISTENT_OR_NOT_IMPLEMENTED, + CC_CAUSE_CONDITIONAL_IE_ERROR, + CC_CAUSE_MESSAGE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE, + CC_CAUSE_RECOVERY_ON_TIMER_EXPIRY, + CC_CAUSE_PROTOCOL_ERROR_UNSPECIFIED, + CC_CAUSE_INTERWORKING_UNSPECIFIED, + CC_CAUSE_END = 128, + + // Reject causes + REJECT_CAUSE_IMSI_UNKNOWN_IN_HLR, + REJECT_CAUSE_ILLEGAL_MS, + REJECT_CAUSE_IMSI_UNKNOWN_IN_VLR, + REJECT_CAUSE_IMEI_NOT_ACCEPTED, + REJECT_CAUSE_ILLEGAL_ME, + REJECT_CAUSE_GPRS_SERVICES_NOT_ALLOWED, + REJECT_CAUSE_GPRS_SERVICES_AND_NON_GPRS_SERVICES_NOT_ALLOWED, + REJECT_CAUSE_MS_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK, + REJECT_CAUSE_IMPLICITLY_DETACHED, + REJECT_CAUSE_PLMN_NOT_ALLOWED, + REJECT_CAUSE_LA_NOT_ALLOWED, + REJECT_CAUSE_NATIONAL_ROAMING_NOT_ALLOWED, + REJECT_CAUSE_GPRS_SERVICES_NOT_ALLOWED_IN_THIS_PLMN, + REJECT_CAUSE_NO_SUITABLE_CELLS_IN_LA, + REJECT_CAUSE_MSC_TEMPORARILY_NOT_REACHABLE, + REJECT_CAUSE_NETWORK_FAILURE, + REJECT_CAUSE_MAC_FAILURE, + REJECT_CAUSE_SYNCH_FAILURE, + REJECT_CAUSE_CONGESTTION, + REJECT_CAUSE_GSM_AUTH_UNACCEPTED, + REJECT_CAUSE_SERVICE_OPTION_NOT_SUPPORTED, + REJECT_CAUSE_REQ_SERV_OPT_NOT_SUBSCRIBED, + REJECT_CAUSE_SERVICE_OPT__OUT_OF_ORDER, + REJECT_CAUSE_CALL_CANNOT_BE_IDENTIFIED, + REJECT_CAUSE_NO_PDP_CONTEXT_ACTIVATED, + REJECT_CAUSE_RETRY_UPON_ENTRY_INTO_A_NEW_CELL_MIN_VALUE, + REJECT_CAUSE_RETRY_UPON_ENTRY_INTO_A_NEW_CELL_MAX_VALUE, + REJECT_CAUSE_SEMANTICALLY_INCORRECT_MSG, + REJECT_CAUSE_INVALID_MANDATORY_INFO, + REJECT_CAUSE_MESSAGE_TYPE_NON_EXISTANT, + REJECT_CAUSE_MESSAGE_TYPE_NOT_COMP_PRT_ST, + REJECT_CAUSE_IE_NON_EXISTANT, + REJECT_CAUSE_MSG_NOT_COMPATIBLE_PROTOCOL_STATE, + + + // Connection Management establishment rejection cause + REJECT_CAUSE_REJ_UNSPECIFIED, + + // AS reject causes + REJECT_CAUSE_AS_REJ_RR_REL_IND, + REJECT_CAUSE_AS_REJ_RR_RANDOM_ACCESS_FAILURE, + REJECT_CAUSE_AS_REJ_RRC_REL_IND, + REJECT_CAUSE_AS_REJ_RRC_CLOSE_SESSION_IND, + REJECT_CAUSE_AS_REJ_RRC_OPEN_SESSION_FAILURE, + REJECT_CAUSE_AS_REJ_LOW_LEVEL_FAIL, + REJECT_CAUSE_AS_REJ_LOW_LEVEL_FAIL_REDIAL_NOT_ALLOWED, + REJECT_CAUSE_AS_REJ_LOW_LEVEL_IMMED_RETRY, + + // MM reject causes + REJECT_CAUSE_MM_REJ_INVALID_SIM, + REJECT_CAUSE_MM_REJ_NO_SERVICE, + REJECT_CAUSE_MM_REJ_TIMER_T3230_EXP, + REJECT_CAUSE_MM_REJ_NO_CELL_AVAILABLE, + REJECT_CAUSE_MM_REJ_WRONG_STATE, + REJECT_CAUSE_MM_REJ_ACCESS_CLASS_BLOCKED, + // Definitions for release ind causes between MM and CNM + REJECT_CAUSE_ABORT_MSG_RECEIVED, + REJECT_CAUSE_OTHER_CAUSE, + + // CNM reject causes + REJECT_CAUSE_CNM_REJ_TIMER_T303_EXP, + REJECT_CAUSE_CNM_REJ_NO_RESOURCES, + REJECT_CAUSE_CNM_MM_REL_PENDING, + REJECT_CAUSE_CNM_INVALID_USER_DATA, + CALL_END_CAUSE_MAX = 255 +} call_end_cause_e_type; + + +struct clcc_call_t { + struct call_CLCC_info { + int id; + enum tcore_call_direction direction; + enum tcore_call_status status; + enum tcore_call_type type; + int mpty; + int num_len; + int num_type; + } + info; + char number[90]; +}; + +typedef struct { + int network_cause; + int tapi_cause; +} call_end_cause_info; + +/************************************************************************** + * Local Function Prototypes + **************************************************************************/ +/************************* REQUESTS ***************************/ +static void _call_status_idle(TcorePlugin *p, CallObject *co); +static void _call_status_active(TcorePlugin *p, CallObject *co); +static void _call_status_dialing(TcorePlugin *p, CallObject *co); +static void _call_status_alert(TcorePlugin *p, CallObject *co); +static void _call_status_incoming(TcorePlugin *p, CallObject *co); +static void _call_status_waiting(TcorePlugin *p, CallObject *co); +static TReturn _call_list_get(CoreObject *o, gboolean *event_flag); +static TReturn _set_dtmf_tone_duration(CoreObject *o, UserRequest *ur); + +/************************* CONFIRMATION ***************************/ +static void on_confirmation_call_message_send(TcorePending *p, gboolean result, void *user_data); // from Kernel +static void on_confirmation_call_hold(TcorePending *p, int data_len, const void *data, void *user_data); +static void on_confirmation_call_swap(TcorePending *p, int data_len, const void *data, void *user_data); +static void on_confirmation_call_split(TcorePending *p, int data_len, const void *data, void *user_data); +static void on_confirmation_call_hold_and_accept(TcorePending *p, int data_len, const void *data, void *user_data); + +static void _on_confirmation_call_release(TcorePending *p, int data_len, const void *data, void *user_data, int type); +static void _on_confirmation_call(TcorePending *p, int data_len, const void *data, void *user_data, int type); +static void _on_confirmation_dtmf_tone_duration(TcorePending *p, int data_len, const void *data, void *user_data); +static void _on_confirmation_call_end_cause(TcorePending *p, int data_len, const void *data, void *user_data); + +/************************* RESPONSES ***************************/ +static void on_response_call_list_get(TcorePending *p, int data_len, const void *data, void *user_data); + +/************************* NOTIIFICATIONS ***************************/ +static void on_notification_call_waiting(CoreObject *o, const void *data, void *user_data); +static void on_notification_call_incoming(CoreObject *o, const void *data, void *user_data); +static void on_notification_call_status(CoreObject *o, const void *data, void *user_data); +static gboolean on_notification_call_info(CoreObject *o, const void *data, void *user_data); +static gboolean on_notification_call_clip_info(CoreObject *o, const void *data, void *user_data); + + +/************************************************************************** + * Local Utility Function Prototypes + **************************************************************************/ +static gboolean _call_request_message(TcorePending *pending, CoreObject *o, UserRequest *ur, void *on_resp, void *user_data); +static void _call_branch_by_status(TcorePlugin *p, CallObject *co, unsigned int status); +static int _callFromCLCCLine(char *line, struct clcc_call_t *p_call); + +/************************************************************************** + * Local Function Definitions + **************************************************************************/ + +const call_end_cause_info call_end_cause_table[] = // call end cause table to convert Netwotk cause to TAPI cause +{ + { 1, CC_CAUSE_UNASSIGNED_NUMBER}, { 3, CC_CAUSE_NO_ROUTE_TO_DEST}, + { 6, CC_CAUSE_CHANNEL_UNACCEPTABLE}, { 8, CC_CAUSE_OPERATOR_DETERMINED_BARRING}, + { 16, CC_CAUSE_NORMAL_CALL_CLEARING}, { 17, CC_CAUSE_USER_BUSY}, + { 18, CC_CAUSE_NO_USER_RESPONDING}, { 19, CC_CAUSE_USER_ALERTING_NO_ANSWER}, + { 21, CC_CAUSE_CALL_REJECTED}, { 22, CC_CAUSE_NUMBER_CHANGED}, + { 26, CC_CAUSE_NON_SELECTED_USER_CLEARING}, { 27, CC_CAUSE_DESTINATION_OUT_OF_ORDER}, + { 28, CC_CAUSE_INVALID_NUMBER_FORMAT}, { 29, CC_CAUSE_FACILITY_REJECTED}, + { 30, CC_CAUSE_RESPONSE_TO_STATUS_ENQUIRY}, { 31, CC_CAUSE_NORMAL_UNSPECIFIED}, + { 34, CC_CAUSE_NO_CIRCUIT_CHANNEL_AVAILABLE}, { 38, CC_CAUSE_NETWORK_OUT_OF_ORDER}, + { 41, CC_CAUSE_TEMPORARY_FAILURE}, { 42, CC_CAUSE_SWITCHING_EQUIPMENT_CONGESTION}, + { 43, CC_CAUSE_ACCESS_INFORMATION_DISCARDED}, { 44, CC_CAUSE_REQUESTED_CIRCUIT_CHANNEL_NOT_AVAILABLE}, + { 47, CC_CAUSE_RESOURCES_UNAVAILABLE_UNSPECIFIED}, { 49, CC_CAUSE_QUALITY_OF_SERVICE_UNAVAILABLE}, + { 50, CC_CAUSE_REQUESTED_FACILITY_NOT_SUBSCRIBED}, { 55, CC_CAUSE_INCOMING_CALL_BARRED_WITHIN_CUG}, + { 57, CC_CAUSE_BEARER_CAPABILITY_NOT_AUTHORISED}, { 58, CC_CAUSE_BEARER_CAPABILITY_NOT_PRESENTLY_AVAILABLE}, + { 63, CC_CAUSE_SERVICE_OR_OPTION_NOT_AVAILABLE}, { 65, CC_CAUSE_BEARER_SERVICE_NOT_IMPLEMENTED}, + { 68, CC_CAUSE_ACM_GEQ_ACMMAX}, { 69, CC_CAUSE_REQUESTED_FACILITY_NOT_IMPLEMENTED}, + { 70, CC_CAUSE_ONLY_RESTRICTED_DIGITAL_INFO_BC_AVAILABLE}, { 79, CC_CAUSE_SERVICE_OR_OPTION_NOT_IMPLEMENTED}, + { 81, CC_CAUSE_INVALID_TRANSACTION_ID_VALUE}, { 87, CC_CAUSE_USER_NOT_MEMBER_OF_CUG}, + { 88, CC_CAUSE_INCOMPATIBLE_DESTINATION}, { 91, CC_CAUSE_INVALID_TRANSIT_NETWORK_SELECTION}, + { 95, CC_CAUSE_SEMANTICALLY_INCORRECT_MESSAGE}, { 96, CC_CAUSE_INVALID_MANDATORY_INFORMATION}, + { 97, CC_CAUSE_MESSAGE_TYPE_NON_EXISTENT}, { 98, CC_CAUSE_MESSAGE_TYPE_NOT_COMPATIBLE_WITH_PROT_STATE}, + { 99, CC_CAUSE_IE_NON_EXISTENT_OR_NOT_IMPLEMENTED}, { 100, CC_CAUSE_CONDITIONAL_IE_ERROR}, + { 101, CC_CAUSE_MESSAGE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE}, { 102, CC_CAUSE_RECOVERY_ON_TIMER_EXPIRY}, + { 111, CC_CAUSE_PROTOCOL_ERROR_UNSPECIFIED}, {127, CC_CAUSE_INTERWORKING_UNSPECIFIED}, +}; + +static enum tcore_call_cli_mode _get_clir_status(char *num) +{ + enum tcore_call_cli_mode clir = CALL_CLI_MODE_DEFAULT; + dbg("Entry"); + + if (!strncmp(num, "*31#", 4)) { + dbg("CLI mode restricted"); + return TCORE_CALL_CLI_MODE_RESTRICT; + } + + if (!strncmp(num, "#31#", 4)) { + dbg("CLI mode allowed"); + return TCORE_CALL_CLI_MODE_PRESENT; + } + + err("Exit"); + return clir; +} + +static enum tcore_call_status _call_status(unsigned int status) +{ + dbg("Entry"); + + switch (status) { + case 0: + return TCORE_CALL_STATUS_ACTIVE; + + case 1: + return TCORE_CALL_STATUS_HELD; + + case 2: + return TCORE_CALL_STATUS_DIALING; + + case 3: + return TCORE_CALL_STATUS_ALERT; + + case 4: + return TCORE_CALL_STATUS_INCOMING; + + case 5: + return TCORE_CALL_STATUS_WAITING; + + case 6: // DISCONNECTED state // FALL THROUGH + default: + return TCORE_CALL_STATUS_IDLE; + } +} + +static gboolean _call_is_in_mpty(int mpty) +{ + dbg("Entry"); + + switch (mpty) { + case 0: + return FALSE; + + case 1: + return TRUE; + + default: + break; + } + + return FALSE; +} + +static enum tcore_call_type call_type(int type) +{ + dbg("Entry"); + + switch (type) { + case 0: + return TCORE_CALL_TYPE_VOICE; + + case 1: + return TCORE_CALL_TYPE_VIDEO; + + default: + break; + } + + return TCORE_CALL_TYPE_VOICE; +} + +static int _compare_call_end_cause(int networkcause) +{ + unsigned int count; + for (count = 0; count < sizeof(call_end_cause_table) / sizeof(call_end_cause_info); count++) { + if (call_end_cause_table[count].network_cause == networkcause) + return (call_end_cause_table[count].tapi_cause); + } + return CC_CAUSE_NORMAL_CALL_CLEARING; + dbg("Exit"); +} + +static gboolean on_notification_call_clip_info(CoreObject *o, const void *data, void *user_data) +{ + dbg("Entry"); + + // TODO + + return TRUE; +} + +static gboolean on_notification_call_info(CoreObject *o, const void *data, void *user_data) +{ + GSList *tokens = NULL; + GSList *lines = NULL; + const char *line = NULL; + char *stat; + int status; + + dbg("Entry"); + + lines = (GSList *) data; + if (1 != g_slist_length(lines)) { + err("Unsolicited message, BUT multiple lines present"); + goto OUT; + } + + line = (char *) (lines->data); + tokens = tcore_at_tok_new(line); + + stat = g_slist_nth_data(tokens, 1); + if (!stat) { + dbg("Stat is missing from %XCALLSTAT indiaction"); + } else { + status = atoi(stat); + + switch (status) { + case STATUS_INCOMING: + dbg("calling on_notification_call_incoming"); + on_notification_call_incoming(o, line, user_data); + break; + + case STATUS_WAITING: + dbg("calling on_notification_call_waiting"); + on_notification_call_waiting(o, line, user_data); + break; + + case STATUS_CONNECTED: /*igonre Connected state. */ + dbg("Connected state"); + break; + + default: + dbg("calling on_notification_call_status"); + on_notification_call_status(o, line, user_data); + break; + } + } + + // Free tokens + tcore_at_tok_free(tokens); + +OUT: + dbg("Exit"); + return TRUE; +} + +static gboolean _call_request_message(TcorePending *pending, + CoreObject *o, + UserRequest *ur, + void *on_resp, + void *user_data) +{ + TcoreHal *hal = NULL; + TReturn ret; + dbg("Entry"); + + tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT); + + if (on_resp) { + tcore_pending_set_response_callback(pending, on_resp, user_data); + } + tcore_pending_set_send_callback(pending, on_confirmation_call_message_send, NULL); + + if (ur) { + tcore_pending_link_user_request(pending, ur); + } else { + err("User Request is NULL, is this internal request??"); + } + + // HAL + hal = tcore_object_get_hal(o); + // Send request to HAL + ret = tcore_hal_send_request(hal, pending); + if (TCORE_RETURN_SUCCESS != ret) { + err("Request send failed"); + return FALSE; + } + + dbg("Exit"); + return TRUE; +} + +static void _call_status_idle(TcorePlugin *p, CallObject *co) +{ + CoreObject *core_obj = NULL; + char *cmd_str = NULL; + TcorePending *pending = NULL; + TcoreATRequest *req = NULL; + gboolean ret = FALSE; + UserRequest *ur; + + dbg("Entry"); + core_obj = tcore_plugin_ref_core_object(p, "call"); + dbg("Call ID [%d], Call Status [%d]", tcore_call_object_get_id(co), tcore_call_object_get_status(co)); + + if (tcore_call_object_get_status(co) != TCORE_CALL_STATUS_IDLE) { + // get call end cause. + cmd_str = g_strdup_printf("%s", "AT+XCEER"); + dbg("Request command string: %s", cmd_str); + + // Create new Pending request + pending = tcore_pending_new(core_obj, 0); + + // Create new AT-Command request + req = tcore_at_request_new(cmd_str, "+XCEER", TCORE_AT_SINGLELINE); + dbg("Command: %s, prefix(if any): %s, Command length: %d", req->cmd, req->prefix, strlen(req->cmd)); + // Free command string + g_free(cmd_str); + + // Set request data (AT command) to Pending request + tcore_pending_set_request_data(pending, 0, req); + + ur = tcore_user_request_new(NULL, NULL); + // Send request + ret = _call_request_message(pending, core_obj, ur, _on_confirmation_call_end_cause, co); + + if (!ret) { + err("Failed to send AT-Command request"); + return; + } + } else { + err("Call object was not free"); + tcore_call_object_free(core_obj, co); + } + dbg("Exit"); + return; +} + +static void _call_status_dialing(TcorePlugin *p, CallObject *co) +{ + struct tnoti_call_status_dialing data; + dbg("Entry"); + + if (tcore_call_object_get_status(co) != TCORE_CALL_STATUS_DIALING) { + data.type = tcore_call_object_get_type(co); + dbg("data.type : [%d]", data.type); + + data.id = tcore_call_object_get_id(co); + dbg("data.id : [%d]", data.id); + + // Set Status + tcore_call_object_set_status(co, TCORE_CALL_STATUS_DIALING); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(p), + tcore_plugin_ref_core_object(p, "call"), + TNOTI_CALL_STATUS_DIALING, + sizeof(struct tnoti_call_status_dialing), + (void *) &data); + } + + dbg("Exit"); + return; +} + +static void _call_status_alert(TcorePlugin *p, CallObject *co) +{ + struct tnoti_call_status_alert data; + dbg("Entry"); + + // Alerting has just 1 data 'CALL ID' + if (tcore_call_object_get_status(co) != TCORE_CALL_STATUS_ALERT) { + data.type = tcore_call_object_get_type(co); + dbg("data.type : [%d]", data.type); + + data.id = tcore_call_object_get_id(co); + dbg("data.id : [%d]", data.id); + + // Set Status + tcore_call_object_set_status(co, TCORE_CALL_STATUS_ALERT); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(p), + tcore_plugin_ref_core_object(p, "call"), + TNOTI_CALL_STATUS_ALERT, + sizeof(struct tnoti_call_status_alert), + (void *) &data); + } + + dbg("Exit"); + return; +} + +static void _call_status_active(TcorePlugin *p, CallObject *co) +{ + struct tnoti_call_status_active data; + dbg("Entry"); + + if (tcore_call_object_get_status(co) != TCORE_CALL_STATUS_ACTIVE) { + data.type = tcore_call_object_get_type(co); + dbg("data.type : [%d]", data.type); + + data.id = tcore_call_object_get_id(co); + dbg("data.id : [%d]", data.id); + + // Set Status + tcore_call_object_set_status(co, TCORE_CALL_STATUS_ACTIVE); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(p), + tcore_plugin_ref_core_object(p, "call"), + TNOTI_CALL_STATUS_ACTIVE, + sizeof(struct tnoti_call_status_active), + (void *) &data); + } + + dbg("Exit"); + return; +} + +static void _call_status_held(TcorePlugin *p, CallObject *co) +{ + struct tnoti_call_status_held data; + dbg("Entry"); + + if (tcore_call_object_get_status(co) != TCORE_CALL_STATUS_HELD) { + data.type = tcore_call_object_get_type(co); + dbg("data.type : [%d]", data.type); + + data.id = tcore_call_object_get_id(co); + dbg("data.id : [%d]", data.id); + + // Set Status + tcore_call_object_set_status(co, TCORE_CALL_STATUS_HELD); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(p), + tcore_plugin_ref_core_object(p, "call"), + TNOTI_CALL_STATUS_HELD, + sizeof(struct tnoti_call_status_held), + (void *) &data); + } + + dbg("Exit"); + return; +} + +static void _call_status_incoming(TcorePlugin *p, CallObject *co) +{ + struct tnoti_call_status_incoming data; + dbg("Entry"); + + if (tcore_call_object_get_status(co) != TCORE_CALL_STATUS_INCOMING) { + tcore_call_object_set_status(co, TCORE_CALL_STATUS_INCOMING); + + data.type = tcore_call_object_get_type(co); + dbg("data.type : [%d]", data.type); + + data.id = tcore_call_object_get_id(co); + dbg("data.id : [%d]", data.id); + + data.cli.mode = tcore_call_object_get_cli_mode(co); + dbg("data.cli.mode : [%d]", data.cli.mode); + + tcore_call_object_get_number(co, data.cli.number); + dbg("data.cli.number : [%s]", data.cli.number); + + data.cna.mode = tcore_call_object_get_cna_mode(co); + dbg("data.cna.mode : [%d]", data.cna.mode); + + tcore_call_object_get_name(co, data.cna.name); + dbg("data.cna.name : [%s]", data.cna.name); + + data.forward = FALSE; // this is tmp code + + data.active_line = tcore_call_object_get_active_line(co); + dbg("data.active_line : [%d]", data.active_line); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(p), + tcore_plugin_ref_core_object(p, "call"), + TNOTI_CALL_STATUS_INCOMING, + sizeof(struct tnoti_call_status_incoming), + (void *) &data); + } + + dbg("Exit"); + return; +} + +static void _call_status_waiting(TcorePlugin *p, CallObject *co) +{ + dbg("Entry"); + _call_status_incoming(p, co); + + dbg("Exit"); + return; +} + +static void _call_branch_by_status(TcorePlugin *p, CallObject *co, unsigned int status) +{ + dbg("Entry"); + + dbg("Call Status is %d", status); + switch (status) { + case TCORE_CALL_STATUS_IDLE: + _call_status_idle(p, co); + break; + + case TCORE_CALL_STATUS_ACTIVE: + _call_status_active(p, co); + break; + + case TCORE_CALL_STATUS_HELD: + _call_status_held(p, co); + break; + + case TCORE_CALL_STATUS_DIALING: + _call_status_dialing(p, co); + break; + + case TCORE_CALL_STATUS_ALERT: + _call_status_alert(p, co); + break; + + case TCORE_CALL_STATUS_INCOMING: + _call_status_incoming(p, co); + break; + + case TCORE_CALL_STATUS_WAITING: + _call_status_waiting(p, co); + break; + } + + dbg("Exit"); + return; +} + +static TReturn _call_list_get(CoreObject *o, gboolean *event_flag) +{ + UserRequest *ur = NULL; + TcorePending *pending = NULL; + char *cmd_str = NULL; + TcoreATRequest *req = NULL; + gboolean ret = FALSE; + + dbg("Entry"); + if (!o) { + err("Core Object is NULL"); + return TCORE_RETURN_FAILURE; + } + + // Create new User Request + ur = tcore_user_request_new(NULL, NULL); + + // Command string + cmd_str = g_strdup("AT+CLCC"); + + // Create new Pending Request + pending = tcore_pending_new(o, 0); + req = tcore_at_request_new(cmd_str, "+CLCC", TCORE_AT_MULTILINE); + + g_free(cmd_str); + + dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_request_data(pending, 0, req); + + ret = _call_request_message(pending, o, ur, on_response_call_list_get, event_flag); + if (!ret) { + err("AT request (%s) sending failed", req->cmd); + return TCORE_RETURN_FAILURE; + } + + dbg("AT request sent success"); + return TCORE_RETURN_SUCCESS; +} + +// CONFIRMATION +static void on_confirmation_call_message_send(TcorePending *p, gboolean result, void *user_data) +{ + dbg("Entry"); + + if (result == FALSE) { // Fail + dbg("SEND FAIL"); + } else { + dbg("SEND OK"); + } + + dbg("Exit"); + return; +} + +static void on_confirmation_call_outgoing(TcorePending *p, int data_len, const void *data, void *user_data) +{ + UserRequest *ur = NULL; + GSList *tokens = NULL; + const char *line = NULL; + const TcoreATResponse *response = data; + struct tresp_call_dial resp; + int error; + dbg("Entry"); + + ur = tcore_pending_ref_user_request(p); + if (ur) { + if (response->success > 0) { + dbg("RESPONSE OK"); + resp.err = TCORE_RETURN_SUCCESS; + } else { + dbg("RESPONSE NOT OK"); + + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + err("Unspecified error cause OR string corrupted"); + resp.err = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + + // TODO: CMEE error mapping is required. + resp.err = TCORE_RETURN_3GPP_ERROR; + } + + // Free tokens + tcore_at_tok_free(tokens); + } + + // Send Response to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_DIAL, sizeof(struct tresp_call_dial), &resp); + } else { + err("User Request is NULL"); + } + + dbg("Exit") + return; +} + +static void on_confirmation_call_accept(TcorePending *p, int data_len, const void *data, void *user_data) +{ + UserRequest *ur = NULL; + GSList *tokens = NULL; + const char *line = NULL; + const TcoreATResponse *response = data; + struct tresp_call_answer resp; + int error; + dbg("Entry"); + + ur = tcore_pending_ref_user_request(p); + if (ur) { + if (response->success > 0) { + dbg("RESPONSE OK"); + resp.err = TCORE_RETURN_SUCCESS; + } else { + dbg("RESPONSE NOT OK"); + + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + err("Unspecified error cause OR string corrupted"); + resp.err = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + + // TODO: CMEE error mapping is required. + resp.err = TCORE_RETURN_3GPP_ERROR; + } + + // Free tokens + tcore_at_tok_free(tokens); + } + + resp.id = tcore_call_object_get_id((CallObject *) user_data); + + // Send Response to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_ANSWER, sizeof(struct tresp_call_answer), &resp); + } else { + err("User Request is NULL"); + } + + dbg("Exit"); + return; +} + + +static void on_confirmation_call_reject(TcorePending *p, int data_len, const void *data, void *user_data) +{ + UserRequest *ur = NULL; + GSList *tokens = NULL; + const char *line = NULL; + const TcoreATResponse *response = data; + struct tresp_call_answer resp; + int error; + + dbg("Entry"); + + ur = tcore_pending_ref_user_request(p); + if (ur) { + if (response->success > 0) { + dbg("RESPONSE OK"); + resp.err = TCORE_RETURN_SUCCESS; + } else { + dbg("RESPONSE NOT OK"); + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + err("Unspecified error cause OR string corrupted"); + resp.err = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + // TODO: CMEE error mapping is required. + resp.err = TCORE_RETURN_3GPP_ERROR; + } + + // Free tokens + tcore_at_tok_free(tokens); + } + + resp.id = tcore_call_object_get_id((CallObject *) user_data); + + // Send Response to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_ANSWER, sizeof(struct tresp_call_answer), &resp); + } else { + err("User Request is NULL"); + } + + dbg("Exit"); + return; +} + +static void on_confirmation_call_replace(TcorePending *p, int data_len, const void *data, void *user_data) +{ + UserRequest *ur = NULL; + GSList *tokens = NULL; + const char *line = NULL; + const TcoreATResponse *response = data; + struct tresp_call_answer resp; + int error; + + dbg("Entry"); + ur = tcore_pending_ref_user_request(p); + if (ur) { + if (response->success > 0) { + dbg("RESPONSE OK"); + resp.err = TCORE_RETURN_SUCCESS; + } else { + dbg("RESPONSE NOT OK"); + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + err("Unspecified error cause OR string corrupted"); + resp.err = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + // TODO: CMEE error mapping is required. + resp.err = TCORE_RETURN_3GPP_ERROR; + } + + // Free tokens + tcore_at_tok_free(tokens); + } + resp.id = tcore_call_object_get_id((CallObject *) user_data); + + // Send Response to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_ANSWER, sizeof(struct tresp_call_answer), &resp); + } else { + dbg("User Request is NULL"); + } + + dbg("Exit"); + return; +} + +static void on_confirmation_call_hold_and_accept(TcorePending *p, int data_len, const void *data, void *user_data) +{ + CoreObject *o = NULL; + UserRequest *ur = NULL; + GSList *tokens = NULL; + const char *line = NULL; + const TcoreATResponse *response = data; + struct tresp_call_answer resp; + int error; + + dbg("Entry"); + + o = tcore_pending_ref_core_object(p); + ur = tcore_pending_ref_user_request(p); + resp.id = tcore_call_object_get_id((CallObject *) user_data); + + if (ur) { + if (response->success > 0) { + dbg("RESPONSE OK"); + resp.err = TCORE_RETURN_SUCCESS; + } else { + err("RESPONSE NOT OK"); + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + err("Unspecified error cause OR string corrupted"); + resp.err = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + + // TODO: CMEE error mapping is required. + resp.err = TCORE_RETURN_3GPP_ERROR; + } + + // Free tokens + tcore_at_tok_free(tokens); + } + + // Send response to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_ANSWER, sizeof(struct tresp_call_answer), &resp); + if (!resp.err) { + GSList *list = 0; + CallObject *co = NULL; + + // Active Call + list = tcore_call_object_find_by_status(o, TCORE_CALL_STATUS_ACTIVE); + if (!list) { + err("Can't find active Call"); + return; + } + + co = (CallObject *) list->data; + if (!co) { + err("Can't get active Call object"); + return; + } + + // Set Call Status + tcore_call_object_set_status(co, TCORE_CALL_STATUS_HELD); + dbg("Call status is set to HELD"); + } + } else { + err("User Request is NULL"); + } + + dbg("Exit"); + return; +} + +static void _on_confirmation_call_release(TcorePending *p, int data_len, const void *data, void *user_data, int type) +{ + UserRequest *ur = NULL; + struct tresp_call_end resp; + GSList *tokens = NULL; + const char *line = NULL; + int error; + const TcoreATResponse *response = data; + + dbg("Entry"); + ur = tcore_pending_ref_user_request(p); + if (ur) { + if (response->success > 0) { + dbg("RESPONSE OK"); + resp.err = TCORE_RETURN_SUCCESS; + } else { + err("RESPONSE NOT OK"); + + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + err("Unspecified error cause OR string corrupted"); + resp.err = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + + // TODO: CMEE error mapping is required. + resp.err = TCORE_RETURN_3GPP_ERROR; + } + tcore_at_tok_free(tokens); + } + + resp.type = type; + resp.id = tcore_call_object_get_id((CallObject *) user_data); + dbg("resp.type = %d resp.id= %d", resp.type, resp.id); + + // Send reponse to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_END, sizeof(struct tresp_call_end), &resp); + } else { + err("User Request is NULL"); + } + + dbg("Exit"); + return; +} + +// RESPONSE +static void on_confirmation_call_endall(TcorePending *p, int data_len, const void *data, void *user_data) +{ + // skip response handling - actual result will be handled in on_confirmation_call_release_all + const TcoreATResponse *response = data; + dbg("Entry"); + + if (response->success > 0) { + dbg("RESPONSE OK"); + } else { + err("RESPONSE NOT OK"); + } + + dbg("Exit"); + return; +} + + +static void on_confirmation_call_release_all(TcorePending *p, int data_len, const void *data, void *user_data) +{ + dbg("Entry"); + _on_confirmation_call_release(p, data_len, data, user_data, CALL_END_TYPE_ALL); + + return; +} + + +static void on_confirmation_call_release_specific(TcorePending *p, int data_len, const void *data, void *user_data) +{ + dbg("Entry"); + _on_confirmation_call_release(p, data_len, data, user_data, CALL_END_TYPE_DEFAULT); + + return; +} + +static void on_confirmation_call_release_all_active(TcorePending *p, int data_len, const void *data, void *user_data) +{ + dbg("Entry"); + _on_confirmation_call_release(p, data_len, data, user_data, CALL_END_TYPE_ACTIVE_ALL); + + return; +} + +static void on_confirmation_call_release_all_held(TcorePending *p, int data_len, const void *data, void *user_data) +{ + dbg("Entry"); + _on_confirmation_call_release(p, data_len, data, user_data, CALL_END_TYPE_HOLD_ALL); + + return; +} + +static void _on_confirmation_call(TcorePending *p, int data_len, const void *data, void *user_data, int type) +{ + UserRequest *ur = NULL; + GSList *tokens = NULL; + const char *line = NULL; + const TcoreATResponse *response = NULL; + int error; + + dbg("Entry"); + ur = tcore_pending_ref_user_request(p); + response = (TcoreATResponse *) data; + if (response->success > 0) { + dbg("RESPONSE OK"); + error = TCORE_RETURN_SUCCESS; + } else { + err("RESPONSE NOT OK"); + + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + err("Unspecified error cause OR string corrupted"); + error = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + + // TODO: CMEE error mapping is required. + error = TCORE_RETURN_3GPP_ERROR; + } + + // Free tokens + tcore_at_tok_free(tokens); + } + + dbg("Response Call type -%d", type); + switch (type) { + case TRESP_CALL_HOLD: + { + struct tresp_call_hold resp; + + resp.err = error; + resp.id = tcore_call_object_get_id((CallObject *) user_data); + dbg("call hold response"); + // Send reponse to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_HOLD, sizeof(struct tresp_call_hold), &resp); + } + break; + + case TRESP_CALL_ACTIVE: + { + struct tresp_call_active resp; + + resp.err = error; + resp.id = tcore_call_object_get_id((CallObject *) user_data); + dbg("call active response"); + // Send reponse to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_ACTIVE, sizeof(struct tresp_call_active), &resp); + } + break; + + case TRESP_CALL_JOIN: + { + struct tresp_call_join resp; + + resp.err = error; + resp.id = tcore_call_object_get_id((CallObject *) user_data); + dbg("call join response"); + + // Send reponse to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_JOIN, sizeof(struct tresp_call_join), &resp); + } + break; + + case TRESP_CALL_SPLIT: + { + struct tresp_call_split resp; + + resp.err = error; + resp.id = tcore_call_object_get_id((CallObject *) user_data); + dbg("call split response"); + // Send reponse to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_SPLIT, sizeof(struct tresp_call_split), &resp); + } + break; + + case TRESP_CALL_DEFLECT: + { + struct tresp_call_deflect resp; + + resp.err = error; + resp.id = tcore_call_object_get_id((CallObject *) user_data); + dbg("call deflect response"); + // Send reponse to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_DEFLECT, sizeof(struct tresp_call_deflect), &resp); + } + + break; + + case TRESP_CALL_TRANSFER: + { + struct tresp_call_transfer resp; + + resp.err = error; + resp.id = tcore_call_object_get_id((CallObject *) user_data); + dbg("call transfer response"); + // Send reponse to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_TRANSFER, sizeof(struct tresp_call_transfer), &resp); + } + break; + + case TRESP_CALL_SEND_DTMF: + { + struct tresp_call_dtmf resp; + + resp.err = error; + dbg("call dtmf response"); + // Send reponse to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_SEND_DTMF, sizeof(struct tresp_call_dtmf), &resp); + } + break; + + default: + { + dbg("type not supported"); + return; + } + } + + if ((type == TRESP_CALL_HOLD) || (type == TRESP_CALL_ACTIVE) || (type == TRESP_CALL_JOIN) + || (type == TRESP_CALL_SPLIT)) { + if (!error) { + CoreObject *core_obj = NULL; + gboolean *eflag = g_new0(gboolean, 1); + + core_obj = tcore_pending_ref_core_object(p); + *eflag = FALSE; + + dbg("Calling _call_list_get"); + _call_list_get(core_obj, eflag); + } + } + + dbg("Exit"); + return; +} + +static void on_confirmation_call_hold(TcorePending *p, int data_len, const void *data, void *user_data) +{ + dbg("Entry"); + _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_HOLD); + + return; +} + +static void on_confirmation_call_active(TcorePending *p, int data_len, const void *data, void *user_data) +{ + dbg("Entry"); + _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_ACTIVE); + + return; +} + +static void on_confirmation_call_join(TcorePending *p, int data_len, const void *data, void *user_data) +{ + dbg("Entry"); + _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_JOIN); + + return; +} + +static void on_confirmation_call_split(TcorePending *p, int data_len, const void *data, void *user_data) +{ + dbg("Entry"); + _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_SPLIT); + + return; +} + +static void on_confirmation_call_deflect(TcorePending *p, int data_len, const void *data, void *user_data) +{ + dbg("Entry"); + _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_DEFLECT); + + return; +} + +static void on_confirmation_call_transfer(TcorePending *p, int data_len, const void *data, void *user_data) +{ + dbg("Entry"); + _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_TRANSFER); + + return; +} + +static void on_confirmation_call_dtmf(TcorePending *p, int data_len, const void *data, void *user_data) +{ + dbg("Entry"); + _on_confirmation_call(p, data_len, data, user_data, TRESP_CALL_SEND_DTMF); + + return; +} + +static void _on_confirmation_dtmf_tone_duration(TcorePending *p, int data_len, const void *data, void *user_data) +{ + GSList *tokens = NULL; + const char *line = NULL; + const TcoreATResponse *response = data; + int error; + + dbg("Entry"); + + if (response->success > 0) { + dbg("RESPONSE OK"); + error = TCORE_RETURN_SUCCESS; + } else { + err("RESPONSE NOT OK"); + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) < 1) { + err("err cause not specified or string corrupted"); + error = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + // TODO: CMEE error mapping is required. + } + + // Free tokens + tcore_at_tok_free(tokens); + } + + dbg("Set dtmf tone duration response - %d", error); + return; +} + +static void on_confirmation_call_swap(TcorePending *p, int data_len, const void *data, void *user_data) +{ + CoreObject *core_obj = NULL; + UserRequest *ur = NULL; + const TcoreATResponse *response = data; + struct tresp_call_swap resp; + GSList *tokens = NULL; + const char *line = NULL; + + dbg("Entry"); + core_obj = tcore_pending_ref_core_object(p); + ur = tcore_pending_ref_user_request(p); + + if (ur) { + if (response->success > 0) { + dbg("RESPONSE OK"); + resp.err = TCORE_RETURN_SUCCESS; + } else { + err("RESPONSE NOT OK"); + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) < 1) { + err("err cause not specified or string corrupted"); + resp.err = TCORE_RETURN_3GPP_ERROR; + } else { + resp.err = atoi(g_slist_nth_data(tokens, 0)); + + // TODO: CMEE error mapping is required. + resp.err = TCORE_RETURN_3GPP_ERROR; + } + + // Free tokens + tcore_at_tok_free(tokens); + } + + resp.id = tcore_call_object_get_id((CallObject *) user_data); + dbg("resp.id = %d", resp.id); + + // Send response to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_SWAP, sizeof(struct tresp_call_swap), &resp); + + if (!resp.err) { + GSList *active = NULL; + GSList *held = NULL; + CallObject *co = NULL; + gboolean *eflag = NULL; + + held = tcore_call_object_find_by_status(core_obj, TCORE_CALL_STATUS_HELD); + if (!held) { + err("Can't find held Call"); + return; + } + + active = tcore_call_object_find_by_status(core_obj, TCORE_CALL_STATUS_ACTIVE); + if (!active) { + dbg("Can't find active Call"); + return; + } + + while (held) { + co = (CallObject *) held->data; + if (!co) { + err("Can't get held Call object"); + return; + } + + resp.id = tcore_call_object_get_id(co); + + // Send response to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_ACTIVE, sizeof(struct tresp_call_active), &resp); + + held = g_slist_next(held); + } + + while (active) { + co = (CallObject *) active->data; + if (!co) { + err("[ error ] can't get active call object"); + return; + } + + resp.id = tcore_call_object_get_id(co); + + // Send response to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_HOLD, sizeof(struct tresp_call_hold), &resp); + active = g_slist_next(active); + } + + eflag = g_new0(gboolean, 1); + *eflag = FALSE; + + dbg("calling _call_list_get"); + _call_list_get(core_obj, eflag); + } + } else { + err("User Request is NULL"); + } + + dbg("Exit"); + return; +} + +static void on_confirmation_call_set_source_sound_path(TcorePending *p, int data_len, const void *data, void *user_data) +{ + UserRequest *ur = NULL; + GSList *tokens = NULL; + const char *line = NULL; + const TcoreATResponse *response = data; + char *resp_str = NULL; + struct tresp_call_sound_set_path resp; + int error; + + dbg("Entry"); + ur = tcore_pending_ref_user_request(p); + + // +XDRV: ,,[,] + if (!response) { + err("Input data is NULL"); + return; + } + + if (response->success > 0) { + dbg("RESPONSE OK"); + + line = (const char *) (((GSList *) response->lines)->data); + tokens = tcore_at_tok_new(line); + + resp_str = g_slist_nth_data(tokens, 0); + if (!g_slist_nth_data(tokens, 0)) { + err("group_id is missing"); + resp.err = TCORE_RETURN_3GPP_ERROR; + goto OUT; + } + + if (!g_slist_nth_data(tokens, 1)) { + err(" function_id is missing"); + resp.err = TCORE_RETURN_3GPP_ERROR; + goto OUT; + } + + resp_str = g_slist_nth_data(tokens, 2); + + if (resp_str) { + error = atoi(resp_str); + if (0 == error) { + dbg("Response is Success"); + resp.err = TCORE_RETURN_SUCCESS; + } else { + resp.err = TCORE_RETURN_3GPP_ERROR; + } + } +OUT: + // Free tokens + tcore_at_tok_free(tokens); + } else { + dbg("RESPONSE NOT OK"); + + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + err("err cause not specified or string corrupted"); + resp.err = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + + // TODO: CMEE error mapping is required. + resp.err = TCORE_RETURN_3GPP_ERROR; + } + + // Free tokens + tcore_at_tok_free(tokens); + } + + if (ur) { + if (resp.err != TCORE_RETURN_SUCCESS) { // Send only failed notification . success notification send when destination device is set. + // Send notification to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_SET_SOUND_PATH, sizeof(struct tresp_call_sound_set_path), &resp); + setsoundpath = TRUE; + } + } else { + err("User Request is NULL"); + } + + dbg("Exit"); + return; +} + +static void on_confirmation_call_set_destination_sound_path(TcorePending *p, int data_len, const void *data, void *user_data) +{ + UserRequest *ur = NULL; + GSList *tokens = NULL; + const char *line = NULL; + char *resp_str = NULL; + struct tresp_call_sound_set_path resp; + const TcoreATResponse *response = data; + int error; + + dbg("Entry"); + + ur = tcore_pending_ref_user_request(p); + // +XDRV: ,,[,] + + if (!response) { + err("Input data is NULL"); + return; + } + + if (ur) { + if (response->success > 0) { + dbg("RESPONSE OK"); + + line = (const char *) (((GSList *) response->lines)->data); + tokens = tcore_at_tok_new(line); + + resp_str = g_slist_nth_data(tokens, 0); + if (!g_slist_nth_data(tokens, 0)) { + dbg("group_id is missing"); + resp.err = TCORE_RETURN_3GPP_ERROR; + goto OUT; + } + + if (!g_slist_nth_data(tokens, 1)) { + dbg("function_id is missing"); + resp.err = TCORE_RETURN_3GPP_ERROR; + goto OUT; + } + + resp_str = g_slist_nth_data(tokens, 2); + if (resp_str) { + error = atoi(resp_str); + if (0 == error) { + dbg("Response is Success"); + resp.err = TCORE_RETURN_SUCCESS; + } else { + resp.err = TCORE_RETURN_3GPP_ERROR; + } + } + +OUT: + // Free tokens + tcore_at_tok_free(tokens); + } else { + dbg("RESPONSE NOT OK"); + + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + err("err cause not specified or string corrupted"); + resp.err = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + // TODO: CMEE error mapping is required. + resp.err = TCORE_RETURN_3GPP_ERROR; + } + + // Free tokens + tcore_at_tok_free(tokens); + } + + if (setsoundpath == TRUE) { + setsoundpath = FALSE; + } else { + // Send response to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_SET_SOUND_PATH, sizeof(struct tresp_call_sound_set_path), &resp); + } + } else { + dbg("User Request is NULL"); + } + + dbg("Exit"); + return; +} + +static void on_confirmation_call_set_source_sound_volume_level(TcorePending *p, int data_len, const void *data, void *user_data) +{ + UserRequest *ur = NULL; + GSList *tokens = NULL; + const char *line = NULL; + const TcoreATResponse *response = data; + char *resp_str = NULL; + struct tresp_call_sound_set_volume_level resp; + int error; + + ur = tcore_pending_ref_user_request(p); + dbg("Entry"); + // +XDRV: ,,[,] + if (!response) { + err("Input data is NULL"); + return; + } + + if (response->success > 0) { + dbg("RESPONSE OK"); + + line = (const char *) (((GSList *) response->lines)->data); + tokens = tcore_at_tok_new(line); + + resp_str = g_slist_nth_data(tokens, 0); + if (!g_slist_nth_data(tokens, 0)) { + err("group_id is missing"); + resp.err = TCORE_RETURN_3GPP_ERROR; + goto OUT; + } + + if (!g_slist_nth_data(tokens, 1)) { + err("function_id is missing"); + resp.err = TCORE_RETURN_3GPP_ERROR; + goto OUT; + } + + resp_str = g_slist_nth_data(tokens, 2); + if (resp_str) { + error = atoi(resp_str); + + if (0 == error) { + dbg("Response is Success "); + resp.err = TCORE_RETURN_SUCCESS; + } else { + resp.err = TCORE_RETURN_3GPP_ERROR; + } + } + +OUT: + // Free tokens + tcore_at_tok_free(tokens); + } else { + dbg("RESPONSE NOT OK"); + + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + err("err cause not specified or string corrupted"); + resp.err = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + + // TODO: CMEE error mapping is required. + resp.err = TCORE_RETURN_3GPP_ERROR; + } + + // Free tokens + tcore_at_tok_free(tokens); + } + + if (ur) { + if (resp.err && soundvolume == FALSE) { // Send only failed notification . success notification send when destination device is set. + // Send reposne to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_SET_SOUND_VOLUME_LEVEL, sizeof(struct tresp_call_sound_set_volume_level), &resp); + soundvolume = TRUE; + } + } else { + err("User Request is NULL"); + } + + dbg("Exit"); + return; +} + + +static void on_confirmation_call_set_destination_sound_volume_level(TcorePending *p, int data_len, const void *data, void *user_data) +{ + UserRequest *ur = NULL; + GSList *tokens = NULL; + const char *line = NULL; + char *resp_str = NULL; + const TcoreATResponse *response = data; + struct tresp_call_sound_set_volume_level resp; + int error; + + dbg("Entry"); + + ur = tcore_pending_ref_user_request(p); + + // +XDRV: ,,[,] + if (!response) { + err("Input data is NULL"); + return; + } + + if (ur) { + if (response->success > 0) { + dbg("RESPONSE OK"); + line = (const char *) (((GSList *) response->lines)->data); + tokens = tcore_at_tok_new(line); + resp_str = g_slist_nth_data(tokens, 0); + + if (!g_slist_nth_data(tokens, 0)) { + err("group_id is missing"); + resp.err = TCORE_RETURN_3GPP_ERROR; + goto OUT; + } + + if (!g_slist_nth_data(tokens, 1)) { + err("function_id is missing"); + resp.err = TCORE_RETURN_3GPP_ERROR; + goto OUT; + } + + resp_str = g_slist_nth_data(tokens, 2); + + if (resp_str) { + error = atoi(resp_str); + + if (0 == error) { + dbg("Response is Success"); + resp.err = TCORE_RETURN_SUCCESS; + } else { + resp.err = TCORE_RETURN_3GPP_ERROR; + } + } + +OUT: + // Free tokens + tcore_at_tok_free(tokens); + } else { + dbg("RESPONSE NOT OK"); + + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + err("err cause not specified or string corrupted"); + resp.err = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + + // TODO: CMEE error mapping is required. + resp.err = TCORE_RETURN_3GPP_ERROR; + } + + tcore_at_tok_free(tokens); + } + + if (soundvolume == TRUE) { + soundvolume = FALSE; + } else { + // Send reposne to TAPI + tcore_user_request_send_response(ur, TRESP_CALL_SET_SOUND_VOLUME_LEVEL, sizeof(struct tresp_call_sound_set_volume_level), &resp); + } + } else { + err("User Request is NULL"); + } + + dbg("Exit"); + return; +} + + +static void on_confirmation_call_mute(TcorePending *p, int data_len, const void *data, void *user_data) +{ + UserRequest *ur = NULL; + GSList *tokens = NULL; + const char *line = NULL; + char *resp_str = NULL; + struct tresp_call_mute resp; + const TcoreATResponse *response = data; + int error; + + dbg("Entry"); + + ur = tcore_pending_ref_user_request(p); + + if (!response) { + err("Input data is NULL"); + return; + } + + if (response->success > 0) { + dbg("RESPONSE OK"); + + line = (const char *) (((GSList *) response->lines)->data); + tokens = tcore_at_tok_new(line); + resp_str = g_slist_nth_data(tokens, 0); + + if (!g_slist_nth_data(tokens, 0)) { + err("group_id is missing"); + resp.err = TCORE_RETURN_3GPP_ERROR; + goto OUT; + } + + if (!g_slist_nth_data(tokens, 1)) { + err(" function_id is missing"); + resp.err = TCORE_RETURN_3GPP_ERROR; + goto OUT; + } + + resp_str = g_slist_nth_data(tokens, 2); + + if (resp_str) { + error = atoi(resp_str); + if (0 == error) { + dbg("Response is Success"); + resp.err = TCORE_RETURN_SUCCESS; + } else { + resp.err = TCORE_RETURN_3GPP_ERROR; + } + } +OUT: + // Free tokens + tcore_at_tok_free(tokens); + } else { + dbg("RESPONSE NOT OK"); + + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + err("err cause not specified or string corrupted"); + resp.err = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + + // TODO: CMEE error mapping is required. + resp.err = TCORE_RETURN_3GPP_ERROR; + } + + // Free tokens + tcore_at_tok_free(tokens); + } + + if (ur) { + tcore_user_request_send_response(ur, TRESP_CALL_MUTE, sizeof(struct tresp_call_mute), &resp); + } else { + err("User Request is NULL"); + } + + dbg("Exit"); + return; +} + +static void on_confirmation_call_unmute(TcorePending *p, int data_len, const void *data, void *user_data) +{ + const TcoreATResponse *response = NULL; + struct tresp_call_unmute resp; + GSList *tokens = NULL; + const char *line = NULL; + UserRequest *ur = NULL; + char *resp_str = NULL; + int error; + + dbg("Entry"); + + response = (TcoreATResponse *) data; + ur = tcore_pending_ref_user_request(p); + + if (!response) { + err("Input data is NULL"); + return; + } + + if (response->success > 0) { + dbg("RESPONSE OK"); + + line = (const char *) (((GSList *) response->lines)->data); + tokens = tcore_at_tok_new(line); + resp_str = g_slist_nth_data(tokens, 0); + + if (!g_slist_nth_data(tokens, 0)) { + err("group_id is missing"); + resp.err = TCORE_RETURN_3GPP_ERROR; + goto OUT; + } + + if (!g_slist_nth_data(tokens, 1)) { + err(" function_id is missing"); + resp.err = TCORE_RETURN_3GPP_ERROR; + goto OUT; + } + + resp_str = g_slist_nth_data(tokens, 2); + + if (resp_str) { + error = atoi(resp_str); + if (0 == error) { + dbg("Response is Success"); + resp.err = TCORE_RETURN_SUCCESS; + } else { + resp.err = TCORE_RETURN_3GPP_ERROR; + } + } +OUT: + // Free tokens + tcore_at_tok_free(tokens); + } else { + dbg("RESPONSE NOT OK"); + + line = (const char *) response->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + err("err cause not specified or string corrupted"); + resp.err = TCORE_RETURN_3GPP_ERROR; + } else { + error = atoi(g_slist_nth_data(tokens, 0)); + + // TODO: CMEE error mapping is required. + resp.err = TCORE_RETURN_3GPP_ERROR; + } + + // Free tokens + tcore_at_tok_free(tokens); + } + + if (ur) { + tcore_user_request_send_response(ur, TRESP_CALL_UNMUTE, sizeof(struct tresp_call_unmute), &resp); + } else { + err("User Request is NULL"); + } + + dbg("Exit"); + return; +} + +// RESPONSE +static void on_response_call_list_get(TcorePending *p, int data_len, const void *data, void *user_data) +{ + TcorePlugin *plugin = NULL; + CoreObject *core_obj = NULL; + CallObject *co = NULL; + struct clcc_call_t *call_list = NULL; + gboolean *event_flag = (gboolean *) user_data; + const TcoreATResponse *response = data; + GSList *resp_data = NULL; + char *line = NULL; + + int cllc_info = 0, countCalls = 0, countValidCalls = 0; + int error = 0; + dbg("Entry"); + + plugin = tcore_pending_ref_plugin(p); + core_obj = tcore_pending_ref_core_object(p); + + if (response->success > 0) { + dbg("RESPONCE OK"); + if (response->lines) { + resp_data = (GSList *) response->lines; + countCalls = g_slist_length(resp_data); + dbg("Total records : %d", countCalls); + } + + if (0 == countCalls) { + err("Call count is zero"); + return; + } + + call_list = g_new0(struct clcc_call_t, countCalls); + + for (countValidCalls = 0; resp_data != NULL; resp_data = resp_data->next, countValidCalls++, cllc_info++) { + line = (char *) (resp_data->data); + + error = _callFromCLCCLine(line, call_list + countValidCalls); + if (0 != error) { + continue; + } + + co = tcore_call_object_find_by_id(core_obj, call_list[cllc_info].info.id); + if (!co) { + co = tcore_call_object_new(core_obj, call_list[cllc_info].info.id); + if (!co) { + err("error : tcore_call_object_new [ id : %d ]", call_list[cllc_info].info.id); + continue; + } + } + + // Call set parameters + tcore_call_object_set_type(co, call_type(call_list[cllc_info].info.type)); + tcore_call_object_set_direction(co, call_list[cllc_info].info.direction); + tcore_call_object_set_multiparty_state(co, _call_is_in_mpty(call_list[cllc_info].info.mpty)); + tcore_call_object_set_cli_info(co, CALL_CLI_MODE_DEFAULT, call_list[cllc_info].number); + tcore_call_object_set_active_line(co, 0); + + if (*event_flag) { + dbg("Call status before calling _call_branch_by_status() : (%d)", call_list[cllc_info].info.status); + _call_branch_by_status(plugin, co, call_list[cllc_info].info.status); + } else { + // Set Status + tcore_call_object_set_status(co, call_list[cllc_info].info.status); + + dbg("Call id : (%d)", call_list[cllc_info].info.id); + dbg("Call direction : (%d)", call_list[cllc_info].info.direction); + dbg("Call type : (%d)", call_list[cllc_info].info.type); + dbg("Call mpty : (%d)", call_list[cllc_info].info.mpty); + dbg("Call number : (%s)", call_list[cllc_info].number); + dbg("Call status : (%d)", call_list[cllc_info].info.status); + } + } + + // Free Call list + g_free(call_list); + } + + // Free User data + g_free(event_flag); + + dbg("Exit"); + return; +} + +static void _on_confirmation_call_end_cause(TcorePending *p, int data_len, const void *data, void *user_data) +{ + TcorePlugin *plugin = NULL; + CoreObject *core_obj = NULL; + CallObject *co = (CallObject *) user_data; + const TcoreATResponse *response = data; + const char *line = NULL; + struct tnoti_call_status_idle call_status; + GSList *tokens = NULL; + char *resp_str; + int error; + + dbg("Entry"); + plugin = tcore_pending_ref_plugin(p); + core_obj = tcore_pending_ref_core_object(p); + + if (response->success > 0) { + dbg("RESPONSE OK"); + line = (const char *) (((GSList *) response->lines)->data); + tokens = tcore_at_tok_new(line); + resp_str = g_slist_nth_data(tokens, 0); + if (!resp_str) { + err("call end cause - report value missing"); + } else { + resp_str = g_slist_nth_data(tokens, 1); + if (!resp_str) { + err("call end cause value missing"); + } + error = atoi(resp_str); + dbg("call end cause - %d", error); + call_status.cause = _compare_call_end_cause(error); + dbg("TAPI call end cause - %d", call_status.cause); + } + + // Free tokens + tcore_at_tok_free(tokens); + } else { + err("RESPONSE NOT OK"); + line = (char *) response->final_response; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) < 1) { + err("err cause not specified or string corrupted"); + } else { + err(" err cause value: %d", atoi(g_slist_nth_data(tokens, 0))); + } + call_status.cause = CC_CAUSE_NORMAL_CALL_CLEARING; + // Free tokens + tcore_at_tok_free(tokens); + } + + call_status.type = tcore_call_object_get_type(co); + dbg("data.type : [%d]", call_status.type); + + call_status.id = tcore_call_object_get_id(co); + dbg("data.id : [%d]", call_status.id); + + // Set Status + tcore_call_object_set_status(co, TCORE_CALL_STATUS_IDLE); + + // Send Notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + core_obj, + TNOTI_CALL_STATUS_IDLE, + sizeof(struct tnoti_call_status_idle), + (void *) &call_status); + + // Free Call object + tcore_call_object_free(core_obj, co); +} + +static int _callFromCLCCLine(char *line, struct clcc_call_t *p_call) +{ + // +CLCC: 1,0,2,0,0,"18005551212",145 + // [+CLCC: , , , ,[,,[,[,]]] + int state; + int mode; + int isMT; + char *num = NULL; + unsigned int num_type; + GSList *tokens = NULL; + char *resp = NULL; + dbg("Entry"); + + tokens = tcore_at_tok_new(line); + // parse + resp = g_slist_nth_data(tokens, 0); + if (!resp) { + err("InValid ID"); + goto ERROR; + } + p_call->info.id = atoi(resp); + dbg("id : [%d]\n", p_call->info.id); + + // parse + resp = g_slist_nth_data(tokens, 1); + if (!resp) { + err("InValid Dir"); + goto ERROR; + } + isMT = atoi(resp); + if (0 == isMT) { + p_call->info.direction = TCORE_CALL_DIRECTION_OUTGOING; + } else { + p_call->info.direction = TCORE_CALL_DIRECTION_INCOMING; + } + dbg("Direction : [ %d ]\n", p_call->info.direction); + + // parse + resp = g_slist_nth_data(tokens, 2); + if (!resp) { + err("InValid Stat"); + goto ERROR; + } + state = atoi(resp); + dbg("Call state : %d", state); + switch (state) { + case 0: // active + p_call->info.status = TCORE_CALL_STATUS_ACTIVE; + break; + + case 1: + p_call->info.status = TCORE_CALL_STATUS_HELD; + break; + + case 2: + p_call->info.status = TCORE_CALL_STATUS_DIALING; + break; + + case 3: + p_call->info.status = TCORE_CALL_STATUS_ALERT; + break; + + case 4: + p_call->info.status = TCORE_CALL_STATUS_INCOMING; + break; + + case 5: + p_call->info.status = TCORE_CALL_STATUS_WAITING; + break; + } + dbg("Status : [%d]\n", p_call->info.status); + + // parse + resp = g_slist_nth_data(tokens, 3); + if (!resp) { + err("InValid Mode"); + goto ERROR; + } + mode = atoi(resp); + switch (mode) { + case 0: + p_call->info.type = TCORE_CALL_TYPE_VOICE; + break; + + case 1: + p_call->info.type = TCORE_CALL_TYPE_VIDEO; + break; + + default: // only Voice/VT call is supported in CS. treat other unknown calls as error + dbg("invalid type : [%d]\n", mode); + goto ERROR; + } + dbg("Call type : [%d]\n", p_call->info.type); + + // parse + resp = g_slist_nth_data(tokens, 4); + if (!resp) { + err("InValid Mpty"); + goto ERROR; + } + + p_call->info.mpty = atoi(resp); + dbg("Mpty : [ %d ]\n", p_call->info.mpty); + + // parse + resp = g_slist_nth_data(tokens, 5); + dbg("Incoming number - %s and its len - %d", resp, strlen(resp)); + + // tolerate null here + if (!resp) { + err("Number is NULL"); + goto ERROR; + } + // Strike off double quotes num = util_removeQuotes(resp); - dbg("num after removing quotes - %s", num); - - p_call->info.num_len = strlen(resp); - dbg("num_len : [0x%x]\n", p_call->info.num_len); - - // parse - resp = g_slist_nth_data(tokens, 6); - if(!resp) { - dbg("InValid Num type"); - goto ERROR; - } - p_call->info.num_type = atoi(resp); - dbg("BCD num type: [0x%x]\n", p_call->info.num_type); - - //check number is international or national. - num_type = ((p_call->info.num_type) >> 4) & 0x07; - dbg("called party's type of number : [0x%x]\n", num_type); - - if(num_type == 1 && num[0] != '+') { - //international number - p_call->number[0] = '+'; - memcpy(&(p_call->number[1]),num,strlen(num)); - } - else{ - memcpy(&(p_call->number),num,strlen(num)); - } - dbg("incoming number - %s", p_call->number); - - g_free(num); - num = NULL; - // Free tokens - tcore_at_tok_free(tokens); - - dbg("Exit"); - return 0; - -ERROR: - err("Invalid CLCC line"); - - if(num){ - g_free(num); - num = NULL; - } - - // Free tokens - tcore_at_tok_free(tokens); - err("Exit"); - return -1; -} - -// NOTIFICATION -static void on_notification_call_waiting(CoreObject *o, const void *data, void *user_data) -{ - GSList *tokens = NULL; - const char *line = NULL; - char *pId; - int call_id; - gboolean *eflag; - GSList* pList = NULL; - CallObject *co = NULL, *dupco = NULL; - - dbg("function entrance"); - // check call with waiting status already exist - pList = tcore_call_object_find_by_status(o, TCORE_CALL_STATUS_WAITING); - - if(pList != NULL) { - dbg("[error]Waiting call already exist. skip"); - return; - } - // check call with incoming status already exist - pList = tcore_call_object_find_by_status(o, TCORE_CALL_STATUS_INCOMING); - - if(pList != NULL){ - dbg("[error]incoming call already exist. skip"); - return; - } - line = (char*)data; - tokens = tcore_at_tok_new(line); - - pId = g_slist_nth_data(tokens, 0); - if(!pId){ - dbg("[error]:Call id is missing from +XCALLSTAT indication"); - return; - } - - call_id = atoi(pId); - dupco = tcore_call_object_find_by_id(o, call_id); - if(dupco!= NULL){ - dbg("co with same id already exist. skip"); - return; - } - co = tcore_call_object_new(o, call_id); - if (!co){ - dbg("[ error ] co is NULL"); - return ; - } - - tcore_at_tok_free(tokens); - - eflag = g_new0(gboolean, 1); - *eflag = TRUE; - dbg("calling _call_list_get"); - _call_list_get(o, eflag); - -} - -static void on_notification_call_incoming(CoreObject *o, const void *data, void *user_data) -{ - GSList *tokens = NULL; - const char *line = NULL; - char *pId; - int call_id; - gboolean *eflag; - GSList* pList = NULL; - CallObject *co = NULL, *dupco = NULL; - - dbg("function entrance"); - // check call with incoming status already exist - pList = tcore_call_object_find_by_status(o, TCORE_CALL_STATUS_INCOMING); - - if(pList != NULL){ - dbg("incoming call already exist. skip"); - return; - } - - line = (char*)data; - tokens = tcore_at_tok_new(line); - - pId = g_slist_nth_data(tokens, 0); - if(!pId){ - dbg("Error:Call id is missing from %XCALLSTAT indication"); - return; - } - - call_id = atoi(pId); - - dupco = tcore_call_object_find_by_id(o, call_id); - if(dupco!= NULL){ - dbg("co with same id already exist. skip"); - return; - } - - co = tcore_call_object_new(o, call_id); - if (!co){ - dbg("[ error ] co is NULL"); - return ; - } - - dbg("freeing at token") - tcore_at_tok_free(tokens); - - eflag = g_new0(gboolean, 1); - *eflag = TRUE; - - dbg("calling _call_list_get"); - _call_list_get(o, eflag); - -} - -static void on_notification_call_status(CoreObject *o, const void *data, void *user_data) -{ - char* cmd = NULL; - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = -1; - int status = 0; - int type = 0; - char *stat = NULL; - char *pCallId = NULL; - GSList *tokens = NULL; - gboolean *eflag = NULL; - enum tcore_call_status co_status; - - dbg("function entrance"); - plugin = tcore_object_ref_plugin(o); - cmd = (char*)data; - tokens = tcore_at_tok_new(cmd); - - // parse - pCallId = g_slist_nth_data(tokens, 0); - if(!pCallId) { - dbg("pCallId is missing from %XCALLSTAT indiaction"); - - } - else { - id = atoi(pCallId); - dbg("call id = %d", id); - //parse - if ((stat = g_slist_nth_data(tokens, 1))) { - status = atoi(stat); - } - dbg("call status = %d", status); - } - - tcore_at_tok_free(tokens); - co_status = _call_status(status); - - dbg("co_status = %d", co_status); - switch (co_status) { - - case CALL_STATUS_ACTIVE: - { - dbg("call(%d) status : [ ACTIVE ]", id); - co = tcore_call_object_find_by_id(o,id); - if (!co) { - dbg("co is NULL"); - return ; - } - _call_status_active(plugin, co); - - } - break; - - case CALL_STATUS_HELD: - dbg("call(%d) status : [ held ]", id); - break; - - case CALL_STATUS_DIALING: - { - dbg("call(%d) status : [ dialing ]", id); - co = tcore_call_object_find_by_id(o,id); - if (!co) { - co = tcore_call_object_new(o, id); - if (!co) { - dbg("error : tcore_call_object_new [ id : %d ]", id); - return ; - } - } - - tcore_call_object_set_type(co, call_type(type)); - tcore_call_object_set_direction(co, TCORE_CALL_DIRECTION_OUTGOING); - _call_status_dialing(plugin, co); - } - break; - case CALL_STATUS_ALERT: - { - dbg("call(%d) status : [ alert ]", id); - co = tcore_call_object_find_by_id(o, id); - if (!co){ - dbg("co is NULL"); - return ; - } - //Store dialed number information into Call object. - eflag = g_new0(gboolean, 1); - *eflag = TRUE; - dbg("calling _call_list_get"); - _call_list_get(o, eflag); - - } - break; - case CALL_STATUS_INCOMING: - case CALL_STATUS_WAITING: - dbg("call(%d) status : [ incoming ]", id); - break; - case CALL_STATUS_IDLE: - { - - dbg("call(%d) status : [ release ]", id); - - co = tcore_call_object_find_by_id(o, id); - if (!co) { - dbg("co is NULL"); - return ; - } - - plugin = tcore_object_ref_plugin(o); - if (!plugin) { - dbg("plugin is NULL"); - return ; - } - _call_status_idle(plugin, co); - } - break; - - default: - dbg("invalid call status", id); - break; - } -} - -static TReturn s_call_outgoing(CoreObject *o, UserRequest *ur) -{ - struct treq_call_dial* data = 0; - char* raw_str= NULL; - char*cmd_str = NULL; - const char *cclir; - enum tcore_call_cli_mode clir = CALL_CLI_MODE_DEFAULT; - TcorePending *pending = NULL; - TcoreATRequest *req; - gboolean ret = FALSE; - - dbg("function entrance"); - data = (struct treq_call_dial*)tcore_user_request_ref_data(ur, 0); - clir = _get_clir_status(data->number); - - //Compose ATD Cmd string - switch (clir) { - case TCORE_CALL_CLI_MODE_PRESENT: - dbg("CALL_CLI_MODE_PRESENT"); - cclir = "I"; - break; //invocation - case TCORE_CALL_CLI_MODE_RESTRICT: - dbg("CALL_CLI_MODE_RESTRICT"); - cclir = "i"; - break; //suppression - case TCORE_CALL_CLI_MODE_DEFAULT: - default: - cclir = ""; - dbg("CALL_CLI_MODE_DEFAULT"); - break; //subscription default - } - - dbg("data->number = %s",data->number); - - raw_str = g_strdup_printf("ATD%s%s;", data->number, cclir); - cmd_str = g_strdup_printf("%s",raw_str); - - dbg("request command : %s", cmd_str); - - pending = tcore_pending_new(o, 0); - req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT); - dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_request_data(pending, 0, req); - ret = _call_request_message (pending, o, ur, on_confirmation_call_outgoing, NULL); - - g_free(raw_str); - g_free(cmd_str); - - if (!ret) { - dbg("AT request(%s) sent failed", req->cmd); - return TCORE_RETURN_FAILURE; - } - - dbg("AT request(%s) sent success",req->cmd); - - return TCORE_RETURN_SUCCESS; -} - -static TReturn s_call_answer(CoreObject *o, UserRequest *ur) -{ - char* cmd_str = NULL; - CallObject* co = NULL; - struct treq_call_answer* data = 0; - TcorePending *pending = NULL; - TcoreATRequest *req; - gboolean ret = FALSE; - - dbg("function entrance"); - - data = (struct treq_call_answer*)tcore_user_request_ref_data(ur, 0); - co = tcore_call_object_find_by_id(o, data->id); - if (data->type == CALL_ANSWER_TYPE_ACCEPT) { - - dbg(" request type CALL_ANSWER_TYPE_ACCEPT"); - - cmd_str = g_strdup_printf("%s","ATA"); - pending = tcore_pending_new(o, 0); - req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT); - dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_request_data(pending, 0, req); - ret = _call_request_message (pending, o, ur, on_confirmation_call_accept, co); - g_free(cmd_str); - - if (!ret) { - dbg("AT request(%s) sent failed", req->cmd); - return TCORE_RETURN_FAILURE; - } - - } - else { - - switch (data->type) { - case CALL_ANSWER_TYPE_REJECT: - { - dbg("call answer reject"); - tcore_call_control_answer_reject(o, ur, on_confirmation_call_reject, co); - } break; - - case CALL_ANSWER_TYPE_REPLACE: - { - dbg("call answer replace"); - tcore_call_control_answer_replace(o, ur, on_confirmation_call_replace, co); - } break; - - case CALL_ANSWER_TYPE_HOLD_ACCEPT: - { - dbg("call answer hold and accept"); - tcore_call_control_answer_hold_and_accept(o, ur, on_confirmation_call_hold_and_accept, co); - } break; - - default : - dbg("[ error ] wrong answer type [ %d ]", data->type); - return TCORE_RETURN_FAILURE; - } - } - - return TCORE_RETURN_SUCCESS; -} - -static TReturn s_call_release(CoreObject *o, UserRequest *ur) -{ - CallObject* co = NULL; - struct treq_call_end* data = 0; - UserRequest* ur_dup = NULL; - char* chld0_cmd = NULL; - char* chld1_cmd = NULL; - TcorePending *pending = NULL, *pending1 = NULL; - TcoreATRequest *req, *req1; - gboolean ret = FALSE; - - dbg("function entrance"); - data = (struct treq_call_end*)tcore_user_request_ref_data(ur, 0); - co = tcore_call_object_find_by_id(o, data->id); - - dbg("type of release call = %d" , data->type); - - if (data->type == CALL_END_TYPE_ALL) { - - //releaseAll do not exist on legacy request. send CHLD=0, CHLD=1 in sequence - chld0_cmd = g_strdup("AT+CHLD=0"); - chld1_cmd = g_strdup("AT+CHLD=1"); - - pending = tcore_pending_new(o, 0); - req = tcore_at_request_new(chld0_cmd, NULL, TCORE_AT_NO_RESULT); - - dbg("input command is %s",chld0_cmd); - dbg("req-cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_request_data(pending, 0, req); - ur_dup = tcore_user_request_new(NULL, NULL); - ret = _call_request_message(pending ,o, ur_dup, on_confirmation_call_endall, NULL); - g_free(chld0_cmd); - - if (!ret) { - dbg("AT request %s has failed ",req->cmd); - return TCORE_RETURN_FAILURE; - } - - pending1 = tcore_pending_new(o, 0); - req1 = tcore_at_request_new(chld1_cmd, NULL, TCORE_AT_NO_RESULT); - - dbg("input command is %s",chld1_cmd); - dbg("req-cmd : %s, prefix(if any) :%s, cmd_len : %d", req1->cmd, req1->prefix, strlen(req1->cmd)); - - tcore_pending_set_request_data(pending1, 0, req1); - ret = _call_request_message(pending1, o, ur, on_confirmation_call_release_all, co); - g_free(chld1_cmd); - - if (!ret) { - dbg("AT request %s has failed ",req->cmd); - return TCORE_RETURN_FAILURE; - } - - } - else { - - switch (data->type) { - - case CALL_END_TYPE_DEFAULT: - { - int id = 0; - id = tcore_call_object_get_id(co); - - dbg("call end call id [%d]", id); - tcore_call_control_end_specific(o, ur, id, on_confirmation_call_release_specific, co); - } break; - - case CALL_END_TYPE_ACTIVE_ALL: - { - - dbg("call end all active"); - tcore_call_control_end_all_active(o, ur, on_confirmation_call_release_all_active, co); - } break; - - case CALL_END_TYPE_HOLD_ALL: - { - - dbg("call end all held"); - tcore_call_control_end_all_held(o, ur, on_confirmation_call_release_all_held, co); - } break; - - default : - dbg("[ error ] wrong end type [ %d ]", data->type); - return TCORE_RETURN_FAILURE; - } - - } - - return TCORE_RETURN_SUCCESS; -} - -static TReturn s_call_hold(CoreObject *o, UserRequest *ur) -{ - struct treq_call_hold *hold = 0; - CallObject *co = NULL; - - dbg("function entrance"); - - hold = (struct treq_call_hold*)tcore_user_request_ref_data(ur, 0); - dbg("call id : [ %d ]", hold->id); - - co = tcore_call_object_find_by_id(o, hold->id); - tcore_call_control_hold(o, ur, on_confirmation_call_hold, co); - - return TCORE_RETURN_SUCCESS; -} - -static TReturn s_call_active(CoreObject *o, UserRequest *ur) -{ - struct treq_call_active *active = 0; - CallObject *co = NULL; - - active = (struct treq_call_active*)tcore_user_request_ref_data(ur, 0); - dbg("call id : [ %d ]", active->id); - - co = tcore_call_object_find_by_id(o, active->id); - tcore_call_control_active(o, ur, on_confirmation_call_active, co); - - return TCORE_RETURN_SUCCESS; -} - -static TReturn s_call_swap(CoreObject *o, UserRequest *ur) -{ - struct treq_call_swap *swap = NULL; - CallObject *co = NULL; - - swap = (struct treq_call_swap*)tcore_user_request_ref_data(ur, 0); - dbg("call id : [ %d ]", swap->id); - - co = tcore_call_object_find_by_id(o, swap->id); - tcore_call_control_swap(o, ur, on_confirmation_call_swap, co); - - return TCORE_RETURN_SUCCESS; -} - -static TReturn s_call_join(CoreObject *o, UserRequest *ur) -{ - struct treq_call_join *join = 0; - CallObject *co = NULL; - - join = (struct treq_call_join*)tcore_user_request_ref_data(ur, 0); - dbg("call id : [ %d ]", join->id); - - co = tcore_call_object_find_by_id(o, join->id); - tcore_call_control_join(o, ur, on_confirmation_call_join, co); - - return TCORE_RETURN_SUCCESS; -} - -static TReturn s_call_split(CoreObject *o, UserRequest *ur) -{ - struct treq_call_split *split = 0; - CallObject *co = NULL; - - split = (struct treq_call_split*)tcore_user_request_ref_data(ur, 0); - co = tcore_call_object_find_by_id (o, split->id); - dbg("call id : [ %d ]", split->id); - - tcore_call_control_split(o, ur, split->id, on_confirmation_call_split, co); - - return TCORE_RETURN_SUCCESS; -} - -static TReturn s_call_deflect(CoreObject *o, UserRequest *ur) -{ - struct treq_call_deflect *deflect = 0; - CallObject *co = NULL; - - deflect = (struct treq_call_deflect*)tcore_user_request_ref_data(ur, 0); - co = tcore_call_object_find_by_number(o, deflect->number); - dbg("deflect number: [ %s ]", deflect->number); - - tcore_call_control_deflect(o, ur, deflect->number, on_confirmation_call_deflect, co); - - return TCORE_RETURN_SUCCESS; -} - -static TReturn s_call_transfer(CoreObject *o, UserRequest *ur) -{ - struct treq_call_transfer *transfer = 0; - CallObject *co = NULL; - - transfer = (struct treq_call_transfer*)tcore_user_request_ref_data(ur, 0); - dbg("call id : [ %d ]", transfer->id); - - co = tcore_call_object_find_by_id(o, transfer->id); - tcore_call_control_transfer(o, ur, on_confirmation_call_transfer, co); - - return TCORE_RETURN_SUCCESS; -} - -static TReturn s_call_send_dtmf(CoreObject *o, UserRequest *ur) -{ - char*cmd_str = NULL; - TcorePending *pending = NULL; - TcoreATRequest *req; - UserRequest *dup; - gboolean ret = FALSE; - struct treq_call_dtmf *dtmf = 0; - char *dtmfstr = NULL, *tmp_dtmf = NULL; - unsigned int dtmf_count; - - dbg("Function enter"); - - dup = tcore_user_request_new(NULL, NULL); - (void)_set_dtmf_tone_duration(o, dup); - - dtmf = (struct treq_call_dtmf*)tcore_user_request_ref_data(ur, 0); - dtmfstr = g_malloc0((MAX_CALL_DTMF_DIGITS_LEN * 2)+ 1); // DTMF digits + comma for each dtmf digit. - - if(dtmfstr == NULL) { - dbg("Memory allocation failed"); - return TCORE_RETURN_FAILURE; - } - - tmp_dtmf = dtmfstr; - - for(dtmf_count = 0; dtmf_count < strlen(dtmf->digits); dtmf_count++) { - - *tmp_dtmf = dtmf->digits[dtmf_count]; - tmp_dtmf ++; - - *tmp_dtmf = COMMA; - tmp_dtmf++; - } - - //last digit is having COMMA , overwrite it with '\0' . - *(--tmp_dtmf) = '\0'; - dbg("Input DTMF string(%s)",dtmfstr); - - //AT+VTS = ,,,,,, ..... - cmd_str = g_strdup_printf("AT+VTS=%s",dtmfstr); - dbg("request command : %s", cmd_str); - - pending = tcore_pending_new(o, 0); - req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT); - dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_request_data(pending, 0, req); - ret = _call_request_message (pending, o, ur, on_confirmation_call_dtmf, NULL); - g_free(dtmfstr); - g_free(cmd_str); - - if (!ret) { - - dbg("AT request sent failed") - return TCORE_RETURN_FAILURE; - } - - return TCORE_RETURN_SUCCESS; -} - -static TReturn s_call_set_sound_path(CoreObject *o, UserRequest *ur) -{ - UserRequest *ur_dup = NULL; - TcorePending *pending = NULL , *pending1 = NULL; - TcoreATRequest *req , *req1; - char *cmd_str = NULL , *cmd_str1 = NULL; - gboolean ret = FALSE; - - dbg("function entrance"); - - //hard coded value for speaker. - cmd_str = g_strdup_printf("%s","AT+XDRV=40,4,3,0,0,0,0,0,1,0,1,0,1"); //source type. - cmd_str1 = g_strdup_printf("%s","AT+XDRV=40,5,2,0,0,0,0,0,1,0,1,0,1"); //destination type - - pending = tcore_pending_new(o, 0); - req = tcore_at_request_new(cmd_str, "+XDRV", TCORE_AT_SINGLELINE); - dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_request_data(pending, 0, req); - ur_dup = tcore_user_request_ref(ur); - - ret = _call_request_message (pending, o, ur_dup, on_confirmation_call_set_source_sound_path, NULL); - - g_free(cmd_str); - - if (!ret) { - - dbg("At request(%s) sent failed",req->cmd); - return TCORE_RETURN_FAILURE; - } - - pending1 = tcore_pending_new(o, 0); - req1 = tcore_at_request_new(cmd_str1,"+XDRV", TCORE_AT_SINGLELINE); - dbg("input command is %s",cmd_str1); - dbg("req-cmd : %s, prefix(if any) :%s, cmd_len : %d", req1->cmd, req1->prefix, strlen(req1->cmd)); - - tcore_pending_set_request_data(pending1, 0, req1); - ret = _call_request_message(pending1, o, ur, on_confirmation_call_set_destination_sound_path, NULL); - - g_free(cmd_str1); - - if (!ret) { - dbg("AT request %s has failed ",req1->cmd); - return TCORE_RETURN_FAILURE; - } - - return TCORE_RETURN_SUCCESS; - -} - -static TReturn s_call_set_sound_volume_level(CoreObject *o, UserRequest *ur) -{ - UserRequest *src_ur = NULL; - UserRequest *dest_ur = NULL; - TcorePending *src_pending = NULL; - TcorePending *dest_pending = NULL; - TcoreATRequest *src_req = NULL; - TcoreATRequest *dest_req = NULL; - char *cmd_str = NULL, *volume_level = NULL; - gboolean ret = FALSE; - - struct treq_call_sound_set_volume_level* data = NULL; - data = (struct treq_call_sound_set_volume_level*)tcore_user_request_ref_data( ur, 0 ); - dbg("Entry"); - // Hard-coded values for MIC & Speakers - // Source volume - dbg("Set Source volume"); - - cmd_str = g_strdup_printf("%s", "AT+XDRV=40,7,3,88"); // Source type - dbg("Request command string: %s", cmd_str); - - // Create new Pending request - src_pending = tcore_pending_new(o, 0); - - // Create new AT-Command request - src_req = tcore_at_request_new(cmd_str, "+XDRV", TCORE_AT_SINGLELINE); - dbg("Command: %s, prefix(if any): %s, Command length: %d", src_req->cmd, src_req->prefix, strlen(src_req->cmd)); - - // Free Command string - g_free(cmd_str); - - tcore_pending_set_request_data(src_pending, 0, src_req); - src_ur = tcore_user_request_ref(ur); - - // Send request - ret = _call_request_message (src_pending, o, src_ur, on_confirmation_call_set_source_sound_volume_level, NULL); - if (!ret) { - err("Failed to send AT-Command request"); - return TCORE_RETURN_FAILURE; - } - - cmd_str = g_strdup_printf("%s", "AT+XDRV=40,7,0,88"); // Destination type - dbg("Request command string: %s", cmd_str); - - // Create new Pending request - src_pending = tcore_pending_new(o, 0); - - // Create new AT-Command request - src_req = tcore_at_request_new(cmd_str,"+XDRV", TCORE_AT_SINGLELINE); - dbg("Command: %s, prefix(if any): %s, Command length: %d", src_req->cmd, src_req->prefix, strlen(src_req->cmd)); - - // Free Command string - g_free(cmd_str); - - tcore_pending_set_request_data(src_pending, 0, src_req); - - src_ur= tcore_user_request_ref(ur); - - // Send request - ret = _call_request_message(src_pending, o, src_ur, on_confirmation_call_set_source_sound_volume_level, NULL); - if (!ret) { - err("Failed to send AT-Command request"); - return TCORE_RETURN_FAILURE; - } - - // Destination volume - dbg("Set Source volume"); - - cmd_str = g_strdup_printf("%s", "AT+XDRV=40,8,0,88"); // Source type - dbg("Request command string: %s", cmd_str); - - // Create new Pending request - dest_pending = tcore_pending_new(o, 0); - - // Create new AT-Command request - dest_req = tcore_at_request_new(cmd_str, "+XDRV", TCORE_AT_SINGLELINE); - dbg("Command: %s, prefix(if any): %s, Command length: %d", dest_req->cmd, dest_req->prefix, strlen(dest_req->cmd)); - - // Free Command string - g_free(cmd_str); - - tcore_pending_set_request_data(dest_pending, 0, dest_req); - dest_ur = tcore_user_request_ref(ur); - - // Send request - ret = _call_request_message (dest_pending, o, dest_ur, on_confirmation_call_set_source_sound_volume_level, NULL); - if (!ret) { - err("Failed to send AT-Command request"); - return TCORE_RETURN_FAILURE; - } - - dbg("Input volume level - %d",data->volume); - switch(data->volume) { - - case CALL_SOUND_MUTE: - volume_level = "0"; - break; - case CALL_SOUND_VOLUME_LEVEL_1: - volume_level = "40"; - break; - case CALL_SOUND_VOLUME_LEVEL_2: - volume_level = "46"; - break; - case CALL_SOUND_VOLUME_LEVEL_3: - volume_level = "52"; - break; - case CALL_SOUND_VOLUME_LEVEL_4: - volume_level = "58"; - break; - case CALL_SOUND_VOLUME_LEVEL_5: - volume_level = "64"; - break; - case CALL_SOUND_VOLUME_LEVEL_6: - volume_level = "70"; - break; - case CALL_SOUND_VOLUME_LEVEL_7: - volume_level = "76"; - break; - case CALL_SOUND_VOLUME_LEVEL_8: - volume_level = "82"; - break; - case CALL_SOUND_VOLUME_LEVEL_9: - default: - volume_level = "88"; - break; - } - cmd_str = g_strdup_printf("%s%s","AT+XDRV=40,8,2,",volume_level); //Destination type - dbg("Request command string: %s", cmd_str); - - // Create new Pending request - dest_pending = tcore_pending_new(o, 0); - - // Create new AT-Command request - dest_req = tcore_at_request_new(cmd_str,"+XDRV", TCORE_AT_SINGLELINE); - dbg("Command: %s, prefix(if any): %s, Command length: %d", dest_req->cmd, dest_req->prefix, strlen(dest_req->cmd)); - - // Free Command string - g_free(cmd_str); - - tcore_pending_set_request_data(dest_pending, 0, dest_req); - - // Send request - ret = _call_request_message(dest_pending, o, ur, on_confirmation_call_set_destination_sound_volume_level, NULL); - if (!ret) { - err("Failed to send AT-Command request"); - return TCORE_RETURN_FAILURE; - } - - return TCORE_RETURN_SUCCESS; -} - - -static TReturn s_call_get_sound_volume_level(CoreObject *o, UserRequest *ur) -{ - dbg("Entry"); - - dbg("Exit"); - return TCORE_RETURN_SUCCESS; -} - -static TReturn s_call_mute(CoreObject *o, UserRequest *ur) -{ - char *cmd_str = NULL; - TcorePending *pending = NULL; - TcoreATRequest *req = NULL; - gboolean ret = FALSE; - - dbg("Entry"); - cmd_str = g_strdup_printf("%s","AT+XDRV=40,8,0,0,0"); - - dbg("Request command string: %s", cmd_str); - - // Create new Pending request - pending = tcore_pending_new(o, 0); - - // Create new AT-Command request - req = tcore_at_request_new(cmd_str, "+XDRV", TCORE_AT_SINGLELINE); - dbg("Command: %s, prefix(if any): %s, Command length: %d", req->cmd, req->prefix, strlen(req->cmd)); - - // Free command string - g_free(cmd_str); - - // Set request data (AT command) to Pending request - tcore_pending_set_request_data(pending, 0, req); - - // Send request - ret = _call_request_message (pending, o, ur, on_confirmation_call_mute, NULL); - if (!ret) { - err("Failed to send AT-Command request"); - return TCORE_RETURN_FAILURE; - } - - dbg("Exit"); - return TCORE_RETURN_SUCCESS; -} - -static TReturn s_call_unmute(CoreObject *o, UserRequest *ur) -{ - char *cmd_str = NULL; - TcorePending *pending = NULL; - TcoreATRequest *req = NULL; - gboolean ret = FALSE; - dbg("Entry"); - - cmd_str = g_strdup_printf("%s","AT+XDRV=40,8,0,0,88"); - dbg("Request command string: %s", cmd_str); - - // Create new Pending request - pending = tcore_pending_new(o, 0); - - // Create new AT-Command request - req = tcore_at_request_new(cmd_str, "+XDRV", TCORE_AT_SINGLELINE); - dbg("Command: %s, prefix(if any): %s, Command length: %d", req->cmd, req->prefix, strlen(req->cmd)); - - // Free command string - g_free(cmd_str); - - // Set request data (AT command) to Pending request - tcore_pending_set_request_data(pending, 0, req); - - // Send request - ret = _call_request_message (pending, o, ur, on_confirmation_call_unmute, NULL); - if (!ret) { - err("Failed to send AT-Command request"); - return TCORE_RETURN_FAILURE; - } - - dbg("Exit"); - return TCORE_RETURN_SUCCESS; - -} - - -static TReturn s_call_get_mute_status(CoreObject *o, UserRequest *ur) -{ - dbg("Entry"); - - dbg("Exit"); - return TCORE_RETURN_SUCCESS; -} - -static TReturn _set_dtmf_tone_duration(CoreObject *o, UserRequest *ur) -{ - char *cmd_str = NULL; - TcorePending *pending = NULL; - TcoreATRequest *req = NULL; - gboolean ret = FALSE; - dbg("Entry"); - - cmd_str = g_strdup_printf("%s", "AT+VTD=3"); // ~300 mili secs. +VTD= n, where n = (0 - 255) * 1/10 secs. - dbg("Request command string: %s", cmd_str); - - // Create new Pending request - pending = tcore_pending_new(o, 0); - - // Create new AT-Command request - req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT); - dbg("Command: %s, prefix(if any): %s, Command length: %d", req->cmd, req->prefix, strlen(req->cmd)); - - // Free command string */ - g_free(cmd_str); - - // Set request data (AT command) to Pending request - tcore_pending_set_request_data(pending, 0, req); - - // Send request - ret = _call_request_message (pending, o, ur, _on_confirmation_dtmf_tone_duration, NULL); - if (!ret) { - err("Failed to send AT-Command request"); - return TCORE_RETURN_FAILURE; - } - - dbg("Exit"); - return TCORE_RETURN_SUCCESS; -} - -//Call Operations -static struct tcore_call_operations call_ops = { - .dial = s_call_outgoing, - .answer = s_call_answer, - .end = s_call_release, - .hold = s_call_hold, - .active = s_call_active, - .swap = s_call_swap, - .join = s_call_join, - .split = s_call_split, - .deflect = s_call_deflect, - .transfer = s_call_transfer, - .send_dtmf = s_call_send_dtmf, - .set_sound_path = s_call_set_sound_path, - .set_sound_volume_level = s_call_set_sound_volume_level, - .get_sound_volume_level = s_call_get_sound_volume_level, - .mute = s_call_mute, - .unmute = s_call_unmute, - .get_mute_status = s_call_get_mute_status, - .set_sound_recording = NULL, - .set_sound_equalization = NULL, - .set_sound_noise_reduction = NULL, -}; - -static void s_call_info_mo_waiting(CoreObject *o) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_current_on_mo_processing(o); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_WAITING, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_mo_forwarded(CoreObject *o) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_current_on_mo_processing(o); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_FORWARDED, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_mo_barred_incoming(CoreObject *o) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_current_on_mo_processing(o); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_BARRED_INCOMING, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_mo_barred_outgoing(CoreObject *o) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_current_on_mo_processing(o); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_BARRED_OUTGOING, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_mo_deflected(CoreObject *o) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_current_on_mo_processing(o); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_DEFLECTED, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_mo_clir_suppression_reject(CoreObject *o) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_current_on_mo_processing(o); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_CLIR_SUPPRESSION_REJECT, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_mo_cfu(CoreObject *o) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_current_on_mo_processing(o); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_FORWARD_UNCONDITIONAL, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_mo_cfc(CoreObject *o) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_current_on_mo_processing(o); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_FORWARD_CONDITIONAL, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_mt_cli(CoreObject *o, enum tcore_call_cli_mode mode, char* number) -{ - CallObject *co = NULL; - dbg("Entry"); - - // Call Core object - co = tcore_call_object_current_on_mt_processing(o); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Set CLI information - tcore_call_object_set_cli_info(co, mode, number); - - dbg("Exit"); - return; -} - -static void s_call_info_mt_cna(CoreObject *o, enum tcore_call_cna_mode mode, char* name, int dcs) -{ - CallObject *co = NULL; - dbg("Entry"); - - // Call Core object - co = tcore_call_object_current_on_mt_processing(o); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Set CNA information - tcore_call_object_set_cna_info(co, mode, name, dcs); - - dbg("Exit"); - return; -} - -static void s_call_info_mt_forwarded_call(CoreObject *o, char* number) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_find_by_number(o, number); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_FORWARDED_CALL, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_mt_deflected_call(CoreObject *o, char* number) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_find_by_number(o, number); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_DEFLECTED_CALL, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_mt_transfered(CoreObject *o, char* number) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_find_by_number(o, number); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_TRANSFERED_CALL, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_held(CoreObject *o, char* number) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_find_by_number(o, number); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_HELD, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_active(CoreObject *o, char* number) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_find_by_number(o, number); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_ACTIVE, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_joined(CoreObject *o, char* number) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - //Parent plugin - plugin = tcore_object_ref_plugin(o); - - //Call Core object - co = tcore_call_object_find_by_number(o, number); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_JOINED, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_released_on_hold(CoreObject *o, char* number) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_find_by_number(o, number); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_RELEASED_ON_HOLD, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_transfer_alert(CoreObject *o, char* number) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - //Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_find_by_number(o, number); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - //Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_TRANSFER_ALERT, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_transfered(CoreObject *o, char* number) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_find_by_number(o, number); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_TRANSFERED, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -static void s_call_info_cf_check_message(CoreObject *o, char* number) -{ - TcorePlugin *plugin = NULL; - CallObject *co = NULL; - int id = 0; - dbg("Entry"); - - // Parent plugin - plugin = tcore_object_ref_plugin(o); - - // Call Core object - co = tcore_call_object_find_by_number(o, number); - if (!co) { - err("Failed to find Call Core object!"); - return; - } - - // Call ID - id = tcore_call_object_get_id(co); - - // Send notification to TAPI - tcore_server_send_notification(tcore_plugin_ref_server(plugin), - tcore_plugin_ref_core_object(plugin, "call"), - TNOTI_CALL_INFO_CF_CHECK_MESSAGE, - sizeof(unsigned int), - (void*)&id); - - dbg("Exit"); - return; -} - -// Call Information Operations -static struct tcore_call_information_operations call_information_ops = { - .mo_call_col = 0, - .mo_call_waiting = s_call_info_mo_waiting, - .mo_call_cug = 0, - .mo_call_forwarded = s_call_info_mo_forwarded, - .mo_call_barred_incoming = s_call_info_mo_barred_incoming, - .mo_call_barred_outgoing = s_call_info_mo_barred_outgoing, - .mo_call_deflected = s_call_info_mo_deflected, - .mo_call_clir_suppression_reject = s_call_info_mo_clir_suppression_reject, - .mo_call_cfu = s_call_info_mo_cfu, - .mo_call_cfc = s_call_info_mo_cfc, - .mt_call_cli = s_call_info_mt_cli, - .mt_call_cna = s_call_info_mt_cna, - .mt_call_forwarded_call = s_call_info_mt_forwarded_call, - .mt_call_cug_call = 0, - .mt_call_deflected_call = s_call_info_mt_deflected_call, - .mt_call_transfered = s_call_info_mt_transfered, - .call_held = s_call_info_held, - .call_active = s_call_info_active, - .call_joined = s_call_info_joined, - .call_released_on_hold = s_call_info_released_on_hold, - .call_transfer_alert = s_call_info_transfer_alert, - .call_transfered = s_call_info_transfered, - .call_cf_check_message = s_call_info_cf_check_message, -}; - -gboolean s_call_init(TcorePlugin *p, TcoreHal *h) -{ - CoreObject *o = NULL; - struct property_call_info *data = NULL; - dbg("Entry"); - - //Creating Call COre object - o = tcore_call_new(p, "call", &call_ops, h); - if (!o) { - err("Failed to create Call Core Object"); - return FALSE; - } - - //Set Call Operations - tcore_call_information_set_operations(o, &call_information_ops); - - // Add Callbacks - tcore_object_add_callback(o, "+XCALLSTAT", on_notification_call_info, NULL); - tcore_object_add_callback(o, "+CLIP", on_notification_call_clip_info, NULL); - - // User Data - data = calloc(sizeof(struct property_call_info *), 1); - tcore_plugin_link_property(p, "CALL", data); - - dbg("Exit"); - return TRUE; -} - -void s_call_exit(TcorePlugin *p) -{ - CoreObject *o = NULL; - struct property_network_info *data = NULL; - dbg("Entry"); - - o = tcore_plugin_ref_core_object(p, "call"); - - // Free Call Core Object */ - tcore_call_free(o); - - // Free 'CALL' property */ - data = tcore_plugin_ref_property(p, "CALL"); - if (data) { - g_free(data); - } - - dbg("Exit"); - return; -} + dbg("num after removing quotes - %s", num); + + p_call->info.num_len = strlen(resp); + dbg("num_len : [0x%x]\n", p_call->info.num_len); + + // parse + resp = g_slist_nth_data(tokens, 6); + if (!resp) { + dbg("InValid Num type"); + goto ERROR; + } + p_call->info.num_type = atoi(resp); + dbg("BCD num type: [0x%x]\n", p_call->info.num_type); + + // check number is international or national. + num_type = ((p_call->info.num_type) >> 4) & 0x07; + dbg("called party's type of number : [0x%x]\n", num_type); + + if (num_type == 1 && num[0] != '+') { + // international number + p_call->number[0] = '+'; + memcpy(&(p_call->number[1]), num, strlen(num)); + } else { + memcpy(&(p_call->number), num, strlen(num)); + } + dbg("incoming number - %s", p_call->number); + + g_free(num); + num = NULL; + // Free tokens + tcore_at_tok_free(tokens); + + dbg("Exit"); + return 0; + +ERROR: + err("Invalid CLCC line"); + + if (num) { + g_free(num); + num = NULL; + } + + // Free tokens + tcore_at_tok_free(tokens); + err("Exit"); + return -1; +} + +// NOTIFICATION +static void on_notification_call_waiting(CoreObject *o, const void *data, void *user_data) +{ + GSList *tokens = NULL; + const char *line = NULL; + char *pId; + int call_id; + gboolean *eflag; + GSList *pList = NULL; + CallObject *co = NULL, *dupco = NULL; + + dbg("function entrance"); + // check call with waiting status already exist + pList = tcore_call_object_find_by_status(o, TCORE_CALL_STATUS_WAITING); + + if (pList != NULL) { + dbg("[error]Waiting call already exist. skip"); + return; + } + // check call with incoming status already exist + pList = tcore_call_object_find_by_status(o, TCORE_CALL_STATUS_INCOMING); + + if (pList != NULL) { + dbg("[error]incoming call already exist. skip"); + return; + } + line = (char *) data; + tokens = tcore_at_tok_new(line); + + pId = g_slist_nth_data(tokens, 0); + if (!pId) { + dbg("[error]:Call id is missing from +XCALLSTAT indication"); + return; + } + + call_id = atoi(pId); + dupco = tcore_call_object_find_by_id(o, call_id); + if (dupco != NULL) { + dbg("co with same id already exist. skip"); + return; + } + co = tcore_call_object_new(o, call_id); + if (!co) { + dbg("[ error ] co is NULL"); + return; + } + + tcore_at_tok_free(tokens); + + eflag = g_new0(gboolean, 1); + *eflag = TRUE; + dbg("calling _call_list_get"); + _call_list_get(o, eflag); +} + +static void on_notification_call_incoming(CoreObject *o, const void *data, void *user_data) +{ + GSList *tokens = NULL; + const char *line = NULL; + char *pId; + int call_id; + gboolean *eflag; + GSList *pList = NULL; + CallObject *co = NULL, *dupco = NULL; + + dbg("function entrance"); + // check call with incoming status already exist + pList = tcore_call_object_find_by_status(o, TCORE_CALL_STATUS_INCOMING); + + if (pList != NULL) { + dbg("incoming call already exist. skip"); + return; + } + + line = (char *) data; + tokens = tcore_at_tok_new(line); + + pId = g_slist_nth_data(tokens, 0); + if (!pId) { + dbg("Error:Call id is missing from %XCALLSTAT indication"); + return; + } + + call_id = atoi(pId); + + dupco = tcore_call_object_find_by_id(o, call_id); + if (dupco != NULL) { + dbg("co with same id already exist. skip"); + return; + } + + co = tcore_call_object_new(o, call_id); + if (!co) { + dbg("[ error ] co is NULL"); + return; + } + + dbg("freeing at token") + tcore_at_tok_free(tokens); + + eflag = g_new0(gboolean, 1); + *eflag = TRUE; + + dbg("calling _call_list_get"); + _call_list_get(o, eflag); +} + +static void on_notification_call_status(CoreObject *o, const void *data, void *user_data) +{ + char *cmd = NULL; + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = -1; + int status = 0; + int type = 0; + char *stat = NULL; + char *pCallId = NULL; + GSList *tokens = NULL; + gboolean *eflag = NULL; + enum tcore_call_status co_status; + + dbg("function entrance"); + plugin = tcore_object_ref_plugin(o); + cmd = (char *) data; + tokens = tcore_at_tok_new(cmd); + + // parse + pCallId = g_slist_nth_data(tokens, 0); + if (!pCallId) { + dbg("pCallId is missing from %XCALLSTAT indiaction"); + } else { + id = atoi(pCallId); + dbg("call id = %d", id); + // parse + if ((stat = g_slist_nth_data(tokens, 1))) { + status = atoi(stat); + } + dbg("call status = %d", status); + } + + tcore_at_tok_free(tokens); + co_status = _call_status(status); + + dbg("co_status = %d", co_status); + switch (co_status) { + case CALL_STATUS_ACTIVE: + { + dbg("call(%d) status : [ ACTIVE ]", id); + co = tcore_call_object_find_by_id(o, id); + if (!co) { + dbg("co is NULL"); + return; + } + _call_status_active(plugin, co); + } + break; + + case CALL_STATUS_HELD: + dbg("call(%d) status : [ held ]", id); + break; + + case CALL_STATUS_DIALING: + { + dbg("call(%d) status : [ dialing ]", id); + co = tcore_call_object_find_by_id(o, id); + if (!co) { + co = tcore_call_object_new(o, id); + if (!co) { + dbg("error : tcore_call_object_new [ id : %d ]", id); + return; + } + } + + tcore_call_object_set_type(co, call_type(type)); + tcore_call_object_set_direction(co, TCORE_CALL_DIRECTION_OUTGOING); + _call_status_dialing(plugin, co); + } + break; + + case CALL_STATUS_ALERT: + { + dbg("call(%d) status : [ alert ]", id); + co = tcore_call_object_find_by_id(o, id); + if (!co) { + dbg("co is NULL"); + return; + } + // Store dialed number information into Call object. + eflag = g_new0(gboolean, 1); + *eflag = TRUE; + dbg("calling _call_list_get"); + _call_list_get(o, eflag); + } + break; + + case CALL_STATUS_INCOMING: + case CALL_STATUS_WAITING: + dbg("call(%d) status : [ incoming ]", id); + break; + + case CALL_STATUS_IDLE: + { + dbg("call(%d) status : [ release ]", id); + + co = tcore_call_object_find_by_id(o, id); + if (!co) { + dbg("co is NULL"); + return; + } + + plugin = tcore_object_ref_plugin(o); + if (!plugin) { + dbg("plugin is NULL"); + return; + } + _call_status_idle(plugin, co); + } + break; + + default: + dbg("invalid call status", id); + break; + } +} + +static TReturn s_call_outgoing(CoreObject *o, UserRequest *ur) +{ + struct treq_call_dial *data = 0; + char *raw_str = NULL; + char *cmd_str = NULL; + const char *cclir; + enum tcore_call_cli_mode clir = CALL_CLI_MODE_DEFAULT; + TcorePending *pending = NULL; + TcoreATRequest *req; + gboolean ret = FALSE; + + dbg("function entrance"); + data = (struct treq_call_dial *) tcore_user_request_ref_data(ur, 0); + clir = _get_clir_status(data->number); + + // Compose ATD Cmd string + switch (clir) { + case TCORE_CALL_CLI_MODE_PRESENT: + dbg("CALL_CLI_MODE_PRESENT"); + cclir = "I"; + break; // invocation + + case TCORE_CALL_CLI_MODE_RESTRICT: + dbg("CALL_CLI_MODE_RESTRICT"); + cclir = "i"; + break; // suppression + + case TCORE_CALL_CLI_MODE_DEFAULT: + default: + cclir = ""; + dbg("CALL_CLI_MODE_DEFAULT"); + break; // subscription default + } + + dbg("data->number = %s", data->number); + + raw_str = g_strdup_printf("ATD%s%s;", data->number, cclir); + cmd_str = g_strdup_printf("%s", raw_str); + + dbg("request command : %s", cmd_str); + + pending = tcore_pending_new(o, 0); + req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT); + dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_request_data(pending, 0, req); + ret = _call_request_message(pending, o, ur, on_confirmation_call_outgoing, NULL); + + g_free(raw_str); + g_free(cmd_str); + + if (!ret) { + dbg("AT request(%s) sent failed", req->cmd); + return TCORE_RETURN_FAILURE; + } + + dbg("AT request(%s) sent success", req->cmd); + + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_answer(CoreObject *o, UserRequest *ur) +{ + char *cmd_str = NULL; + CallObject *co = NULL; + struct treq_call_answer *data = 0; + TcorePending *pending = NULL; + TcoreATRequest *req; + gboolean ret = FALSE; + + dbg("function entrance"); + + data = (struct treq_call_answer *) tcore_user_request_ref_data(ur, 0); + co = tcore_call_object_find_by_id(o, data->id); + if (data->type == CALL_ANSWER_TYPE_ACCEPT) { + dbg(" request type CALL_ANSWER_TYPE_ACCEPT"); + + cmd_str = g_strdup_printf("%s", "ATA"); + pending = tcore_pending_new(o, 0); + req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT); + dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_request_data(pending, 0, req); + ret = _call_request_message(pending, o, ur, on_confirmation_call_accept, co); + g_free(cmd_str); + + if (!ret) { + dbg("AT request(%s) sent failed", req->cmd); + return TCORE_RETURN_FAILURE; + } + } else { + switch (data->type) { + case CALL_ANSWER_TYPE_REJECT: + { + dbg("call answer reject"); + tcore_call_control_answer_reject(o, ur, on_confirmation_call_reject, co); + } + break; + + case CALL_ANSWER_TYPE_REPLACE: + { + dbg("call answer replace"); + tcore_call_control_answer_replace(o, ur, on_confirmation_call_replace, co); + } + break; + + case CALL_ANSWER_TYPE_HOLD_ACCEPT: + { + dbg("call answer hold and accept"); + tcore_call_control_answer_hold_and_accept(o, ur, on_confirmation_call_hold_and_accept, co); + } + break; + + default: + dbg("[ error ] wrong answer type [ %d ]", data->type); + return TCORE_RETURN_FAILURE; + } + } + + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_release(CoreObject *o, UserRequest *ur) +{ + CallObject *co = NULL; + struct treq_call_end *data = 0; + UserRequest *ur_dup = NULL; + char *chld0_cmd = NULL; + char *chld1_cmd = NULL; + TcorePending *pending = NULL, *pending1 = NULL; + TcoreATRequest *req, *req1; + gboolean ret = FALSE; + + dbg("function entrance"); + data = (struct treq_call_end *) tcore_user_request_ref_data(ur, 0); + co = tcore_call_object_find_by_id(o, data->id); + + dbg("type of release call = %d", data->type); + + if (data->type == CALL_END_TYPE_ALL) { + // releaseAll do not exist on legacy request. send CHLD=0, CHLD=1 in sequence + chld0_cmd = g_strdup("AT+CHLD=0"); + chld1_cmd = g_strdup("AT+CHLD=1"); + + pending = tcore_pending_new(o, 0); + req = tcore_at_request_new(chld0_cmd, NULL, TCORE_AT_NO_RESULT); + + dbg("input command is %s", chld0_cmd); + dbg("req-cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_request_data(pending, 0, req); + ur_dup = tcore_user_request_new(NULL, NULL); + ret = _call_request_message(pending, o, ur_dup, on_confirmation_call_endall, NULL); + g_free(chld0_cmd); + + if (!ret) { + dbg("AT request %s has failed ", req->cmd); + return TCORE_RETURN_FAILURE; + } + + pending1 = tcore_pending_new(o, 0); + req1 = tcore_at_request_new(chld1_cmd, NULL, TCORE_AT_NO_RESULT); + + dbg("input command is %s", chld1_cmd); + dbg("req-cmd : %s, prefix(if any) :%s, cmd_len : %d", req1->cmd, req1->prefix, strlen(req1->cmd)); + + tcore_pending_set_request_data(pending1, 0, req1); + ret = _call_request_message(pending1, o, ur, on_confirmation_call_release_all, co); + g_free(chld1_cmd); + + if (!ret) { + dbg("AT request %s has failed ", req->cmd); + return TCORE_RETURN_FAILURE; + } + } else { + switch (data->type) { + case CALL_END_TYPE_DEFAULT: + { + int id = 0; + id = tcore_call_object_get_id(co); + + dbg("call end call id [%d]", id); + tcore_call_control_end_specific(o, ur, id, on_confirmation_call_release_specific, co); + } + break; + + case CALL_END_TYPE_ACTIVE_ALL: + { + dbg("call end all active"); + tcore_call_control_end_all_active(o, ur, on_confirmation_call_release_all_active, co); + } + break; + + case CALL_END_TYPE_HOLD_ALL: + { + dbg("call end all held"); + tcore_call_control_end_all_held(o, ur, on_confirmation_call_release_all_held, co); + } + break; + + default: + dbg("[ error ] wrong end type [ %d ]", data->type); + return TCORE_RETURN_FAILURE; + } + } + + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_hold(CoreObject *o, UserRequest *ur) +{ + struct treq_call_hold *hold = 0; + CallObject *co = NULL; + + dbg("function entrance"); + + hold = (struct treq_call_hold *) tcore_user_request_ref_data(ur, 0); + dbg("call id : [ %d ]", hold->id); + + co = tcore_call_object_find_by_id(o, hold->id); + tcore_call_control_hold(o, ur, on_confirmation_call_hold, co); + + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_active(CoreObject *o, UserRequest *ur) +{ + struct treq_call_active *active = 0; + CallObject *co = NULL; + + active = (struct treq_call_active *) tcore_user_request_ref_data(ur, 0); + dbg("call id : [ %d ]", active->id); + + co = tcore_call_object_find_by_id(o, active->id); + tcore_call_control_active(o, ur, on_confirmation_call_active, co); + + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_swap(CoreObject *o, UserRequest *ur) +{ + struct treq_call_swap *swap = NULL; + CallObject *co = NULL; + + swap = (struct treq_call_swap *) tcore_user_request_ref_data(ur, 0); + dbg("call id : [ %d ]", swap->id); + + co = tcore_call_object_find_by_id(o, swap->id); + tcore_call_control_swap(o, ur, on_confirmation_call_swap, co); + + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_join(CoreObject *o, UserRequest *ur) +{ + struct treq_call_join *join = 0; + CallObject *co = NULL; + + join = (struct treq_call_join *) tcore_user_request_ref_data(ur, 0); + dbg("call id : [ %d ]", join->id); + + co = tcore_call_object_find_by_id(o, join->id); + tcore_call_control_join(o, ur, on_confirmation_call_join, co); + + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_split(CoreObject *o, UserRequest *ur) +{ + struct treq_call_split *split = 0; + CallObject *co = NULL; + + split = (struct treq_call_split *) tcore_user_request_ref_data(ur, 0); + co = tcore_call_object_find_by_id(o, split->id); + dbg("call id : [ %d ]", split->id); + + tcore_call_control_split(o, ur, split->id, on_confirmation_call_split, co); + + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_deflect(CoreObject *o, UserRequest *ur) +{ + struct treq_call_deflect *deflect = 0; + CallObject *co = NULL; + + deflect = (struct treq_call_deflect *) tcore_user_request_ref_data(ur, 0); + co = tcore_call_object_find_by_number(o, deflect->number); + dbg("deflect number: [ %s ]", deflect->number); + + tcore_call_control_deflect(o, ur, deflect->number, on_confirmation_call_deflect, co); + + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_transfer(CoreObject *o, UserRequest *ur) +{ + struct treq_call_transfer *transfer = 0; + CallObject *co = NULL; + + transfer = (struct treq_call_transfer *) tcore_user_request_ref_data(ur, 0); + dbg("call id : [ %d ]", transfer->id); + + co = tcore_call_object_find_by_id(o, transfer->id); + tcore_call_control_transfer(o, ur, on_confirmation_call_transfer, co); + + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_send_dtmf(CoreObject *o, UserRequest *ur) +{ + char *cmd_str = NULL; + TcorePending *pending = NULL; + TcoreATRequest *req; + UserRequest *dup; + gboolean ret = FALSE; + struct treq_call_dtmf *dtmf = 0; + char *dtmfstr = NULL, *tmp_dtmf = NULL; + unsigned int dtmf_count; + + dbg("Function enter"); + + dup = tcore_user_request_new(NULL, NULL); + (void) _set_dtmf_tone_duration(o, dup); + + dtmf = (struct treq_call_dtmf *) tcore_user_request_ref_data(ur, 0); + dtmfstr = g_malloc0((MAX_CALL_DTMF_DIGITS_LEN * 2) + 1); // DTMF digits + comma for each dtmf digit. + + if (dtmfstr == NULL) { + dbg("Memory allocation failed"); + return TCORE_RETURN_FAILURE; + } + + tmp_dtmf = dtmfstr; + + for (dtmf_count = 0; dtmf_count < strlen(dtmf->digits); dtmf_count++) { + *tmp_dtmf = dtmf->digits[dtmf_count]; + tmp_dtmf++; + + *tmp_dtmf = COMMA; + tmp_dtmf++; + } + + // last digit is having COMMA , overwrite it with '\0' . + *(--tmp_dtmf) = '\0'; + dbg("Input DTMF string(%s)", dtmfstr); + + // AT+VTS = ,,,,,, ..... + cmd_str = g_strdup_printf("AT+VTS=%s", dtmfstr); + dbg("request command : %s", cmd_str); + + pending = tcore_pending_new(o, 0); + req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT); + dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_request_data(pending, 0, req); + ret = _call_request_message(pending, o, ur, on_confirmation_call_dtmf, NULL); + g_free(dtmfstr); + g_free(cmd_str); + + if (!ret) { + dbg("AT request sent failed") + return TCORE_RETURN_FAILURE; + } + + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_set_sound_path(CoreObject *o, UserRequest *ur) +{ + UserRequest *ur_dup = NULL; + TcorePending *pending = NULL, *pending1 = NULL; + TcoreATRequest *req, *req1; + char *cmd_str = NULL, *cmd_str1 = NULL; + gboolean ret = FALSE; + + dbg("function entrance"); + + // hard coded value for speaker. + cmd_str = g_strdup_printf("%s", "AT+XDRV=40,4,3,0,0,0,0,0,1,0,1,0,1"); // source type. + cmd_str1 = g_strdup_printf("%s", "AT+XDRV=40,5,2,0,0,0,0,0,1,0,1,0,1"); // destination type + + pending = tcore_pending_new(o, 0); + req = tcore_at_request_new(cmd_str, "+XDRV", TCORE_AT_SINGLELINE); + dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_request_data(pending, 0, req); + ur_dup = tcore_user_request_ref(ur); + + ret = _call_request_message(pending, o, ur_dup, on_confirmation_call_set_source_sound_path, NULL); + + g_free(cmd_str); + + if (!ret) { + dbg("At request(%s) sent failed", req->cmd); + return TCORE_RETURN_FAILURE; + } + + pending1 = tcore_pending_new(o, 0); + req1 = tcore_at_request_new(cmd_str1, "+XDRV", TCORE_AT_SINGLELINE); + dbg("input command is %s", cmd_str1); + dbg("req-cmd : %s, prefix(if any) :%s, cmd_len : %d", req1->cmd, req1->prefix, strlen(req1->cmd)); + + tcore_pending_set_request_data(pending1, 0, req1); + ret = _call_request_message(pending1, o, ur, on_confirmation_call_set_destination_sound_path, NULL); + + g_free(cmd_str1); + + if (!ret) { + dbg("AT request %s has failed ", req1->cmd); + return TCORE_RETURN_FAILURE; + } + + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_set_sound_volume_level(CoreObject *o, UserRequest *ur) +{ + UserRequest *src_ur = NULL; + UserRequest *dest_ur = NULL; + TcorePending *src_pending = NULL; + TcorePending *dest_pending = NULL; + TcoreATRequest *src_req = NULL; + TcoreATRequest *dest_req = NULL; + char *cmd_str = NULL, *volume_level = NULL; + gboolean ret = FALSE; + + struct treq_call_sound_set_volume_level *data = NULL; + data = (struct treq_call_sound_set_volume_level *) tcore_user_request_ref_data(ur, 0); + dbg("Entry"); + // Hard-coded values for MIC & Speakers + // Source volume + dbg("Set Source volume"); + + cmd_str = g_strdup_printf("%s", "AT+XDRV=40,7,3,88"); // Source type + dbg("Request command string: %s", cmd_str); + + // Create new Pending request + src_pending = tcore_pending_new(o, 0); + + // Create new AT-Command request + src_req = tcore_at_request_new(cmd_str, "+XDRV", TCORE_AT_SINGLELINE); + dbg("Command: %s, prefix(if any): %s, Command length: %d", src_req->cmd, src_req->prefix, strlen(src_req->cmd)); + + // Free Command string + g_free(cmd_str); + + tcore_pending_set_request_data(src_pending, 0, src_req); + src_ur = tcore_user_request_ref(ur); + + // Send request + ret = _call_request_message(src_pending, o, src_ur, on_confirmation_call_set_source_sound_volume_level, NULL); + if (!ret) { + err("Failed to send AT-Command request"); + return TCORE_RETURN_FAILURE; + } + + cmd_str = g_strdup_printf("%s", "AT+XDRV=40,7,0,88"); // Destination type + dbg("Request command string: %s", cmd_str); + + // Create new Pending request + src_pending = tcore_pending_new(o, 0); + + // Create new AT-Command request + src_req = tcore_at_request_new(cmd_str, "+XDRV", TCORE_AT_SINGLELINE); + dbg("Command: %s, prefix(if any): %s, Command length: %d", src_req->cmd, src_req->prefix, strlen(src_req->cmd)); + + // Free Command string + g_free(cmd_str); + + tcore_pending_set_request_data(src_pending, 0, src_req); + + src_ur = tcore_user_request_ref(ur); + + // Send request + ret = _call_request_message(src_pending, o, src_ur, on_confirmation_call_set_source_sound_volume_level, NULL); + if (!ret) { + err("Failed to send AT-Command request"); + return TCORE_RETURN_FAILURE; + } + + // Destination volume + dbg("Set Source volume"); + + cmd_str = g_strdup_printf("%s", "AT+XDRV=40,8,0,88"); // Source type + dbg("Request command string: %s", cmd_str); + + // Create new Pending request + dest_pending = tcore_pending_new(o, 0); + + // Create new AT-Command request + dest_req = tcore_at_request_new(cmd_str, "+XDRV", TCORE_AT_SINGLELINE); + dbg("Command: %s, prefix(if any): %s, Command length: %d", dest_req->cmd, dest_req->prefix, strlen(dest_req->cmd)); + + // Free Command string + g_free(cmd_str); + + tcore_pending_set_request_data(dest_pending, 0, dest_req); + dest_ur = tcore_user_request_ref(ur); + + // Send request + ret = _call_request_message(dest_pending, o, dest_ur, on_confirmation_call_set_source_sound_volume_level, NULL); + if (!ret) { + err("Failed to send AT-Command request"); + return TCORE_RETURN_FAILURE; + } + + dbg("Input volume level - %d", data->volume); + switch (data->volume) { + case CALL_SOUND_MUTE: + volume_level = "0"; + break; + + case CALL_SOUND_VOLUME_LEVEL_1: + volume_level = "40"; + break; + + case CALL_SOUND_VOLUME_LEVEL_2: + volume_level = "46"; + break; + + case CALL_SOUND_VOLUME_LEVEL_3: + volume_level = "52"; + break; + + case CALL_SOUND_VOLUME_LEVEL_4: + volume_level = "58"; + break; + + case CALL_SOUND_VOLUME_LEVEL_5: + volume_level = "64"; + break; + + case CALL_SOUND_VOLUME_LEVEL_6: + volume_level = "70"; + break; + + case CALL_SOUND_VOLUME_LEVEL_7: + volume_level = "76"; + break; + + case CALL_SOUND_VOLUME_LEVEL_8: + volume_level = "82"; + break; + + case CALL_SOUND_VOLUME_LEVEL_9: + default: + volume_level = "88"; + break; + } + cmd_str = g_strdup_printf("%s%s", "AT+XDRV=40,8,2,", volume_level); // Destination type + dbg("Request command string: %s", cmd_str); + + // Create new Pending request + dest_pending = tcore_pending_new(o, 0); + + // Create new AT-Command request + dest_req = tcore_at_request_new(cmd_str, "+XDRV", TCORE_AT_SINGLELINE); + dbg("Command: %s, prefix(if any): %s, Command length: %d", dest_req->cmd, dest_req->prefix, strlen(dest_req->cmd)); + + // Free Command string + g_free(cmd_str); + + tcore_pending_set_request_data(dest_pending, 0, dest_req); + + // Send request + ret = _call_request_message(dest_pending, o, ur, on_confirmation_call_set_destination_sound_volume_level, NULL); + if (!ret) { + err("Failed to send AT-Command request"); + return TCORE_RETURN_FAILURE; + } + + return TCORE_RETURN_SUCCESS; +} + + +static TReturn s_call_get_sound_volume_level(CoreObject *o, UserRequest *ur) +{ + dbg("Entry"); + + dbg("Exit"); + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_mute(CoreObject *o, UserRequest *ur) +{ + char *cmd_str = NULL; + TcorePending *pending = NULL; + TcoreATRequest *req = NULL; + gboolean ret = FALSE; + + dbg("Entry"); + cmd_str = g_strdup_printf("%s", "AT+XDRV=40,8,0,0,0"); + + dbg("Request command string: %s", cmd_str); + + // Create new Pending request + pending = tcore_pending_new(o, 0); + + // Create new AT-Command request + req = tcore_at_request_new(cmd_str, "+XDRV", TCORE_AT_SINGLELINE); + dbg("Command: %s, prefix(if any): %s, Command length: %d", req->cmd, req->prefix, strlen(req->cmd)); + + // Free command string + g_free(cmd_str); + + // Set request data (AT command) to Pending request + tcore_pending_set_request_data(pending, 0, req); + + // Send request + ret = _call_request_message(pending, o, ur, on_confirmation_call_mute, NULL); + if (!ret) { + err("Failed to send AT-Command request"); + return TCORE_RETURN_FAILURE; + } + + dbg("Exit"); + return TCORE_RETURN_SUCCESS; +} + +static TReturn s_call_unmute(CoreObject *o, UserRequest *ur) +{ + char *cmd_str = NULL; + TcorePending *pending = NULL; + TcoreATRequest *req = NULL; + gboolean ret = FALSE; + dbg("Entry"); + + cmd_str = g_strdup_printf("%s", "AT+XDRV=40,8,0,0,88"); + dbg("Request command string: %s", cmd_str); + + // Create new Pending request + pending = tcore_pending_new(o, 0); + + // Create new AT-Command request + req = tcore_at_request_new(cmd_str, "+XDRV", TCORE_AT_SINGLELINE); + dbg("Command: %s, prefix(if any): %s, Command length: %d", req->cmd, req->prefix, strlen(req->cmd)); + + // Free command string + g_free(cmd_str); + + // Set request data (AT command) to Pending request + tcore_pending_set_request_data(pending, 0, req); + + // Send request + ret = _call_request_message(pending, o, ur, on_confirmation_call_unmute, NULL); + if (!ret) { + err("Failed to send AT-Command request"); + return TCORE_RETURN_FAILURE; + } + + dbg("Exit"); + return TCORE_RETURN_SUCCESS; +} + + +static TReturn s_call_get_mute_status(CoreObject *o, UserRequest *ur) +{ + dbg("Entry"); + + dbg("Exit"); + return TCORE_RETURN_SUCCESS; +} + +static TReturn _set_dtmf_tone_duration(CoreObject *o, UserRequest *ur) +{ + char *cmd_str = NULL; + TcorePending *pending = NULL; + TcoreATRequest *req = NULL; + gboolean ret = FALSE; + dbg("Entry"); + + cmd_str = g_strdup_printf("%s", "AT+VTD=3"); // ~300 mili secs. +VTD= n, where n = (0 - 255) * 1/10 secs. + dbg("Request command string: %s", cmd_str); + + // Create new Pending request + pending = tcore_pending_new(o, 0); + + // Create new AT-Command request + req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT); + dbg("Command: %s, prefix(if any): %s, Command length: %d", req->cmd, req->prefix, strlen(req->cmd)); + + // Free command string */ + g_free(cmd_str); + + // Set request data (AT command) to Pending request + tcore_pending_set_request_data(pending, 0, req); + + // Send request + ret = _call_request_message(pending, o, ur, _on_confirmation_dtmf_tone_duration, NULL); + if (!ret) { + err("Failed to send AT-Command request"); + return TCORE_RETURN_FAILURE; + } + + dbg("Exit"); + return TCORE_RETURN_SUCCESS; +} + +// Call Operations +static struct tcore_call_operations call_ops = { + .dial = s_call_outgoing, + .answer = s_call_answer, + .end = s_call_release, + .hold = s_call_hold, + .active = s_call_active, + .swap = s_call_swap, + .join = s_call_join, + .split = s_call_split, + .deflect = s_call_deflect, + .transfer = s_call_transfer, + .send_dtmf = s_call_send_dtmf, + .set_sound_path = s_call_set_sound_path, + .set_sound_volume_level = s_call_set_sound_volume_level, + .get_sound_volume_level = s_call_get_sound_volume_level, + .mute = s_call_mute, + .unmute = s_call_unmute, + .get_mute_status = s_call_get_mute_status, + .set_sound_recording = NULL, + .set_sound_equalization = NULL, + .set_sound_noise_reduction = NULL, +}; + +static void s_call_info_mo_waiting(CoreObject *o) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_current_on_mo_processing(o); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_WAITING, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_mo_forwarded(CoreObject *o) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_current_on_mo_processing(o); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_FORWARDED, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_mo_barred_incoming(CoreObject *o) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_current_on_mo_processing(o); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_BARRED_INCOMING, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_mo_barred_outgoing(CoreObject *o) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_current_on_mo_processing(o); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_BARRED_OUTGOING, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_mo_deflected(CoreObject *o) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_current_on_mo_processing(o); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_DEFLECTED, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_mo_clir_suppression_reject(CoreObject *o) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_current_on_mo_processing(o); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_CLIR_SUPPRESSION_REJECT, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_mo_cfu(CoreObject *o) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_current_on_mo_processing(o); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_FORWARD_UNCONDITIONAL, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_mo_cfc(CoreObject *o) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_current_on_mo_processing(o); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_FORWARD_CONDITIONAL, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_mt_cli(CoreObject *o, enum tcore_call_cli_mode mode, char *number) +{ + CallObject *co = NULL; + dbg("Entry"); + + // Call Core object + co = tcore_call_object_current_on_mt_processing(o); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Set CLI information + tcore_call_object_set_cli_info(co, mode, number); + + dbg("Exit"); + return; +} + +static void s_call_info_mt_cna(CoreObject *o, enum tcore_call_cna_mode mode, char *name, int dcs) +{ + CallObject *co = NULL; + dbg("Entry"); + + // Call Core object + co = tcore_call_object_current_on_mt_processing(o); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Set CNA information + tcore_call_object_set_cna_info(co, mode, name, dcs); + + dbg("Exit"); + return; +} + +static void s_call_info_mt_forwarded_call(CoreObject *o, char *number) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_find_by_number(o, number); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_FORWARDED_CALL, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_mt_deflected_call(CoreObject *o, char *number) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_find_by_number(o, number); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_DEFLECTED_CALL, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_mt_transfered(CoreObject *o, char *number) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_find_by_number(o, number); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_TRANSFERED_CALL, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_held(CoreObject *o, char *number) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_find_by_number(o, number); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_HELD, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_active(CoreObject *o, char *number) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_find_by_number(o, number); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_ACTIVE, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_joined(CoreObject *o, char *number) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_find_by_number(o, number); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_JOINED, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_released_on_hold(CoreObject *o, char *number) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_find_by_number(o, number); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_RELEASED_ON_HOLD, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_transfer_alert(CoreObject *o, char *number) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_find_by_number(o, number); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_TRANSFER_ALERT, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_transfered(CoreObject *o, char *number) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_find_by_number(o, number); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_TRANSFERED, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +static void s_call_info_cf_check_message(CoreObject *o, char *number) +{ + TcorePlugin *plugin = NULL; + CallObject *co = NULL; + int id = 0; + dbg("Entry"); + + // Parent plugin + plugin = tcore_object_ref_plugin(o); + + // Call Core object + co = tcore_call_object_find_by_number(o, number); + if (!co) { + err("Failed to find Call Core object!"); + return; + } + + // Call ID + id = tcore_call_object_get_id(co); + + // Send notification to TAPI + tcore_server_send_notification(tcore_plugin_ref_server(plugin), + tcore_plugin_ref_core_object(plugin, "call"), + TNOTI_CALL_INFO_CF_CHECK_MESSAGE, + sizeof(unsigned int), + (void *) &id); + + dbg("Exit"); + return; +} + +// Call Information Operations +static struct tcore_call_information_operations call_information_ops = { + .mo_call_col = 0, + .mo_call_waiting = s_call_info_mo_waiting, + .mo_call_cug = 0, + .mo_call_forwarded = s_call_info_mo_forwarded, + .mo_call_barred_incoming = s_call_info_mo_barred_incoming, + .mo_call_barred_outgoing = s_call_info_mo_barred_outgoing, + .mo_call_deflected = s_call_info_mo_deflected, + .mo_call_clir_suppression_reject = s_call_info_mo_clir_suppression_reject, + .mo_call_cfu = s_call_info_mo_cfu, + .mo_call_cfc = s_call_info_mo_cfc, + .mt_call_cli = s_call_info_mt_cli, + .mt_call_cna = s_call_info_mt_cna, + .mt_call_forwarded_call = s_call_info_mt_forwarded_call, + .mt_call_cug_call = 0, + .mt_call_deflected_call = s_call_info_mt_deflected_call, + .mt_call_transfered = s_call_info_mt_transfered, + .call_held = s_call_info_held, + .call_active = s_call_info_active, + .call_joined = s_call_info_joined, + .call_released_on_hold = s_call_info_released_on_hold, + .call_transfer_alert = s_call_info_transfer_alert, + .call_transfered = s_call_info_transfered, + .call_cf_check_message = s_call_info_cf_check_message, +}; + +gboolean s_call_init(TcorePlugin *p, TcoreHal *h) +{ + CoreObject *o = NULL; + struct property_call_info *data = NULL; + dbg("Entry"); + + // Creating Call COre object + o = tcore_call_new(p, "call", &call_ops, h); + if (!o) { + err("Failed to create Call Core Object"); + return FALSE; + } + + // Set Call Operations + tcore_call_information_set_operations(o, &call_information_ops); + + // Add Callbacks + tcore_object_add_callback(o, "+XCALLSTAT", on_notification_call_info, NULL); + tcore_object_add_callback(o, "+CLIP", on_notification_call_clip_info, NULL); + + // User Data + data = calloc(sizeof(struct property_call_info *), 1); + tcore_plugin_link_property(p, "CALL", data); + + dbg("Exit"); + return TRUE; +} + +void s_call_exit(TcorePlugin *p) +{ + CoreObject *o = NULL; + struct property_network_info *data = NULL; + dbg("Entry"); + + o = tcore_plugin_ref_core_object(p, "call"); + + // Free Call Core Object */ + tcore_call_free(o); + + // Free 'CALL' property */ + data = tcore_plugin_ref_property(p, "CALL"); + if (data) { + g_free(data); + } + + dbg("Exit"); + return; +} diff --git a/src/s_common.c b/src/s_common.c index ef41b05..0c83ac5 100755 --- a/src/s_common.c +++ b/src/s_common.c @@ -1,286 +1,271 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Ja-young Gu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include - - -#include "s_common.h" - -#include - -#undef MAX -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) - -#undef MIN -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) - -#define bitsize(type) (sizeof(type) * 8) - -#define copymask(type) ((0xffffffff) >> (32 - bitsize(type))) - -#define MASK(width, offset, data) \ - (((width) == bitsize(data)) ? (data) : \ - ((((copymask(data) << (bitsize(data) - ((width) % bitsize(data)))) & copymask(data)) >> (offset)) & (data))) \ - - -#define MASK_AND_SHIFT(width, offset, shift, data) \ - ((((signed) (shift)) < 0) ? \ - MASK((width), (offset), (data)) << -(shift) : \ - MASK((width), (offset), (data)) >> (((signed) (shift)))) \ - -char _util_unpackb(const char *src, int pos, int len); -char _util_convert_byte_hexChar (char val); -gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes); - -void util_hex_dump(char *pad, int size, const void *data) -{ - char buf[255] = {0, }; - char hex[4] = {0, }; - int i; - unsigned char *p; - - if (size <= 0) { - msg("%sno data", pad); - return; - } - - p = (unsigned char *)data; - - snprintf(buf, 255, "%s%04X: ", pad, 0); - for (i = 0; imsg_auto_id_current == 0) { - gd->msg_auto_id_current = gd->msg_auto_id_start; - dbg("pending_auto_id_current is 0, reset to start"); - } - else if (gd->msg_auto_id_current >= gd->msg_auto_id_end) { - gd->msg_auto_id_current = gd->msg_auto_id_start; - dbg("pending_auto_id_current is over, reset to start"); - } - else { - gd->msg_auto_id_current++; - } - - dbg("message_sequence_id = %d", gd->msg_auto_id_current); - - return gd->msg_auto_id_current; -} - -gboolean util_add_waiting_job(GQueue *queue, unsigned int id, UserRequest *ur) -{ - struct work_queue_data *wqd; - - if (!queue) - return FALSE; - - wqd = calloc(sizeof(struct work_queue_data), 1); - if (!wqd) - return FALSE; - - wqd->id = id; - wqd->ur = tcore_user_request_ref(ur); - g_queue_push_tail(queue, wqd); - - dbg("id = %d, ur = 0x%x", wqd->id, wqd->ur); - return TRUE; -} - -UserRequest *util_pop_waiting_job(GQueue *queue, unsigned int id) -{ - int i = 0; - UserRequest *ur; - struct work_queue_data *wqd; - - if (!queue) - return NULL; - - - dbg("before waiting job count: %d", g_queue_get_length(queue)); - - do { - wqd = g_queue_peek_nth(queue, i); - if (!wqd) - return NULL; - - if (wqd->id == id) { - wqd = g_queue_pop_nth(queue, i); - break; - } - - i++; - } while (wqd != NULL); - - dbg("after waiting job count: %d", g_queue_get_length(queue)); - - if (!wqd) - return NULL; - - ur = wqd->ur; - free(wqd); - - return ur; -} - -unsigned char util_hexCharToInt(char c) -{ - if (c >= '0' && c <= '9') - return (c - '0'); - else if (c >= 'A' && c <= 'F') - return (c - 'A' + 10); - else if (c >= 'a' && c <= 'f') - return (c - 'a' + 10); - else - { - dbg("invalid charater!!"); - return -1; - } -} - -char * util_hexStringToBytes(char * s) -{ - char * ret; - int i; - int sz; - - if (s == NULL) - return NULL; - - sz = strlen(s); - - ret = calloc((sz/2)+1, 1); - - dbg("Convert String to Binary!!"); - - for (i = 0; i < sz; i += 2) - { - ret[i / 2] = (char) ((util_hexCharToInt(s[i]) << 4) | util_hexCharToInt(s[i + 1])); - dbg("[%02x]", ret[i/2]); - } - - return ret; -} - -char _util_unpackb(const char *src, int pos, int len) -{ - char result = 0; - int rshift = 0; - - src += pos/8; - pos %= 8; - - rshift = MAX( 8 - (pos + len), 0); - - if ( rshift > 0 ) { - - result = MASK_AND_SHIFT(len, pos, rshift, *src); - - } else { - - result = MASK(8-pos, pos, *src); - src++; - len -= 8 - pos; - - if ( len > 0 ) result = ( result<> (8-len)); // if any bits left - } - - return result; -} - -char _util_convert_byte_hexChar (char val) -{ - char hex_char; - - if (val <= 9) - { - hex_char = (char)(val+'0'); - } - else if (val >= 10 && val <= 15) - { - hex_char = (char)(val-10+'A'); - } - else - { - hex_char = '0'; - } - - return (hex_char); -} - -gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes) -{ - int i; - char nibble; - int buf_pos = 0; - - for (i=0; i + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include + + +#include "s_common.h" + +#include + +#undef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) + +#undef MIN +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + +#define bitsize(type) (sizeof(type) * 8) + +#define copymask(type) ((0xffffffff) >> (32 - bitsize(type))) + +#define MASK(width, offset, data) \ + (((width) == bitsize(data)) ? (data) : \ + ((((copymask(data) << (bitsize(data) - ((width) % bitsize(data)))) & copymask(data)) >> (offset)) & (data))) \ + + +#define MASK_AND_SHIFT(width, offset, shift, data) \ + ((((signed) (shift)) < 0) ? \ + MASK((width), (offset), (data)) << -(shift) : \ + MASK((width), (offset), (data)) >> (((signed) (shift)))) \ + +char _util_unpackb(const char *src, int pos, int len); +char _util_convert_byte_hexChar(char val); +gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes); + +void util_hex_dump(char *pad, int size, const void *data) +{ + char buf[255] = {0, }; + char hex[4] = {0, }; + int i; + unsigned char *p; + + if (size <= 0) { + msg("%sno data", pad); + return; + } + + p = (unsigned char *) data; + + snprintf(buf, 255, "%s%04X: ", pad, 0); + for (i = 0; i < size; i++) { + snprintf(hex, 4, "%02X ", p[i]); + strcat(buf, hex); + + if ((i + 1) % 8 == 0) { + if ((i + 1) % 16 == 0) { + msg("%s", buf); + memset(buf, 0, 255); + snprintf(buf, 255, "%s%04X: ", pad, i + 1); + } else { + strcat(buf, " "); + } + } + } + + msg("%s", buf); +} + +void hook_hex_dump(enum direction_e d, int size, const void *data) +{ + msg("=== TX data DUMP ====="); + util_hex_dump(" ", size, data); + msg("=== TX data DUMP ====="); +} + +unsigned int util_assign_message_sequence_id(TcorePlugin *p) +{ + struct global_data *gd; + + if (!p) { + dbg("plugin is NULL"); + return -1; + } + + gd = tcore_plugin_ref_user_data(p); + if (!gd) { + dbg("global data is NULL"); + return -1; + } + + if (gd->msg_auto_id_current == 0) { + gd->msg_auto_id_current = gd->msg_auto_id_start; + dbg("pending_auto_id_current is 0, reset to start"); + } else if (gd->msg_auto_id_current >= gd->msg_auto_id_end) { + gd->msg_auto_id_current = gd->msg_auto_id_start; + dbg("pending_auto_id_current is over, reset to start"); + } else { + gd->msg_auto_id_current++; + } + + dbg("message_sequence_id = %d", gd->msg_auto_id_current); + + return gd->msg_auto_id_current; +} + +gboolean util_add_waiting_job(GQueue *queue, unsigned int id, UserRequest *ur) +{ + struct work_queue_data *wqd; + + if (!queue) + return FALSE; + + wqd = calloc(sizeof(struct work_queue_data), 1); + if (!wqd) + return FALSE; + + wqd->id = id; + wqd->ur = tcore_user_request_ref(ur); + g_queue_push_tail(queue, wqd); + + dbg("id = %d, ur = 0x%x", wqd->id, wqd->ur); + return TRUE; +} + +UserRequest* util_pop_waiting_job(GQueue *queue, unsigned int id) +{ + int i = 0; + UserRequest *ur; + struct work_queue_data *wqd; + + if (!queue) + return NULL; + + + dbg("before waiting job count: %d", g_queue_get_length(queue)); + + do { + wqd = g_queue_peek_nth(queue, i); + if (!wqd) + return NULL; + + if (wqd->id == id) { + wqd = g_queue_pop_nth(queue, i); + break; + } + + i++; + } while (wqd != NULL); + + dbg("after waiting job count: %d", g_queue_get_length(queue)); + + if (!wqd) + return NULL; + + ur = wqd->ur; + free(wqd); + + return ur; +} + +unsigned char util_hexCharToInt(char c) +{ + if (c >= '0' && c <= '9') + return (c - '0'); + else if (c >= 'A' && c <= 'F') + return (c - 'A' + 10); + else if (c >= 'a' && c <= 'f') + return (c - 'a' + 10); + else { + dbg("invalid charater!!"); + return -1; + } +} + +char* util_hexStringToBytes(char *s) +{ + char *ret; + int i; + int sz; + + if (s == NULL) + return NULL; + + sz = strlen(s); + + ret = calloc((sz / 2) + 1, 1); + + dbg("Convert String to Binary!!"); + + for (i = 0; i < sz; i += 2) { + ret[i / 2] = (char) ((util_hexCharToInt(s[i]) << 4) | util_hexCharToInt(s[i + 1])); + dbg("[%02x]", ret[i / 2]); + } + + return ret; +} + +char _util_unpackb(const char *src, int pos, int len) +{ + char result = 0; + int rshift = 0; + + src += pos / 8; + pos %= 8; + + rshift = MAX(8 - (pos + len), 0); + + if (rshift > 0) { + result = MASK_AND_SHIFT(len, pos, rshift, *src); + } else { + result = MASK(8 - pos, pos, *src); + src++; + len -= 8 - pos; + + if (len > 0) result = (result << len) | (*src >> (8 - len)); // if any bits left + } + + return result; +} + +char _util_convert_byte_hexChar(char val) +{ + char hex_char; + + if (val <= 9) { + hex_char = (char) (val + '0'); + } else if (val >= 10 && val <= 15) { + hex_char = (char) (val - 10 + 'A'); + } else { + hex_char = '0'; + } + + return (hex_char); +} + +gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes) +{ + int i; + char nibble; + int buf_pos = 0; + + for (i = 0; i < num_bytes * 2; i++) { + nibble = _util_unpackb(byte_pdu, buf_pos, 4); + buf_pos += 4; + hex_pdu[i] = _util_convert_byte_hexChar(nibble); + } + + return TRUE; } char* util_removeQuotes(void *data) @@ -288,14 +273,13 @@ char* util_removeQuotes(void *data) char *tmp = NULL; int data_len = 0; - data_len = strlen((const char*)data); + data_len = strlen((const char *) data); dbg("data_len: %d----%s", data_len, data); - if(data_len <= 0) - { + if (data_len <= 0) { return NULL; - } - tmp = calloc(1, data_len-1); - memcpy(tmp, data+1, data_len-2); + } + tmp = calloc(1, data_len - 1); + memcpy(tmp, data + 1, data_len - 2); dbg("tmp: %s", tmp); return tmp; diff --git a/src/s_modem.c b/src/s_modem.c index f222a8b..de4aac8 100755 --- a/src/s_modem.c +++ b/src/s_modem.c @@ -1,981 +1,950 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Harish Bishnoi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "s_common.h" -#include "s_modem.h" - - -#define ID_RESERVED_AT 0x0229 - -#define MAX_VERSION_LEN 32 -#define TAPI_MISC_ME_SN_LEN_MAX 32 -#define TAPI_MISC_PRODUCT_CODE_LEN_MAX 32 -#define TAPI_MISC_MODEL_ID_LEN_MAX 17 -#define TAPI_MISC_PRL_ERI_VER_LEN_MAX 17 - -#define CPAS_RES_READY 0 -#define CPAS_RES_UNAVAIL 1 -#define CPAS_RES_UNKNOWN 2 -#define CPAS_RES_RINGING 3 -#define CPAS_RES_CALL_PROGRESS 4 -#define CPAS_RES_ASLEEP 5 -#define AT_VER_LEN 20 - - -enum cp_state { - CP_STATE_OFFLINE, - CP_STATE_CRASH_RESET, - CP_STATE_CRASH_EXIT, - CP_STATE_BOOTING, - CP_STATE_ONLINE, - CP_STATE_NV_REBUILDING, - CP_STATE_LOADER_DONE, -}; - -typedef enum { - TAPI_MISC_ME_IMEI = 0x00, /**< 0x00: IMEI, GSM/UMTS device */ - TAPI_MISC_ME_ESN = 0x01, /**< 0x01: ESN(Electronic Serial Number), It`s essentially run out. CDMA device */ - TAPI_MISC_ME_MEID = 0x02, /**< 0x02: MEID, This value can have hexa decimal digits. CDMA device */ - TAPI_MISC_ME_MAX = 0xff /**< 0xff: reserved */ -} TelMiscSNIndexType_t; - -typedef struct { - TelMiscSNIndexType_t sn_index; /**< serial number index */ - int sn_len; /**< Length */ - unsigned char szNumber[TAPI_MISC_ME_SN_LEN_MAX]; /**< Number */ -} TelMiscSNInformation; - -/** - * Mobile Equipment Version Information - */ -typedef struct { - unsigned char ver_mask; /**< version mask - 0x01:SW_ver, 0x02:HW_ver, 0x04:RF_CAL_date, 0x08:Product_code, 0x10:Model_ID, 0x20:PRL, 0x04:ERI, 0xff:all */ - unsigned char szSwVersion[MAX_VERSION_LEN]; /**< Software version, null termination */ - unsigned char szHwVersion[MAX_VERSION_LEN]; /**< Hardware version, null termination */ - unsigned char szRfCalDate[MAX_VERSION_LEN]; /**< Calculation Date, null termination */ - unsigned char szProductCode[TAPI_MISC_PRODUCT_CODE_LEN_MAX]; /**< product code, null termination */ - unsigned char szModelId[TAPI_MISC_MODEL_ID_LEN_MAX]; /**< model id (only for CDMA), null termination */ - unsigned char prl_nam_num; /**< number of PRL NAM fields */ - unsigned char szPrlVersion[TAPI_MISC_PRL_ERI_VER_LEN_MAX * 3];/**< prl version (only for CDMA), null termination */ - unsigned char eri_nam_num; /**< number of PRL NAM fields */ - unsigned char szEriVersion[TAPI_MISC_PRL_ERI_VER_LEN_MAX * 3];/**< eri version (only for CDMA), null termination */ -} TelMiscVersionInformation; - - -void prepare_and_send_pending_request(TcorePlugin *plugin, char *co_name, const char *at_cmd, const char* prefix, enum tcore_at_command_type at_cmd_type, TcorePendingResponseCallback callback); -static void on_confirmation_modem_message_send(TcorePending *p, gboolean result, void *user_data); // from Kernel -void on_response_bootup_subscription(TcorePending *p, int data_len, const void *data, void *user_data); -void on_response_last_bootup_subscription(TcorePending *p, int data_len, const void *data, void *user_data); -static void on_timeout_modem_poweron(TcorePending *p, void *user_data); -static void on_response_enable_proactive_command(TcorePending *p, int data_len, const void *data, void *user_data); - -static void on_timeout_modem_poweron(TcorePending *p, void *user_data) -{ - unsigned int data_len = 0; - char data[] = "AT+CPAS"; - dbg("TIMEOUT for 1st AT Command !!!!! NO Response for initial AT command. Resending it"); - data_len = sizeof(data); - - /* Retransmit 1st AT command directly via HAL, don't disturb pending queue. */ - /* HAL was passed as user_data, re-use it */ - if (user_data) - { - tcore_hal_send_data(user_data, data_len, (void *)data); - } -} - -static void on_confirmation_modem_message_send(TcorePending *p, gboolean result, void *user_data) -{ - dbg("on_confirmation_modem_message_send - msg out from queue.\n"); - - if (result == FALSE) { - /* Fail */ - dbg("SEND FAIL"); - } - else { - dbg("SEND OK"); - } -} - -static void on_response_enable_proactive_command(TcorePending *p, int data_len, const void *data, void *user_data) -{ - const TcoreATResponse *resp = data; - - if(resp->success > 0){ - dbg("RESPONSE OK proactive command enabled"); - - } - else { - dbg("RESPONSE NOK proactive command disabled"); - } -} - -void prepare_and_send_pending_request(TcorePlugin *plugin, char *co_name, const char *at_cmd, const char* prefix, enum tcore_at_command_type at_cmd_type, TcorePendingResponseCallback callback) -{ - TcoreATRequest *req = NULL; - TcoreHal *hal = NULL; - CoreObject *o= NULL; - TcorePending *pending = NULL; - TReturn ret; - - o = tcore_plugin_ref_core_object(plugin, co_name); - hal = tcore_object_get_hal(o); - dbg("hal: %p", hal); - - pending = tcore_pending_new(o, 0); - if(!pending) - dbg("Pending is NULL"); - req = tcore_at_request_new(at_cmd, prefix, at_cmd_type); - - dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_request_data(pending, 0, req); - tcore_pending_set_response_callback(pending, callback, NULL); - tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); - tcore_pending_link_user_request(pending, NULL); //set user request to NULL - this is intenal request - ret = tcore_hal_send_request(hal, pending); - return; -} - -void on_response_bootup_subscription(TcorePending *p, int data_len, const void *data, void *user_data) -{ - const TcoreATResponse *resp = data; - dbg("entry of on_response_bootup_subscription() - response comes\n"); - - if(resp->success){ - dbg("result OK"); - } - else{ - dbg("result ERROR"); - } -} - -void on_response_last_bootup_subscription(TcorePending *p, int data_len, const void *data, void *user_data) -{ - const TcoreATResponse *resp = data; - dbg("enry of on_response_last_bootup_subscription() - final response comes\n"); - if(resp->success){ - dbg("SEND OK"); - } - else{ - dbg("SEND FAIL"); - } - dbg("Response for AT+CLIP. Boot-up configration completed for IMC modem. Bring CP to online based on Flightmode status\n"); - on_event_modem_power(NULL, NULL, tcore_pending_ref_plugin(p)); -} - -static void on_response_power_off(TcorePending *p, int data_len, const void *data, void *user_data) -{ - CoreObject *o = 0; - TcoreHal *h = 0; - o = tcore_pending_ref_core_object(p); - h = tcore_object_get_hal(o); - - dbg("modem power off"); - - tcore_hal_set_power_state(h, FALSE); -} - -static void on_response_set_flight_mode(TcorePending *p, int data_len, const void *data, void *user_data) -{ - CoreObject *o = NULL; - UserRequest *ur = NULL; - const TcoreATResponse *ATresp = data; - GSList *tokens=NULL; - const char *line = NULL; - struct tresp_modem_set_flightmode res = {0}; - int response = 0; - struct tnoti_modem_flight_mode modem_flight_mode = {0}; - const struct treq_modem_set_flightmode *req_data = NULL; - - o = tcore_pending_ref_core_object(p); - - if(ATresp->success > 0){ - dbg("RESPONSE OK - flight mode operation finished"); - res.result = TCORE_RETURN_SUCCESS; - } - else { - dbg("RESPONSE NOK"); - line = (const char*)ATresp->final_response; - tokens = tcore_at_tok_new(line); - - if (g_slist_length(tokens) < 1) { - dbg("err cause not specified or string corrupted"); - res.result = TCORE_RETURN_3GPP_ERROR; - } - else { - response = atoi(g_slist_nth_data(tokens, 0)); - /* TODO: CMEE error mapping is required. */ - res.result = TCORE_RETURN_3GPP_ERROR; - } - } - - ur = tcore_pending_ref_user_request(p); - if(NULL == ur){ - dbg("No user request. Internal request created during boot-up sequence"); - - if(ATresp->success > 0){ - modem_flight_mode.enable = tcore_modem_get_flight_mode_state(o); - dbg("sucess case - Sending Flight Mode Notification (%d) to Telephony Server",modem_flight_mode.enable); - - tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_MODEM_FLIGHT_MODE, - sizeof(struct tnoti_modem_flight_mode), &modem_flight_mode); - } - } - else{ - dbg("Sending response for Flight mode operation"); - tcore_user_request_send_response(ur, TRESP_MODEM_SET_FLIGHTMODE, sizeof(struct tresp_modem_set_flightmode), &res); - - req_data = tcore_user_request_ref_data(ur, NULL); - - if (req_data->enable == 0) { - dbg("Flight mode is disabled, trigger COPS to register on network"); - /* Trigger Network registration (for the moment automatic) */ - prepare_and_send_pending_request(tcore_object_ref_plugin(o), "modem", "AT+COPS=0", NULL, TCORE_AT_NO_RESULT, NULL); - } - } - - tcore_at_tok_free(tokens); -} - -static void on_response_imei(TcorePending *p, int data_len, const void *data, void *user_data) -{ - const TcoreATResponse* resp = data; - TcorePlugin *plugin = NULL; - struct tresp_modem_get_imei res; - TelMiscSNInformation *imei_property = NULL; - UserRequest* ur = NULL; - GSList *tokens=NULL; - const char *line; - int response = 0; - - memset(&res, 0, sizeof(struct tresp_modem_get_imei)); - - if(resp->success > 0) - { - dbg("RESPONSE OK"); - if(resp->lines) { - line = (const char*)resp->lines->data; - tokens = tcore_at_tok_new(line); - if (g_slist_length(tokens) != 1) { - msg("invalid message"); - goto OUT; - } - } - res.result = TCORE_RETURN_SUCCESS; - strncpy(res.imei, g_slist_nth_data(tokens, 0), 16); - - dbg("imei = [%s]", res.imei); - - plugin = tcore_pending_ref_plugin(p); - imei_property = tcore_plugin_ref_property(plugin, "IMEI"); - if (imei_property) - { - imei_property->sn_index = TAPI_MISC_ME_IMEI; - imei_property->sn_len = strlen(res.imei); - memcpy(imei_property->szNumber, res.imei, imei_property->sn_len); - } - } - else - { - dbg("RESPONSE NOK"); - if(resp->lines) { - line = (const char*)resp->lines->data; - tokens = tcore_at_tok_new(line); - } - - - if (g_slist_length(tokens) < 1) { - dbg("err cause not specified or string corrupted"); - res.result = TCORE_RETURN_3GPP_ERROR; - } - else - { - response = atoi(g_slist_nth_data(tokens, 0)); - /* TODO: CMEE error mapping is required. */ - res.result = TCORE_RETURN_3GPP_ERROR; - } - } - - ur = tcore_pending_ref_user_request(p); - tcore_user_request_send_response(ur, TRESP_MODEM_GET_IMEI, sizeof(struct tresp_modem_get_imei), &res); - -OUT: - if(tokens != NULL) - tcore_at_tok_free(tokens); - - return; -} - -static void on_response_version(TcorePending *p, int data_len, const void *data, void *user_data) -{ - const TcoreATResponse *resp = data; - TcorePlugin *plugin = NULL; - struct tresp_modem_get_version res = {0}; - TelMiscVersionInformation *vi_property = NULL; - TelMiscVersionInformation *vi = NULL; - UserRequest *ur = NULL; - GSList* tokens = NULL; - const char* line=NULL; - char *swver= NULL; - char *hwver=NULL; - char *caldate=NULL; - char *pcode=NULL; - char *id=NULL; - - int response = 0; - - if(resp->success > 0) - { - dbg("RESPONSE OK"); - if(resp->lines) { - line = (const char*)resp->lines->data; - tokens = tcore_at_tok_new(line); - if (g_slist_length(tokens) != 5) { - msg("invalid message"); - goto OUT; - } - } - - swver = g_slist_nth_data(tokens, 0); - hwver = g_slist_nth_data(tokens, 1); - caldate = g_slist_nth_data(tokens, 2); - pcode = g_slist_nth_data(tokens, 3); - id = g_slist_nth_data(tokens, 4); - - dbg("version: sw=[%s], hw=[%s], rf_cal=[%s], product_code=[%s], model_id=[%s]", swver, hwver, caldate, pcode, id); - - vi = calloc(sizeof(TelMiscVersionInformation), 1); - if(NULL!=swver) - memcpy(vi->szSwVersion, swver, strlen(swver)); - if(NULL!=hwver) - memcpy(vi->szHwVersion, hwver, strlen(hwver)); - if(NULL!=caldate) - memcpy(vi->szRfCalDate, caldate, strlen(caldate)); - if(NULL!=pcode) - memcpy(vi->szProductCode, pcode,strlen(pcode)); - if(NULL!=id) - memcpy(vi->szModelId, id, strlen(id)); - - memset(&res, 0, sizeof(struct tresp_modem_get_version)); - - if(NULL!=swver) - snprintf(res.software, (AT_VER_LEN >strlen(swver) ?strlen(swver):AT_VER_LEN), "%s", swver); - if(NULL!=hwver) - snprintf(res.hardware, (AT_VER_LEN >strlen(hwver) ?strlen(hwver):AT_VER_LEN), "%s", hwver); - - plugin = tcore_pending_ref_plugin(p); - vi_property = tcore_plugin_ref_property(plugin, "VERSION"); - memcpy(vi_property, vi, sizeof(TelMiscVersionInformation)); - free(vi); - } - else - { - dbg("RESPONSE NOK"); - if(resp->lines) { - line = (const char*)resp->lines->data; - tokens = tcore_at_tok_new(line); - } - - memset(&res, 0, sizeof(struct tresp_modem_get_version)); - - - if (g_slist_length(tokens) < 1) { - dbg("err cause not specified or string corrupted"); - res.result = TCORE_RETURN_3GPP_ERROR; - } - else - { - response = atoi(g_slist_nth_data(tokens, 0)); - /* TODO: CMEE error mapping is required. */ - res.result = TCORE_RETURN_3GPP_ERROR; - } - } - - ur = tcore_pending_ref_user_request(p); - tcore_user_request_send_response(ur, TRESP_MODEM_GET_VERSION, sizeof(struct tresp_modem_get_version), &res); - -OUT: - if(tokens != NULL) - tcore_at_tok_free(tokens); - - return; -} - -static gboolean on_event_bootup_sim_status(CoreObject *o, const void *event_info, void *user_data) -{ - GSList *tok = NULL; - GSList *lines = NULL; - int value = -1; - char* line = NULL; - - lines = (GSList*)event_info; - if (1 != g_slist_length(lines)) { - dbg("unsolicited msg but multiple line"); - goto OUT; - } - line = (char*)(lines->data); - dbg("on_bootup_event_sim_status notification : %s", line); - - tok = tcore_at_tok_new(line); - value = atoi(g_slist_nth_data(tok, 0)); - - if(7 == value){ - dbg("SIM ready. request COPS & remove callback"); - dbg("power on done set for proactive command receiving mode"); - prepare_and_send_pending_request(tcore_object_ref_plugin(o), "sat", "AT+CFUN=6", NULL, TCORE_AT_NO_RESULT, on_response_enable_proactive_command); - prepare_and_send_pending_request(tcore_object_ref_plugin(o), "umts_network", "AT+COPS=0", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - return FALSE; - } - -OUT: - if (tok != NULL) - tcore_at_tok_free(tok); - - return TRUE; -} - - - -gboolean on_event_modem_power(TcoreAT *at, const char *line, TcorePlugin *p) -{ - CoreObject *o = NULL; - struct treq_modem_set_flightmode flight_mode_set = {0}; - struct tnoti_modem_power modem_power = {0}; - TcoreHal *h = NULL; - Storage *strg = NULL; - - o = tcore_plugin_ref_core_object(p, "modem"); - - strg = tcore_server_find_storage(tcore_plugin_ref_server(p), "vconf"); - flight_mode_set.enable = tcore_storage_get_bool(strg, STORAGE_KEY_SETAPPL_FLIGHT_MODE_BOOL); - - h = tcore_object_get_hal(o); - tcore_hal_set_power_state(h, TRUE); - - /* Set Flight mode as per AP settings */ - if (flight_mode_set.enable) - { /* Radio Off */ - prepare_and_send_pending_request(p, "modem", "AT+CFUN=4", NULL, TCORE_AT_NO_RESULT, on_response_set_flight_mode); - tcore_modem_set_flight_mode_state(o, TRUE); - } - else - {/* Radio On */ - prepare_and_send_pending_request(p, "modem", "AT+CFUN=1", NULL, TCORE_AT_NO_RESULT, on_response_set_flight_mode); - tcore_modem_set_flight_mode_state(o, FALSE); - } - - /* Get IMEI */ - prepare_and_send_pending_request(p, "modem", "AT+CGSN", NULL, TCORE_AT_NUMERIC, on_response_imei); - - /* Get Version Number */ - prepare_and_send_pending_request(p, "modem", "AT+CGMR", NULL, TCORE_AT_SINGLELINE, on_response_version); - - tcore_modem_set_powered(o, TRUE); - - modem_power.state = MODEM_STATE_ONLINE; - - tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_MODEM_POWER, - sizeof(struct tnoti_modem_power), &modem_power); - - return TRUE; -} - -static void _modem_subscribe_events(TcorePlugin *plugin) -{ - dbg("Entry"); - - /* XCALLSTAT subscription */ - prepare_and_send_pending_request(plugin, "call", "at+xcallstat=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /* XSIMSTATE subscription */ - prepare_and_send_pending_request(plugin, "sim", "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - prepare_and_send_pending_request(plugin, "umts_sms", "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - prepare_and_send_pending_request(plugin, "modem", "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /* CREG subscription */ - prepare_and_send_pending_request(plugin, "umts_network", "at+creg=2", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /* CGREG subscription */ - prepare_and_send_pending_request(plugin, "umts_network", "at+cgreg=2", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /* Allow automatic time Zone updation via NITZ */ - prepare_and_send_pending_request(plugin, "umts_network", "at+ctzu=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /* TZ, time & daylight changing event reporting subscription */ - prepare_and_send_pending_request(plugin, "umts_network", "at+ctzr=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /* XMER subscription */ - prepare_and_send_pending_request(plugin, "umts_network", "at+xmer=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /* CGEREP subscription */ - prepare_and_send_pending_request(plugin, "umts_ps", "at+cgerep=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /* XDATASTAT subscription */ - prepare_and_send_pending_request(plugin, "umts_ps", "at+xdatastat=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /* CSSN subscription */ - prepare_and_send_pending_request(plugin, "call", "at+cssn=1,1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /* CUSD subscription */ - prepare_and_send_pending_request(plugin, "call", "at+cusd=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /* XDNS subscription */ - prepare_and_send_pending_request(plugin, "umts_ps", "at+xdns=1,1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /* CLIP subscription */ - prepare_and_send_pending_request(plugin, "call", "at+clip=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /*CMEE subscription*/ - prepare_and_send_pending_request(plugin,"umts_ps","at+cmee=2",NULL,TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /*incoming sms,cb,status report subscription*/ - prepare_and_send_pending_request(plugin,"umts_sms","at+cnmi=1,2,2,1,0",NULL,TCORE_AT_NO_RESULT, on_response_bootup_subscription); - - /* text/pdu mode subscription*/ - prepare_and_send_pending_request(plugin,"umts_sms","at+cmgf=0",NULL,TCORE_AT_NO_RESULT, on_response_last_bootup_subscription); - - dbg("Exit"); - return; -} - - -static void on_response_setupmux(TcorePending *p, int data_len, const void *data, void *user_data) -{ - TcorePlugin *plugin = NULL; - TcoreHal *hal = NULL; - TReturn ret; - dbg("Entry"); - - /* IMC Plugin dereferenced from pending request */ - plugin = tcore_pending_ref_plugin(p); - - /* Actual HAL - like svnet(2) */ - hal = (TcoreHal *)user_data; - - /* Initialize CMUX */ - ret = tcore_cmux_init(plugin, hal); - if(TCORE_RETURN_SUCCESS == ret) { - dbg("Successfully initialized CMUX"); - } - else { - err("Failed to initialize CMUX"); - } - - dbg("Exit"); - return; -} - - - -static void setup_mux(CoreObject *o) -{ - TcoreHal* hal = NULL; - TcorePending *pending = NULL; - dbg("Entered"); - - /* HAL has type itself, - * e.g.) TCORE_HAL_MODE_AT - */ - hal = tcore_object_get_hal(o); - - pending = tcore_at_pending_new(o, "AT+CMUX=0,0,,1509,10,3,30,,", "+CMUX", TCORE_AT_NO_RESULT, on_response_setupmux, hal); - - tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); - - /* Send callback */ - tcore_hal_send_request(hal, pending); - - dbg("Exit"); - return; -} - - -static gboolean on_event_mux_channel_up(CoreObject *o, const void *event_info, void *user_data) -{ - TcorePlugin *plugin = NULL; - dbg("Entry"); - - plugin = (TcorePlugin *)user_data; - _modem_subscribe_events(plugin); - dbg("Exit"); - return TRUE; -} - - -static void on_response_enable_logging(TcorePending *p, int data_len, const void *data, void *user_data) -{ - const TcoreATResponse *resp = data; - TcorePlugin *plugin = NULL; - - plugin = tcore_pending_ref_plugin(p); - - /* DELETE ME: only for DEBUG */ - if (!resp) - dbg("no data"); - - dbg("response...(result = %d, final_response = '%s')", resp->success, resp->final_response); - - if(resp->success){ - dbg("RESPONSE OK"); - dbg("Enabling CP logging is success !!!\n"); - - }else { - dbg("RESPONSE NOK"); - dbg("Enabling CP logging is failed !!!\n"); - } - - dbg("Calling setup_mux"); - setup_mux(tcore_pending_ref_core_object(p)); - - - dbg("Exit"); - return; - -} - -static void _send_enable_logging_command(CoreObject *o) -{ - TcoreATRequest *req = NULL; - TcoreHal *hal = NULL; - TcorePending *pending = NULL; - TReturn ret = 0; - - /* DLELTE ME */ - dbg("Send Trace enabling command for CP logging. \n"); - - if(!o){ - dbg("Co-object is Null !!\n"); - //goto error; - } - - hal = tcore_object_get_hal(o); - pending = tcore_pending_new(o, 0); - req = tcore_at_request_new("at+xsystrace=1,\"digrf=1;bb_sw=1;3g_sw=1\",\"digrf=0x84\",\"oct=4\";+xsystrace=11;+trace=1", NULL, TCORE_AT_NO_RESULT); - - dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_request_data(pending, 0, req); - tcore_pending_set_response_callback(pending, on_response_enable_logging, hal); - tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); - - ret = tcore_hal_send_request(hal, pending); - if(ret != TCORE_RETURN_SUCCESS) - dbg("tcore_hal_send_request fail !!! (hal: 0x%x, pending: 0x%x)\n", hal, pending); - -} - -static void on_response_poweron(TcorePending *p, int data_len, const void *data, void *user_data) -{ - const TcoreATResponse *resp = data; - GSList*tokens=NULL; - const char *line=NULL; - gboolean bpoweron = FALSE; - int response = 0; - - if(resp->success){ - dbg("RESPONSE OK"); - /* Parse AT Response */ - if (resp->lines) { - line = (const char *)resp->lines->data; - tokens = tcore_at_tok_new(line); - if (g_slist_length(tokens) != 1) { - dbg("invalid message"); - bpoweron = FALSE; - goto error; - } - } - - response = atoi(g_slist_nth_data(tokens, 0)); - - dbg("CPAS: response %d",response); - - switch(response) - { - case CPAS_RES_READY: - case CPAS_RES_RINGING: - case CPAS_RES_CALL_PROGRESS: - case CPAS_RES_ASLEEP: - bpoweron = TRUE; - break; - - case CPAS_RES_UNAVAIL: - case CPAS_RES_UNKNOWN: - default: - dbg("value is unvail/unknown - but CP responded - proceed poweron"); - //bpoweron = FALSE; - bpoweron = TRUE; - break; - } - }else{ - dbg("CPAS: RESPONSE NOK"); - bpoweron = FALSE; - } - -error: - /* DELE ME: AT request & response are freed after AT processing in HAL. - * ref.) _emit_pending_response (libtcore/src/at.c) - */ - if(tokens != NULL) - tcore_at_tok_free(tokens); - - if(bpoweron == TRUE){ - dbg("Power on NOTI received, (pending: 0x%x, co: 0x%x)\n", p, tcore_pending_ref_core_object(p)); - - _send_enable_logging_command(tcore_pending_ref_core_object(p)); - } - else{ - dbg("CP is not ready, let us send CPAS once again"); - s_modem_send_poweron(tcore_object_ref_plugin(tcore_pending_ref_core_object(p))); - } - return; -} - -static TReturn power_off(CoreObject *o, UserRequest *ur) -{ - TcoreHal *hal = NULL; - TcoreATRequest *req = NULL; - TcorePending *pending = NULL; - - hal = tcore_object_get_hal(o); - pending = tcore_pending_new(o, 0); - - req = tcore_at_request_new("AT+CFUN=0", NULL, TCORE_AT_NO_RESULT); - - dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_request_data(pending, 0, req); - tcore_pending_set_response_callback(pending, on_response_power_off, hal); - tcore_pending_link_user_request(pending, ur); - tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); - - tcore_hal_send_request(hal, pending); - - return TCORE_RETURN_SUCCESS; -} - -static TReturn get_imei(CoreObject *o, UserRequest *ur) -{ - TcoreHal* hal; - TcoreATRequest *req; - TcorePending *pending = NULL; - - hal = tcore_object_get_hal(o); - pending = tcore_pending_new(o, 0); - - req = tcore_at_request_new("AT+CGSN", NULL, TCORE_AT_NUMERIC); - - dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_request_data(pending, 0, req); - tcore_pending_set_response_callback(pending, on_response_imei, hal); - tcore_pending_link_user_request(pending, ur); - tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); - - tcore_hal_send_request(hal, pending); - - return TCORE_RETURN_SUCCESS; -} - - -static TReturn get_version(CoreObject *o, UserRequest *ur) -{ - TcoreHal* hal; - TcoreATRequest *req; - TcorePending *pending = NULL; - - hal = tcore_object_get_hal(o); - pending = tcore_pending_new(o, 0); - - req = tcore_at_request_new("AT+CGMR", NULL, TCORE_AT_SINGLELINE); - - dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_request_data(pending, 0, req); - tcore_pending_set_response_callback(pending, on_response_version, hal); - tcore_pending_link_user_request(pending, ur); - tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); - - tcore_hal_send_request(hal, pending); - - return TCORE_RETURN_SUCCESS; -} - -static TReturn set_flight_mode(CoreObject *o, UserRequest *ur) -{ - TcoreHal *hal = NULL; - TcoreATRequest *req = NULL; - TcorePending *pending = NULL; - const struct treq_modem_set_flightmode *req_data = NULL; - char *cmd_str = NULL; - - hal = tcore_object_get_hal(o); - pending = tcore_pending_new(o, 0); - - req_data = tcore_user_request_ref_data(ur, NULL); - - if (req_data->enable) { - dbg("Flight mode on/n"); - cmd_str = g_strdup("AT+CFUN=4"); - } - else { - dbg("Flight mode off/n"); - cmd_str = g_strdup("AT+CFUN=1"); - } - - req = tcore_at_request_new((const char*)cmd_str, NULL, TCORE_AT_NO_RESULT); - - dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_request_data(pending, 0, req); - tcore_pending_set_response_callback(pending, on_response_set_flight_mode, hal); - tcore_pending_link_user_request(pending, ur); - tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); - - tcore_hal_send_request(hal, pending); - - return TCORE_RETURN_SUCCESS; -} - - -static struct tcore_modem_operations modem_ops = -{ - .power_on = NULL, - .power_off = power_off, - .power_reset = NULL, - .set_flight_mode = set_flight_mode, - .get_imei = get_imei, - .get_version = get_version, - .get_sn = NULL, - .dun_pin_ctrl = NULL, -}; - -gboolean s_modem_init(TcorePlugin *p, TcoreHal *h) -{ - CoreObject *o = NULL; - GQueue *work_queue = NULL; - TelMiscVersionInformation *vi_property = NULL; - TelMiscSNInformation *imei_property = NULL; - TelMiscSNInformation *sn_property = NULL; - - o = tcore_modem_new(p, "modem", &modem_ops, h); - if (!o) - return FALSE; - - work_queue = g_queue_new(); - tcore_object_link_user_data(o, work_queue); - - vi_property = calloc(sizeof(TelMiscVersionInformation), 1); - tcore_plugin_link_property(p, "VERSION", vi_property); - - imei_property = calloc(sizeof(TelMiscSNInformation), 1); - tcore_plugin_link_property(p, "IMEI", imei_property); - - sn_property = calloc(sizeof(TelMiscSNInformation), 1); - tcore_plugin_link_property(p, "SN", sn_property); - - dbg("Registerind for CMUX-UP event"); - tcore_object_add_callback(o, "CMUX-UP", on_event_mux_channel_up, p); - - dbg("Registering for +XSIM event"); - tcore_object_add_callback(o, "+XSIM", on_event_bootup_sim_status, NULL); - - return TRUE; -} - -void s_modem_exit(TcorePlugin *p) -{ - CoreObject *o = NULL; - GQueue *work_queue = NULL; - TelMiscVersionInformation *vi_property = NULL; - TelMiscSNInformation *imei_property = NULL; - TelMiscSNInformation *sn_property = NULL; - - if (!p) - return; - - o = tcore_plugin_ref_core_object(p, "modem"); - - work_queue = tcore_object_ref_user_data(o); - g_queue_free(work_queue); - - vi_property = tcore_plugin_ref_property(p, "VERSION"); - if (vi_property) - free(vi_property); - - imei_property = tcore_plugin_ref_property(p, "IMEI"); - if (imei_property) - free(imei_property); - - sn_property = tcore_plugin_ref_property(p, "SN"); - if (sn_property) - free(sn_property); - - tcore_modem_free(o); - return; -} - -gboolean s_modem_send_poweron(TcorePlugin *p) -{ - TcoreHal* hal; - TcoreATRequest *req; - TcorePending *pending = NULL; - CoreObject *o; - - o = tcore_plugin_ref_core_object(p, "modem"); - hal = tcore_object_get_hal(o); - - pending = tcore_pending_new(o, 0); - - req = tcore_at_request_new("AT+CPAS", "+CPAS", TCORE_AT_SINGLELINE); - - dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_timeout(pending, 10); - tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT); - tcore_pending_set_timeout_callback(pending, on_timeout_modem_poweron, hal); - - tcore_pending_set_request_data(pending, 0, req); - tcore_pending_set_response_callback(pending, on_response_poweron, hal); - tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); - - tcore_hal_send_request(hal, pending); - - return TRUE; -} +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Harish Bishnoi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "s_common.h" +#include "s_modem.h" + + +#define ID_RESERVED_AT 0x0229 + +#define MAX_VERSION_LEN 32 +#define TAPI_MISC_ME_SN_LEN_MAX 32 +#define TAPI_MISC_PRODUCT_CODE_LEN_MAX 32 +#define TAPI_MISC_MODEL_ID_LEN_MAX 17 +#define TAPI_MISC_PRL_ERI_VER_LEN_MAX 17 + +#define CPAS_RES_READY 0 +#define CPAS_RES_UNAVAIL 1 +#define CPAS_RES_UNKNOWN 2 +#define CPAS_RES_RINGING 3 +#define CPAS_RES_CALL_PROGRESS 4 +#define CPAS_RES_ASLEEP 5 +#define AT_VER_LEN 20 + + +enum cp_state { + CP_STATE_OFFLINE, + CP_STATE_CRASH_RESET, + CP_STATE_CRASH_EXIT, + CP_STATE_BOOTING, + CP_STATE_ONLINE, + CP_STATE_NV_REBUILDING, + CP_STATE_LOADER_DONE, +}; + +typedef enum { + TAPI_MISC_ME_IMEI = 0x00, /**< 0x00: IMEI, GSM/UMTS device */ + TAPI_MISC_ME_ESN = 0x01, /**< 0x01: ESN(Electronic Serial Number), It`s essentially run out. CDMA device */ + TAPI_MISC_ME_MEID = 0x02, /**< 0x02: MEID, This value can have hexa decimal digits. CDMA device */ + TAPI_MISC_ME_MAX = 0xff /**< 0xff: reserved */ +} TelMiscSNIndexType_t; + +typedef struct { + TelMiscSNIndexType_t sn_index; /**< serial number index */ + int sn_len; /**< Length */ + unsigned char szNumber[TAPI_MISC_ME_SN_LEN_MAX]; /**< Number */ +} TelMiscSNInformation; + +/** + * Mobile Equipment Version Information + */ +typedef struct { + unsigned char ver_mask; /**< version mask - 0x01:SW_ver, 0x02:HW_ver, 0x04:RF_CAL_date, 0x08:Product_code, 0x10:Model_ID, 0x20:PRL, 0x04:ERI, 0xff:all */ + unsigned char szSwVersion[MAX_VERSION_LEN]; /**< Software version, null termination */ + unsigned char szHwVersion[MAX_VERSION_LEN]; /**< Hardware version, null termination */ + unsigned char szRfCalDate[MAX_VERSION_LEN]; /**< Calculation Date, null termination */ + unsigned char szProductCode[TAPI_MISC_PRODUCT_CODE_LEN_MAX]; /**< product code, null termination */ + unsigned char szModelId[TAPI_MISC_MODEL_ID_LEN_MAX]; /**< model id (only for CDMA), null termination */ + unsigned char prl_nam_num; /**< number of PRL NAM fields */ + unsigned char szPrlVersion[TAPI_MISC_PRL_ERI_VER_LEN_MAX * 3]; /**< prl version (only for CDMA), null termination */ + unsigned char eri_nam_num; /**< number of PRL NAM fields */ + unsigned char szEriVersion[TAPI_MISC_PRL_ERI_VER_LEN_MAX * 3]; /**< eri version (only for CDMA), null termination */ +} TelMiscVersionInformation; + + +void prepare_and_send_pending_request(TcorePlugin *plugin, char *co_name, const char *at_cmd, const char *prefix, enum tcore_at_command_type at_cmd_type, TcorePendingResponseCallback callback); +static void on_confirmation_modem_message_send(TcorePending *p, gboolean result, void *user_data); // from Kernel +void on_response_bootup_subscription(TcorePending *p, int data_len, const void *data, void *user_data); +void on_response_last_bootup_subscription(TcorePending *p, int data_len, const void *data, void *user_data); +static void on_timeout_modem_poweron(TcorePending *p, void *user_data); +static void on_response_enable_proactive_command(TcorePending *p, int data_len, const void *data, void *user_data); + +static void on_timeout_modem_poweron(TcorePending *p, void *user_data) +{ + unsigned int data_len = 0; + char data[] = "AT+CPAS"; + dbg("TIMEOUT for 1st AT Command !!!!! NO Response for initial AT command. Resending it"); + data_len = sizeof(data); + + /* Retransmit 1st AT command directly via HAL, don't disturb pending queue. */ + /* HAL was passed as user_data, re-use it */ + if (user_data) { + tcore_hal_send_data(user_data, data_len, (void *) data); + } +} + +static void on_confirmation_modem_message_send(TcorePending *p, gboolean result, void *user_data) +{ + dbg("on_confirmation_modem_message_send - msg out from queue.\n"); + + if (result == FALSE) { + /* Fail */ + dbg("SEND FAIL"); + } else { + dbg("SEND OK"); + } +} + +static void on_response_enable_proactive_command(TcorePending *p, int data_len, const void *data, void *user_data) +{ + const TcoreATResponse *resp = data; + + if (resp->success > 0) { + dbg("RESPONSE OK proactive command enabled"); + } else { + dbg("RESPONSE NOK proactive command disabled"); + } +} + +void prepare_and_send_pending_request(TcorePlugin *plugin, char *co_name, const char *at_cmd, const char *prefix, enum tcore_at_command_type at_cmd_type, TcorePendingResponseCallback callback) +{ + TcoreATRequest *req = NULL; + TcoreHal *hal = NULL; + CoreObject *o = NULL; + TcorePending *pending = NULL; + TReturn ret; + + o = tcore_plugin_ref_core_object(plugin, co_name); + hal = tcore_object_get_hal(o); + dbg("hal: %p", hal); + + pending = tcore_pending_new(o, 0); + if (!pending) + dbg("Pending is NULL"); + req = tcore_at_request_new(at_cmd, prefix, at_cmd_type); + + dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_request_data(pending, 0, req); + tcore_pending_set_response_callback(pending, callback, NULL); + tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); + tcore_pending_link_user_request(pending, NULL); // set user request to NULL - this is intenal request + ret = tcore_hal_send_request(hal, pending); + return; +} + +void on_response_bootup_subscription(TcorePending *p, int data_len, const void *data, void *user_data) +{ + const TcoreATResponse *resp = data; + dbg("entry of on_response_bootup_subscription() - response comes\n"); + + if (resp->success) { + dbg("result OK"); + } else { + dbg("result ERROR"); + } +} + +void on_response_last_bootup_subscription(TcorePending *p, int data_len, const void *data, void *user_data) +{ + const TcoreATResponse *resp = data; + dbg("enry of on_response_last_bootup_subscription() - final response comes\n"); + if (resp->success) { + dbg("SEND OK"); + } else { + dbg("SEND FAIL"); + } + dbg("Response for AT+CLIP. Boot-up configration completed for IMC modem. Bring CP to online based on Flightmode status\n"); + on_event_modem_power(NULL, NULL, tcore_pending_ref_plugin(p)); +} + +static void on_response_power_off(TcorePending *p, int data_len, const void *data, void *user_data) +{ + CoreObject *o = 0; + TcoreHal *h = 0; + o = tcore_pending_ref_core_object(p); + h = tcore_object_get_hal(o); + + dbg("modem power off"); + + tcore_hal_set_power_state(h, FALSE); +} + +static void on_response_set_flight_mode(TcorePending *p, int data_len, const void *data, void *user_data) +{ + CoreObject *o = NULL; + UserRequest *ur = NULL; + const TcoreATResponse *ATresp = data; + GSList *tokens = NULL; + const char *line = NULL; + struct tresp_modem_set_flightmode res = {0}; + int response = 0; + struct tnoti_modem_flight_mode modem_flight_mode = {0}; + const struct treq_modem_set_flightmode *req_data = NULL; + + o = tcore_pending_ref_core_object(p); + + if (ATresp->success > 0) { + dbg("RESPONSE OK - flight mode operation finished"); + res.result = TCORE_RETURN_SUCCESS; + } else { + dbg("RESPONSE NOK"); + line = (const char *) ATresp->final_response; + tokens = tcore_at_tok_new(line); + + if (g_slist_length(tokens) < 1) { + dbg("err cause not specified or string corrupted"); + res.result = TCORE_RETURN_3GPP_ERROR; + } else { + response = atoi(g_slist_nth_data(tokens, 0)); + /* TODO: CMEE error mapping is required. */ + res.result = TCORE_RETURN_3GPP_ERROR; + } + } + + ur = tcore_pending_ref_user_request(p); + if (NULL == ur) { + dbg("No user request. Internal request created during boot-up sequence"); + + if (ATresp->success > 0) { + modem_flight_mode.enable = tcore_modem_get_flight_mode_state(o); + dbg("sucess case - Sending Flight Mode Notification (%d) to Telephony Server", modem_flight_mode.enable); + + tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_MODEM_FLIGHT_MODE, + sizeof(struct tnoti_modem_flight_mode), &modem_flight_mode); + } + } else { + dbg("Sending response for Flight mode operation"); + tcore_user_request_send_response(ur, TRESP_MODEM_SET_FLIGHTMODE, sizeof(struct tresp_modem_set_flightmode), &res); + + req_data = tcore_user_request_ref_data(ur, NULL); + + if (req_data->enable == 0) { + dbg("Flight mode is disabled, trigger COPS to register on network"); + /* Trigger Network registration (for the moment automatic) */ + prepare_and_send_pending_request(tcore_object_ref_plugin(o), "modem", "AT+COPS=0", NULL, TCORE_AT_NO_RESULT, NULL); + } + } + + tcore_at_tok_free(tokens); +} + +static void on_response_imei(TcorePending *p, int data_len, const void *data, void *user_data) +{ + const TcoreATResponse *resp = data; + TcorePlugin *plugin = NULL; + struct tresp_modem_get_imei res; + TelMiscSNInformation *imei_property = NULL; + UserRequest *ur = NULL; + GSList *tokens = NULL; + const char *line; + int response = 0; + + memset(&res, 0, sizeof(struct tresp_modem_get_imei)); + + if (resp->success > 0) { + dbg("RESPONSE OK"); + if (resp->lines) { + line = (const char *) resp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) != 1) { + msg("invalid message"); + goto OUT; + } + } + res.result = TCORE_RETURN_SUCCESS; + strncpy(res.imei, g_slist_nth_data(tokens, 0), 16); + + dbg("imei = [%s]", res.imei); + + plugin = tcore_pending_ref_plugin(p); + imei_property = tcore_plugin_ref_property(plugin, "IMEI"); + if (imei_property) { + imei_property->sn_index = TAPI_MISC_ME_IMEI; + imei_property->sn_len = strlen(res.imei); + memcpy(imei_property->szNumber, res.imei, imei_property->sn_len); + } + } else { + dbg("RESPONSE NOK"); + if (resp->lines) { + line = (const char *) resp->lines->data; + tokens = tcore_at_tok_new(line); + } + + + if (g_slist_length(tokens) < 1) { + dbg("err cause not specified or string corrupted"); + res.result = TCORE_RETURN_3GPP_ERROR; + } else { + response = atoi(g_slist_nth_data(tokens, 0)); + /* TODO: CMEE error mapping is required. */ + res.result = TCORE_RETURN_3GPP_ERROR; + } + } + + ur = tcore_pending_ref_user_request(p); + tcore_user_request_send_response(ur, TRESP_MODEM_GET_IMEI, sizeof(struct tresp_modem_get_imei), &res); + +OUT: + if (tokens != NULL) + tcore_at_tok_free(tokens); + + return; +} + +static void on_response_version(TcorePending *p, int data_len, const void *data, void *user_data) +{ + const TcoreATResponse *resp = data; + TcorePlugin *plugin = NULL; + struct tresp_modem_get_version res = {0}; + TelMiscVersionInformation *vi_property = NULL; + TelMiscVersionInformation *vi = NULL; + UserRequest *ur = NULL; + GSList *tokens = NULL; + const char *line = NULL; + char *swver = NULL; + char *hwver = NULL; + char *caldate = NULL; + char *pcode = NULL; + char *id = NULL; + + int response = 0; + + if (resp->success > 0) { + dbg("RESPONSE OK"); + if (resp->lines) { + line = (const char *) resp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) != 5) { + msg("invalid message"); + goto OUT; + } + } + + swver = g_slist_nth_data(tokens, 0); + hwver = g_slist_nth_data(tokens, 1); + caldate = g_slist_nth_data(tokens, 2); + pcode = g_slist_nth_data(tokens, 3); + id = g_slist_nth_data(tokens, 4); + + dbg("version: sw=[%s], hw=[%s], rf_cal=[%s], product_code=[%s], model_id=[%s]", swver, hwver, caldate, pcode, id); + + vi = calloc(sizeof(TelMiscVersionInformation), 1); + if (NULL != swver) + memcpy(vi->szSwVersion, swver, strlen(swver)); + if (NULL != hwver) + memcpy(vi->szHwVersion, hwver, strlen(hwver)); + if (NULL != caldate) + memcpy(vi->szRfCalDate, caldate, strlen(caldate)); + if (NULL != pcode) + memcpy(vi->szProductCode, pcode, strlen(pcode)); + if (NULL != id) + memcpy(vi->szModelId, id, strlen(id)); + + memset(&res, 0, sizeof(struct tresp_modem_get_version)); + + if (NULL != swver) + snprintf(res.software, (AT_VER_LEN > strlen(swver) ? strlen(swver) : AT_VER_LEN), "%s", swver); + if (NULL != hwver) + snprintf(res.hardware, (AT_VER_LEN > strlen(hwver) ? strlen(hwver) : AT_VER_LEN), "%s", hwver); + + plugin = tcore_pending_ref_plugin(p); + vi_property = tcore_plugin_ref_property(plugin, "VERSION"); + memcpy(vi_property, vi, sizeof(TelMiscVersionInformation)); + free(vi); + } else { + dbg("RESPONSE NOK"); + if (resp->lines) { + line = (const char *) resp->lines->data; + tokens = tcore_at_tok_new(line); + } + + memset(&res, 0, sizeof(struct tresp_modem_get_version)); + + + if (g_slist_length(tokens) < 1) { + dbg("err cause not specified or string corrupted"); + res.result = TCORE_RETURN_3GPP_ERROR; + } else { + response = atoi(g_slist_nth_data(tokens, 0)); + /* TODO: CMEE error mapping is required. */ + res.result = TCORE_RETURN_3GPP_ERROR; + } + } + + ur = tcore_pending_ref_user_request(p); + tcore_user_request_send_response(ur, TRESP_MODEM_GET_VERSION, sizeof(struct tresp_modem_get_version), &res); + +OUT: + if (tokens != NULL) + tcore_at_tok_free(tokens); + + return; +} + +static gboolean on_event_bootup_sim_status(CoreObject *o, const void *event_info, void *user_data) +{ + GSList *tok = NULL; + GSList *lines = NULL; + int value = -1; + char *line = NULL; + + lines = (GSList *) event_info; + if (1 != g_slist_length(lines)) { + dbg("unsolicited msg but multiple line"); + goto OUT; + } + line = (char *) (lines->data); + dbg("on_bootup_event_sim_status notification : %s", line); + + tok = tcore_at_tok_new(line); + value = atoi(g_slist_nth_data(tok, 0)); + + if (7 == value) { + dbg("SIM ready. request COPS & remove callback"); + dbg("power on done set for proactive command receiving mode"); + prepare_and_send_pending_request(tcore_object_ref_plugin(o), "sat", "AT+CFUN=6", NULL, TCORE_AT_NO_RESULT, on_response_enable_proactive_command); + prepare_and_send_pending_request(tcore_object_ref_plugin(o), "umts_network", "AT+COPS=0", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + return FALSE; + } + +OUT: + if (tok != NULL) + tcore_at_tok_free(tok); + + return TRUE; +} + + + +gboolean on_event_modem_power(TcoreAT *at, const char *line, TcorePlugin *p) +{ + CoreObject *o = NULL; + struct treq_modem_set_flightmode flight_mode_set = {0}; + struct tnoti_modem_power modem_power = {0}; + TcoreHal *h = NULL; + Storage *strg = NULL; + + o = tcore_plugin_ref_core_object(p, "modem"); + + strg = tcore_server_find_storage(tcore_plugin_ref_server(p), "vconf"); + flight_mode_set.enable = tcore_storage_get_bool(strg, STORAGE_KEY_SETAPPL_FLIGHT_MODE_BOOL); + + h = tcore_object_get_hal(o); + tcore_hal_set_power_state(h, TRUE); + + /* Set Flight mode as per AP settings */ + if (flight_mode_set.enable) { /* Radio Off */ + prepare_and_send_pending_request(p, "modem", "AT+CFUN=4", NULL, TCORE_AT_NO_RESULT, on_response_set_flight_mode); + tcore_modem_set_flight_mode_state(o, TRUE); + } else { /* Radio On */ + prepare_and_send_pending_request(p, "modem", "AT+CFUN=1", NULL, TCORE_AT_NO_RESULT, on_response_set_flight_mode); + tcore_modem_set_flight_mode_state(o, FALSE); + } + + /* Get IMEI */ + prepare_and_send_pending_request(p, "modem", "AT+CGSN", NULL, TCORE_AT_NUMERIC, on_response_imei); + + /* Get Version Number */ + prepare_and_send_pending_request(p, "modem", "AT+CGMR", NULL, TCORE_AT_SINGLELINE, on_response_version); + + tcore_modem_set_powered(o, TRUE); + + modem_power.state = MODEM_STATE_ONLINE; + + tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_MODEM_POWER, + sizeof(struct tnoti_modem_power), &modem_power); + + return TRUE; +} + +static void _modem_subscribe_events(TcorePlugin *plugin) +{ + dbg("Entry"); + + /* XCALLSTAT subscription */ + prepare_and_send_pending_request(plugin, "call", "at+xcallstat=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /* XSIMSTATE subscription */ + prepare_and_send_pending_request(plugin, "sim", "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + prepare_and_send_pending_request(plugin, "umts_sms", "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + prepare_and_send_pending_request(plugin, "modem", "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /* CREG subscription */ + prepare_and_send_pending_request(plugin, "umts_network", "at+creg=2", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /* CGREG subscription */ + prepare_and_send_pending_request(plugin, "umts_network", "at+cgreg=2", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /* Allow automatic time Zone updation via NITZ */ + prepare_and_send_pending_request(plugin, "umts_network", "at+ctzu=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /* TZ, time & daylight changing event reporting subscription */ + prepare_and_send_pending_request(plugin, "umts_network", "at+ctzr=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /* XMER subscription */ + prepare_and_send_pending_request(plugin, "umts_network", "at+xmer=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /* CGEREP subscription */ + prepare_and_send_pending_request(plugin, "umts_ps", "at+cgerep=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /* XDATASTAT subscription */ + prepare_and_send_pending_request(plugin, "umts_ps", "at+xdatastat=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /* CSSN subscription */ + prepare_and_send_pending_request(plugin, "call", "at+cssn=1,1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /* CUSD subscription */ + prepare_and_send_pending_request(plugin, "call", "at+cusd=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /* XDNS subscription */ + prepare_and_send_pending_request(plugin, "umts_ps", "at+xdns=1,1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /* CLIP subscription */ + prepare_and_send_pending_request(plugin, "call", "at+clip=1", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /*CMEE subscription*/ + prepare_and_send_pending_request(plugin, "umts_ps", "at+cmee=2", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /*incoming sms,cb,status report subscription*/ + prepare_and_send_pending_request(plugin, "umts_sms", "at+cnmi=1,2,2,1,0", NULL, TCORE_AT_NO_RESULT, on_response_bootup_subscription); + + /* text/pdu mode subscription*/ + prepare_and_send_pending_request(plugin, "umts_sms", "at+cmgf=0", NULL, TCORE_AT_NO_RESULT, on_response_last_bootup_subscription); + + dbg("Exit"); + return; +} + + +static void on_response_setupmux(TcorePending *p, int data_len, const void *data, void *user_data) +{ + TcorePlugin *plugin = NULL; + TcoreHal *hal = NULL; + TReturn ret; + dbg("Entry"); + + /* IMC Plugin dereferenced from pending request */ + plugin = tcore_pending_ref_plugin(p); + + /* Actual HAL - like svnet(2) */ + hal = (TcoreHal *) user_data; + + /* Initialize CMUX */ + ret = tcore_cmux_init(plugin, hal); + if (TCORE_RETURN_SUCCESS == ret) { + dbg("Successfully initialized CMUX"); + } else { + err("Failed to initialize CMUX"); + } + + dbg("Exit"); + return; +} + + + +static void setup_mux(CoreObject *o) +{ + TcoreHal *hal = NULL; + TcorePending *pending = NULL; + dbg("Entered"); + + /* HAL has type itself, + * e.g.) TCORE_HAL_MODE_AT + */ + hal = tcore_object_get_hal(o); + + pending = tcore_at_pending_new(o, "AT+CMUX=0,0,,1509,10,3,30,,", "+CMUX", TCORE_AT_NO_RESULT, on_response_setupmux, hal); + + tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); + + /* Send callback */ + tcore_hal_send_request(hal, pending); + + dbg("Exit"); + return; +} + + +static gboolean on_event_mux_channel_up(CoreObject *o, const void *event_info, void *user_data) +{ + TcorePlugin *plugin = NULL; + dbg("Entry"); + + plugin = (TcorePlugin *) user_data; + _modem_subscribe_events(plugin); + dbg("Exit"); + return TRUE; +} + + +static void on_response_enable_logging(TcorePending *p, int data_len, const void *data, void *user_data) +{ + const TcoreATResponse *resp = data; + TcorePlugin *plugin = NULL; + + plugin = tcore_pending_ref_plugin(p); + + /* DELETE ME: only for DEBUG */ + if (!resp) + dbg("no data"); + + dbg("response...(result = %d, final_response = '%s')", resp->success, resp->final_response); + + if (resp->success) { + dbg("RESPONSE OK"); + dbg("Enabling CP logging is success !!!\n"); + } else { + dbg("RESPONSE NOK"); + dbg("Enabling CP logging is failed !!!\n"); + } + + dbg("Calling setup_mux"); + setup_mux(tcore_pending_ref_core_object(p)); + + + dbg("Exit"); + return; +} + +static void _send_enable_logging_command(CoreObject *o) +{ + TcoreATRequest *req = NULL; + TcoreHal *hal = NULL; + TcorePending *pending = NULL; + TReturn ret = 0; + + /* DLELTE ME */ + dbg("Send Trace enabling command for CP logging. \n"); + + if (!o) { + dbg("Co-object is Null !!\n"); + // goto error; + } + + hal = tcore_object_get_hal(o); + pending = tcore_pending_new(o, 0); + req = tcore_at_request_new("at+xsystrace=1,\"digrf=1;bb_sw=1;3g_sw=1\",\"digrf=0x84\",\"oct=4\";+xsystrace=11;+trace=1", NULL, TCORE_AT_NO_RESULT); + + dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_request_data(pending, 0, req); + tcore_pending_set_response_callback(pending, on_response_enable_logging, hal); + tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); + + ret = tcore_hal_send_request(hal, pending); + if (ret != TCORE_RETURN_SUCCESS) + dbg("tcore_hal_send_request fail !!! (hal: 0x%x, pending: 0x%x)\n", hal, pending); +} + +static void on_response_poweron(TcorePending *p, int data_len, const void *data, void *user_data) +{ + const TcoreATResponse *resp = data; + GSList *tokens = NULL; + const char *line = NULL; + gboolean bpoweron = FALSE; + int response = 0; + + if (resp->success) { + dbg("RESPONSE OK"); + /* Parse AT Response */ + if (resp->lines) { + line = (const char *) resp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) != 1) { + dbg("invalid message"); + bpoweron = FALSE; + goto error; + } + } + + response = atoi(g_slist_nth_data(tokens, 0)); + + dbg("CPAS: response %d", response); + + switch (response) { + case CPAS_RES_READY: + case CPAS_RES_RINGING: + case CPAS_RES_CALL_PROGRESS: + case CPAS_RES_ASLEEP: + bpoweron = TRUE; + break; + + case CPAS_RES_UNAVAIL: + case CPAS_RES_UNKNOWN: + default: + dbg("value is unvail/unknown - but CP responded - proceed poweron"); + // bpoweron = FALSE; + bpoweron = TRUE; + break; + } + } else { + dbg("CPAS: RESPONSE NOK"); + bpoweron = FALSE; + } + +error: + /* DELE ME: AT request & response are freed after AT processing in HAL. + * ref.) _emit_pending_response (libtcore/src/at.c) + */ + if (tokens != NULL) + tcore_at_tok_free(tokens); + + if (bpoweron == TRUE) { + dbg("Power on NOTI received, (pending: 0x%x, co: 0x%x)\n", p, tcore_pending_ref_core_object(p)); + + _send_enable_logging_command(tcore_pending_ref_core_object(p)); + } else { + dbg("CP is not ready, let us send CPAS once again"); + s_modem_send_poweron(tcore_object_ref_plugin(tcore_pending_ref_core_object(p))); + } + return; +} + +static TReturn power_off(CoreObject *o, UserRequest *ur) +{ + TcoreHal *hal = NULL; + TcoreATRequest *req = NULL; + TcorePending *pending = NULL; + + hal = tcore_object_get_hal(o); + pending = tcore_pending_new(o, 0); + + req = tcore_at_request_new("AT+CFUN=0", NULL, TCORE_AT_NO_RESULT); + + dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_request_data(pending, 0, req); + tcore_pending_set_response_callback(pending, on_response_power_off, hal); + tcore_pending_link_user_request(pending, ur); + tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); + + tcore_hal_send_request(hal, pending); + + return TCORE_RETURN_SUCCESS; +} + +static TReturn get_imei(CoreObject *o, UserRequest *ur) +{ + TcoreHal *hal; + TcoreATRequest *req; + TcorePending *pending = NULL; + + hal = tcore_object_get_hal(o); + pending = tcore_pending_new(o, 0); + + req = tcore_at_request_new("AT+CGSN", NULL, TCORE_AT_NUMERIC); + + dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_request_data(pending, 0, req); + tcore_pending_set_response_callback(pending, on_response_imei, hal); + tcore_pending_link_user_request(pending, ur); + tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); + + tcore_hal_send_request(hal, pending); + + return TCORE_RETURN_SUCCESS; +} + + +static TReturn get_version(CoreObject *o, UserRequest *ur) +{ + TcoreHal *hal; + TcoreATRequest *req; + TcorePending *pending = NULL; + + hal = tcore_object_get_hal(o); + pending = tcore_pending_new(o, 0); + + req = tcore_at_request_new("AT+CGMR", NULL, TCORE_AT_SINGLELINE); + + dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_request_data(pending, 0, req); + tcore_pending_set_response_callback(pending, on_response_version, hal); + tcore_pending_link_user_request(pending, ur); + tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); + + tcore_hal_send_request(hal, pending); + + return TCORE_RETURN_SUCCESS; +} + +static TReturn set_flight_mode(CoreObject *o, UserRequest *ur) +{ + TcoreHal *hal = NULL; + TcoreATRequest *req = NULL; + TcorePending *pending = NULL; + const struct treq_modem_set_flightmode *req_data = NULL; + char *cmd_str = NULL; + + hal = tcore_object_get_hal(o); + pending = tcore_pending_new(o, 0); + + req_data = tcore_user_request_ref_data(ur, NULL); + + if (req_data->enable) { + dbg("Flight mode on/n"); + cmd_str = g_strdup("AT+CFUN=4"); + } else { + dbg("Flight mode off/n"); + cmd_str = g_strdup("AT+CFUN=1"); + } + + req = tcore_at_request_new((const char *) cmd_str, NULL, TCORE_AT_NO_RESULT); + + dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_request_data(pending, 0, req); + tcore_pending_set_response_callback(pending, on_response_set_flight_mode, hal); + tcore_pending_link_user_request(pending, ur); + tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); + + tcore_hal_send_request(hal, pending); + + return TCORE_RETURN_SUCCESS; +} + + +static struct tcore_modem_operations modem_ops = { + .power_on = NULL, + .power_off = power_off, + .power_reset = NULL, + .set_flight_mode = set_flight_mode, + .get_imei = get_imei, + .get_version = get_version, + .get_sn = NULL, + .dun_pin_ctrl = NULL, +}; + +gboolean s_modem_init(TcorePlugin *p, TcoreHal *h) +{ + CoreObject *o = NULL; + GQueue *work_queue = NULL; + TelMiscVersionInformation *vi_property = NULL; + TelMiscSNInformation *imei_property = NULL; + TelMiscSNInformation *sn_property = NULL; + + o = tcore_modem_new(p, "modem", &modem_ops, h); + if (!o) + return FALSE; + + work_queue = g_queue_new(); + tcore_object_link_user_data(o, work_queue); + + vi_property = calloc(sizeof(TelMiscVersionInformation), 1); + tcore_plugin_link_property(p, "VERSION", vi_property); + + imei_property = calloc(sizeof(TelMiscSNInformation), 1); + tcore_plugin_link_property(p, "IMEI", imei_property); + + sn_property = calloc(sizeof(TelMiscSNInformation), 1); + tcore_plugin_link_property(p, "SN", sn_property); + + dbg("Registerind for CMUX-UP event"); + tcore_object_add_callback(o, "CMUX-UP", on_event_mux_channel_up, p); + + dbg("Registering for +XSIM event"); + tcore_object_add_callback(o, "+XSIM", on_event_bootup_sim_status, NULL); + + return TRUE; +} + +void s_modem_exit(TcorePlugin *p) +{ + CoreObject *o = NULL; + GQueue *work_queue = NULL; + TelMiscVersionInformation *vi_property = NULL; + TelMiscSNInformation *imei_property = NULL; + TelMiscSNInformation *sn_property = NULL; + + if (!p) + return; + + o = tcore_plugin_ref_core_object(p, "modem"); + + work_queue = tcore_object_ref_user_data(o); + g_queue_free(work_queue); + + vi_property = tcore_plugin_ref_property(p, "VERSION"); + if (vi_property) + free(vi_property); + + imei_property = tcore_plugin_ref_property(p, "IMEI"); + if (imei_property) + free(imei_property); + + sn_property = tcore_plugin_ref_property(p, "SN"); + if (sn_property) + free(sn_property); + + tcore_modem_free(o); + return; +} + +gboolean s_modem_send_poweron(TcorePlugin *p) +{ + TcoreHal *hal; + TcoreATRequest *req; + TcorePending *pending = NULL; + CoreObject *o; + + o = tcore_plugin_ref_core_object(p, "modem"); + hal = tcore_object_get_hal(o); + + pending = tcore_pending_new(o, 0); + + req = tcore_at_request_new("AT+CPAS", "+CPAS", TCORE_AT_SINGLELINE); + + dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_timeout(pending, 10); + tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT); + tcore_pending_set_timeout_callback(pending, on_timeout_modem_poweron, hal); + + tcore_pending_set_request_data(pending, 0, req); + tcore_pending_set_response_callback(pending, on_response_poweron, hal); + tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL); + + tcore_hal_send_request(hal, pending); + + return TRUE; +} diff --git a/src/s_network.c b/src/s_network.c index a08438d..ac279c4 100755 --- a/src/s_network.c +++ b/src/s_network.c @@ -1,2223 +1,2114 @@ -/* - * tel-plugin-imc - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Harish Bishnoi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "s_common.h" -#include "s_network.h" - -#define AT_CREG_STAT_NOT_REG 0 /* not registered, MT is not currently searching a new operator to register to */ -#define AT_CREG_STAT_REG_HOME 1 /* registered, home network */ -#define AT_CREG_STAT_SEARCHING 2 /* not registered, but MT is currently searching a new operator to register to */ -#define AT_CREG_STAT_REG_DENIED 3 /* registration denied */ -#define AT_CREG_STAT_UNKNOWN 4 /* unknown */ -#define AT_CREG_STAT_REG_ROAM 5 /* registered, roaming */ - -#define AT_COPS_MODE_AUTOMATIC 0 /* automatic ( field is ignored) */ -#define AT_COPS_MODE_MANUAL 1 /* manual ( field shall be present, and optionally) */ -#define AT_COPS_MODE_DEREGISTER 2 /* deregister from network */ -#define AT_COPS_MODE_SET_ONLY 3 /* set only */ -#define AT_COPS_MODE_MANUAL_AUTOMATIC 4 /*automatic - manual*/ - -#define AT_COPS_FORMAT_LONG_ALPHANUMERIC 0 /* long format alphanumeric */ -#define AT_COPS_FORMAT_SHORT_ALPHANUMERIC 1 /* short format alphanumeric */ -#define AT_COPS_FORMAT_NUMERIC 2 /* numeric */ - -#define AT_COPS_ACT_GSM 0 /* GSM */ -#define AT_COPS_ACT_GSM_COMPACT 1 /* GSM Compact */ -#define AT_COPS_ACT_UTRAN 2 /* UTRAN */ -#define AT_COPS_ACT_GSM_EGPRS 3 /* GSM w/EGPRS */ -#define AT_COPS_ACT_UTRAN_HSDPA 4 /* UTRAN w/HSDPA */ -#define AT_COPS_ACT_UTRAN_HSUPA 5 /* UTRAN w/HSUPA */ -#define AT_COPS_ACT_UTRAN_HSDPA_HSUPA 6 /* UTRAN w/HSDPA and HSUPA */ -#define AT_COPS_ACT_E_UTRAN 7 /* E-UTRAN */ - -#define AT_GSM_XBANDSEL_AUTOMATIC 0 -#define AT_GSM_XBANDSEL_1800 1800 -#define AT_GSM_XBANDSEL_1900 1900 -#define AT_GSM_XBANDSEL_900 900 -#define AT_GSM_XBANDSEL_850 850 -#define AT_GSM_XBANDSEL_450 450 -#define AT_GSM_XBANDSEL_480 480 -#define AT_GSM_XBANDSEL_750 750 -#define AT_GSM_XBANDSEL_380 380 -#define AT_GSM_XBANDSEL_410 410 - -#define AT_XRAT_GSM 0 -#define AT_XRAT_DUAL 1 -#define AT_XRAT_UMTS 2 - -#define MAX_NETWORKS_PREF_PLMN_SUPPORT 150 -#define MAX_NETWORKS_MANUAL_SEARCH_SUPPORT 20 - -static unsigned int lookup_tbl_net_status[] = { - [AT_CREG_STAT_NOT_REG] = NETWORK_SERVICE_DOMAIN_STATUS_NO, - [AT_CREG_STAT_REG_HOME] = NETWORK_SERVICE_DOMAIN_STATUS_FULL, - [AT_CREG_STAT_SEARCHING] = NETWORK_SERVICE_DOMAIN_STATUS_SEARCH, - [AT_CREG_STAT_REG_DENIED] = NETWORK_SERVICE_DOMAIN_STATUS_EMERGENCY, - [AT_CREG_STAT_UNKNOWN] = NETWORK_SERVICE_DOMAIN_STATUS_NO, - [AT_CREG_STAT_REG_ROAM] = NETWORK_SERVICE_DOMAIN_STATUS_FULL, -}; - -static unsigned int lookup_tbl_access_technology[] = { - [AT_COPS_ACT_GSM] = NETWORK_ACT_GSM, - [AT_COPS_ACT_GSM_COMPACT] = NETWORK_ACT_GSM, - [AT_COPS_ACT_UTRAN] = NETWORK_ACT_UTRAN, - [AT_COPS_ACT_GSM_EGPRS] = NETWORK_ACT_EGPRS, - [AT_COPS_ACT_UTRAN_HSDPA] = NETWORK_ACT_UTRAN, - [AT_COPS_ACT_UTRAN_HSUPA] = NETWORK_ACT_UTRAN, - [AT_COPS_ACT_UTRAN_HSDPA_HSUPA] = NETWORK_ACT_UTRAN, - [AT_COPS_ACT_E_UTRAN] = NETWORK_ACT_GSM_UTRAN, -}; - -static gboolean get_serving_network(CoreObject *o, UserRequest *ur); - - -static void on_confirmation_network_message_send(TcorePending *p, gboolean result, void *user_data) -{ - dbg("on_confirmation_modem_message_send - msg out from queue.\n"); - - if (result == FALSE) { - /* Fail */ - dbg("SEND FAIL"); - } - else { - dbg("SEND OK"); - } -} - -static void nwk_prepare_and_send_pending_request(TcorePlugin *plugin, char *co_name, const char *at_cmd, const char* prefix,enum tcore_at_command_type at_cmd_type, UserRequest *ur, TcorePendingResponseCallback callback) -{ - TcoreATRequest *req = NULL; - TcoreHal *hal; - CoreObject *o= NULL; - TcorePending *pending = NULL; - TReturn ret; - - o = tcore_plugin_ref_core_object(plugin, co_name); - hal = tcore_object_get_hal(o); - - pending = tcore_pending_new(o, 0); - req = tcore_at_request_new(at_cmd, prefix, at_cmd_type); - - dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); - - tcore_pending_set_request_data(pending, 0, req); - tcore_pending_set_response_callback(pending, callback, req->cmd); - tcore_pending_link_user_request(pending, ur); - tcore_pending_set_send_callback(pending, on_confirmation_network_message_send, NULL); - - ret = tcore_hal_send_request(hal, pending); - return; -} - - -static void _insert_mcc_mnc_oper_list(TcorePlugin *p, CoreObject *o) -{ - Server *s; - Storage *strg; - void *handle; - char query[255] = { 0, }; - GHashTableIter iter; - gpointer key, value; - GHashTable *result = NULL, *row = NULL; - struct tcore_network_operator_info *noi = NULL; - int count = 0; - - s = tcore_plugin_ref_server(p); - strg = tcore_server_find_storage(s, "database"); - - handle = tcore_storage_create_handle(strg, "/opt/dbspace/.mcc_mnc_oper_list.db"); - if (!handle) { - dbg("fail to create database handle"); - return; - } - - snprintf(query, 255, "select country, mcc, mnc, oper from mcc_mnc_oper_list"); - - result = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, - (GDestroyNotify) g_hash_table_destroy); - - tcore_storage_read_query_database(strg, handle, query, NULL, result, 4); - - g_hash_table_iter_init(&iter, result); - while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) { - row = value; - - noi = calloc(sizeof(struct tcore_network_operator_info), 1); - - snprintf(noi->mcc, 4, "%s", (char *)g_hash_table_lookup(row, "1")); - snprintf(noi->mnc, 4, "%s", (char *)g_hash_table_lookup(row, "2")); - snprintf(noi->name, 41, "%s", (char *)g_hash_table_lookup(row, "3")); - snprintf(noi->country, 4, "%s", (char *)g_hash_table_lookup(row, "0")); - - tcore_network_operator_info_add(o, noi); - - count++; - } - - dbg("count = %d", count); - - g_hash_table_destroy(result); - - tcore_storage_remove_handle(strg, handle); -} - -static enum telephony_network_service_type _get_service_type(enum telephony_network_service_type prev_type, - int domain, int act, int cs_status, int ps_status) -{ - enum telephony_network_service_type ret; - - ret = prev_type; - - switch (act) { - case NETWORK_ACT_UNKNOWN: - ret = NETWORK_SERVICE_TYPE_UNKNOWN; - break; - - case NETWORK_ACT_GSM: - if (prev_type == NETWORK_SERVICE_TYPE_2_5G_EDGE && domain == NETWORK_SERVICE_DOMAIN_CS) - ret = NETWORK_SERVICE_TYPE_2_5G_EDGE; - else - ret = NETWORK_SERVICE_TYPE_2G; - break; - - case NETWORK_ACT_EGPRS: - return NETWORK_SERVICE_TYPE_2_5G_EDGE; - break; - - case NETWORK_ACT_UMTS: - ret = NETWORK_SERVICE_TYPE_3G; - break; - - } - - if (cs_status == NETWORK_SERVICE_DOMAIN_STATUS_NO && ps_status == NETWORK_SERVICE_DOMAIN_STATUS_NO) { - ret = NETWORK_SERVICE_TYPE_NO_SERVICE; - } - else if (cs_status == NETWORK_SERVICE_DOMAIN_STATUS_SEARCH || ps_status == NETWORK_SERVICE_DOMAIN_STATUS_SEARCH) - { - if (cs_status == NETWORK_SERVICE_DOMAIN_STATUS_FULL || ps_status == NETWORK_SERVICE_DOMAIN_STATUS_FULL) - { - /* no change */ - } - else - { - ret = NETWORK_SERVICE_TYPE_SEARCH; - } - } - else if (cs_status == NETWORK_SERVICE_DOMAIN_STATUS_EMERGENCY || ps_status == NETWORK_SERVICE_DOMAIN_STATUS_EMERGENCY) - { - if (cs_status == NETWORK_SERVICE_DOMAIN_STATUS_FULL || ps_status == NETWORK_SERVICE_DOMAIN_STATUS_FULL) - { - /* no change */ - } - else - { - ret = NETWORK_SERVICE_TYPE_EMERGENCY; - } - } - - return ret; -} - -static void _ps_set(TcorePlugin *p, int status) -{ - GSList *co_list = NULL; - - co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_PS); - do { - CoreObject *o = NULL; - o = (CoreObject *) co_list->data; - if (!o) - break; - - if (status == NETWORK_SERVICE_DOMAIN_STATUS_FULL) { - tcore_ps_set_online(o, TRUE); - } - else { - tcore_ps_set_online(o, FALSE); - } - } while ((co_list = g_slist_next(co_list))); - - g_slist_free(co_list); -} - - -static void on_response_set_plmn_selection_mode(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur; - const TcoreATResponse *atResp = data; - //GSList *tokens = NULL; - //char * line = NULL; - struct tresp_network_set_plmn_selection_mode resp = {0}; - - if(atResp->success > 0) - { - dbg("RESPONSE OK"); - resp.result = TCORE_RETURN_SUCCESS; - } - else - { - dbg("RESPONSE NOK"); - resp.result = TCORE_RETURN_FAILURE; - } - - ur = tcore_pending_ref_user_request(p); - if (ur) { - tcore_user_request_send_response(ur, TRESP_NETWORK_SET_PLMN_SELECTION_MODE, sizeof(struct tresp_network_set_plmn_selection_mode), &resp); - } -} - -static void on_response_get_plmn_selection_mode(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur; - struct tresp_network_get_plmn_selection_mode resp = {0}; - const TcoreATResponse *atResp = data; - GSList *tokens = NULL; - char * line = NULL; - int mode = 0; - - resp.result = TCORE_RETURN_FAILURE; - - if(atResp->success > 0) - { - dbg("RESPONSE OK"); - /* Format of output - +COPS: [,,[,< AcT>]] - */ - - if(atResp->lines) - { - line = (char*)atResp->lines->data; - tokens = tcore_at_tok_new(line); - if (g_slist_length(tokens) < 1){ - msg("invalid message"); - goto OUT; - } - mode = atoi(tcore_at_tok_nth(tokens, 0)); - dbg("mode = %d", mode); - - switch(mode) { - case AT_COPS_MODE_AUTOMATIC: - resp.mode = NETWORK_SELECT_MODE_GLOBAL_AUTOMATIC; - break; - case AT_COPS_MODE_MANUAL: - case AT_COPS_MODE_MANUAL_AUTOMATIC: - resp.mode = NETWORK_SELECT_MODE_GSM_MANUAL; - break; - case AT_COPS_MODE_DEREGISTER: - case AT_COPS_MODE_SET_ONLY: - resp.result = TCORE_RETURN_FAILURE; - goto OUT; - } - resp.result = TCORE_RETURN_SUCCESS; - } - } - else - { - dbg("RESPONSE NOK"); - resp.result = TCORE_RETURN_FAILURE; - } - -OUT: - ur = tcore_pending_ref_user_request(p); - if (ur) { - tcore_user_request_send_response(ur, TRESP_NETWORK_GET_PLMN_SELECTION_MODE, sizeof(struct tresp_network_get_plmn_selection_mode), &resp); - } - - if(tokens != NULL) - tcore_at_tok_free(tokens); - - return; - -} - -static void on_response_search_network(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur; - struct tresp_network_search resp; - int i = 0; - char* line=NULL; - const TcoreATResponse *atResp = data; - GSList *tokens = NULL; - GSList *network_token = NULL; - int AcT=0; - char* temp_plmn_info =NULL; - char *pResp = NULL; - int num_network_avail = 0; - - memset(&resp, 0, sizeof(struct tresp_network_search)); - resp.result = TCORE_RETURN_FAILURE; - resp.list_count = 0; - - if(atResp->success > 0) - { - dbg("RESPONSE OK"); - if(atResp->lines) { - line = (char*)atResp->lines->data; - tokens = tcore_at_tok_new(line); - num_network_avail = g_slist_length(tokens); - dbg(" length of tokens is %d\n", num_network_avail); - if (num_network_avail < 1) { - msg("invalid message"); - goto OUT; - } - } - - resp.result = TCORE_RETURN_SUCCESS; - /* - * +COPS: [list of supported (,long alphanumeric ,short alphanumeric ,numeric [,])s] - * [,,(list of supported s),(list of supported s)] - */ - - /* (2,"IND airtel","airtel","40445",2,),(1,"IND airtel","airtel","40445",0,),(3,"TATA DOCOMO","TATA DO","405034",2,) */ - - for(i=0; ((i 0) - /* Strip off starting quote & ending quote */ - strncpy(resp.list[i].name, pResp+1, strlen(pResp)-2); - } - else if ((pResp = tcore_at_tok_nth(network_token, 2))) - { - dbg("Short Aplha name : %s",pResp); - /* Short Aplha name */ - /* Strip off starting quote & ending quote */ - if(strlen(pResp) > 0) - strncpy(resp.list[i].name, pResp+1, strlen(pResp)-2); - } - - /* PLMN ID */ - pResp = tcore_at_tok_nth(network_token, 3); - if(pResp != NULL) - { - dbg("PLMN ID : %s",pResp); +/* + * tel-plugin-imc + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Harish Bishnoi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "s_common.h" +#include "s_network.h" + +#define AT_CREG_STAT_NOT_REG 0 /* not registered, MT is not currently searching a new operator to register to */ +#define AT_CREG_STAT_REG_HOME 1 /* registered, home network */ +#define AT_CREG_STAT_SEARCHING 2 /* not registered, but MT is currently searching a new operator to register to */ +#define AT_CREG_STAT_REG_DENIED 3 /* registration denied */ +#define AT_CREG_STAT_UNKNOWN 4 /* unknown */ +#define AT_CREG_STAT_REG_ROAM 5 /* registered, roaming */ + +#define AT_COPS_MODE_AUTOMATIC 0 /* automatic ( field is ignored) */ +#define AT_COPS_MODE_MANUAL 1 /* manual ( field shall be present, and optionally) */ +#define AT_COPS_MODE_DEREGISTER 2 /* deregister from network */ +#define AT_COPS_MODE_SET_ONLY 3 /* set only */ +#define AT_COPS_MODE_MANUAL_AUTOMATIC 4 /*automatic - manual*/ + +#define AT_COPS_FORMAT_LONG_ALPHANUMERIC 0 /* long format alphanumeric */ +#define AT_COPS_FORMAT_SHORT_ALPHANUMERIC 1 /* short format alphanumeric */ +#define AT_COPS_FORMAT_NUMERIC 2 /* numeric */ + +#define AT_COPS_ACT_GSM 0 /* GSM */ +#define AT_COPS_ACT_GSM_COMPACT 1 /* GSM Compact */ +#define AT_COPS_ACT_UTRAN 2 /* UTRAN */ +#define AT_COPS_ACT_GSM_EGPRS 3 /* GSM w/EGPRS */ +#define AT_COPS_ACT_UTRAN_HSDPA 4 /* UTRAN w/HSDPA */ +#define AT_COPS_ACT_UTRAN_HSUPA 5 /* UTRAN w/HSUPA */ +#define AT_COPS_ACT_UTRAN_HSDPA_HSUPA 6 /* UTRAN w/HSDPA and HSUPA */ +#define AT_COPS_ACT_E_UTRAN 7 /* E-UTRAN */ + +#define AT_GSM_XBANDSEL_AUTOMATIC 0 +#define AT_GSM_XBANDSEL_1800 1800 +#define AT_GSM_XBANDSEL_1900 1900 +#define AT_GSM_XBANDSEL_900 900 +#define AT_GSM_XBANDSEL_850 850 +#define AT_GSM_XBANDSEL_450 450 +#define AT_GSM_XBANDSEL_480 480 +#define AT_GSM_XBANDSEL_750 750 +#define AT_GSM_XBANDSEL_380 380 +#define AT_GSM_XBANDSEL_410 410 + +#define AT_XRAT_GSM 0 +#define AT_XRAT_DUAL 1 +#define AT_XRAT_UMTS 2 + +#define MAX_NETWORKS_PREF_PLMN_SUPPORT 150 +#define MAX_NETWORKS_MANUAL_SEARCH_SUPPORT 20 + +static unsigned int lookup_tbl_net_status[] = { + [AT_CREG_STAT_NOT_REG] = NETWORK_SERVICE_DOMAIN_STATUS_NO, + [AT_CREG_STAT_REG_HOME] = NETWORK_SERVICE_DOMAIN_STATUS_FULL, + [AT_CREG_STAT_SEARCHING] = NETWORK_SERVICE_DOMAIN_STATUS_SEARCH, + [AT_CREG_STAT_REG_DENIED] = NETWORK_SERVICE_DOMAIN_STATUS_EMERGENCY, + [AT_CREG_STAT_UNKNOWN] = NETWORK_SERVICE_DOMAIN_STATUS_NO, + [AT_CREG_STAT_REG_ROAM] = NETWORK_SERVICE_DOMAIN_STATUS_FULL, +}; + +static unsigned int lookup_tbl_access_technology[] = { + [AT_COPS_ACT_GSM] = NETWORK_ACT_GSM, + [AT_COPS_ACT_GSM_COMPACT] = NETWORK_ACT_GSM, + [AT_COPS_ACT_UTRAN] = NETWORK_ACT_UTRAN, + [AT_COPS_ACT_GSM_EGPRS] = NETWORK_ACT_EGPRS, + [AT_COPS_ACT_UTRAN_HSDPA] = NETWORK_ACT_UTRAN, + [AT_COPS_ACT_UTRAN_HSUPA] = NETWORK_ACT_UTRAN, + [AT_COPS_ACT_UTRAN_HSDPA_HSUPA] = NETWORK_ACT_UTRAN, + [AT_COPS_ACT_E_UTRAN] = NETWORK_ACT_GSM_UTRAN, +}; + +static gboolean get_serving_network(CoreObject *o, UserRequest *ur); + + +static void on_confirmation_network_message_send(TcorePending *p, gboolean result, void *user_data) +{ + dbg("on_confirmation_modem_message_send - msg out from queue.\n"); + + if (result == FALSE) { + /* Fail */ + dbg("SEND FAIL"); + } else { + dbg("SEND OK"); + } +} + +static void nwk_prepare_and_send_pending_request(TcorePlugin *plugin, char *co_name, const char *at_cmd, const char *prefix, enum tcore_at_command_type at_cmd_type, UserRequest *ur, TcorePendingResponseCallback callback) +{ + TcoreATRequest *req = NULL; + TcoreHal *hal; + CoreObject *o = NULL; + TcorePending *pending = NULL; + TReturn ret; + + o = tcore_plugin_ref_core_object(plugin, co_name); + hal = tcore_object_get_hal(o); + + pending = tcore_pending_new(o, 0); + req = tcore_at_request_new(at_cmd, prefix, at_cmd_type); + + dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd)); + + tcore_pending_set_request_data(pending, 0, req); + tcore_pending_set_response_callback(pending, callback, req->cmd); + tcore_pending_link_user_request(pending, ur); + tcore_pending_set_send_callback(pending, on_confirmation_network_message_send, NULL); + + ret = tcore_hal_send_request(hal, pending); + return; +} + + +static void _insert_mcc_mnc_oper_list(TcorePlugin *p, CoreObject *o) +{ + Server *s; + Storage *strg; + void *handle; + char query[255] = { 0, }; + GHashTableIter iter; + gpointer key, value; + GHashTable *result = NULL, *row = NULL; + struct tcore_network_operator_info *noi = NULL; + int count = 0; + + s = tcore_plugin_ref_server(p); + strg = tcore_server_find_storage(s, "database"); + + handle = tcore_storage_create_handle(strg, "/opt/dbspace/.mcc_mnc_oper_list.db"); + if (!handle) { + dbg("fail to create database handle"); + return; + } + + snprintf(query, 255, "select country, mcc, mnc, oper from mcc_mnc_oper_list"); + + result = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, + (GDestroyNotify) g_hash_table_destroy); + + tcore_storage_read_query_database(strg, handle, query, NULL, result, 4); + + g_hash_table_iter_init(&iter, result); + while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) { + row = value; + + noi = calloc(sizeof(struct tcore_network_operator_info), 1); + + snprintf(noi->mcc, 4, "%s", (char *) g_hash_table_lookup(row, "1")); + snprintf(noi->mnc, 4, "%s", (char *) g_hash_table_lookup(row, "2")); + snprintf(noi->name, 41, "%s", (char *) g_hash_table_lookup(row, "3")); + snprintf(noi->country, 4, "%s", (char *) g_hash_table_lookup(row, "0")); + + tcore_network_operator_info_add(o, noi); + + count++; + } + + dbg("count = %d", count); + + g_hash_table_destroy(result); + + tcore_storage_remove_handle(strg, handle); +} + +static enum telephony_network_service_type _get_service_type(enum telephony_network_service_type prev_type, + int domain, int act, int cs_status, int ps_status) +{ + enum telephony_network_service_type ret; + + ret = prev_type; + + switch (act) { + case NETWORK_ACT_UNKNOWN: + ret = NETWORK_SERVICE_TYPE_UNKNOWN; + break; + + case NETWORK_ACT_GSM: + if (prev_type == NETWORK_SERVICE_TYPE_2_5G_EDGE && domain == NETWORK_SERVICE_DOMAIN_CS) + ret = NETWORK_SERVICE_TYPE_2_5G_EDGE; + else + ret = NETWORK_SERVICE_TYPE_2G; + break; + + case NETWORK_ACT_EGPRS: + return NETWORK_SERVICE_TYPE_2_5G_EDGE; + break; + + case NETWORK_ACT_UMTS: + ret = NETWORK_SERVICE_TYPE_3G; + break; + } + + if (cs_status == NETWORK_SERVICE_DOMAIN_STATUS_NO && ps_status == NETWORK_SERVICE_DOMAIN_STATUS_NO) { + ret = NETWORK_SERVICE_TYPE_NO_SERVICE; + } else if (cs_status == NETWORK_SERVICE_DOMAIN_STATUS_SEARCH || ps_status == NETWORK_SERVICE_DOMAIN_STATUS_SEARCH) { + if (cs_status == NETWORK_SERVICE_DOMAIN_STATUS_FULL || ps_status == NETWORK_SERVICE_DOMAIN_STATUS_FULL) { + /* no change */ + } else { + ret = NETWORK_SERVICE_TYPE_SEARCH; + } + } else if (cs_status == NETWORK_SERVICE_DOMAIN_STATUS_EMERGENCY || ps_status == NETWORK_SERVICE_DOMAIN_STATUS_EMERGENCY) { + if (cs_status == NETWORK_SERVICE_DOMAIN_STATUS_FULL || ps_status == NETWORK_SERVICE_DOMAIN_STATUS_FULL) { + /* no change */ + } else { + ret = NETWORK_SERVICE_TYPE_EMERGENCY; + } + } + + return ret; +} + +static void _ps_set(TcorePlugin *p, int status) +{ + GSList *co_list = NULL; + + co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_PS); + do { + CoreObject *o = NULL; + o = (CoreObject *) co_list->data; + if (!o) + break; + + if (status == NETWORK_SERVICE_DOMAIN_STATUS_FULL) { + tcore_ps_set_online(o, TRUE); + } else { + tcore_ps_set_online(o, FALSE); + } + } while ((co_list = g_slist_next(co_list))); + + g_slist_free(co_list); +} + + +static void on_response_set_plmn_selection_mode(TcorePending *p, int data_len, const void *data, void *user_data) +{ + UserRequest *ur; + const TcoreATResponse *atResp = data; + // GSList *tokens = NULL; + // char * line = NULL; + struct tresp_network_set_plmn_selection_mode resp = {0}; + + if (atResp->success > 0) { + dbg("RESPONSE OK"); + resp.result = TCORE_RETURN_SUCCESS; + } else { + dbg("RESPONSE NOK"); + resp.result = TCORE_RETURN_FAILURE; + } + + ur = tcore_pending_ref_user_request(p); + if (ur) { + tcore_user_request_send_response(ur, TRESP_NETWORK_SET_PLMN_SELECTION_MODE, sizeof(struct tresp_network_set_plmn_selection_mode), &resp); + } +} + +static void on_response_get_plmn_selection_mode(TcorePending *p, int data_len, const void *data, void *user_data) +{ + UserRequest *ur; + struct tresp_network_get_plmn_selection_mode resp = {0}; + const TcoreATResponse *atResp = data; + GSList *tokens = NULL; + char *line = NULL; + int mode = 0; + + resp.result = TCORE_RETURN_FAILURE; + + if (atResp->success > 0) { + dbg("RESPONSE OK"); + /* Format of output + +COPS: [,,[,< AcT>]] + */ + + if (atResp->lines) { + line = (char *) atResp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) < 1) { + msg("invalid message"); + goto OUT; + } + mode = atoi(tcore_at_tok_nth(tokens, 0)); + dbg("mode = %d", mode); + + switch (mode) { + case AT_COPS_MODE_AUTOMATIC: + resp.mode = NETWORK_SELECT_MODE_GLOBAL_AUTOMATIC; + break; + + case AT_COPS_MODE_MANUAL: + case AT_COPS_MODE_MANUAL_AUTOMATIC: + resp.mode = NETWORK_SELECT_MODE_GSM_MANUAL; + break; + + case AT_COPS_MODE_DEREGISTER: + case AT_COPS_MODE_SET_ONLY: + resp.result = TCORE_RETURN_FAILURE; + goto OUT; + } + resp.result = TCORE_RETURN_SUCCESS; + } + } else { + dbg("RESPONSE NOK"); + resp.result = TCORE_RETURN_FAILURE; + } + +OUT: + ur = tcore_pending_ref_user_request(p); + if (ur) { + tcore_user_request_send_response(ur, TRESP_NETWORK_GET_PLMN_SELECTION_MODE, sizeof(struct tresp_network_get_plmn_selection_mode), &resp); + } + + if (tokens != NULL) + tcore_at_tok_free(tokens); + + return; +} + +static void on_response_search_network(TcorePending *p, int data_len, const void *data, void *user_data) +{ + UserRequest *ur; + struct tresp_network_search resp; + int i = 0; + char *line = NULL; + const TcoreATResponse *atResp = data; + GSList *tokens = NULL; + GSList *network_token = NULL; + int AcT = 0; + char *temp_plmn_info = NULL; + char *pResp = NULL; + int num_network_avail = 0; + + memset(&resp, 0, sizeof(struct tresp_network_search)); + resp.result = TCORE_RETURN_FAILURE; + resp.list_count = 0; + + if (atResp->success > 0) { + dbg("RESPONSE OK"); + if (atResp->lines) { + line = (char *) atResp->lines->data; + tokens = tcore_at_tok_new(line); + num_network_avail = g_slist_length(tokens); + dbg(" length of tokens is %d\n", num_network_avail); + if (num_network_avail < 1) { + msg("invalid message"); + goto OUT; + } + } + + resp.result = TCORE_RETURN_SUCCESS; + /* + * +COPS: [list of supported (,long alphanumeric ,short alphanumeric ,numeric [,])s] + * [,,(list of supported s),(list of supported s)] + */ + + /* (2,"IND airtel","airtel","40445",2,),(1,"IND airtel","airtel","40445",0,),(3,"TATA DOCOMO","TATA DO","405034",2,) */ + + for (i = 0; ((i < num_network_avail) && (i < MAX_NETWORKS_MANUAL_SEARCH_SUPPORT)); i++) { + /* (2,"IND airtel","airtel","40445",2,) */ + network_token = tcore_at_tok_new(g_slist_nth_data(tokens, i)); + + pResp = (tcore_at_tok_nth(network_token, 0)); + if (pResp != NULL) { + dbg("status : %s", pResp); + resp.list[i].status = (enum telephony_network_plmn_status) atoi(pResp); + } + + if ((pResp = tcore_at_tok_nth(network_token, 1))) { /* Long Aplha name */ + dbg("Long Aplha name : %s", pResp); + + if (strlen(pResp) > 0) + /* Strip off starting quote & ending quote */ + strncpy(resp.list[i].name, pResp + 1, strlen(pResp) - 2); + } else if ((pResp = tcore_at_tok_nth(network_token, 2))) { + dbg("Short Aplha name : %s", pResp); + /* Short Aplha name */ + /* Strip off starting quote & ending quote */ + if (strlen(pResp) > 0) + strncpy(resp.list[i].name, pResp + 1, strlen(pResp) - 2); + } + + /* PLMN ID */ + pResp = tcore_at_tok_nth(network_token, 3); + if (pResp != NULL) { + dbg("PLMN ID : %s", pResp); temp_plmn_info = util_removeQuotes(pResp); - } - - memcpy(resp.list[i].plmn, temp_plmn_info, 6); - if (resp.list[i].plmn[5] == '#') - resp.list[i].plmn[5] = '\0'; - - /* Parse Access Technology */ - if((pResp = tcore_at_tok_nth(tokens, 4))) - { - if(strlen(pResp) > 0){ - AcT = atoi(pResp); - - if (0 == AcT) - resp.list[i].act = NETWORK_ACT_GSM; - else if(2 == AcT) - resp.list[i].act = NETWORK_ACT_UMTS; - } - } - - dbg("Operator [%d] :: stat = %d, Name =%s, plmnId = %s, AcT=%d\n", resp.list_count, resp.list[i].status, resp.list[i].name, resp.list[i].plmn, resp.list[i].act); - resp.list_count++; - - tcore_at_tok_free(network_token); - } - } - else - { - dbg("RESPONSE NOK"); - resp.result = TCORE_RETURN_FAILURE; - } - -OUT: - ur = tcore_pending_ref_user_request(p); - if (ur) { - tcore_user_request_send_response(ur, TRESP_NETWORK_SEARCH, sizeof(struct tresp_network_search), &resp); - } - - if(tokens) - tcore_at_tok_free(tokens); - - if(temp_plmn_info) + } + + memcpy(resp.list[i].plmn, temp_plmn_info, 6); + if (resp.list[i].plmn[5] == '#') + resp.list[i].plmn[5] = '\0'; + + /* Parse Access Technology */ + if ((pResp = tcore_at_tok_nth(tokens, 4))) { + if (strlen(pResp) > 0) { + AcT = atoi(pResp); + + if (0 == AcT) + resp.list[i].act = NETWORK_ACT_GSM; + else if (2 == AcT) + resp.list[i].act = NETWORK_ACT_UMTS; + } + } + + dbg("Operator [%d] :: stat = %d, Name =%s, plmnId = %s, AcT=%d\n", resp.list_count, resp.list[i].status, resp.list[i].name, resp.list[i].plmn, resp.list[i].act); + resp.list_count++; + + tcore_at_tok_free(network_token); + } + } else { + dbg("RESPONSE NOK"); + resp.result = TCORE_RETURN_FAILURE; + } + +OUT: + ur = tcore_pending_ref_user_request(p); + if (ur) { + tcore_user_request_send_response(ur, TRESP_NETWORK_SEARCH, sizeof(struct tresp_network_search), &resp); + } + + if (tokens) + tcore_at_tok_free(tokens); + + if (temp_plmn_info) free(temp_plmn_info); - - return; -} - -static void on_response_set_umts_band(TcorePending *p, int data_len, const void *data, void *user_data) -{ - const TcoreATResponse *atResp = data; - - dbg("On Response Set UMTS Band"); - - if(atResp->success > 0) { - dbg("Response OK"); - } - else { - dbg("Response NOK"); - } - - dbg("Wait for response of XRAT before sending final band setting response to AP"); - return; -} - - -static void on_response_set_gsm_band(TcorePending *p, int data_len, const void *data, void *user_data) -{ - const TcoreATResponse *atResp = data; - - dbg("On Response Set GSM Band"); - if(atResp->success > 0){ - dbg("Response OK"); - } - else{ - dbg("Response NOK"); - } - - dbg("Wait for response of XRAT before sending final band setting response to AP"); - return; -} - -static void on_response_get_umts_band(TcorePending *p, int data_len, const void *data, void *user_data) -{ - const TcoreATResponse *atResp = data; - GSList *tokens = NULL; - const char *line=NULL; - int total_umts_bands = 0; - int i = 0; - char *band_token = NULL; - char umts_band[20] = {0}; - char umts_band_1 = 0; - char umts_band_2 = 0; - char umts_band_5 = 0; - UserRequest *ur = NULL; - struct tresp_network_get_band resp = {0}; - - dbg("Entry on_response_get_umts_band"); - - resp.mode = NETWORK_BAND_MODE_PREFERRED; - resp.result = TCORE_RETURN_SUCCESS; - - if(atResp->success > 0) - { - dbg("RESPONSE OK"); - if(atResp->lines) { - line = (char*)atResp->lines->data; - tokens = tcore_at_tok_new(line); - total_umts_bands = g_slist_length(tokens); - dbg("Total UMTS bands enabled are : %d\n", total_umts_bands); - if (total_umts_bands < 1) { - goto OUT; - } - } - } - else - { - dbg("RESPONSE NOK"); - goto OUT; - } - - for (i = 0; isuccess > 0) - { - dbg("RESPONSE OK"); - if(atResp->lines) { - line = (char*)atResp->lines->data; - tokens = tcore_at_tok_new(line); - total_gsm_bands = g_slist_length(tokens); - dbg("Total GSM bands enabled are : %d\n", total_gsm_bands); - if (total_gsm_bands < 1) - goto OUT; - } - } - - for (i = 0; isuccess > 0) - { - dbg("RESPONSE OK"); - if(atResp->lines) { - line = (char*)atResp->lines->data; - tokens = tcore_at_tok_new(line); - if ( g_slist_length(tokens) < 1){ - msg("invalid message"); - goto OUT; - } - } - - if((pResp = tcore_at_tok_nth(tokens, 0))){ - cp_xrat = atoi(pResp); - - if((cp_xrat == AT_XRAT_DUAL)){ /* mode is Dual, send reply to Telephony */ - resp.result = TCORE_RETURN_SUCCESS; - resp.band = NETWORK_BAND_TYPE_ANY; - - ur = tcore_pending_ref_user_request(p); - if (ur) { - tcore_user_request_send_response(ur, TRESP_NETWORK_GET_BAND, sizeof(struct tresp_network_get_band), &resp); - } - goto OUT; - } - else if((cp_xrat == AT_XRAT_UMTS)){ - /* Get UMTS Band Information */ - dup_ur = tcore_user_request_ref(ur); /* duplicate user request for AT+XUBANDSEL */ - cmd_str = g_strdup_printf("AT+XUBANDSEL?"); - atreq = tcore_at_request_new(cmd_str, "+XUBANDSEL", TCORE_AT_SINGLELINE); - pending = tcore_pending_new(o, 0); - tcore_pending_set_request_data(pending, 0, atreq); - tcore_pending_set_response_callback(pending, on_response_get_umts_band, NULL); - tcore_pending_link_user_request(pending, ur); - tcore_pending_set_send_callback(pending, on_confirmation_network_message_send, NULL); - tcore_hal_send_request(h, pending); + + return; +} + +static void on_response_set_umts_band(TcorePending *p, int data_len, const void *data, void *user_data) +{ + const TcoreATResponse *atResp = data; + + dbg("On Response Set UMTS Band"); + + if (atResp->success > 0) { + dbg("Response OK"); + } else { + dbg("Response NOK"); + } + + dbg("Wait for response of XRAT before sending final band setting response to AP"); + return; +} + + +static void on_response_set_gsm_band(TcorePending *p, int data_len, const void *data, void *user_data) +{ + const TcoreATResponse *atResp = data; + + dbg("On Response Set GSM Band"); + if (atResp->success > 0) { + dbg("Response OK"); + } else { + dbg("Response NOK"); + } + + dbg("Wait for response of XRAT before sending final band setting response to AP"); + return; +} + +static void on_response_get_umts_band(TcorePending *p, int data_len, const void *data, void *user_data) +{ + const TcoreATResponse *atResp = data; + GSList *tokens = NULL; + const char *line = NULL; + int total_umts_bands = 0; + int i = 0; + char *band_token = NULL; + char umts_band[20] = {0}; + char umts_band_1 = 0; + char umts_band_2 = 0; + char umts_band_5 = 0; + UserRequest *ur = NULL; + struct tresp_network_get_band resp = {0}; + + dbg("Entry on_response_get_umts_band"); + + resp.mode = NETWORK_BAND_MODE_PREFERRED; + resp.result = TCORE_RETURN_SUCCESS; + + if (atResp->success > 0) { + dbg("RESPONSE OK"); + if (atResp->lines) { + line = (char *) atResp->lines->data; + tokens = tcore_at_tok_new(line); + total_umts_bands = g_slist_length(tokens); + dbg("Total UMTS bands enabled are : %d\n", total_umts_bands); + if (total_umts_bands < 1) { + goto OUT; + } + } + } else { + dbg("RESPONSE NOK"); + goto OUT; + } + + for (i = 0; i < total_umts_bands; i++) { + band_token = tcore_at_tok_nth(tokens, i); + + if (band_token == NULL) + continue; + + memset(umts_band, 0x00, sizeof(umts_band)); + + if (atoi(band_token) == 0) { /* 0 means UMTS automatic */ + umts_band_1 = umts_band_2 = umts_band_5 = TRUE; + break; + } + + /* Strip off starting quotes & ending quotes */ + strncpy(umts_band, band_token + 1, strlen(band_token) - 2); + + if (!strcmp(umts_band, "UMTS_BAND_I")) { + umts_band_1 = TRUE; + } else if (!strcmp(umts_band, "UMTS_BAND_II")) { + umts_band_2 = TRUE; + } else if (!strcmp(umts_band, "UMTS_BAND_II")) { + umts_band_5 = TRUE; + } else { + /* Telephony is not interest */ + dbg("Telephony is not interested in %s band", umts_band); + } + } + +OUT: + if ((umts_band_1) && (umts_band_2) && (umts_band_5)) { + resp.band = NETWORK_BAND_TYPE_WCDMA; + } else if (umts_band_1) { + resp.band = NETWORK_BAND_TYPE_WCDMA2100; + } else if (umts_band_2) { + resp.band = NETWORK_BAND_TYPE_WCDMA1900; + } else if (umts_band_5) { + resp.band = NETWORK_BAND_TYPE_WCDMA850; + } else { + resp.result = TCORE_RETURN_FAILURE; + } + + dbg("Final resp.band sent to TS = %d", resp.band); + + ur = tcore_pending_ref_user_request(p); + if (ur) { + tcore_user_request_send_response(ur, TRESP_NETWORK_GET_BAND, sizeof(struct tresp_network_get_band), &resp); + } + + if (tokens != NULL) + tcore_at_tok_free(tokens); + + dbg("Exit on_response_get_umts_band"); + return; +} + +static void on_response_get_gsm_band(TcorePending *p, int data_len, const void *data, void *user_data) +{ + struct tresp_network_get_band resp = {0}; + const TcoreATResponse *atResp = data; + GSList *tokens = NULL; + int total_gsm_bands = 0; + const char *line = NULL; + int i = 0; + char *band_token = NULL; + UserRequest *ur = NULL; + int gsm_850 = 0; + int gsm_900 = 0; + int gsm_1800 = 0; + int gsm_1900 = 0; + + dbg("Entry on_response_get_gsm_band"); + + resp.mode = NETWORK_BAND_MODE_PREFERRED; + resp.result = TCORE_RETURN_SUCCESS; + + if (atResp->success > 0) { + dbg("RESPONSE OK"); + if (atResp->lines) { + line = (char *) atResp->lines->data; + tokens = tcore_at_tok_new(line); + total_gsm_bands = g_slist_length(tokens); + dbg("Total GSM bands enabled are : %d\n", total_gsm_bands); + if (total_gsm_bands < 1) + goto OUT; + } + } + + for (i = 0; i < total_gsm_bands; i++) { + band_token = tcore_at_tok_nth(tokens, i); + + if (band_token == NULL) + continue; + + if (atoi(band_token) == 0) { /* 0 means GSM automatic */ + gsm_850 = gsm_900 = gsm_1800 = gsm_1900 = TRUE; + break; + } + + switch (atoi(band_token)) { + case AT_GSM_XBANDSEL_850: + gsm_850 = TRUE; + break; + + case AT_GSM_XBANDSEL_900: + gsm_900 = TRUE; + break; + + case AT_GSM_XBANDSEL_1800: + gsm_1800 = TRUE; + break; + + case AT_GSM_XBANDSEL_1900: + gsm_1900 = TRUE; + break; + + default: + break; + } + } + +OUT: + + if (gsm_850 && gsm_900 && gsm_1800 && gsm_1900) { + resp.band = NETWORK_BAND_TYPE_GSM; + } else if (gsm_850 && gsm_1900) { + resp.band = NETWORK_BAND_TYPE_GSM_850_1900; + } else if (gsm_900 && gsm_1800) { + resp.band = NETWORK_BAND_TYPE_GSM_900_1800; + } else if (gsm_1900) { + resp.band = NETWORK_BAND_TYPE_GSM1900; + } else if (gsm_850) { + resp.band = NETWORK_BAND_TYPE_GSM850; + } else if (gsm_1800) { + resp.band = NETWORK_BAND_TYPE_GSM1800; + } else if (gsm_900) { + resp.band = NETWORK_BAND_TYPE_GSM900; + } else { + resp.result = TCORE_RETURN_FAILURE; + } + + dbg("Final resp.band sent to TS = %d", resp.band); + + ur = tcore_pending_ref_user_request(p); + if (ur) { + tcore_user_request_send_response(ur, TRESP_NETWORK_GET_BAND, sizeof(struct tresp_network_get_band), &resp); + } + + if (tokens != NULL) + tcore_at_tok_free(tokens); + + dbg("Exit on_response_get_gsm_band"); + return; +} + + +static void on_response_get_xrat(TcorePending *p, int data_len, const void *data, void *user_data) +{ + TcoreHal *h = NULL; + UserRequest *ur = NULL; + + TcoreATRequest *atreq; + char *cmd_str = NULL; + UserRequest *dup_ur = NULL; + const TcoreATResponse *atResp = data; + const char *line = NULL; + char *pResp = NULL; + GSList *tokens = NULL; + TcorePending *pending = NULL; + CoreObject *o = NULL; + int cp_xrat = 0; + struct tresp_network_get_band resp = {0}; + + dbg("Enter on_response_get_xrat !!"); + + resp.mode = NETWORK_BAND_MODE_PREFERRED; + + ur = tcore_pending_ref_user_request(p); + h = tcore_object_get_hal(tcore_pending_ref_core_object(p)); + o = tcore_pending_ref_core_object(p); + + if (atResp->success > 0) { + dbg("RESPONSE OK"); + if (atResp->lines) { + line = (char *) atResp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) < 1) { + msg("invalid message"); + goto OUT; + } + } + + if ((pResp = tcore_at_tok_nth(tokens, 0))) { + cp_xrat = atoi(pResp); + + if ((cp_xrat == AT_XRAT_DUAL)) { /* mode is Dual, send reply to Telephony */ + resp.result = TCORE_RETURN_SUCCESS; + resp.band = NETWORK_BAND_TYPE_ANY; + + ur = tcore_pending_ref_user_request(p); + if (ur) { + tcore_user_request_send_response(ur, TRESP_NETWORK_GET_BAND, sizeof(struct tresp_network_get_band), &resp); + } + goto OUT; + } else if ((cp_xrat == AT_XRAT_UMTS)) { + /* Get UMTS Band Information */ + dup_ur = tcore_user_request_ref(ur); /* duplicate user request for AT+XUBANDSEL */ + cmd_str = g_strdup_printf("AT+XUBANDSEL?"); + atreq = tcore_at_request_new(cmd_str, "+XUBANDSEL", TCORE_AT_SINGLELINE); + pending = tcore_pending_new(o, 0); + tcore_pending_set_request_data(pending, 0, atreq); + tcore_pending_set_response_callback(pending, on_response_get_umts_band, NULL); + tcore_pending_link_user_request(pending, ur); + tcore_pending_set_send_callback(pending, on_confirmation_network_message_send, NULL); + tcore_hal_send_request(h, pending); g_free(cmd_str); - } - else if((cp_xrat == AT_XRAT_UMTS)){ - /* Get GSM Band Information */ - dup_ur = tcore_user_request_ref(ur); /* duplicate user request for AT+XBANDSEL */ - cmd_str = g_strdup_printf("AT+XBANDSEL?"); - atreq = tcore_at_request_new(cmd_str, "+XBANDSEL", TCORE_AT_SINGLELINE); - pending = tcore_pending_new(o, 0); - tcore_pending_set_request_data(pending, 0, atreq); - tcore_pending_set_response_callback(pending, on_response_get_gsm_band, NULL); - tcore_pending_link_user_request(pending, dup_ur); - tcore_pending_set_send_callback(pending, on_confirmation_network_message_send, NULL); - tcore_hal_send_request(h, pending); + } else if ((cp_xrat == AT_XRAT_UMTS)) { + /* Get GSM Band Information */ + dup_ur = tcore_user_request_ref(ur); /* duplicate user request for AT+XBANDSEL */ + cmd_str = g_strdup_printf("AT+XBANDSEL?"); + atreq = tcore_at_request_new(cmd_str, "+XBANDSEL", TCORE_AT_SINGLELINE); + pending = tcore_pending_new(o, 0); + tcore_pending_set_request_data(pending, 0, atreq); + tcore_pending_set_response_callback(pending, on_response_get_gsm_band, NULL); + tcore_pending_link_user_request(pending, dup_ur); + tcore_pending_set_send_callback(pending, on_confirmation_network_message_send, NULL); + tcore_hal_send_request(h, pending); g_free(cmd_str); - } - } - } - else { - dbg("RESPONSE NOK"); - - resp.result = TCORE_RETURN_FAILURE; - resp.band = NETWORK_BAND_TYPE_ANY; - - ur = tcore_pending_ref_user_request(p); - if (ur) { - tcore_user_request_send_response(ur, TRESP_NETWORK_GET_BAND, sizeof(struct tresp_network_get_band), &resp); - } - } -OUT: - - if(tokens != NULL) - tcore_at_tok_free(tokens); - - dbg("Exit on_response_get_xrat !!"); - - return; -} - - -static void on_response_set_xrat(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur = NULL; - struct tresp_network_set_band resp = {0}; - const TcoreATResponse *atResp = data; - - dbg("On Response Set XRAT"); - - if(atResp->success > 0){ - dbg("Response OK"); - resp.result = TCORE_RETURN_SUCCESS; - }else{ - dbg("Response NOK"); - resp.result = TCORE_RETURN_FAILURE; - } - - ur = tcore_pending_ref_user_request(p); - if (ur) { - tcore_user_request_send_response(ur, TRESP_NETWORK_SET_BAND, sizeof(struct tresp_network_set_band), &resp); - } - - return; -} - -static void on_response_set_preferred_plmn(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur = NULL; - struct tresp_network_set_preferred_plmn resp = {0}; - const TcoreATResponse *atResp = data; - - dbg("ENTER on_response_set_preferred_plmn"); - - if(atResp->success > 0) - { - dbg("Response OK"); - resp.result = TCORE_RETURN_SUCCESS; - }else - { - dbg("Response NOK"); - resp.result = TCORE_RETURN_FAILURE; - } - - ur = tcore_pending_ref_user_request(p); - if (ur) { - tcore_user_request_send_response(ur, TRESP_NETWORK_SET_PREFERRED_PLMN, sizeof(struct tresp_network_set_preferred_plmn), &resp); - } - - dbg("Exit on_response_set_preferred_plmn"); - return; -} - -static void on_response_get_nitz_name(TcorePending *p, int data_len, const void *data, void *user_data) -{ - - - const TcoreATResponse *atResp = data; - GSList *tokens = NULL; - const char *line=NULL; - CoreObject *o = NULL; - struct tnoti_network_identity noti; - int nol = 0; - int count = 0; - int net_name_type = 0; - char *pResp = NULL; - - dbg("Entry on_response_get_nitz_name (+XCOPS)"); - o = tcore_pending_ref_core_object(p); - if(atResp->success > 0) - { - dbg("RESPONSE OK"); - - if(atResp->lines) { - nol = g_slist_length(atResp->lines); - if(nol > 3){ - msg("invalid message"); - goto OUT; - } - - for(count =0; count < nol; count++){ - //parse each line - line = g_slist_nth_data(atResp->lines, count); - tokens = tcore_at_tok_new(line); - dbg("line %d start---------------",count); - - if ((pResp = tcore_at_tok_nth(tokens, 0))){ - net_name_type = atoi(pResp); - dbg("Net name type : %d", net_name_type); - - switch(net_name_type) - { - case 0: /* plmn_id (mcc, mnc) */ - if ((pResp = tcore_at_tok_nth(tokens, 1))){ - strncpy(noti.plmn, pResp+1, strlen(pResp)-2); /* skip quotes (") while copying */ - } - break; - - case 5: /* Short Nitz name*/ - if ((pResp = tcore_at_tok_nth(tokens, 1))){ - strncpy(noti.short_name, pResp+1, strlen(pResp)-2); /* skip quotes (") while copying */ - } - break; - - case 6: /* Full Nitz name */ - if ((pResp = tcore_at_tok_nth(tokens, 1))){ - strncpy(noti.full_name, pResp+1, strlen(pResp)-2); /* skip quotes (") while copying */ - } - break; - - default: - break; - } - } - if(tokens != NULL) - tcore_at_tok_free(tokens); - } - - tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_NETWORK_IDENTITY, - sizeof(struct tnoti_network_identity), ¬i); - } - } - else{ - dbg("RESPONSE NOK"); - } - -OUT: - dbg("Exit on_response_get_nitz_name"); - -} - -static void on_response_get_preferred_plmn(TcorePending *p, int data_len, const void *data, void *user_data) -{ - UserRequest *ur; - int i = 0; - char* line=NULL; - const TcoreATResponse *atResp = data; - GSList *tokens = NULL; - char temp_plmn_info[17] = {0}; - char *pResp = NULL; - int plmn_format = 0; - - struct tresp_network_get_preferred_plmn resp = {0}; - int total_lines = 0; - int GSM_AcT2 = 0, GSM_Compact_AcT2= 0, UTRAN_AcT2 = 0; - - dbg("Entry on_response_get_preferred_plmn"); - - if(atResp->success > 0) - { - dbg("RESPONSE OK"); - if(atResp->lines) { - total_lines = g_slist_length(atResp->lines); - dbg("Total number of network present in Preferred PLMN list is %d\n", total_lines); - - if (total_lines < 1) { - msg("invalid message"); - goto OUT; - } - - if (total_lines >= MAX_NETWORKS_PREF_PLMN_SUPPORT) - total_lines = MAX_NETWORKS_PREF_PLMN_SUPPORT; - -/* -+COPL: ,,[,,,,] [ -+CPOL: ,,[,,,,] -*/ - - resp.result = TCORE_RETURN_SUCCESS; - - for (i=0; ilines, i); - tokens = tcore_at_tok_new(line); - - /* ,,[,,,,] */ - - /* EF Index */ - if ((pResp = tcore_at_tok_nth(tokens, 0))) - { - dbg("Index : %s",pResp); - resp.list[i].ef_index = atoi(pResp); - } - /* Format */ - if((pResp = tcore_at_tok_nth(tokens, 1))) - { - dbg("format : %s",pResp); - plmn_format = atoi(pResp); - } - - /* Operator PLMN ID */ - if((pResp = tcore_at_tok_nth(tokens, 2))) - { - dbg("plmn ID : %s",pResp); - - if(strlen(pResp) > 0){ - strncpy(temp_plmn_info, pResp+1, (strlen(pResp))-2); - - //Get only PLMN ID - if (plmn_format == 2) - { - //cp_plmn = util_hexStringToBytes(temp_plmn_info); - - if (strncmp((char *)temp_plmn_info, "000000", 6) == 0) - continue; - - memcpy(resp.list[i].plmn, temp_plmn_info, 6); - if (resp.list[i].plmn[5] == '#') - resp.list[i].plmn[5] = '\0'; - - //free(cp_plmn); - } - } - } - - if((pResp = tcore_at_tok_nth(tokens, 3))){ - dbg("GSM_AcT2 : %s",pResp); - GSM_AcT2 = atoi(pResp); - } - - if((pResp = tcore_at_tok_nth(tokens, 4))){ - dbg("GSM_Compact AcT2 : %s",pResp); - GSM_Compact_AcT2 = atoi(pResp); - } - - if((pResp = tcore_at_tok_nth(tokens, 5))){ - dbg("UTRAN_AcT2 : %s",pResp); - UTRAN_AcT2 = atoi(pResp); - } - - if(UTRAN_AcT2 && (GSM_AcT2 ||GSM_Compact_AcT2)) - resp.list[i].act = NETWORK_ACT_GSM_UTRAN; - else if (UTRAN_AcT2) - resp.list[i].act = NETWORK_ACT_UMTS; - else if (GSM_AcT2 || GSM_Compact_AcT2) - resp.list[i].act = NETWORK_ACT_GPRS; - - (resp.list_count)++; - - tcore_at_tok_free(tokens); - } - } - } -OUT: - ur = tcore_pending_ref_user_request(p); - if (ur) { - tcore_user_request_send_response(ur, TRESP_NETWORK_GET_PREFERRED_PLMN, sizeof(struct tresp_network_get_preferred_plmn), &resp); - } - dbg("Exit"); - return; -} - -static void on_response_get_serving_network(TcorePending *p, int data_len, const void *data, void *user_data) -{ - const TcoreATResponse* resp = data; - UserRequest *ur; - struct tresp_network_get_serving_network Tresp = {0}; - char plmn[7] = {0}; - char *long_plmn_name = NULL; - char *short_plmn_name = NULL; - CoreObject *o; - GSList *tokens=NULL; - const char *line; - int network_mode = -1; - int plmn_format = -1; - int AcT = -1; - struct tnoti_network_identity noti; - char *pResp = NULL; - int nol, count =0; - - o = tcore_pending_ref_core_object(p); - - if(resp->success <= 0){ - dbg("RESPONSE NOK"); - - ur = tcore_pending_ref_user_request(p); - if (ur) { - Tresp.result = TCORE_RETURN_FAILURE; - tcore_user_request_send_response(ur, TRESP_NETWORK_GET_SERVING_NETWORK, sizeof(struct tresp_network_get_serving_network), &Tresp); - } - - return; + } + } + } else { + dbg("RESPONSE NOK"); + + resp.result = TCORE_RETURN_FAILURE; + resp.band = NETWORK_BAND_TYPE_ANY; + + ur = tcore_pending_ref_user_request(p); + if (ur) { + tcore_user_request_send_response(ur, TRESP_NETWORK_GET_BAND, sizeof(struct tresp_network_get_band), &resp); + } } - else - { - dbg("RESPONSE OK"); - nol = g_slist_length(resp->lines); - dbg("nol : %d", nol); - - for(count =0; count < nol; count++){ - //parse each line - line = g_slist_nth_data(resp->lines, count); - tokens = tcore_at_tok_new(line); - dbg("line %d start---------------",count); - //mode - if((pResp = tcore_at_tok_nth(tokens, 0))){ - dbg("mode : %s",pResp); - network_mode = atoi(pResp); - } - - //format (optional) - if((pResp = tcore_at_tok_nth(tokens, 1))) - { - dbg("format : %s",pResp); - if(strlen(pResp)>0) - plmn_format = atoi(pResp); - } - - //plmn - switch(plmn_format) - { - case AT_COPS_FORMAT_LONG_ALPHANUMERIC: - if((pResp = tcore_at_tok_nth(tokens, 2))) - { - dbg("long PLMN : %s",pResp); - if(strlen(pResp) > 0){ - long_plmn_name = util_removeQuotes(pResp); - - //set network name into po - tcore_network_set_network_name(o,TCORE_NETWORK_NAME_TYPE_FULL,long_plmn_name); - } - } - break; - - case AT_COPS_FORMAT_SHORT_ALPHANUMERIC: - if((pResp = tcore_at_tok_nth(tokens, 2))) - { - dbg("short PLMN : %s",pResp); - if(strlen(pResp)>0){ - short_plmn_name = util_removeQuotes(pResp); - - //set network name into po - tcore_network_set_network_name(o,TCORE_NETWORK_NAME_TYPE_SHORT,short_plmn_name); - } - } - break; - - case AT_COPS_FORMAT_NUMERIC: - if((pResp = tcore_at_tok_nth(tokens, 2))) - { - dbg("numeric : %s", pResp); - if(strlen(pResp)>0){ - memset(plmn, 0, 7); - - /* Strip off starting quotes & ending quotes */ - strncpy(plmn, pResp+1, strlen(pResp)-2); - tcore_network_set_plmn(o,plmn); - } - } - break; - - default: - break; - } - - //act - if((pResp = tcore_at_tok_nth(tokens, 3))) - { - dbg("AcT : %s",pResp); - if(strlen(pResp)>0){ - AcT = atoi(pResp); - tcore_network_set_access_technology(o, lookup_tbl_access_technology[AcT]); - } - } - - tcore_at_tok_free(tokens); - } - - memcpy(Tresp.plmn, plmn, 7); - tcore_network_get_access_technology(o, &(Tresp.act)); - tcore_network_get_lac(o, &(Tresp.gsm.lac)); - - ur = tcore_pending_ref_user_request(p); - if (ur) { - Tresp.result = TCORE_RETURN_SUCCESS; - tcore_user_request_send_response(ur, TRESP_NETWORK_GET_SERVING_NETWORK, sizeof(struct tresp_network_get_serving_network), &Tresp); - } - else - { - /* Network change noti */ - struct tnoti_network_change network_change; - - memset(&network_change, 0, sizeof(struct tnoti_network_change)); - memcpy(network_change.plmn, plmn, 7); - tcore_network_get_access_technology(o, &(network_change.act)); - tcore_network_get_lac(o, &(network_change.gsm.lac)); - - tcore_server_send_notification(tcore_plugin_ref_server(tcore_pending_ref_plugin(p)), tcore_pending_ref_core_object(p), - TNOTI_NETWORK_CHANGE, sizeof(struct tnoti_network_change), &network_change); - dbg("dbg.. network_change.plmn : %s",network_change.plmn); - dbg("dbg.. network_change.act : %d",network_change.act); - dbg("dbg.. network_change.gsm.lac : %d",network_change.gsm.lac); - - if((AT_COPS_MODE_DEREGISTER !=network_mode) && - (AT_COPS_MODE_SET_ONLY != network_mode)){ - /*Network identity noti*/ - memset(¬i, 0x0, sizeof(struct tnoti_network_change)); - if(long_plmn_name) - memcpy(noti.full_name, long_plmn_name, MIN(33, strlen(long_plmn_name)) ); - if(short_plmn_name) - memcpy(noti.short_name, short_plmn_name, MIN(17, strlen(long_plmn_name)) ); - memcpy(noti.plmn, plmn,7); - tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), - o, TNOTI_NETWORK_IDENTITY, sizeof(struct tnoti_network_identity), ¬i); - dbg("dbg.. noti.short_name : %s",noti.short_name); - dbg("dbg.. noti.full_name : %s",noti.full_name); - dbg("dbg.. noti.plmn : %s",noti.plmn); - } - } - if(long_plmn_name) - free(long_plmn_name); - if(short_plmn_name) - free(short_plmn_name); - - } - return; -} - -static gboolean on_event_ps_network_regist(CoreObject *o, const void *data, void *user_data) -{ - struct tnoti_network_registration_status regist_status; - enum telephony_network_service_domain_status cs_status; - enum telephony_network_service_domain_status ps_status; - enum telephony_network_service_type service_type; - enum telephony_network_access_technology act = NETWORK_ACT_UNKNOWN; - struct tnoti_network_location_cellinfo net_lac_cell_info = {0}; - struct tnoti_ps_protocol_status noti = {0}; - unsigned char svc_domain = NETWORK_SERVICE_DOMAIN_PS; - int stat= 0, AcT=0; - unsigned int lac=0xffff, ci=0xffff; - unsigned int rac = 0xffff; - GSList* tokens = NULL; - char* pResp; - char *line = NULL; - GSList *lines = NULL; - - lines = (GSList*)data; - if (1 != g_slist_length(lines)) { - dbg("unsolicited msg but multiple line"); - goto OUT; - } - line = (char*)(lines->data); - dbg("+CGREG NOTI RECEIVED"); - -/* -+CREG: [[,,[AcT]] - -Possible values of can be -0 Not registered, ME is not currently searching a new operator to register to -1 Registered, home network -2 Not registered, but ME is currently searching a new operator to register -3 Registration denied -4 Unknown -5 Registered, in roaming - - -string type; two byte location area code in hexadecimal format (e.g. �00C3�) - - -string type; four byte cell ID in hexadecimal format (e.g. �0000A13F�) - - -0 GSM -2 UTRAN -3 GSM w/EGPRS -4 UTRAN w/HSDPA -5 UTRAN w/HSUPA -6 UTRAN w/HSDPA and HSUPA -Note: is supporting from R7 and above Protocol Stack. - -: is R7 and above feature, string type; one byte routing area code in hexadecimal format. -*/ - if (line!=NULL) - { - tokens = tcore_at_tok_new(line); - if(g_slist_length(tokens) < 1) { - msg("invalid message"); - goto OUT; - } - - if(!(pResp = g_slist_nth_data(tokens, 0))) - { - dbg("No STAT in +CGREG"); - goto OUT; - } - else - { - stat = atoi(pResp); - if((pResp = g_slist_nth_data(tokens, 1))) - lac = atoi(pResp); - - if((pResp = g_slist_nth_data(tokens, 2))) - ci = atoi(pResp); - else - dbg("No ci in +CGREG"); - - if((pResp = g_slist_nth_data(tokens, 3))) - AcT = atoi(pResp); - else - dbg("No AcT in +CGREG"); - - if((pResp = g_slist_nth_data(tokens, 4))) - rac = atoi(pResp); - else - dbg("No rac in +CGREG"); - } - - - dbg("stat=%d, lac=0x%lx, ci=0x%lx, Act=%d, rac = 0x%x", stat, lac, ci, AcT, rac); - - ps_status = lookup_tbl_net_status[stat]; - - tcore_network_set_service_status(o, TCORE_NETWORK_SERVICE_DOMAIN_TYPE_PACKET, ps_status); - _ps_set(tcore_object_ref_plugin(o), ps_status); - - tcore_network_get_service_status(o, TCORE_NETWORK_SERVICE_DOMAIN_TYPE_CIRCUIT, &cs_status); - - act = lookup_tbl_access_technology[AcT]; - tcore_network_set_access_technology(o, act); - - if (stat == AT_CREG_STAT_REG_ROAM) - tcore_network_set_roaming_state(o, TRUE); - else - tcore_network_set_roaming_state(o, FALSE); - - tcore_network_get_service_type(o, &service_type); - dbg("prev_service_type = 0x%x", service_type); - service_type = _get_service_type(service_type, svc_domain, act, cs_status, ps_status); - dbg("new_service_type = 0x%x", service_type); - tcore_network_set_service_type(o, service_type); - - tcore_network_set_lac(o, lac); - tcore_network_set_cell_id(o, ci); - tcore_network_set_rac(o, rac); - - net_lac_cell_info.lac = lac; - net_lac_cell_info.cell_id = ci; - - tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_NETWORK_LOCATION_CELLINFO, - sizeof(struct tnoti_network_location_cellinfo), &net_lac_cell_info); - - regist_status.cs_domain_status = cs_status; - regist_status.ps_domain_status = ps_status; - regist_status.service_type = service_type; - regist_status.roaming_status = tcore_network_get_roaming_state(o); - - tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, - TNOTI_NETWORK_REGISTRATION_STATUS, sizeof(struct tnoti_network_registration_status), ®ist_status); - - if(service_type == NETWORK_SERVICE_TYPE_HSDPA) - noti.status = TELEPHONY_HSDPA_ON; - else - noti.status = TELEPHONY_HSDPA_OFF; - - tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_PS_PROTOCOL_STATUS, - sizeof(struct tnoti_ps_protocol_status), ¬i); - - /* Get PLMN ID needed to application */ - //get_serving_network(o, NULL); - - - } - else - { - dbg("Response NOK"); - } - -OUT: - if(NULL!=tokens) - tcore_at_tok_free(tokens); - return TRUE; -} - -static gboolean on_event_cs_network_regist(CoreObject *o, const void *event_info, void *user_data) -{ - GSList *lines = NULL; - char *line = NULL; - struct tnoti_network_registration_status regist_status; - enum telephony_network_service_domain_status cs_status; - enum telephony_network_service_domain_status ps_status; - enum telephony_network_service_type service_type; - enum telephony_network_access_technology act = NETWORK_ACT_UNKNOWN; - struct tnoti_network_location_cellinfo net_lac_cell_info = {0}; - - - unsigned char svc_domain = NETWORK_SERVICE_DOMAIN_CS; - int stat= 0, AcT=0; - unsigned int lac=0xffff, ci=0xffff; - GSList* tokens = NULL; - char* pResp; - - lines = (GSList*)event_info; - if (1 != g_slist_length(lines)) { - dbg("unsolicited msg but multiple line"); - goto OUT; - } - line = (char*)(lines->data); - - dbg("+CREG NOTI RECEIVED"); - -/* -+CREG: [[,,[AcT]] - -Possible values of can be -0 Not registered, ME is not currently searching a new operator to register to -1 Registered, home network -2 Not registered, but ME is currently searching a new operator to register -3 Registration denied -4 Unknown -5 Registered, in roaming - - -string type; two byte location area code in hexadecimal format (e.g. �00C3�) - - -string type; four byte cell ID in hexadecimal format (e.g. �0000A13F�) - - -0 GSM -2 UTRAN -3 GSM w/EGPRS -4 UTRAN w/HSDPA -5 UTRAN w/HSUPA -6 UTRAN w/HSDPA and HSUPA -Note: is supporting from R7 and above Protocol Stack. -*/ - if (line!=NULL) - { - tokens = tcore_at_tok_new(line); - if(g_slist_length(tokens) < 1) { - msg("invalid message"); - goto OUT; - } - - if(!(pResp = g_slist_nth_data(tokens, 0))) - { - dbg("No STAT in +CREG"); - goto OUT; - } - else - { - stat = atoi(pResp); - if((pResp = g_slist_nth_data(tokens, 1))) - lac = atoi(pResp); - - if((pResp = g_slist_nth_data(tokens, 2))) - ci = atoi(pResp); - else - dbg("No ci in +CREG"); - - if((pResp = g_slist_nth_data(tokens, 3))) - AcT = atoi(pResp); - else - dbg("No AcT in +CREG"); - } - - - dbg("stat=%d, lac=0x%lx, ci=0x%lx, Act=%d", stat, lac, ci, AcT); - - cs_status = lookup_tbl_net_status[stat]; - tcore_network_set_service_status(o, TCORE_NETWORK_SERVICE_DOMAIN_TYPE_CIRCUIT, cs_status); - - // tcore_network_get_service_status(o, TCORE_NETWORK_SERVICE_DOMAIN_TYPE_CIRCUIT, &cs_status); - tcore_network_get_service_status(o, TCORE_NETWORK_SERVICE_DOMAIN_TYPE_PACKET, &ps_status); - - act = lookup_tbl_access_technology[AcT]; - tcore_network_set_access_technology(o, act); - - if (stat == AT_CREG_STAT_REG_ROAM) - tcore_network_set_roaming_state(o, TRUE); - else - tcore_network_set_roaming_state(o, FALSE); - - tcore_network_get_service_type(o, &service_type); - dbg("prev_service_type = 0x%x", service_type); - service_type = _get_service_type(service_type, svc_domain, act, cs_status, ps_status); - dbg("new_service_type = 0x%x", service_type); - tcore_network_set_service_type(o, service_type); - - tcore_network_set_lac(o, lac); - tcore_network_set_cell_id(o, ci); - - net_lac_cell_info.lac = lac; - net_lac_cell_info.cell_id = ci; - - tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_NETWORK_LOCATION_CELLINFO, - sizeof(struct tnoti_network_location_cellinfo), &net_lac_cell_info); - - regist_status.cs_domain_status = cs_status; - regist_status.ps_domain_status = ps_status; - regist_status.service_type = service_type; - regist_status.roaming_status = tcore_network_get_roaming_state(o); - - tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, - TNOTI_NETWORK_REGISTRATION_STATUS, sizeof(struct tnoti_network_registration_status), ®ist_status); - - /* Get PLMN ID needed to application */ - if((NETWORK_SERVICE_DOMAIN_STATUS_FULL == cs_status )|| - NETWORK_SERVICE_DOMAIN_STATUS_FULL ==ps_status ) - get_serving_network(o, NULL); - } - else - { - dbg("Response NOK"); - } - -OUT: - if(NULL!=tokens) - tcore_at_tok_free(tokens); - return TRUE; - -} - -static gboolean on_event_network_icon_info(CoreObject *o, const void *event_info, void *user_data) -{ - struct tnoti_network_icon_info net_icon_info = {0}; - char *line = NULL; - char * rssiToken = NULL; - char *batteryToken = NULL; - GSList* tokens = NULL; - GSList *lines = NULL; - - lines = (GSList*)event_info; - if (1 != g_slist_length(lines)) { - dbg("unsolicited msg but multiple line"); - goto OUT; - } - line = (char*)(lines->data); - dbg("+XCIEV Network Icon Info Noti Recieve"); - memset(&net_icon_info, 0, sizeof(struct tnoti_network_icon_info)); - - if(line != NULL) - { - dbg("Response OK"); - - tokens = tcore_at_tok_new(line); - if (g_slist_length(tokens) != 2) { - msg("invalid message"); - goto OUT; - } - - rssiToken = (char *)g_slist_nth_data(tokens, 0); - - if (strlen(rssiToken)>0) - { - net_icon_info.type = NETWORK_ICON_INFO_RSSI; - net_icon_info.rssi= atoi(g_slist_nth_data(tokens, 0)); - dbg("rssi level : %d",net_icon_info.rssi); - } - - batteryToken = (char *)g_slist_nth_data(tokens,1); - if (strlen(batteryToken)>0) - { - net_icon_info.type = NETWORK_ICON_INFO_BATTERY; - net_icon_info.battery= atoi(g_slist_nth_data(tokens, 1)); - dbg("battery level : %d",net_icon_info.battery); - } - - tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_NETWORK_ICON_INFO, - sizeof(struct tnoti_network_icon_info), &net_icon_info); - } - else - { - dbg("Response NOK"); - } - - -OUT: - if(NULL!=tokens) - tcore_at_tok_free(tokens); - - return TRUE; - -} - -static gboolean on_event_network_ctzv_time_info(CoreObject *o, const void *event_info, void *user_data) -{ - struct tnoti_network_timeinfo net_time_info = {0}; - char *line = NULL; - GSList* tokens = NULL; - char *time= NULL; - char *time_zone = NULL; - GSList *lines = NULL; - char ptime_param[20] = {0}; - UserRequest *ur = NULL; - dbg("Enter : on_event_network_ctzv_time_info"); - - lines = (GSList*)event_info; - if (1 != g_slist_length(lines)) { - dbg("unsolicited msg but multiple line"); - goto OUT; - } - line = (char*)(lines->data); - -/* -+CTZV: ,