From 8f94be819dc3173ff0f023bf5a3d41a527a612ed Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 15 Jan 2007 20:05:22 +0000 Subject: Add LMP test utility --- test/Makefile.am | 4 +- test/lmptest.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/sttest.c | 141 -------------------------------------------- 3 files changed, 177 insertions(+), 143 deletions(-) create mode 100644 test/lmptest.c delete mode 100644 test/sttest.c (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 93ad39b9..18989ba5 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -12,7 +12,7 @@ sbin_PROGRAMS = hciemu bin_PROGRAMS = l2test rctest -noinst_PROGRAMS = sdptest scotest attest hstest bdaddr sttest +noinst_PROGRAMS = sdptest scotest attest hstest bdaddr lmptest hciemu_LDADD = $(glib_ldadd) @BLUEZ_LIBS@ $(top_builddir)/common/libhelper.a @@ -32,7 +32,7 @@ bdaddr_SOURCES = bdaddr.c bdaddr_LDADD = @BLUEZ_LIBS@ $(top_builddir)/common/libhelper.a -sttest_LDADD = @BLUEZ_LIBS@ +lmptest_LDADD = @BLUEZ_LIBS@ noinst_MANS = bdaddr.8 diff --git a/test/lmptest.c b/test/lmptest.c new file mode 100644 index 00000000..39a906a2 --- /dev/null +++ b/test/lmptest.c @@ -0,0 +1,175 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2005-2007 Marcel Holtmann + * + * + * 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 + +#if 0 +#define OCF_ERICSSON_SEND_LMP 0x0021 +typedef struct { + uint16_t handle; + uint8_t length; + uint8_t data[17]; +} __attribute__ ((packed)) ericsson_send_lmp_cp; +#define ERICSSON_SEND_LMP_CP_SIZE 20 + +static int ericsson_send_lmp(int dd, uint16_t handle, uint8_t length, uint8_t *data) +{ + struct hci_request rq; + ericsson_send_lmp_cp cp; + + memset(&cp, 0, sizeof(cp)); + cp.handle = htobs(handle); + cp.length = length; + memcpy(cp.data, data, length); + + memset(&rq, 0, sizeof(rq)); + rq.ogf = OGF_VENDOR_CMD; + rq.ocf = OCF_ERICSSON_SEND_LMP; + rq.cparam = &cp; + rq.clen = ERICSSON_SEND_LMP_CP_SIZE; + rq.rparam = NULL; + rq.rlen = 0; + + if (hci_send_req(dd, &rq, 1000) < 0) + return -1; + + return 0; +} +#endif + +#define OCF_ERICSSON_WRITE_EVENTS 0x0043 +typedef struct { + uint8_t mask; + uint8_t opcode; + uint8_t opcode_ext; +} __attribute__ ((packed)) ericsson_write_events_cp; +#define ERICSSON_WRITE_EVENTS_CP_SIZE 3 + +static int ericsson_write_events(int dd, uint8_t mask) +{ + struct hci_request rq; + ericsson_write_events_cp cp; + + memset(&cp, 0, sizeof(cp)); + cp.mask = mask; + cp.opcode = 0x00; + cp.opcode_ext = 0x00; + + memset(&rq, 0, sizeof(rq)); + rq.ogf = OGF_VENDOR_CMD; + rq.ocf = OCF_ERICSSON_WRITE_EVENTS; + rq.cparam = &cp; + rq.clen = ERICSSON_WRITE_EVENTS_CP_SIZE; + rq.rparam = NULL; + rq.rlen = 0; + + if (hci_send_req(dd, &rq, 1000) < 0) + return -1; + + return 0; +} + +static void usage(void) +{ + printf("lmptest - Utility for testing special LMP functions\n\n"); + printf("Usage:\n" + "\tlmptest [-i ]\n"); +} + +static struct option main_options[] = { + { "device", 1, 0, 'i' }, + { "help", 0, 0, 'h' }, + { 0, 0, 0, 0 } +}; + +int main(int argc, char *argv[]) +{ + struct hci_version ver; + int dd, opt, dev = 0; + + while ((opt=getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) { + switch (opt) { + case 'i': + dev = hci_devid(optarg); + if (dev < 0) { + perror("Invalid device"); + exit(1); + } + break; + + case 'h': + default: + usage(); + exit(0); + } + } + + argc -= optind; + argv += optind; + optind = 0; + + dd = hci_open_dev(dev); + if (dd < 0) { + fprintf(stderr, "Can't open device hci%d: %s (%d)\n", + dev, strerror(errno), errno); + exit(1); + } + + if (hci_read_local_version(dd, &ver, 1000) < 0) { + fprintf(stderr, "Can't read version for hci%d: %s (%d)\n", + dev, strerror(errno), errno); + hci_close_dev(dd); + exit(1); + } + + if (ver.manufacturer != 37 && ver.manufacturer != 48) { + fprintf(stderr, "Can't find supported device hci%d: %s (%d)\n", + dev, strerror(ENOSYS), ENOSYS); + hci_close_dev(dd); + exit(1); + } + + if (ericsson_write_events(dd, 0x03) < 0) { + fprintf(stderr, "Can't activate events for hci%d: %s (%d)\n", + dev, strerror(errno), errno); + hci_close_dev(dd); + exit(1); + } + + hci_close_dev(dd); + + return 0; +} diff --git a/test/sttest.c b/test/sttest.c deleted file mode 100644 index 8f714489..00000000 --- a/test/sttest.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * Copyright (C) 2005-2007 Marcel Holtmann - * - * - * 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 - -#define OCF_ERICSSON_WRITE_EVENTS 0x0043 -typedef struct { - uint8_t mask; - uint8_t opcode; - uint8_t opcode_ext; -} __attribute__ ((packed)) ericsson_write_events_cp; -#define ERICSSON_WRITE_EVENTS_CP_SIZE 3 - -static int ericsson_write_events(int dd) -{ - struct hci_request rq; - ericsson_write_events_cp cp; - - memset(&cp, 0, sizeof(cp)); - cp.mask = 0x03; - cp.opcode = 0x00; - cp.opcode_ext = 0x00; - - memset(&rq, 0, sizeof(rq)); - rq.ogf = OGF_VENDOR_CMD; - rq.ocf = OCF_ERICSSON_WRITE_EVENTS; - rq.cparam = &cp; - rq.clen = ERICSSON_WRITE_EVENTS_CP_SIZE; - rq.rparam = NULL; - rq.rlen = 0; - - if (hci_send_req(dd, &rq, 1000) < 0) - return -1; - - return 0; -} - -static void usage(void) -{ - printf("sttest - Utility for ST Microelectronics chips\n\n"); - printf("Usage:\n" - "\tsttest [-i ]\n"); -} - -static struct option main_options[] = { - { "device", 1, 0, 'i' }, - { "help", 0, 0, 'h' }, - { 0, 0, 0, 0 } -}; - -int main(int argc, char *argv[]) -{ - struct hci_version ver; - int dd, opt, dev = 0; - - while ((opt=getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) { - switch (opt) { - case 'i': - dev = hci_devid(optarg); - if (dev < 0) { - perror("Invalid device"); - exit(1); - } - break; - - case 'h': - default: - usage(); - exit(0); - } - } - - argc -= optind; - argv += optind; - optind = 0; - - dd = hci_open_dev(dev); - if (dd < 0) { - fprintf(stderr, "Can't open device hci%d: %s (%d)\n", - dev, strerror(errno), errno); - exit(1); - } - - if (hci_read_local_version(dd, &ver, 1000) < 0) { - fprintf(stderr, "Can't read version for hci%d: %s (%d)\n", - dev, strerror(errno), errno); - hci_close_dev(dd); - exit(1); - } - - if (ver.manufacturer != 37 && ver.manufacturer != 48) { - fprintf(stderr, "Can't find supported device hci%d: %s (%d)\n", - dev, strerror(ENOSYS), ENOSYS); - hci_close_dev(dd); - exit(1); - } - - if (ericsson_write_events(dd) < 0) { - fprintf(stderr, "Can't activate events for hci%d: %s (%d)\n", - dev, strerror(errno), errno); - hci_close_dev(dd); - exit(1); - } - - hci_close_dev(dd); - - return 0; -} -- cgit