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_
28 #define LOG_TAG "BLUETOOTH_HF_AGENT"
30 #define LOG_COLOR_RESET "\033[0m"
31 #define LOG_COLOR_RED "\033[31m"
32 #define LOG_COLOR_YELLOW "\033[33m"
33 #define LOG_COLOR_GREEN "\033[32m"
34 #define LOG_COLOR_BLUE "\033[36m"
35 #define LOG_COLOR_PURPLE "\033[35m"
37 #define DBG(fmt, args...) SLOGD(fmt, ##args)
38 #define INFO(fmt, args...) SLOGI(fmt, ##args)
39 #define ERR(fmt, args...) SLOGE(fmt, ##args)
40 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
41 #define INFO_SECURE(fmt, args...) SECURE_SLOGI(fmt, ##args)
42 #define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
43 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
44 #define INFO_C(fmt, arg...) \
45 SLOGI_IF(TRUE, LOG_COLOR_BLUE" "fmt" "LOG_COLOR_RESET, ##arg)
46 #define ERR_C(fmt, arg...) \
47 SLOGI_IF(TRUE, LOG_COLOR_RED" "fmt" "LOG_COLOR_RESET, ##arg)
58 #include <sys/socket.h>
62 #define BT_HF_DATA_BUF_SIZE 1024
63 #define BT_HF_CMD_BUF_SIZE 32
64 #define BT_HF_INDICATOR_DESCR_SIZE 20
65 #define BT_HF_CALLER_NUM_SIZE 64 /* size of number + type */
66 #define BT_HF_FMT_STR_SIZE 32
68 #define BT_HF_AGENT_ERROR (__bt_hf_agent_error_quark())
70 #define BT_ERROR_INTERNAL "InternalError"
71 #define BT_ERROR_NOT_AVAILABLE "NotAvailable"
72 #define BT_ERROR_NOT_CONNECTED "NotConnected"
73 #define BT_ERROR_NOT_CONNECTION_FAILED "ConnectionFailed"
74 #define BT_ERROR_BUSY "InProgress"
75 #define BT_ERROR_INVALID_PARAM "InvalidArguments"
76 #define BT_ERROR_ALREADY_EXIST "AlreadyExists"
77 #define BT_ERROR_ALREADY_CONNECTED "Already Connected"
78 #define BT_ERROR_NO_MEMORY "No memory"
79 #define BT_ERROR_I_O_ERROR "I/O error"
80 #define BT_ERROR_OPERATION_NOT_AVAILABLE "Operation currently not available"
81 #define BT_ERROR_OPERATION_NOT_ALLOWED "Operation not allowed"
82 #define BT_ERROR_OPERATION_NOT_SUPPORTED "Operation not supported"
83 #define BT_ERROR_INVALID_FILE_DESCRIPTOR "Invalid File Descriptor"
86 BT_HF_AGENT_ERROR_NONE,
87 BT_HF_AGENT_ERROR_INTERNAL,
88 BT_HF_AGENT_ERROR_NOT_AVAILABLE,
89 BT_HF_AGENT_ERROR_NOT_CONNECTED,
90 BT_HF_AGENT_ERROR_CONNECTION_FAILED,
91 BT_HF_AGENT_ERROR_BUSY,
92 BT_HF_AGENT_ERROR_INVALID_PARAM,
93 BT_HF_AGENT_ERROR_ALREADY_EXIST,
94 BT_HF_AGENT_ERROR_ALREADY_CONNECTED,
95 BT_HF_AGENT_ERROR_NO_MEMORY,
96 BT_HF_AGENT_ERROR_I_O_ERROR,
97 BT_HF_AGENT_ERROR_APPLICATION,
98 BT_HF_AGENT_ERROR_NOT_ALLOWED,
99 BT_HF_AGENT_ERROR_NOT_SUPPORTED,
100 BT_HF_AGENT_ERROR_INVALID_FILE_DESCRIPTOR,
101 } bt_hf_agent_error_t;
103 /* Extended Audio Gateway Error Result Codes */
105 BT_AG_CME_ERROR_NONE = -1,
106 BT_AG_CME_ERROR_AG_FAILURE = 0,
107 BT_AG_CME_ERROR_NO_PHONE_CONNECTION = 1,
108 BT_AG_CME_ERROR_NOT_ALLOWED = 3,
109 BT_AG_CME_ERROR_NOT_SUPPORTED = 4,
110 BT_AG_CME_ERROR_PH_SIM_PIN_REQUIRED = 5,
111 BT_AG_CME_ERROR_SIM_NOT_INSERTED = 10,
112 BT_AG_CME_ERROR_SIM_PIN_REQUIRED = 11,
113 BT_AG_CME_ERROR_SIM_PUK_REQUIRED = 12,
114 BT_AG_CME_ERROR_SIM_FAILURE = 13,
115 BT_AG_CME_ERROR_SIM_BUSY = 14,
116 BT_AG_CME_ERROR_INCORRECT_PASSWORD = 16,
117 BT_AG_CME_ERROR_SIM_PIN2_REQUIRED = 17,
118 BT_AG_CME_ERROR_SIM_PUK2_REQUIRED = 18,
119 BT_AG_CME_ERROR_MEMORY_FULL = 20,
120 BT_AG_CME_ERROR_INVALID_INDEX = 21,
121 BT_AG_CME_ERROR_MEMORY_FAILURE = 23,
122 BT_AG_CME_ERROR_TEXT_STRING_TOO_LONG = 24,
123 BT_AG_CME_ERROR_INVALID_TEXT_STRING = 25,
124 BT_AG_CME_ERROR_DIAL_STRING_TOO_LONG = 26,
125 BT_AG_CME_ERROR_INVALID_DIAL_STRING = 27,
126 BT_AG_CME_ERROR_NO_NETWORK_SERVICE = 30,
127 BT_AG_CME_ERROR_NETWORK_TIMEOUT = 31,
128 BT_AG_CME_ERROR_NETWORK_NOT_ALLOWED = 32,
132 BT_HF_CALL_DIR_OUTGOING,
133 BT_HF_CALL_DIR_INCOMING,
134 } bt_hf_call_direction_t;
136 /* Call status as per spec */
138 BT_HF_CALL_STAT_ACTIVE,
139 BT_HF_CALL_STAT_HELD,
140 BT_HF_CALL_STAT_DIALING,
141 BT_HF_CALL_STAT_ALERTING,
142 BT_HF_CALL_STAT_INCOMING,
143 BT_HF_CALL_STAT_WAITING,
144 } bt_hf_call_status_t;
147 HFP_VERSION_1_5 = 0x0105,
148 HFP_VERSION_1_6 = 0x0106,
149 HFP_VERSION_LATEST = HFP_VERSION_1_6,
152 /*Handsfree supported features*/
153 #define BT_HF_FEATURE_EC_ANDOR_NR 0x0001
154 #define BT_HF_FEATURE_CALL_WAITING_AND_3WAY 0x0002
155 #define BT_HF_FEATURE_CLI_PRESENTATION 0x0004
156 #define BT_HF_FEATURE_VOICE_RECOGNITION 0x0008
157 #define BT_HF_FEATURE_REMOTE_VOLUME_CONTROL 0x0010
158 #define BT_HF_FEATURE_ENHANCED_CALL_STATUS 0x0020
159 #define BT_HF_FEATURE_ENHANCED_CALL_CONTROL 0x0040
160 #define BT_HF_FEATURE_CODEC_NEGOTIATION 0x0080
162 /*AG suported feature*/
163 #define BT_AG_FEATURE_3WAY 0x1
164 #define BT_AG_FEATURE_NREC 0x0002
165 #define BT_AG_FEATURE_EXTENDED_RES_CODE 0x100
166 #define BT_AG_FEATURE_CODEC_NEGOTIATION 0x0200
168 #define BT_HF_CODEC_ID_CVSD 1
169 #define BT_HF_CODEC_ID_MSBC 2
171 #define BT_HF_AUDIO_DISCONNECTED 0
172 #define BT_HF_AUDIO_CONNECTED 1
174 #define BT_MAX_TEL_NUM_STR 100
176 #define BT_HF_FEATURES "AT+BRSF=%d\r" /* = 0x7F = All features supported */
177 #define BT_HF_INDICATORS_SUPP "AT+CIND=?\r"
178 #define BT_HF_INDICATORS_VAL "AT+CIND?\r"
179 #define BT_HF_INDICATORS_ENABLE "AT+CMER=3,0,0,1\r"
180 #define BT_HF_HOLD_MPTY_SUPP "AT+CHLD=?\r"
181 #define BT_HF_CALLER_IDENT_ENABLE "AT+CLIP=1\r"
182 #define BT_HF_CARRIER_FORMAT "AT+COPS=3,0\r"
183 #define BT_HF_EXTENDED_RESULT_CODE "AT+CMEE=1\r"
184 #define BT_HF_INDICATORS_ACTIVATION "AT+BIA="
185 #define BT_HF_ANSWER_CALL "ATA\r"
186 #define BT_HF_END_CALL "AT+CHUP\r"
187 #define BT_HF_REDIAL "AT+BLDN\r"
188 #define BT_HF_DIAL_NO "ATD%.100s;\r"
189 #define BT_HF_VOICE_RECOGNITION "AT+BVRA=%d\r"
190 #define BT_HF_XSAT "AT+XSAT=00,TY,WA\r"
191 #define BT_HF_BSSF "AT+BSSF=8\r"
192 #define BT_HF_CALLLIST "AT+CLCC\r"
193 #define BT_HF_AVAILABLE_CODEC "AT+BAC=%d,%d\r"
194 #define BT_HF_CODEC_SELECT "AT+BCS=%d\r"
195 #define BT_HF_SPEAKER_GAIN "AT+VGS=%d\r"
196 #define BT_HF_DTMF "AT+VTS=%s\r"
197 #define BT_HF_NREC "AT+NREC=0\r"
198 #define BT_HF_CALLWAIT_NOTI_ENABLE "AT+CCWA=1\r"
199 #define BT_HF_RELEASE_ALL "AT+CHLD=0\r"
200 #define BT_HF_RELEASE_AND_ACCEPT "AT+CHLD=1\r"
201 #define BT_HF_ACCEPT_AND_HOLD "AT+CHLD=2\r"
202 #define BT_HF_JOIN_CALL "AT+CHLD=3\r"
204 #define BT_MAX_EVENT_STR_LENGTH 50
205 #define BT_AGENT_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS 200
207 #define BT_HF_MAX_SPEAKER_GAIN 15
208 #define BT_HF_MIN_SPEAKER_GAIN 0
212 BT_AGENT_EVENT_HANDSFREE_CONNECT = 0x1100,
213 BT_AGENT_EVENT_HANDSFREE_DISCONNECT = 0x1200,
214 } bt_hfp_agent_event_type_t;
216 /* Hold and multipary AG features.
217 * Comments below are copied from hands-free spec for reference */
218 /* Releases all held calls or sets User Determined User Busy (UDUB)
219 * for a waiting call */
220 #define BT_HF_CHLD_0 0x01
221 /* Releases all active calls (if any exist) and accepts the other
222 * (held or waiting) call */
223 #define BT_HF_CHLD_1 0x02
224 /* Releases specified active call only <x> */
225 #define BT_HF_CHLD_1x 0x04
226 /* Places all active calls (if any exist) on hold and accepts the other
227 * (held or waiting) call */
228 #define BT_HF_CHLD_2 0x08
229 /* Request private consultation mode with specified call <x> (Place all
230 * calls on hold EXCEPT the call <x>) */
231 #define BT_HF_CHLD_2x 0x10
232 /* Adds a held call to the conversation */
233 #define BT_HF_CHLD_3 0x20
234 /* Connects the two calls and disconnects the subscriber from both calls
235 * (Explicit Call Transfer). Support for this value and its associated
236 * functionality is optional for the HF. */
237 #define BT_HF_CHLD_4 0x40
239 #define BT_HF_OK_RESPONSE "\r\nOK\r\n"
240 #define BT_HF_ERROR_RESPONSE "ERROR"
241 #define BT_HF_SEC_ERROR_RESPONSE "SERR"
243 #define BT_HF_SERVICE_NAME "org.bluez.hf_agent"
244 #define BT_HF_AGENT_OBJECT_PATH "/org/bluez/handsfree_agent"
245 #define BT_HF_SERVICE_INTERFACE "org.tizen.HfApp"
247 #define BT_HF_BLUEZ_OBJECT_PATH "/org/tizen/handsfree"
248 #define BT_HF_BLUEZ_INTERFACE "org.bluez.HandsfreeAgent"
250 #define BLUEZ_SERVICE_NAME "org.bluez"
251 #define BLUEZ_HF_INTERFACE_NAME "org.bluez.HandsfreeGateway"
253 #define PM_SERVICE_NAME "org.tizen.system.deviced"
254 #define PM_OBJECT_PATH "/Org/Tizen/System/DeviceD/Display"
255 #define PM_INTERFACE_NAME "org.tizen.system.deviced.display"
256 #define AT_CMD_BUFF_SIZE 500
257 #define BLUEZ_PROFILE_MGMT_INTERFACE "org.bluez.ProfileManager1"
258 #define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
259 #define BT_ADAPTER_INTERFACE "org.bluez.Adapter1"
261 #define BT_INTERFACES_ADDED "InterfacesAdded"
262 #define BT_INTERFACES_REMOVED "InterfacesRemoved"
264 #define retv_if(expr, val) \
267 ERR("(%s) return", #expr); \
273 BT_HF_STATE_DISCONNECTED,
274 BT_HF_STATE_CONNECTED
283 GIOChannel *sco_io_chan;
288 guint cli_sco_watch_id;
291 guint hold_multiparty_features;
295 gboolean call_active;
297 guint ciev_call_status;
298 guint ciev_call_setup_status;
305 GSList *cmd_send_queue;
307 GDBusMethodInvocation *context;
309 } bt_hf_agent_info_t;
313 char at_cmd[AT_CMD_BUFF_SIZE];
315 GDBusMethodInvocation *context;
318 } bt_hf_agent_send_at_info;
322 int (*callback) (bt_hf_agent_info_t *bt_hf_info, const char *buf);
327 } __attribute__((packed)) bdaddr_t;
329 /* Remote socket address */
330 struct sockaddr_remote {
332 bdaddr_t remote_bdaddr;
336 /* SCO socket address */
337 struct sockaddr_sco {
338 sa_family_t sco_family;
342 #endif /* __DEF_BT_HF_AGENT_H_ */