~ubuntu-branches/ubuntu/wily/bluez/wily

« back to all changes in this revision

Viewing changes to attrib/manager.c

ImportĀ upstreamĀ versionĀ 4.81

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  BlueZ - Bluetooth protocol stack for Linux
 
4
 *
 
5
 *  Copyright (C) 2010  Nokia Corporation
 
6
 *  Copyright (C) 2010  Marcel Holtmann <marcel@holtmann.org>
 
7
 *
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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
 
22
 *
 
23
 */
 
24
 
 
25
#ifdef HAVE_CONFIG_H
 
26
#include <config.h>
 
27
#endif
 
28
 
 
29
#include <bluetooth/bluetooth.h>
 
30
#include <bluetooth/sdp.h>
 
31
#include <bluetooth/sdp_lib.h>
 
32
 
 
33
#include "../src/adapter.h"
 
34
#include "../src/device.h"
 
35
 
 
36
#include "manager.h"
 
37
#include "client.h"
 
38
#include "example.h"
 
39
 
 
40
#define GATT_UUID       "00001801-0000-1000-8000-00805f9b34fb"
 
41
 
 
42
static DBusConnection *connection;
 
43
 
 
44
static int client_probe(struct btd_device *device, GSList *uuids)
 
45
{
 
46
        const sdp_record_t *rec;
 
47
        int psm = -1;
 
48
 
 
49
        rec = btd_device_get_record(device, GATT_UUID);
 
50
        if (rec) {
 
51
                sdp_list_t *list;
 
52
                if (sdp_get_access_protos(rec, &list) < 0)
 
53
                        return -1;
 
54
 
 
55
                psm = sdp_get_proto_port(list, L2CAP_UUID);
 
56
 
 
57
                sdp_list_foreach(list, (sdp_list_func_t) sdp_list_free, NULL);
 
58
                sdp_list_free(list, NULL);
 
59
 
 
60
                if (psm < 0)
 
61
                        return -1;
 
62
        }
 
63
 
 
64
        return attrib_client_register(device, psm);
 
65
}
 
66
 
 
67
static void client_remove(struct btd_device *device)
 
68
{
 
69
        attrib_client_unregister(device);
 
70
}
 
71
 
 
72
static struct btd_device_driver client_driver = {
 
73
        .name = "gatt-client",
 
74
        .uuids = BTD_UUIDS(GATT_UUID),
 
75
        .probe = client_probe,
 
76
        .remove = client_remove,
 
77
};
 
78
 
 
79
int attrib_manager_init(DBusConnection *conn)
 
80
{
 
81
        connection = dbus_connection_ref(conn);
 
82
 
 
83
        attrib_client_init(connection);
 
84
 
 
85
        btd_register_device_driver(&client_driver);
 
86
 
 
87
        /*
 
88
         * FIXME: Add config file option to allow
 
89
         * enable/disable the GATT server and client.
 
90
         */
 
91
 
 
92
        return server_example_init();
 
93
}
 
94
 
 
95
void attrib_manager_exit(void)
 
96
{
 
97
        btd_unregister_device_driver(&client_driver);
 
98
 
 
99
        server_example_exit();
 
100
        attrib_client_exit();
 
101
 
 
102
        dbus_connection_unref(connection);
 
103
}