From 11aaf468edbacac397d1d8b20b032eb35cf028ea Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Mon, 14 Jan 2019 01:47:11 -0800 Subject: binding: bluetooth: replace rfkill code with network service Remove bluetooth-rfkill.c and replace with agl-service-network calls which in turn allows ConnMan to correctly manage bluetooth rfkill state. Bug-AGL: SPEC-2124 Change-Id: Ibe0460be0f29957f99ea06975a1fa12d01840080 Signed-off-by: Matt Ranostay --- binding/CMakeLists.txt | 2 +- binding/bluetooth-api.c | 13 ++++- binding/bluetooth-rfkill.c | 129 --------------------------------------------- 3 files changed, 12 insertions(+), 132 deletions(-) delete mode 100644 binding/bluetooth-rfkill.c (limited to 'binding') diff --git a/binding/CMakeLists.txt b/binding/CMakeLists.txt index 103838d..f5cdf9d 100644 --- a/binding/CMakeLists.txt +++ b/binding/CMakeLists.txt @@ -21,7 +21,7 @@ PROJECT_TARGET_ADD(afm-bluetooth-binding) # Define project Targets - add_library(afm-bluetooth-binding MODULE bluetooth-api.c bluetooth-agent.c bluetooth-conf.c bluetooth-rfkill.c bluetooth-util.c bluetooth-bluez.c) + add_library(afm-bluetooth-binding MODULE bluetooth-api.c bluetooth-agent.c bluetooth-conf.c bluetooth-util.c bluetooth-bluez.c) # Binder exposes a unique public entry point SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES diff --git a/binding/bluetooth-api.c b/binding/bluetooth-api.c index 3f66033..52d4f19 100644 --- a/binding/bluetooth-api.c +++ b/binding/bluetooth-api.c @@ -544,8 +544,6 @@ static struct bluetooth_state *bluetooth_init(GMainLoop *loop) g_mutex_init(&ns->cw_mutex); ns->next_cw_id = 1; - bluetooth_monitor_init(); - g_timeout_add_seconds(5, bluetooth_autoconnect, ns); return ns; @@ -623,6 +621,7 @@ err_no_loop: static int init(afb_api_t api) { struct init_data init_data, *id = &init_data; + json_object *args = NULL; gint64 end_time; int ret; @@ -639,6 +638,16 @@ static int init(afb_api_t api) return ret; } + ret = afb_daemon_require_api("network-manager", 1); + if (ret < 0) { + AFB_ERROR("Cannot request network manager service"); + return ret; + } + + args = json_object_new_object(); + json_object_object_add(args , "technology", json_object_new_string("bluetooth")); + afb_api_call_sync(api, "network-manager", "enable_technology", args, NULL, NULL, NULL); + global_thread = g_thread_new("agl-service-bluetooth", bluetooth_func, id); diff --git a/binding/bluetooth-rfkill.c b/binding/bluetooth-rfkill.c deleted file mode 100644 index 5419e8f..0000000 --- a/binding/bluetooth-rfkill.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2018 Konsulko Group - * Author: Matt Ranostay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include -#include -#include - -#define AFB_BINDING_VERSION 3 -#include - -#define HCIDEVUP _IOW('H', 201, int) -#define BTPROTO_HCI 1 - - - -static int hci_interface_enable(int hdev) -{ - int ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); - int ret; - - if (ctl < 0) - return ctl; - - ret = ioctl(ctl, HCIDEVUP, hdev); - - close(ctl); - - return ret; -} - -static gboolean bluetooth_rfkill_event(GIOChannel *chan, GIOCondition cond, gpointer ptr) -{ - struct rfkill_event event; - gchar *name, buf[8]; - ssize_t len; - int fd; - - fd = g_io_channel_unix_get_fd(chan); - len = read(fd, &event, sizeof(struct rfkill_event)); - - if (len != sizeof(struct rfkill_event)) - return TRUE; - - if (event.type != RFKILL_TYPE_BLUETOOTH) - return TRUE; - - if (event.op == RFKILL_OP_DEL) - return TRUE; - - name = g_strdup_printf("/sys/class/rfkill/rfkill%u/soft", event.idx); - - fd = g_open(name, O_WRONLY); - len = write(fd, "0", 1); - g_close(fd, NULL); - - g_free(name); - - memset(&buf, 0, sizeof(buf)); - - name = g_strdup_printf("/sys/class/rfkill/rfkill%u/name", event.idx); - fd = g_open(name, O_RDONLY); - len = read(fd, &buf, sizeof(buf) - 1); - - if (len > 0) - { - int idx = 0; - sscanf(buf, "hci%d", &idx); - - /* - * 50 millisecond delay to allow time for rfkill to unblock before - * attempting to bring up HCI interface - */ - g_usleep(50000); - - hci_interface_enable(idx); - } - - g_free(name); - - return TRUE; -} - -int bluetooth_monitor_init(void) -{ - int fd = g_open("/dev/rfkill", O_RDWR); - GIOChannel *chan = NULL; - int ret = -EINVAL; - - if (fd < 0) - { - AFB_ERROR("Cannot open /dev/rfkill"); - return ret; - } - - chan = g_io_channel_unix_new(fd); - g_io_channel_set_close_on_unref(chan, TRUE); - - ret = g_io_add_watch(chan, G_IO_IN, bluetooth_rfkill_event, NULL); - - g_io_channel_unref(chan); - - return 0; -} -- cgit 1.2.3-korg