From patchwork Mon Dec 10 02:29:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Hung X-Patchwork-Id: 204812 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 8B1812C0253 for ; Mon, 10 Dec 2012 13:29:30 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Tht7Z-0006RH-Cg; Mon, 10 Dec 2012 02:29:29 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Tht7W-0006RB-Kp for fwts-devel@lists.ubuntu.com; Mon, 10 Dec 2012 02:29:26 +0000 Received: from [175.41.48.77] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1Tht7V-0008AC-MY; Mon, 10 Dec 2012 02:29:26 +0000 From: Alex Hung To: fwts-devel@lists.ubuntu.com Subject: [PATCH 1/2] oem: wireless: add tests for toggling the states of wireless device, including WIFI, Bluetooth and WWAN (3G), via a kernel interface that will be created for different OEM systems (i.e. ASUS, Dell, HP, and so on). Date: Mon, 10 Dec 2012 10:29:14 +0800 Message-Id: <1355106555-21026-2-git-send-email-alex.hung@canonical.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1355106555-21026-1-git-send-email-alex.hung@canonical.com> References: <1355106555-21026-1-git-send-email-alex.hung@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com Signed-off-by: Alex Hung --- src/Makefile.am | 3 +- src/oem/wireless/wireless.c | 189 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 src/oem/wireless/wireless.c diff --git a/src/Makefile.am b/src/Makefile.am index 478c522..3a6c374 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -68,7 +68,8 @@ fwts_SOURCES = main.c \ kernel/oops/oops.c \ uefi/csm/csm.c \ uefi/uefidump/uefidump.c \ - uefi/uefirttime/uefirttime.c + uefi/uefirttime/uefirttime.c \ + oem/wireless/wireless.c fwts_LDFLAGS = -ljson -lm diff --git a/src/oem/wireless/wireless.c b/src/oem/wireless/wireless.c new file mode 100644 index 0000000..f40c4f0 --- /dev/null +++ b/src/oem/wireless/wireless.c @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2012 Canonical + * + * 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 Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + */ + +#include +#include +#include +#include +#include + +#include "fwts.h" +#include "fwts-oem.h" + +static int get_wireless_device(int fd, int device, fwts_oem_wireless *wd) { + long ioret; + + wd->oem_parameter.func = GET_DEVICE; + wd->device.device_type = device; + + ioret = ioctl(fd, OEM_WIRELESS_CMD, wd); + if (ioret) + return FWTS_ERROR; + return FWTS_OK; +} + +static int set_wireless_device(int fd, int device, int sw_status) { + fwts_oem_wireless wd; + long ioret; + + wd.oem_parameter.func = SET_DEVICE; + wd.device.device_type = device; + wd.device.soft_kill_status = sw_status; + ioret = ioctl(fd, OEM_WIRELESS_CMD, &wd); + if (ioret) + return -1; + return 0; +} + +static int test_wireless_device(fwts_framework *fw, int fd, int radio) +{ + fwts_oem_wireless wd; + u8 sw_kill_status; + int err; + + err = get_wireless_device(fd, radio, &wd); + if (err) + goto test_failed; + + if (wd.oem_parameter.func_status == FWTS_NOT_PRESENT) + goto no_such_device; + + sw_kill_status = wd.device.soft_kill_status; + err = set_wireless_device(fd, radio, !wd.device.soft_kill_status); + if (err) + goto test_failed; + err = get_wireless_device(fd, radio, &wd); + if (err) + goto test_failed; + if (sw_kill_status == wd.device.soft_kill_status) + fwts_warning(fw, "failed to change from %x to %x", + sw_kill_status, !sw_kill_status); + + sw_kill_status = wd.device.soft_kill_status; + err = set_wireless_device(fd, radio, !wd.device.soft_kill_status); + if (err) + goto test_failed; + err = get_wireless_device(fd, radio, &wd); + if (err) + goto test_failed; + if (sw_kill_status == wd.device.soft_kill_status) + fwts_warning(fw, "failed to change from %x to %x", + sw_kill_status, !sw_kill_status); + + fwts_passed(fw, "OEM wireless interface is able to toggle its state\n"); + + return FWTS_OK; + + no_such_device: + fwts_log_info(fw, "wireless device is not present.\n"); + return FWTS_ABORTED; + + test_failed: + return FWTS_ERROR; +} + +static int oem_wireless_init(fwts_framework *fw) +{ + int ret = FWTS_OK; + int fd; + + fd = open("/dev/fwts_oem", O_RDONLY); + if (fd == -1) { + fwts_log_info(fw, "Cannot open fwts_oem driver. Aborted."); + ret = FWTS_ABORTED; + } + + close(fd); + return ret; +} + +static int oem_wireless_deinit(fwts_framework *fw) +{ + FWTS_UNUSED(fw); + return FWTS_OK; +} + +static int oem_wireless_test1(fwts_framework *fw) +{ + int ret = FWTS_OK; + int fd; + + fd = open("/dev/fwts_oem", O_RDONLY); + + if (fd == -1) { + fwts_log_info(fw, "Cannot open fwts_oem driver. Aborted."); + ret = FWTS_ABORTED; + } else + ret = test_wireless_device(fw, fd, FWTS_WIFI); + + close(fd); + return ret; +} + +static int oem_wireless_test2(fwts_framework *fw) +{ + int ret = FWTS_OK; + int fd; + + fd = open("/dev/fwts_oem", O_RDONLY); + + if (fd == -1) { + fwts_log_info(fw, "Cannot open fwts_oem driver. Aborted."); + ret = FWTS_ABORTED; + } else + ret = test_wireless_device(fw, fd, FWTS_BLUETOOTH); + + close(fd); + return ret; +} + +static int oem_wireless_test3(fwts_framework *fw) +{ + int ret; + int fd; + + fd = open("/dev/fwts_oem", O_RDONLY); + + if (fd == -1) { + fwts_log_info(fw, "Cannot open fwts_oem driver. Aborted."); + ret = FWTS_ABORTED; + } else + ret = test_wireless_device(fw, fd, FWTS_WWAN); + + close(fd); + return ret; +} + +static fwts_framework_minor_test oem_wireless_tests[] = { + { oem_wireless_test1, "Test OEM's WIFI control interfaces." }, + { oem_wireless_test2, "Test OEM's Bluetooth control interfaces." }, + { oem_wireless_test3, "Test OEM's WWAN control interfaces." }, + { NULL, NULL } +}; + +static fwts_framework_ops oem_wireless_ops = { + .description = "OEM wireless control interface tests.", + .init = oem_wireless_init, + .deinit = oem_wireless_deinit, + .minor_tests = oem_wireless_tests +}; + +FWTS_REGISTER(oem_wireless, &oem_wireless_ops, FWTS_TEST_ANYTIME, + FWTS_FLAG_UNSAFE | FWTS_FLAG_ROOT_PRIV);