~morphis/phablet-extras/ofono-sms-status-report

« back to all changes in this revision

Viewing changes to plugins/hfp_ag.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-08-22 19:59:08 UTC
  • mfrom: (1.3.3) (6.1.5 experimental)
  • Revision ID: package-import@ubuntu.com-20120822195908-0bmmk1hlh989bgk6
Tags: 1.9-1ubuntu1
* Merge with Debian experimental; remaining changes:
  - debian/control: explicitly Conflicts with modemmanager: having both
    installed / running at the same time causes issues causes issues with
    both claiming modem devices.
  - debian/patches/02-dont-handle-stacktraces.patch: stop catching stacktraces
    and printing the information internally, so apport can catch and report
    the possible bugs.
  - debian/ofono.postinst: on configure, notify the user that a reboot is
    required (so ofono can get started by upstart). (LP: #600501)
  - debian/rules: pass --no-restart-on-upgrade so ofono isn't automatically
    restarted when upgrades.
  - Adding upstart config / Removing standard init script
  - Adding Apport support
  - Patch for recognizing special Huawei devices with weird serial
  - Override lintian to avoid script-in-etc-init.d... warnings.
  - Update debian/compat to 7
* debian/series: add our patches to debian/patches/series now that the package
  uses quilt.
* debian/patches/02-dont-handle-stacktraces.patch: refreshed.
* debian/ofono-dev.install, debian/ofono.install:
  - Install usr/sbin/dundee and ofono.pc to the proper packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  oFono - Open Source Telephony
 
3
 *
 
4
 *  Copyright (C) 2011  Intel Corporation. All rights reserved.
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 *
 
19
 */
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include <config.h>
 
23
#endif
 
24
#include <stdio.h>
 
25
#include <string.h>
 
26
#include <errno.h>
 
27
#include <glib.h>
 
28
#include <ofono.h>
 
29
 
 
30
#define OFONO_API_SUBJECT_TO_CHANGE
 
31
#include <ofono/plugin.h>
 
32
#include <ofono/log.h>
 
33
#include <ofono/modem.h>
 
34
#include <gdbus.h>
 
35
 
 
36
#include "bluetooth.h"
 
37
 
 
38
#define HFP_AG_CHANNEL  13
 
39
 
 
40
static struct server *server;
 
41
static guint modemwatch_id;
 
42
static GList *modems;
 
43
static GHashTable *sim_hash = NULL;
 
44
 
 
45
static const gchar *hfp_ag_record =
 
46
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 
47
"<record>\n"
 
48
"  <attribute id=\"0x0001\">\n"
 
49
"    <sequence>\n"
 
50
"      <uuid value=\"0x111F\"/>\n"
 
51
"      <uuid value=\"0x1203\"/>\n"
 
52
"    </sequence>\n"
 
53
"  </attribute>\n"
 
54
"\n"
 
55
"  <attribute id=\"0x0004\">\n"
 
56
"    <sequence>\n"
 
57
"      <sequence>\n"
 
58
"        <uuid value=\"0x0100\"/>\n"
 
59
"      </sequence>\n"
 
60
"      <sequence>\n"
 
61
"        <uuid value=\"0x0003\"/>\n"
 
62
"        <uint8 value=\"13\" name=\"channel\"/>\n"
 
63
"      </sequence>\n"
 
64
"    </sequence>\n"
 
65
"  </attribute>\n"
 
66
"\n"
 
67
"  <attribute id=\"0x0009\">\n"
 
68
"    <sequence>\n"
 
69
"      <sequence>\n"
 
70
"        <uuid value=\"0x111E\"/>\n"
 
71
"        <uint16 value=\"0x0105\" name=\"version\"/>\n"
 
72
"      </sequence>\n"
 
73
"    </sequence>\n"
 
74
"  </attribute>\n"
 
75
"\n"
 
76
"  <attribute id=\"0x0100\">\n"
 
77
"    <text value=\"Hands-Free Audio Gateway\" name=\"name\"/>\n"
 
78
"  </attribute>\n"
 
79
"\n"
 
80
"  <attribute id=\"0x0301\">\n"
 
81
"    <uint8 value=\"0x01\" />\n"
 
82
"  </attribute>\n"
 
83
"\n"
 
84
"  <attribute id=\"0x0311\">\n"
 
85
"    <uint16 value=\"0x0001\" />\n"
 
86
"  </attribute>\n"
 
87
"</record>\n";
 
88
 
 
89
static void hfp_ag_connect_cb(GIOChannel *io, GError *err, gpointer user_data)
 
90
{
 
91
        struct ofono_modem *modem;
 
92
        struct ofono_emulator *em;
 
93
        int fd;
 
94
 
 
95
        DBG("");
 
96
 
 
97
        if (err) {
 
98
                DBG("%s", err->message);
 
99
                return;
 
100
        }
 
101
 
 
102
        /* Pick the first voicecall capable modem */
 
103
        modem = modems->data;
 
104
        if (modem == NULL)
 
105
                return;
 
106
 
 
107
        DBG("Picked modem %p for emulator", modem);
 
108
 
 
109
        em = ofono_emulator_create(modem, OFONO_EMULATOR_TYPE_HFP);
 
110
        if (em == NULL)
 
111
                return;
 
112
 
 
113
        fd = g_io_channel_unix_get_fd(io);
 
114
        g_io_channel_set_close_on_unref(io, FALSE);
 
115
 
 
116
        ofono_emulator_register(em, fd);
 
117
}
 
118
 
 
119
static void sim_state_watch(enum ofono_sim_state new_state, void *data)
 
120
{
 
121
        struct ofono_modem *modem = data;
 
122
 
 
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);
 
127
                        server = NULL;
 
128
                }
 
129
 
 
130
                return;
 
131
        }
 
132
 
 
133
        if (__ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_VOICECALL) == NULL)
 
134
                return;
 
135
 
 
136
        modems = g_list_append(modems, modem);
 
137
 
 
138
        if (modems->next != NULL)
 
139
                return;
 
140
 
 
141
        server = bluetooth_register_server(HFP_AG_CHANNEL, hfp_ag_record,
 
142
                                                hfp_ag_connect_cb, NULL);
 
143
}
 
144
 
 
145
static gboolean sim_watch_remove(gpointer key, gpointer value,
 
146
                                gpointer user_data)
 
147
{
 
148
        struct ofono_sim *sim = key;
 
149
 
 
150
        ofono_sim_remove_state_watch(sim, GPOINTER_TO_UINT(value));
 
151
 
 
152
        return TRUE;
 
153
}
 
154
 
 
155
static void sim_watch(struct ofono_atom *atom,
 
156
                                enum ofono_atom_watch_condition cond,
 
157
                                void *data)
 
158
{
 
159
        struct ofono_sim *sim = __ofono_atom_get_data(atom);
 
160
        struct ofono_modem *modem = data;
 
161
        int watch;
 
162
 
 
163
        if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) {
 
164
                sim_state_watch(OFONO_SIM_STATE_NOT_PRESENT, modem);
 
165
 
 
166
                sim_watch_remove(sim, g_hash_table_lookup(sim_hash, sim), NULL);
 
167
                g_hash_table_remove(sim_hash, sim);
 
168
 
 
169
                return;
 
170
        }
 
171
 
 
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);
 
175
}
 
176
 
 
177
static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
 
178
{
 
179
        DBG("modem: %p, added: %d", modem, added);
 
180
 
 
181
        if (added == FALSE)
 
182
                return;
 
183
 
 
184
        __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_SIM,
 
185
                                        sim_watch, modem, NULL);
 
186
}
 
187
 
 
188
static void call_modemwatch(struct ofono_modem *modem, void *user)
 
189
{
 
190
        modem_watch(modem, TRUE, user);
 
191
}
 
192
 
 
193
static int hfp_ag_init(void)
 
194
{
 
195
        sim_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
 
196
 
 
197
        modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
 
198
        __ofono_modem_foreach(call_modemwatch, NULL);
 
199
 
 
200
        return 0;
 
201
}
 
202
 
 
203
static void hfp_ag_exit(void)
 
204
{
 
205
        __ofono_modemwatch_remove(modemwatch_id);
 
206
        g_list_free(modems);
 
207
        g_hash_table_foreach_remove(sim_hash, sim_watch_remove, NULL);
 
208
        g_hash_table_destroy(sim_hash);
 
209
 
 
210
        if (server) {
 
211
                bluetooth_unregister_server(server);
 
212
                server = NULL;
 
213
        }
 
214
}
 
215
 
 
216
OFONO_PLUGIN_DEFINE(hfp_ag, "Hands-Free Audio Gateway Profile Plugins", VERSION,
 
217
                        OFONO_PLUGIN_PRIORITY_DEFAULT, hfp_ag_init, hfp_ag_exit)