2
* oFono - Open Source Telephony
4
* Copyright (C) 2011 Intel Corporation. All rights reserved.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
#define OFONO_API_SUBJECT_TO_CHANGE
31
#include <ofono/plugin.h>
32
#include <ofono/log.h>
33
#include <ofono/modem.h>
36
#include "bluetooth.h"
38
#define HFP_AG_CHANNEL 13
40
static struct server *server;
41
static guint modemwatch_id;
43
static GHashTable *sim_hash = NULL;
45
static const gchar *hfp_ag_record =
46
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
48
" <attribute id=\"0x0001\">\n"
50
" <uuid value=\"0x111F\"/>\n"
51
" <uuid value=\"0x1203\"/>\n"
55
" <attribute id=\"0x0004\">\n"
58
" <uuid value=\"0x0100\"/>\n"
61
" <uuid value=\"0x0003\"/>\n"
62
" <uint8 value=\"13\" name=\"channel\"/>\n"
67
" <attribute id=\"0x0009\">\n"
70
" <uuid value=\"0x111E\"/>\n"
71
" <uint16 value=\"0x0105\" name=\"version\"/>\n"
76
" <attribute id=\"0x0100\">\n"
77
" <text value=\"Hands-Free Audio Gateway\" name=\"name\"/>\n"
80
" <attribute id=\"0x0301\">\n"
81
" <uint8 value=\"0x01\" />\n"
84
" <attribute id=\"0x0311\">\n"
85
" <uint16 value=\"0x0001\" />\n"
89
static void hfp_ag_connect_cb(GIOChannel *io, GError *err, gpointer user_data)
91
struct ofono_modem *modem;
92
struct ofono_emulator *em;
98
DBG("%s", err->message);
102
/* Pick the first voicecall capable modem */
103
modem = modems->data;
107
DBG("Picked modem %p for emulator", modem);
109
em = ofono_emulator_create(modem, OFONO_EMULATOR_TYPE_HFP);
113
fd = g_io_channel_unix_get_fd(io);
114
g_io_channel_set_close_on_unref(io, FALSE);
116
ofono_emulator_register(em, fd);
119
static void sim_state_watch(enum ofono_sim_state new_state, void *data)
121
struct ofono_modem *modem = data;
123
if (new_state != OFONO_SIM_STATE_READY) {
124
modems = g_list_remove(modems, modem);
125
if (modems == NULL && server != NULL) {
126
bluetooth_unregister_server(server);
133
if (__ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_VOICECALL) == NULL)
136
modems = g_list_append(modems, modem);
138
if (modems->next != NULL)
141
server = bluetooth_register_server(HFP_AG_CHANNEL, hfp_ag_record,
142
hfp_ag_connect_cb, NULL);
145
static gboolean sim_watch_remove(gpointer key, gpointer value,
148
struct ofono_sim *sim = key;
150
ofono_sim_remove_state_watch(sim, GPOINTER_TO_UINT(value));
155
static void sim_watch(struct ofono_atom *atom,
156
enum ofono_atom_watch_condition cond,
159
struct ofono_sim *sim = __ofono_atom_get_data(atom);
160
struct ofono_modem *modem = data;
163
if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) {
164
sim_state_watch(OFONO_SIM_STATE_NOT_PRESENT, modem);
166
sim_watch_remove(sim, g_hash_table_lookup(sim_hash, sim), NULL);
167
g_hash_table_remove(sim_hash, sim);
172
watch = ofono_sim_add_state_watch(sim, sim_state_watch, modem, NULL);
173
g_hash_table_insert(sim_hash, sim, GUINT_TO_POINTER(watch));
174
sim_state_watch(ofono_sim_get_state(sim), modem);
177
static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
179
DBG("modem: %p, added: %d", modem, added);
184
__ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_SIM,
185
sim_watch, modem, NULL);
188
static void call_modemwatch(struct ofono_modem *modem, void *user)
190
modem_watch(modem, TRUE, user);
193
static int hfp_ag_init(void)
195
sim_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
197
modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
198
__ofono_modem_foreach(call_modemwatch, NULL);
203
static void hfp_ag_exit(void)
205
__ofono_modemwatch_remove(modemwatch_id);
207
g_hash_table_foreach_remove(sim_hash, sim_watch_remove, NULL);
208
g_hash_table_destroy(sim_hash);
211
bluetooth_unregister_server(server);
216
OFONO_PLUGIN_DEFINE(hfp_ag, "Hands-Free Audio Gateway Profile Plugins", VERSION,
217
OFONO_PLUGIN_PRIORITY_DEFAULT, hfp_ag_init, hfp_ag_exit)