Blob: hfp.h

Blob id: 045e1f7abd24baac3c26db6376140852f70c39c2

Size: 8.4 KB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 *
 *  BlueZ - Bluetooth protocol stack for Linux
 *
 *  Copyright (C) 2012-2014  Intel Corporation. All rights reserved.
 *
 *
 */

#include <stdbool.h>

#define HFP_HF_FEAT_ECNR				0x00000001
#define HFP_HF_FEAT_3WAY				0x00000002
#define HFP_HF_FEAT_CLIP				0x00000004
#define HFP_HF_FEAT_VOICE_RECOGNITION			0x00000008
#define HFP_HF_FEAT_REMOTE_VOLUME_CONTROL		0x00000010
#define HFP_HF_FEAT_ENHANCED_CALL_STATUS		0x00000020
#define HFP_HF_FEAT_ENHANCED_CALL_CONTROL		0x00000040
#define HFP_HF_FEAT_CODEC_NEGOTIATION			0x00000080
#define HFP_HF_FEAT_HF_INDICATORS			0x00000100
#define HFP_HF_FEAT_ESCO_S4_T2				0x00000200
#define HFP_HF_FEAT_ENHANCED_VOICE_RECOGNITION_STATUS	0x00000400
#define HFP_HF_FEAT_VOICE_RECOGNITION_TEXT		0x00000800

#define HFP_AG_FEAT_3WAY				0x00000001
#define HFP_AG_FEAT_ECNR				0x00000002
#define HFP_AG_FEAT_VOICE_RECOGNITION			0x00000004
#define HFP_AG_FEAT_IN_BAND_RING_TONE			0x00000008
#define HFP_AG_FEAT_ATTACH_VOICE_TAG			0x00000010
#define HFP_AG_FEAT_REJECT_CALL				0x00000020
#define HFP_AG_FEAT_ENHANCED_CALL_STATUS		0x00000040
#define HFP_AG_FEAT_ENHANCED_CALL_CONTROL		0x00000080
#define HFP_AG_FEAT_EXTENDED_RES_CODE			0x00000100
#define HFP_AG_FEAT_CODEC_NEGOTIATION			0x00000200
#define HFP_AG_FEAT_HF_INDICATORS			0x00000400
#define HFP_AG_FEAT_ESCO_S4_T2				0x00000800
#define HFP_AG_FEAT_ENHANCED_VOICE_RECOGNITION_STATUS	0x00001000
#define HFP_AG_FEAT_VOICE_RECOGNITION_TEXT		0x00002000

#define HFP_CHLD_0	1 << 0
#define HFP_CHLD_1	1 << 1
#define HFP_CHLD_2	1 << 2
#define HFP_CHLD_3	1 << 3
#define HFP_CHLD_4	1 << 4
#define HFP_CHLD_1x	1 << 5
#define HFP_CHLD_2x	1 << 6

enum hfp_result {
	HFP_RESULT_OK		= 0,
	HFP_RESULT_CONNECT	= 1,
	HFP_RESULT_RING		= 2,
	HFP_RESULT_NO_CARRIER	= 3,
	HFP_RESULT_ERROR	= 4,
	HFP_RESULT_NO_DIALTONE	= 6,
	HFP_RESULT_BUSY		= 7,
	HFP_RESULT_NO_ANSWER	= 8,
	HFP_RESULT_DELAYED	= 9,
	HFP_RESULT_REJECTED	= 10,
	HFP_RESULT_CME_ERROR	= 11,
};

enum hfp_error {
	HFP_ERROR_AG_FAILURE			= 0,
	HFP_ERROR_NO_CONNECTION_TO_PHONE	= 1,
	HFP_ERROR_OPERATION_NOT_ALLOWED		= 3,
	HFP_ERROR_OPERATION_NOT_SUPPORTED	= 4,
	HFP_ERROR_PH_SIM_PIN_REQUIRED		= 5,
	HFP_ERROR_SIM_NOT_INSERTED		= 10,
	HFP_ERROR_SIM_PIN_REQUIRED		= 11,
	HFP_ERROR_SIM_PUK_REQUIRED		= 12,
	HFP_ERROR_SIM_FAILURE			= 13,
	HFP_ERROR_SIM_BUSY			= 14,
	HFP_ERROR_INCORRECT_PASSWORD		= 16,
	HFP_ERROR_SIM_PIN2_REQUIRED		= 17,
	HFP_ERROR_SIM_PUK2_REQUIRED		= 18,
	HFP_ERROR_MEMORY_FULL			= 20,
	HFP_ERROR_INVALID_INDEX			= 21,
	HFP_ERROR_MEMORY_FAILURE		= 23,
	HFP_ERROR_TEXT_STRING_TOO_LONG		= 24,
	HFP_ERROR_INVALID_CHARS_IN_TEXT_STRING	= 25,
	HFP_ERROR_DIAL_STRING_TO_LONG		= 26,
	HFP_ERROR_INVALID_CHARS_IN_DIAL_STRING	= 27,
	HFP_ERROR_NO_NETWORK_SERVICE		= 30,
	HFP_ERROR_NETWORK_TIMEOUT		= 31,
	HFP_ERROR_NETWORK_NOT_ALLOWED		= 32,
};

enum hfp_gw_cmd_type {
	HFP_GW_CMD_TYPE_READ,
	HFP_GW_CMD_TYPE_SET,
	HFP_GW_CMD_TYPE_TEST,
	HFP_GW_CMD_TYPE_COMMAND
};

enum hfp_indicator {
	HFP_INDICATOR_SERVICE = 0,
	HFP_INDICATOR_CALL,
	HFP_INDICATOR_CALLSETUP,
	HFP_INDICATOR_CALLHELD,
	HFP_INDICATOR_SIGNAL,
	HFP_INDICATOR_ROAM,
	HFP_INDICATOR_BATTCHG,
	HFP_INDICATOR_LAST
};

enum hfp_call {
	CIND_CALL_NONE = 0,
	CIND_CALL_IN_PROGRESS
};

enum hfp_call_setup {
	CIND_CALLSETUP_NONE = 0,
	CIND_CALLSETUP_INCOMING,
	CIND_CALLSETUP_DIALING,
	CIND_CALLSETUP_ALERTING
};

enum hfp_call_held {
	CIND_CALLHELD_NONE = 0,
	CIND_CALLHELD_HOLD_AND_ACTIVE,
	CIND_CALLHELD_HOLD
};

enum hfp_call_status {
	CALL_STATUS_ACTIVE = 0,
	CALL_STATUS_HELD,
	CALL_STATUS_DIALING,
	CALL_STATUS_ALERTING,
	CALL_STATUS_INCOMING,
	CALL_STATUS_WAITING,
	CALL_STATUS_RESPONSE_AND_HOLD
};

struct hfp_context;

typedef void (*hfp_result_func_t)(struct hfp_context *context,
				enum hfp_gw_cmd_type type, void *user_data);

typedef void (*hfp_destroy_func_t)(void *user_data);
typedef void (*hfp_debug_func_t)(const char *str, void *user_data);

typedef void (*hfp_command_func_t)(const char *command, void *user_data);
typedef void (*hfp_disconnect_func_t)(void *user_data);

struct hfp_gw;

struct hfp_gw *hfp_gw_new(int fd);

struct hfp_gw *hfp_gw_ref(struct hfp_gw *hfp);
void hfp_gw_unref(struct hfp_gw *hfp);

bool hfp_gw_set_debug(struct hfp_gw *hfp, hfp_debug_func_t callback,
				void *user_data, hfp_destroy_func_t destroy);

bool hfp_gw_set_close_on_unref(struct hfp_gw *hfp, bool do_close);
bool hfp_gw_set_permissive_syntax(struct hfp_gw *hfp, bool permissive);

bool hfp_gw_send_result(struct hfp_gw *hfp, enum hfp_result result);
bool hfp_gw_send_error(struct hfp_gw *hfp, enum hfp_error error);
bool hfp_gw_send_info(struct hfp_gw *hfp, const char *format, ...)
					__attribute__((format(printf, 2, 3)));

bool hfp_gw_set_command_handler(struct hfp_gw *hfp,
				hfp_command_func_t callback,
				void *user_data, hfp_destroy_func_t destroy);

bool hfp_gw_set_disconnect_handler(struct hfp_gw *hfp,
					hfp_disconnect_func_t callback,
					void *user_data,
					hfp_destroy_func_t destroy);

bool hfp_gw_disconnect(struct hfp_gw *hfp);

bool hfp_gw_register(struct hfp_gw *hfp, hfp_result_func_t callback,
						const char *prefix,
						void *user_data,
						hfp_destroy_func_t destroy);
bool hfp_gw_unregister(struct hfp_gw *hfp, const char *prefix);

bool hfp_context_get_number(struct hfp_context *context,
							unsigned int *val);
bool hfp_context_get_number_default(struct hfp_context *context,
						unsigned int *val,
						unsigned int default_val);
bool hfp_context_open_container(struct hfp_context *context);
bool hfp_context_close_container(struct hfp_context *context);
bool hfp_context_is_container_close(struct hfp_context *context);
bool hfp_context_get_string(struct hfp_context *context, char *buf,
								uint8_t len);
bool hfp_context_get_unquoted_string(struct hfp_context *context,
						char *buf, uint8_t len);
bool hfp_context_get_range(struct hfp_context *context, unsigned int *min,
							unsigned int *max);
bool hfp_context_has_next(struct hfp_context *context);
void hfp_context_skip_field(struct hfp_context *context);

typedef void (*hfp_hf_result_func_t)(struct hfp_context *context,
							void *user_data);

typedef void (*hfp_response_func_t)(enum hfp_result result,
							enum hfp_error cme_err,
							void *user_data);

struct hfp_hf;

struct hfp_hf_callbacks {
	void (*session_ready)(enum hfp_result result, enum hfp_error cme_err,
							void *user_data);
	void (*update_indicator)(enum hfp_indicator indicator, uint32_t val,
							void *user_data);
	void (*update_operator)(const char *operator_name, void *user_data);
	void (*update_inband_ring)(bool enabled, void *user_data);

	void (*call_added)(uint id, enum hfp_call_status status,
							void *user_data);
	void (*call_removed)(uint id, void *user_data);
	void (*call_status_updated)(uint id, enum hfp_call_status status,
							void *user_data);
	void (*call_line_id_updated)(uint id, const char *number, uint type,
							void *user_data);
	void (*call_mpty_updated)(uint id, bool mpty, void *user_data);
};

struct hfp_hf *hfp_hf_new(int fd);

struct hfp_hf *hfp_hf_ref(struct hfp_hf *hfp);
void hfp_hf_unref(struct hfp_hf *hfp);
bool hfp_hf_set_debug(struct hfp_hf *hfp, hfp_debug_func_t callback,
				void *user_data, hfp_destroy_func_t destroy);
bool hfp_hf_set_close_on_unref(struct hfp_hf *hfp, bool do_close);
bool hfp_hf_set_disconnect_handler(struct hfp_hf *hfp,
					hfp_disconnect_func_t callback,
					void *user_data,
					hfp_destroy_func_t destroy);
bool hfp_hf_disconnect(struct hfp_hf *hfp);
bool hfp_hf_register(struct hfp_hf *hfp, hfp_hf_result_func_t callback,
					const char *prefix, void *user_data,
					hfp_destroy_func_t destroy);
bool hfp_hf_unregister(struct hfp_hf *hfp, const char *prefix);
bool hfp_hf_send_command(struct hfp_hf *hfp, hfp_response_func_t resp_cb,
				void *user_data, const char *format, ...);

bool hfp_hf_session_register(struct hfp_hf *hfp,
				struct hfp_hf_callbacks *callbacks,
				void *callbacks_data);
bool hfp_hf_session(struct hfp_hf *hfp);

const char *hfp_hf_call_get_number(struct hfp_hf *hfp, uint id);

bool hfp_hf_dial(struct hfp_hf *hfp, const char *number,
				hfp_response_func_t resp_cb,
				void *user_data);
bool hfp_hf_release_and_accept(struct hfp_hf *hfp,
				hfp_response_func_t resp_cb,
				void *user_data);
bool hfp_hf_swap_calls(struct hfp_hf *hfp,
				hfp_response_func_t resp_cb,
				void *user_data);
bool hfp_hf_call_answer(struct hfp_hf *hfp, uint id,
				hfp_response_func_t resp_cb,
				void *user_data);
bool hfp_hf_call_hangup(struct hfp_hf *hfp, uint id,
				hfp_response_func_t resp_cb,
				void *user_data);