blob: b38ed2980780b32c600a4b56f39df93974d262d4 [file] [log] [blame] [edit]
/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2011 Nokia Corporation
* Copyright (C) 2011 Marcel Holtmann <marcel@holtmann.org>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdbool.h>
#include <errno.h>
#include <gdbus/gdbus.h>
#include <glib.h>
#include "lib/bluetooth.h"
#include "lib/sdp.h"
#include "lib/sdp_lib.h"
#include "lib/uuid.h"
#include "src/log.h"
#include "src/adapter.h"
#include "src/device.h"
#include "src/profile.h"
#include "src/service.h"
#include "attrib/att.h"
#include "attrib/gattrib.h"
#include "attrib/gatt.h"
#include "btvoice.h"
#include "manager.h"
#define AUD_UUID "0000fff0-0000-1000-8000-00805f9b34fb"
static struct btvoiceenable voiceenable = {
.audioOverBle = TRUE,
};
static int btvoice_audioOverBle_probe(struct btd_service *service)
{
struct btd_device *device = btd_service_get_device(service);
struct gatt_primary *audioOverBlePrim;
const char *path = device_get_path(device);
DBG("path %s", path);
audioOverBlePrim = btd_device_get_primary(device, AUD_UUID);
if (audioOverBlePrim == NULL)
return -1;
return btvoice_register_audioOverBle(service, device, &voiceenable, audioOverBlePrim);
}
static void btvoice_audioOverBle_remove(struct btd_service *service)
{
struct btd_device *device = btd_service_get_device(service);
btvoice_unregister_audioOverBle(device);
}
static struct btd_profile pxp_btvoice_audioOverBle_profile = {
.name = "audioOverBle",
.remote_uuid = AUD_UUID,
.device_probe = btvoice_audioOverBle_probe,
.device_remove = btvoice_audioOverBle_remove,
.accept = btvoice_accept,
.disconnect = btvoice_disconnect,
.auto_connect = true,
};
static void load_config_file(GKeyFile *config)
{
char **list;
char *str;
int i;
if (config == NULL)
{
DBG("No Config found, assume default value");
voiceenable.audioOverBle = 1;
voiceenable.mode = 3;
voiceenable.l2capChannel = 0;
return;
}
list = g_key_file_get_string_list(config, "General", "Disable",
NULL, NULL);
for (i = 0; list && list[i] != NULL; i++) {
if (g_str_equal(list[i], "audioOverBle"))
voiceenable.audioOverBle = FALSE;
}
DBG("audio OverBLE Enable? %d", voiceenable.audioOverBle);
g_strfreev(list);
str = g_key_file_get_string(config, "General", "Mode", NULL);
if (str) {
DBG("Mode: %s", str);
if (g_str_equal(str, "PROP_MODE"))
voiceenable.mode = 1;
else if (g_str_equal(str, "L2CAP_MODE"))
voiceenable.mode = 2;
else if (g_str_equal(str, "ATT_MODE"))
voiceenable.mode = 3;
g_free(str);
}
DBG("audio OverBLE Mode? %d", voiceenable.mode);
voiceenable.l2capChannel = g_key_file_get_integer(config, "General", "l2capChannel", NULL);
DBG("audio OverBLE L2cap Channel? %d", voiceenable.l2capChannel);
}
void audioOverBle_manager_exit(void)
{
btd_profile_unregister(&pxp_btvoice_audioOverBle_profile);
}
int audioOverBle_manager_init(GKeyFile *config)
{
load_config_file(config);
if (btd_profile_register(&pxp_btvoice_audioOverBle_profile) < 0)
{
DBG("Fail to register...");
audioOverBle_manager_exit();
return -1;
}
else
{
return 0;
}
}