From 5bde7c3b04ebdee3e83abb0f53ba985ae937e2ea Mon Sep 17 00:00:00 2001 From: Andy Nguyen Date: Sun, 23 Aug 2020 11:51:54 +0200 Subject: executor/common_linux.h: unblock rfkill and retry HCIDEVUP on ERFKILL --- executor/common_linux.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'executor') diff --git a/executor/common_linux.h b/executor/common_linux.h index 68be3eeff..410e97bdc 100644 --- a/executor/common_linux.h +++ b/executor/common_linux.h @@ -1981,6 +1981,7 @@ static long syz_init_net_socket(volatile long domain, volatile long type, volati #if SYZ_EXECUTOR || SYZ_VHCI_INJECTION #include #include +#include #include #include #include @@ -2089,6 +2090,22 @@ struct vhci_vendor_pkt { static int vhci_fd = -1; +void rfkill_unblock_all() +{ + int fd = open("/dev/rfkill", O_WRONLY); + if (fd < 0) + fail("open /dev/rfkill failed"); + struct rfkill_event event = {0}; + event.idx = 0; + event.type = RFKILL_TYPE_ALL; + event.op = RFKILL_OP_CHANGE_ALL; + event.soft = 0; + event.hard = 0; + if (write(fd, &event, sizeof(event)) < 0) + fail("write rfkill event failed\n"); + close(fd); +} + static void hci_send_event_packet(int fd, uint8 evt, void* data, size_t data_len) { struct iovec iv[3]; @@ -2232,8 +2249,16 @@ static void initialize_vhci() fail("pthread_create failed"); // Bring hci device up - if (ioctl(hci_sock, HCIDEVUP, vendor_pkt.id) && errno != EALREADY) - fail("ioctl(HCIDEVUP) failed"); + int ret = ioctl(hci_sock, HCIDEVUP, vendor_pkt.id); + if (ret) { + if (errno == ERFKILL) { + rfkill_unblock_all(); + ret = ioctl(hci_sock, HCIDEVUP, vendor_pkt.id); + } + + if (ret && errno != EALREADY) + fail("ioctl(HCIDEVUP) failed"); + } // Activate page scanning mode which is required to fake a connection. struct hci_dev_req dr = {0}; -- cgit mrf-deployment