From d69fd6bacf59f4425a10e3e26d4d6c5cd902419d Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 8 Jan 2013 13:22:45 +0200 Subject: [PATCH] core: Remove no longer used src/mgmt.{c,h} --- Makefile.am | 2 +- src/adapter.c | 1 - src/main.c | 10 -- src/mgmt.c | 264 -------------------------------------------------- src/mgmt.h | 26 ----- 5 files changed, 1 insertion(+), 302 deletions(-) delete mode 100644 src/mgmt.c delete mode 100644 src/mgmt.h diff --git a/Makefile.am b/Makefile.am index 3a7fe9188..f956255d1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -142,7 +142,7 @@ src_bluetoothd_SOURCES = $(gdbus_sources) $(builtin_sources) \ src/profile.h src/profile.c \ src/device.h src/device.c src/attio.h \ src/dbus-common.c src/dbus-common.h \ - src/eir.h src/eir.c src/mgmt.c src/mgmt.h \ + src/eir.h src/eir.c \ src/shared/util.h src/shared/util.c \ src/shared/mgmt.h src/shared/mgmt.c src_bluetoothd_LDADD = lib/libbluetooth-private.la @GLIB_LIBS@ @DBUS_LIBS@ \ diff --git a/src/adapter.c b/src/adapter.c index 6a37021e9..236fe2d29 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -67,7 +67,6 @@ #include "attrib/gatt.h" #include "attrib-server.h" #include "eir.h" -#include "mgmt.h" #define ADAPTER_INTERFACE "org.bluez.Adapter1" diff --git a/src/main.c b/src/main.c index 8b6ad25bb..57f1fa926 100644 --- a/src/main.c +++ b/src/main.c @@ -54,7 +54,6 @@ #include "dbus-common.h" #include "agent.h" #include "profile.h" -#include "mgmt.h" #include "systemd.h" #define BLUEZ_NAME "org.bluez" @@ -473,7 +472,6 @@ int main(int argc, char *argv[]) GKeyFile *config; guint signal, watchdog; const char *watchdog_usec; - int mgmt_err; init_defaults(); @@ -542,12 +540,6 @@ int main(int argc, char *argv[]) /* no need to keep parsed option in memory */ free_options(); - mgmt_err = mgmt_setup(); - if (mgmt_err < 0) { - error("mgmt setup failed: %s", strerror(-mgmt_err)); - exit(1); - } - rfkill_init(); DBG("Entering main loop"); @@ -591,8 +583,6 @@ int main(int argc, char *argv[]) if (config) g_key_file_free(config); - mgmt_cleanup(); - disconnect_dbus(); info("Exit"); diff --git a/src/mgmt.c b/src/mgmt.c deleted file mode 100644 index 86a4e921b..000000000 --- a/src/mgmt.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * Copyright (C) 2010 Nokia Corporation - * Copyright (C) 2010 Marcel Holtmann - * Copyright (C) 2011-2012 Intel Corporation. All rights reserved. - * - * 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 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include "log.h" -#include "adapter.h" -#include "device.h" -#include "eir.h" -#include "storage.h" -#include "mgmt.h" - -#define MGMT_BUF_SIZE 1024 - -static int mgmt_sock = -1; -static guint mgmt_watch = 0; - -static void mgmt_cmd_complete(uint16_t index, void *buf, size_t len) -{ - struct mgmt_ev_cmd_complete *ev = buf; - uint16_t opcode; - - if (len < sizeof(*ev)) { - error("Too small management command complete event packet"); - return; - } - - opcode = bt_get_le16(&ev->opcode); - - len -= sizeof(*ev); - - DBG("%s (0x%04x) status 0x%02x len %zu", mgmt_opstr(opcode), opcode, - ev->status, len); -} - -static void mgmt_cmd_status(uint16_t index, void *buf, size_t len) -{ - struct mgmt_ev_cmd_status *ev = buf; - uint16_t opcode; - - if (len < sizeof(*ev)) { - error("Too small management command status event packet"); - return; - } - - opcode = bt_get_le16(&ev->opcode); - - DBG("hci%u: %s (0x%04x) status: %s (0x%02x)", index, - mgmt_opstr(opcode), opcode, mgmt_errstr(ev->status), - ev->status); -} - -static gboolean mgmt_event(GIOChannel *channel, GIOCondition cond, - gpointer user_data) -{ - char buf[MGMT_BUF_SIZE]; - struct mgmt_hdr *hdr = (void *) buf; - ssize_t ret; - uint16_t len, opcode, index; - - if (cond & G_IO_NVAL) - return FALSE; - - if (cond & (G_IO_ERR | G_IO_HUP)) { - error("Error on management socket"); - return FALSE; - } - - ret = read(mgmt_sock, buf, sizeof(buf)); - if (ret < 0) { - error("Unable to read from management socket: %s (%d)", - strerror(errno), errno); - return TRUE; - } - - if (ret < MGMT_HDR_SIZE) { - error("Too small Management packet"); - return TRUE; - } - - opcode = bt_get_le16(&hdr->opcode); - len = bt_get_le16(&hdr->len); - index = bt_get_le16(&hdr->index); - - if (ret != MGMT_HDR_SIZE + len) { - error("Packet length mismatch. ret %zd len %u", ret, len); - return TRUE; - } - - switch (opcode) { - case MGMT_EV_CMD_COMPLETE: - mgmt_cmd_complete(index, buf + MGMT_HDR_SIZE, len); - break; - case MGMT_EV_CMD_STATUS: - mgmt_cmd_status(index, buf + MGMT_HDR_SIZE, len); - break; - case MGMT_EV_CONTROLLER_ERROR: - DBG("controller_error event"); - break; - case MGMT_EV_INDEX_ADDED: - DBG("index_added event"); - break; - case MGMT_EV_INDEX_REMOVED: - DBG("index_removed event"); - break; - case MGMT_EV_NEW_SETTINGS: - DBG("new_settings event"); - break; - case MGMT_EV_CLASS_OF_DEV_CHANGED: - DBG("class_of_dev_changed event"); - break; - case MGMT_EV_LOCAL_NAME_CHANGED: - DBG("local_name_changed event"); - break; - case MGMT_EV_NEW_LINK_KEY: - DBG("new_link_key event"); - break; - case MGMT_EV_DEVICE_CONNECTED: - DBG("device_connected event"); - break; - case MGMT_EV_DEVICE_DISCONNECTED: - DBG("device_disconnected event"); - break; - case MGMT_EV_CONNECT_FAILED: - DBG("connect_failed event"); - break; - case MGMT_EV_PIN_CODE_REQUEST: - DBG("pin_code_request event"); - break; - case MGMT_EV_USER_CONFIRM_REQUEST: - DBG("user_confirm_request event"); - break; - case MGMT_EV_AUTH_FAILED: - DBG("auth_failed event"); - break; - case MGMT_EV_DEVICE_FOUND: - DBG("device_found event"); - break; - case MGMT_EV_DISCOVERING: - DBG("discovering event"); - break; - case MGMT_EV_DEVICE_BLOCKED: - DBG("device_blocked event"); - break; - case MGMT_EV_DEVICE_UNBLOCKED: - DBG("device_unblocked event"); - break; - case MGMT_EV_DEVICE_UNPAIRED: - DBG("device_unpaired event"); - break; - case MGMT_EV_USER_PASSKEY_REQUEST: - DBG("passkey_request event"); - break; - case MGMT_EV_PASSKEY_NOTIFY: - DBG("passkey_notify event"); - break; - case MGMT_EV_NEW_LONG_TERM_KEY: - DBG("new_long_term_key event"); - break; - default: - error("Unknown Management opcode %u (index %u)", opcode, index); - break; - } - - return TRUE; -} - -int mgmt_setup(void) -{ - struct mgmt_hdr hdr; - struct sockaddr_hci addr; - GIOChannel *io; - GIOCondition condition; - int dd, err; - - dd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); - if (dd < 0) - return -errno; - - memset(&addr, 0, sizeof(addr)); - addr.hci_family = AF_BLUETOOTH; - addr.hci_dev = HCI_DEV_NONE; - addr.hci_channel = HCI_CHANNEL_CONTROL; - - if (bind(dd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { - err = -errno; - goto fail; - } - - memset(&hdr, 0, sizeof(hdr)); - hdr.opcode = htobs(MGMT_OP_READ_INDEX_LIST); - hdr.index = htobs(MGMT_INDEX_NONE); - if (write(dd, &hdr, sizeof(hdr)) < 0) { - err = -errno; - goto fail; - } - - io = g_io_channel_unix_new(dd); - condition = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL; - mgmt_watch = g_io_add_watch(io, condition, mgmt_event, NULL); - g_io_channel_unref(io); - - mgmt_sock = dd; - - return 0; - -fail: - close(dd); - return err; -} - -void mgmt_cleanup(void) -{ - if (mgmt_sock >= 0) { - close(mgmt_sock); - mgmt_sock = -1; - } - - if (mgmt_watch > 0) { - g_source_remove(mgmt_watch); - mgmt_watch = 0; - } -} diff --git a/src/mgmt.h b/src/mgmt.h deleted file mode 100644 index deaa6174f..000000000 --- a/src/mgmt.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * Copyright (C) 2010 Nokia Corporation - * Copyright (C) 2010 Marcel Holtmann - * Copyright (C) 2011-2012 Intel Corporation. All rights reserved. - * - * 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 - * - */ - -int mgmt_setup(void); -void mgmt_cleanup(void); -- 2.47.3