3 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
22 #include <tapi_common.h>
23 #include <ITapiModem.h>
28 #include "dr-common.h"
32 #define ACM_WAIT_TIME 300000
34 extern dr_info_t dr_info;
35 volatile gboolean dsr_status = FALSE;
36 TapiHandle *tapi_handle = NULL;
39 static void __usb_status_noti_handler(void *data)
45 if (_get_usb_state(&usb_state) < 0) {
46 ERR(" Unable to get usb status !\n");
50 ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &usb_mode);
52 DBG("Vconf get failed\n");
56 DBG("USB noti handler, USB state : %d, Mode : %d\n", usb_state, usb_mode);
57 DBG("usb_fd = 0x%x\n", dr_info.usb.usb_fd);
61 * If USB driver builted in the Kernel, VCONFKEY_SYSMAN_USB_CONNECTED is not used.
62 * If USB driver loaded in DR/MTP then need to check VCONFKEY_SYSMAN_USB_CONNECTED.
63 * After usb driver loaded, MTP will be set vconf value as VCONFKEY_SYSMAN_USB_CONNECTED
65 if (usb_state != VCONFKEY_SYSMAN_USB_DISCONNECTED &&
66 usb_mode == SETTING_USB_DEFAULT_MODE) {
68 } else if (usb_state == VCONFKEY_SYSMAN_USB_DISCONNECTED) {
75 static void __usb_mode_noti_handler(void *data)
81 ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &usb_mode);
83 DBG("Vconf get failed\n");
87 DBG("USB Mode noti handler, USB Mode : %d\n", usb_mode);
88 DBG("usb_fd = 0x%x\n", dr_info.usb.usb_fd);
90 if (usb_mode != SETTING_USB_DEFAULT_MODE) {
99 gboolean _register_vconf_notification(void)
104 vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS, (vconf_callback_fn) __usb_status_noti_handler, NULL);
106 ERR("Error !!! VCONFKEY reg noti : %s\n", VCONFKEY_SYSMAN_USB_STATUS);
110 vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
111 (vconf_callback_fn) __usb_mode_noti_handler, NULL);
113 ERR("Error !!! VCONFKEY reg noti : %s\n", VCONFKEY_SETAPPL_USB_MODE_INT);
119 void _unregister_vconf_notification(void)
121 vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS, (vconf_callback_fn) __usb_status_noti_handler);
122 vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT, (vconf_callback_fn) __usb_mode_noti_handler);
127 static void __dcd_pin_handler(tapi_ps_btdun_pincontrol_status status)
131 if (status == GPRS_SIGNAL_STATUS_ON) {
132 DBG("Receive DCD + from Modem\n");
133 dr_info.line.output_line_state.bits.dcd = TRUE;
134 DBG("Current modem output line status = 0x%X\n",
135 dr_info.line.output_line_state.state);
136 }else if (status == GPRS_SIGNAL_STATUS_OFF) {
137 DBG("Receive DCD - from Modem\n");
138 dr_info.line.output_line_state.bits.dcd = FALSE;
139 DBG("Current modem output line status = 0x%X\n",
140 dr_info.line.output_line_state.state);
142 _send_usb_line_state(dr_info.line.output_line_state.state);
145 static void __dsr_pin_handler(tapi_ps_btdun_pincontrol_status status)
147 if (status == GPRS_SIGNAL_STATUS_ON) {
148 dr_info.line.output_line_state.bits.dsr = TRUE;
150 DBG("Receive DSR+ from modem\n");
151 }else if (status == GPRS_SIGNAL_STATUS_OFF) {
152 dr_info.line.output_line_state.bits.dsr = FALSE;
155 DBG("Receive DSR- from modem\n");
157 _send_usb_line_state(dr_info.line.output_line_state.state);
162 static void __tel_dun_pincontrol_handler(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
169 tapi_ps_btdun_pincontrol *pinctrl;
170 pinctrl = (tapi_ps_btdun_pincontrol *)data;
172 DBG("pincontrol - Signal: %d, status: %d\n", pinctrl->signal, pinctrl->status);
173 switch (pinctrl->signal) {
174 case GPRS_DATA_SIGNAL_DSR:
175 __dsr_pin_handler(pinctrl->status);
177 case GPRS_SIGNAL_DCD:
178 __dcd_pin_handler(pinctrl->status);
188 gboolean _register_telephony_event(void)
192 tapi_handle = tel_init(NULL);
193 if (tapi_handle == NULL) {
194 ERR("tel_init failed !!!\n");
198 ret = tel_register_noti_event(tapi_handle, TAPI_NOTI_MODEM_DUN_PIN_CTRL,
199 __tel_dun_pincontrol_handler,
205 void _unregister_telephony_event(void)
207 tel_deregister_noti_event(tapi_handle, TAPI_NOTI_MODEM_DUN_PIN_CTRL);
209 if (tel_deinit(tapi_handle) != TAPI_API_SUCCESS) {
210 ERR("tel_deinit failed !!!\n");