4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
24 #ifndef __DEF_BT_HF_AGENT_H_
25 #define __DEF_BT_HF_AGENT_H_
38 #include <sys/socket.h>
41 #define LOG_TAG "BLUETOOTH_HF_AGENT"
43 #define LOG_COLOR_RESET "\033[0m"
44 #define LOG_COLOR_RED "\033[31m"
45 #define LOG_COLOR_YELLOW "\033[33m"
46 #define LOG_COLOR_GREEN "\033[32m"
47 #define LOG_COLOR_BLUE "\033[36m"
48 #define LOG_COLOR_PURPLE "\033[35m"
50 #define DBG(fmt, args...) SLOGD(fmt, ##args)
51 #define INFO(fmt, args...) SLOGI(fmt, ##args)
52 #define ERR(fmt, args...) SLOGE(fmt, ##args)
53 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
54 #define INFO_SECURE(fmt, args...) SECURE_SLOGI(fmt, ##args)
55 #define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
56 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
57 #define INFO_C(fmt, arg...) \
58 SLOGI_IF(TRUE, LOG_COLOR_BLUE" "fmt" "LOG_COLOR_RESET, ##arg)
59 #define ERR_C(fmt, arg...) \
60 SLOGI_IF(TRUE, LOG_COLOR_RED" "fmt" "LOG_COLOR_RESET, ##arg)
62 #define retv_if(expr, val) \
65 ERR("(%s) return", #expr); \
71 #define BT_HF_DATA_BUF_SIZE 1024
72 #define BT_HF_CMD_BUF_SIZE 32
73 #define BT_HF_INDICATOR_DESCR_SIZE 20
74 #define BT_HF_CALLER_NUM_SIZE 64 /* size of number + type */
75 #define BT_HF_FMT_STR_SIZE 32
76 #define BT_ADDRESS_LENGTH_MAX 6
77 #define BT_ADAPTER_OBJECT_PATH_MAX 50
78 #define AT_CMD_BUFF_SIZE 500
79 #define BT_MAX_TEL_NUM_STR 100
81 #define BT_HF_AGENT_ERROR (__bt_hf_agent_error_quark())
83 #define BT_ERROR_INTERNAL "InternalError"
84 #define BT_ERROR_NOT_AVAILABLE "NotAvailable"
85 #define BT_ERROR_NOT_CONNECTED "NotConnected"
86 #define BT_ERROR_NOT_CONNECTION_FAILED "ConnectionFailed"
87 #define BT_ERROR_BUSY "InProgress"
88 #define BT_ERROR_INVALID_PARAM "InvalidArguments"
89 #define BT_ERROR_ALREADY_EXIST "AlreadyExists"
90 #define BT_ERROR_ALREADY_CONNECTED "Already Connected"
91 #define BT_ERROR_NO_MEMORY "No memory"
92 #define BT_ERROR_NO_DATA "No data"
93 #define BT_ERROR_I_O_ERROR "I/O error"
94 #define BT_ERROR_OPERATION_NOT_AVAILABLE "Operation currently not available"
95 #define BT_ERROR_OPERATION_NOT_ALLOWED "Operation not allowed"
96 #define BT_ERROR_OPERATION_NOT_SUPPORTED "Operation not supported"
97 #define BT_ERROR_INVALID_FILE_DESCRIPTOR "Invalid File Descriptor"
99 #define BT_HF_OK_RESPONSE "\r\nOK\r\n"
100 #define BT_HF_ERROR_RESPONSE "ERROR"
101 #define BT_HF_SEC_ERROR_RESPONSE "SERR"
103 /* dbus interfaces */
104 #define BT_HF_SERVICE_NAME "org.bluez.hf_agent"
105 #define BT_HF_AGENT_OBJECT_PATH "/org/bluez/handsfree_agent"
106 #define BT_HF_SERVICE_INTERFACE "org.tizen.HfApp"
107 #define BT_HF_BLUEZ_OBJECT_PATH "/org/tizen/handsfree"
108 #define BT_HF_BLUEZ_INTERFACE "org.bluez.HandsfreeAgent"
109 #define BLUEZ_SERVICE_NAME "org.bluez"
110 #define BLUEZ_HF_INTERFACE_NAME "org.bluez.HandsfreeGateway"
111 #define BLUEZ_PROFILE_MGMT_INTERFACE "org.bluez.ProfileManager1"
112 #define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
113 #define BT_ADAPTER_INTERFACE "org.bluez.Adapter1"
115 #define BT_INTERFACES_ADDED "InterfacesAdded"
116 #define BT_INTERFACES_REMOVED "InterfacesRemoved"
118 /* Handsfree features */
119 #define BT_HF_FEATURE_EC_ANDOR_NR 0x0001
120 #define BT_HF_FEATURE_CALL_WAITING_AND_3WAY 0x0002
121 #define BT_HF_FEATURE_CLI_PRESENTATION 0x0004
122 #define BT_HF_FEATURE_VOICE_RECOGNITION 0x0008
123 #define BT_HF_FEATURE_REMOTE_VOLUME_CONTROL 0x0010
124 #define BT_HF_FEATURE_ENHANCED_CALL_STATUS 0x0020
125 #define BT_HF_FEATURE_ENHANCED_CALL_CONTROL 0x0040
126 #define BT_HF_FEATURE_CODEC_NEGOTIATION 0x0080
128 /* Audio Gateway features */
129 #define BT_AG_FEATURE_3WAY 0x1
130 #define BT_AG_FEATURE_NREC 0x0002
131 #define BT_AG_FEATURE_VOICE_RECOGNITION 0x0004
132 #define BT_AG_FEATURE_INBAND_RINGTONE 0x0008
133 #define BT_AG_FEATURE_VOICE_TAG 0x0010
134 #define BT_AG_FEATURE_REJECT_CALL 0x0020
135 #define BT_AG_FEATURE_ENHANCED_CALL_STATUS 0x0040
136 #define BT_AG_FEATURE_ENHANCED_CALL_CONTROL 0x0080
137 #define BT_AG_FEATURE_EXTENDED_RES_CODE 0x100
138 #define BT_AG_FEATURE_CODEC_NEGOTIATION 0x0200
140 /* SCO Codec types */
141 #define BT_HF_CODEC_ID_CVSD 1
142 #define BT_HF_CODEC_ID_MSBC 2
145 #define BT_HF_FEATURES "AT+BRSF=%d\r" /* = 0x7F = All features supported */
146 #define BT_HF_INDICATORS_SUPP "AT+CIND=?\r"
147 #define BT_HF_INDICATORS_VAL "AT+CIND?\r"
148 #define BT_HF_INDICATORS_ENABLE "AT+CMER=3,0,0,1\r"
149 #define BT_HF_HOLD_MPTY_SUPP "AT+CHLD=?\r"
150 #define BT_HF_CALLER_IDENT_ENABLE "AT+CLIP=1\r"
151 #define BT_HF_CARRIER_FORMAT "AT+COPS=3,0\r"
152 #define BT_HF_EXTENDED_RESULT_CODE "AT+CMEE=1\r"
153 #define BT_HF_INDICATORS_ACTIVATION "AT+BIA="
154 #define BT_HF_ANSWER_CALL "ATA\r"
155 #define BT_HF_END_CALL "AT+CHUP\r"
156 #define BT_HF_REDIAL "AT+BLDN\r"
157 #define BT_HF_DIAL_NO "ATD%.100s;\r"
158 #define BT_HF_VOICE_RECOGNITION "AT+BVRA=%d\r"
159 #define BT_HF_XSAT "AT+XSAT=00,TY,WA\r"
160 #define BT_HF_BSSF "AT+BSSF=8\r"
161 #define BT_HF_CALLLIST "AT+CLCC\r"
162 #define BT_HF_AVAILABLE_CODEC "AT+BAC=%d,%d\r"
163 #define BT_HF_CODEC_SELECT "AT+BCS=%d\r"
164 #define BT_HF_SPEAKER_GAIN "AT+VGS=%d\r"
165 #define BT_HF_DTMF "AT+VTS=%s\r"
166 #define BT_HF_NREC "AT+NREC=0\r"
167 #define BT_HF_CALLWAIT_NOTI_ENABLE "AT+CCWA=1\r"
168 #define BT_HF_RELEASE_ALL "AT+CHLD=0\r"
169 #define BT_HF_RELEASE_AND_ACCEPT "AT+CHLD=1\r"
170 #define BT_HF_ACCEPT_AND_HOLD "AT+CHLD=2\r"
171 #define BT_HF_JOIN_CALL "AT+CHLD=3\r"
173 #define BT_HF_MAX_SPEAKER_GAIN 15
174 #define BT_HF_MIN_SPEAKER_GAIN 0
176 /* Hold and multipary services on AG */
177 #define BT_HF_CHLD_0 0x01 /* Releases all held calls or sets User Busy for a waiting call */
178 #define BT_HF_CHLD_1 0x02 /* Releases all active calls and accept others */
179 #define BT_HF_CHLD_1x 0x04 /* Releases specified active call only (<idx>) */
180 #define BT_HF_CHLD_2 0x08 /* Places all active calls on hold and accepts others */
181 #define BT_HF_CHLD_2x 0x10 /* Place all calls on hold EXCEPT the call indicated by <idx> */
182 #define BT_HF_CHLD_3 0x20 /* Adds a held call to the conversation */
183 #define BT_HF_CHLD_4 0x40 /* Explicit Call Transfer */
186 HFP_VERSION_1_5 = 0x0105,
187 HFP_VERSION_1_6 = 0x0106,
188 HFP_VERSION_LATEST = HFP_VERSION_1_6,
192 BT_HF_AGENT_ERROR_NONE,
193 BT_HF_AGENT_ERROR_INTERNAL,
194 BT_HF_AGENT_ERROR_NOT_AVAILABLE,
195 BT_HF_AGENT_ERROR_NOT_CONNECTED,
196 BT_HF_AGENT_ERROR_CONNECTION_FAILED,
197 BT_HF_AGENT_ERROR_BUSY,
198 BT_HF_AGENT_ERROR_INVALID_PARAM,
199 BT_HF_AGENT_ERROR_ALREADY_EXIST,
200 BT_HF_AGENT_ERROR_ALREADY_CONNECTED,
201 BT_HF_AGENT_ERROR_NO_MEMORY,
202 BT_HF_AGENT_ERROR_NO_DATA,
203 BT_HF_AGENT_ERROR_I_O_ERROR,
204 BT_HF_AGENT_ERROR_APPLICATION,
205 BT_HF_AGENT_ERROR_NOT_ALLOWED,
206 BT_HF_AGENT_ERROR_NOT_SUPPORTED,
207 BT_HF_AGENT_ERROR_INVALID_FILE_DESCRIPTOR,
208 } bt_hf_agent_error_t;
210 /* Extended Audio Gateway Error Result Codes */
212 BT_AG_CME_ERROR_NONE = -1,
213 BT_AG_CME_ERROR_AG_FAILURE = 0,
214 BT_AG_CME_ERROR_NO_PHONE_CONNECTION = 1,
215 BT_AG_CME_ERROR_NOT_ALLOWED = 3,
216 BT_AG_CME_ERROR_NOT_SUPPORTED = 4,
217 BT_AG_CME_ERROR_PH_SIM_PIN_REQUIRED = 5,
218 BT_AG_CME_ERROR_SIM_NOT_INSERTED = 10,
219 BT_AG_CME_ERROR_SIM_PIN_REQUIRED = 11,
220 BT_AG_CME_ERROR_SIM_PUK_REQUIRED = 12,
221 BT_AG_CME_ERROR_SIM_FAILURE = 13,
222 BT_AG_CME_ERROR_SIM_BUSY = 14,
223 BT_AG_CME_ERROR_INCORRECT_PASSWORD = 16,
224 BT_AG_CME_ERROR_SIM_PIN2_REQUIRED = 17,
225 BT_AG_CME_ERROR_SIM_PUK2_REQUIRED = 18,
226 BT_AG_CME_ERROR_MEMORY_FULL = 20,
227 BT_AG_CME_ERROR_INVALID_INDEX = 21,
228 BT_AG_CME_ERROR_MEMORY_FAILURE = 23,
229 BT_AG_CME_ERROR_TEXT_STRING_TOO_LONG = 24,
230 BT_AG_CME_ERROR_INVALID_TEXT_STRING = 25,
231 BT_AG_CME_ERROR_DIAL_STRING_TOO_LONG = 26,
232 BT_AG_CME_ERROR_INVALID_DIAL_STRING = 27,
233 BT_AG_CME_ERROR_NO_NETWORK_SERVICE = 30,
234 BT_AG_CME_ERROR_NETWORK_TIMEOUT = 31,
235 BT_AG_CME_ERROR_NETWORK_NOT_ALLOWED = 32,
239 BT_HF_STATE_DISCONNECTED,
240 BT_HF_STATE_CONNECTED
244 BT_HF_AUDIO_DISCONNECTED,
245 BT_HF_AUDIO_CONNECTED
249 BT_HF_CALL_DIR_OUTGOING,
250 BT_HF_CALL_DIR_INCOMING,
251 } bt_hf_call_direction_t;
254 BT_HF_CALL_STAT_ACTIVE,
255 BT_HF_CALL_STAT_HELD,
256 BT_HF_CALL_STAT_DIALING,
257 BT_HF_CALL_STAT_ALERTING,
258 BT_HF_CALL_STAT_INCOMING,
259 BT_HF_CALL_STAT_WAITING,
260 } bt_hf_call_status_t;
268 GIOChannel *sco_io_chan;
273 guint cli_sco_watch_id;
276 guint hold_multiparty_features;
280 gboolean call_active;
281 gboolean inband_ringtone_support;
282 gboolean is_companion_dev;
284 guint ciev_call_status;
285 guint ciev_call_setup_status;
292 GSList *cmd_send_queue;
294 GDBusMethodInvocation *context;
296 } bt_hf_agent_info_t;
300 char at_cmd[AT_CMD_BUFF_SIZE];
302 GDBusMethodInvocation *context;
305 } bt_hf_agent_send_at_info;
309 int (*callback) (bt_hf_agent_info_t *bt_hf_info, const char *buf);
314 } __attribute__((packed)) bdaddr_t;
316 /* Remote socket address */
317 struct sockaddr_remote {
319 bdaddr_t remote_bdaddr;
323 /* SCO socket address */
324 struct sockaddr_sco {
325 sa_family_t sco_family;
332 #endif /* __DEF_BT_HF_AGENT_H_ */