3
* BlueZ - Bluetooth protocol stack for Linux
5
* Copyright (C) 2006-2007 Nokia Corporation
6
* Copyright (C) 2004-2008 Marcel Holtmann <marcel@holtmann.org>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33
#include <dbus/dbus.h>
37
#include "telephony.h"
39
static char *subscriber_number = NULL;
40
static char *active_call_number = NULL;
41
static int active_call_status = 0;
42
static int active_call_dir = 0;
44
static gboolean events_enabled = FALSE;
46
/* Response and hold state
48
* 0 = incoming call is put on hold in the AG
49
* 1 = held incoming call is accepted in the AG
50
* 2 = held incoming call is rejected in the AG
52
static int response_and_hold = -1;
54
static struct indicator dummy_indicators[] =
56
{ "battchg", "0-5", 5 },
57
{ "signal", "0-5", 5 },
58
{ "service", "0,1", 1 },
60
{ "callsetup", "0-3", 0 },
61
{ "callheld", "0-2", 0 },
66
void telephony_device_connected(void *telephony_device)
68
debug("telephony-dummy: device %p connected", telephony_device);
71
void telephony_device_disconnected(void *telephony_device)
73
debug("telephony-dummy: device %p disconnected", telephony_device);
74
events_enabled = FALSE;
77
void telephony_event_reporting_req(void *telephony_device, int ind)
79
events_enabled = ind == 1 ? TRUE : FALSE;
81
telephony_event_reporting_rsp(telephony_device, CME_ERROR_NONE);
84
void telephony_response_and_hold_req(void *telephony_device, int rh)
86
response_and_hold = rh;
88
telephony_response_and_hold_ind(response_and_hold);
90
telephony_response_and_hold_rsp(telephony_device, CME_ERROR_NONE);
93
void telephony_last_dialed_number_req(void *telephony_device)
95
telephony_last_dialed_number_rsp(telephony_device, CME_ERROR_NONE);
97
/* Notify outgoing call set-up successfully initiated */
98
telephony_update_indicator(dummy_indicators, "callsetup",
99
EV_CALLSETUP_OUTGOING);
100
telephony_update_indicator(dummy_indicators, "callsetup",
101
EV_CALLSETUP_ALERTING);
103
active_call_status = CALL_STATUS_ALERTING;
104
active_call_dir = CALL_DIR_OUTGOING;
107
void telephony_terminate_call_req(void *telephony_device)
109
g_free(active_call_number);
110
active_call_number = NULL;
112
telephony_terminate_call_rsp(telephony_device, CME_ERROR_NONE);
114
if (telephony_get_indicator(dummy_indicators, "callsetup") > 0)
115
telephony_update_indicator(dummy_indicators, "callsetup",
116
EV_CALLSETUP_INACTIVE);
118
telephony_update_indicator(dummy_indicators, "call",
122
void telephony_answer_call_req(void *telephony_device)
124
telephony_answer_call_rsp(telephony_device, CME_ERROR_NONE);
126
telephony_update_indicator(dummy_indicators, "call", EV_CALL_ACTIVE);
127
telephony_update_indicator(dummy_indicators, "callsetup",
128
EV_CALLSETUP_INACTIVE);
130
active_call_status = CALL_STATUS_ACTIVE;
133
void telephony_dial_number_req(void *telephony_device, const char *number)
135
g_free(active_call_number);
136
active_call_number = g_strdup(number);
138
telephony_dial_number_rsp(telephony_device, CME_ERROR_NONE);
140
/* Notify outgoing call set-up successfully initiated */
141
telephony_update_indicator(dummy_indicators, "callsetup",
142
EV_CALLSETUP_OUTGOING);
143
telephony_update_indicator(dummy_indicators, "callsetup",
144
EV_CALLSETUP_ALERTING);
146
active_call_status = CALL_STATUS_ALERTING;
147
active_call_dir = CALL_DIR_OUTGOING;
150
void telephony_transmit_dtmf_req(void *telephony_device, char tone)
152
debug("telephony-dummy: transmit dtmf: %c", tone);
153
telephony_transmit_dtmf_rsp(telephony_device, CME_ERROR_NONE);
156
void telephony_subscriber_number_req(void *telephony_device)
158
debug("telephony-dummy: subscriber number request");
159
if (subscriber_number)
160
telephony_subscriber_number_ind(subscriber_number, 0,
161
SUBSCRIBER_SERVICE_VOICE);
162
telephony_subscriber_number_rsp(telephony_device, CME_ERROR_NONE);
165
void telephony_list_current_calls_req(void *telephony_device)
167
debug("telephony-dummy: list current calls request");
168
if (active_call_number)
169
telephony_list_current_call_ind(1, active_call_dir,
175
telephony_list_current_calls_rsp(telephony_device, CME_ERROR_NONE);
178
/* D-Bus method handlers */
179
static DBusMessage *outgoing_call(DBusConnection *conn, DBusMessage *msg,
184
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &number,
188
debug("telephony-dummy: outgoing call to %s", number);
190
g_free(active_call_number);
191
active_call_number = g_strdup(number);
193
telephony_update_indicator(dummy_indicators, "callsetup",
194
EV_CALLSETUP_OUTGOING);
195
telephony_update_indicator(dummy_indicators, "callsetup",
196
EV_CALLSETUP_ALERTING);
198
active_call_status = CALL_STATUS_ALERTING;
199
active_call_dir = CALL_DIR_OUTGOING;
201
return dbus_message_new_method_return(msg);
204
static DBusMessage *incoming_call(DBusConnection *conn, DBusMessage *msg,
209
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &number,
213
debug("telephony-dummy: incoming call to %s", number);
215
g_free(active_call_number);
216
active_call_number = g_strdup(number);
218
telephony_update_indicator(dummy_indicators, "callsetup",
219
EV_CALLSETUP_INCOMING);
221
active_call_status = CALL_STATUS_INCOMING;
222
active_call_dir = CALL_DIR_INCOMING;
224
telephony_incoming_call_ind(number, 0);
226
return dbus_message_new_method_return(msg);
229
static DBusMessage *cancel_call(DBusConnection *conn, DBusMessage *msg,
232
debug("telephony-dummy: cancel call");
234
g_free(active_call_number);
235
active_call_number = NULL;
237
if (telephony_get_indicator(dummy_indicators, "callsetup") > 0) {
238
telephony_update_indicator(dummy_indicators, "callsetup",
239
EV_CALLSETUP_INACTIVE);
240
telephony_calling_stopped_ind();
243
if (telephony_get_indicator(dummy_indicators, "call") > 0)
244
telephony_update_indicator(dummy_indicators, "call",
247
return dbus_message_new_method_return(msg);
250
static DBusMessage *signal_strength(DBusConnection *conn, DBusMessage *msg,
253
dbus_uint32_t strength;
255
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &strength,
262
telephony_update_indicator(dummy_indicators, "signal", strength);
264
debug("telephony-dummy: signal strength set to %u", strength);
266
return dbus_message_new_method_return(msg);
269
static DBusMessage *battery_level(DBusConnection *conn, DBusMessage *msg,
274
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &level,
281
telephony_update_indicator(dummy_indicators, "battchg", level);
283
debug("telephony-dummy: battery level set to %u", level);
285
return dbus_message_new_method_return(msg);
288
static DBusMessage *roaming_status(DBusConnection *conn, DBusMessage *msg,
294
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &roaming,
298
val = roaming ? EV_ROAM_ACTIVE : EV_ROAM_INACTIVE;
300
telephony_update_indicator(dummy_indicators, "roam", val);
302
debug("telephony-dummy: roaming status set to %d", val);
304
return dbus_message_new_method_return(msg);
307
static DBusMessage *registration_status(DBusConnection *conn, DBusMessage *msg,
310
dbus_bool_t registration;
313
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, ®istration,
317
val = registration ? EV_SERVICE_PRESENT : EV_SERVICE_NONE;
319
telephony_update_indicator(dummy_indicators, "service", val);
321
debug("telephony-dummy: registration status set to %d", val);
323
return dbus_message_new_method_return(msg);
326
static DBusMessage *set_subscriber_number(DBusConnection *conn,
332
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &number,
336
g_free(subscriber_number);
337
subscriber_number = g_strdup(number);
339
debug("telephony-dummy: subscriber number set to %s", number);
341
return dbus_message_new_method_return(msg);
344
static GDBusMethodTable dummy_methods[] = {
345
{ "OutgoingCall", "s", "", outgoing_call },
346
{ "IncomingCall", "s", "", incoming_call },
347
{ "CancelCall", "", "", cancel_call },
348
{ "SignalStrength", "u", "", signal_strength },
349
{ "BatteryLevel", "u", "", battery_level },
350
{ "RoamingStatus", "b", "", roaming_status },
351
{ "RegistrationStatus", "b", "", registration_status },
352
{ "SetSubscriberNumber","s", "", set_subscriber_number },
356
static DBusConnection *connection = NULL;
358
int telephony_init(void)
360
uint32_t features = AG_FEATURE_REJECT_A_CALL |
361
AG_FEATURE_ENHANCED_CALL_STATUS |
362
AG_FEATURE_EXTENDED_ERROR_RESULT_CODES;
364
connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
366
g_dbus_register_interface(connection, "/org/bluez/test",
367
"org.bluez.TelephonyTest",
371
telephony_ready_ind(features, dummy_indicators, response_and_hold);
376
void telephony_exit(void)
378
dbus_connection_unref(connection);