diff mbox

[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).

Message ID 1355106555-21026-2-git-send-email-alex.hung@canonical.com
State Rejected
Headers show

Commit Message

Alex Hung Dec. 10, 2012, 2:29 a.m. UTC
Signed-off-by: Alex Hung <alex.hung@canonical.com>
---
 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 mbox

Patch

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 <inttypes.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+
+#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);