3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2005-2010 Marcel Holtmann <marcel@holtmann.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #include <sys/ioctl.h>
33 #include <sys/socket.h>
35 #include <bluetooth/bluetooth.h>
36 #include <bluetooth/hci.h>
37 #include <bluetooth/hci_lib.h>
40 #define OCF_ERICSSON_SEND_LMP 0x0021
45 } __attribute__ ((packed)) ericsson_send_lmp_cp;
46 #define ERICSSON_SEND_LMP_CP_SIZE 20
48 static int ericsson_send_lmp(int dd, uint16_t handle, uint8_t length, uint8_t *data)
50 struct hci_request rq;
51 ericsson_send_lmp_cp cp;
53 memset(&cp, 0, sizeof(cp));
54 cp.handle = htobs(handle);
56 memcpy(cp.data, data, length);
58 memset(&rq, 0, sizeof(rq));
59 rq.ogf = OGF_VENDOR_CMD;
60 rq.ocf = OCF_ERICSSON_SEND_LMP;
62 rq.clen = ERICSSON_SEND_LMP_CP_SIZE;
66 if (hci_send_req(dd, &rq, 1000) < 0)
73 #define OCF_ERICSSON_WRITE_EVENTS 0x0043
78 } __attribute__ ((packed)) ericsson_write_events_cp;
79 #define ERICSSON_WRITE_EVENTS_CP_SIZE 3
81 static int ericsson_write_events(int dd, uint8_t mask)
83 struct hci_request rq;
84 ericsson_write_events_cp cp;
86 memset(&cp, 0, sizeof(cp));
91 memset(&rq, 0, sizeof(rq));
92 rq.ogf = OGF_VENDOR_CMD;
93 rq.ocf = OCF_ERICSSON_WRITE_EVENTS;
95 rq.clen = ERICSSON_WRITE_EVENTS_CP_SIZE;
99 if (hci_send_req(dd, &rq, 1000) < 0)
105 static void usage(void)
107 printf("lmptest - Utility for testing special LMP functions\n\n");
109 "\tlmptest [-i <dev>]\n");
112 static struct option main_options[] = {
113 { "device", 1, 0, 'i' },
114 { "help", 0, 0, 'h' },
118 int main(int argc, char *argv[])
120 struct hci_version ver;
121 int dd, opt, dev = 0;
123 while ((opt=getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) {
126 dev = hci_devid(optarg);
128 perror("Invalid device");
144 dd = hci_open_dev(dev);
146 fprintf(stderr, "Can't open device hci%d: %s (%d)\n",
147 dev, strerror(errno), errno);
151 if (hci_read_local_version(dd, &ver, 1000) < 0) {
152 fprintf(stderr, "Can't read version for hci%d: %s (%d)\n",
153 dev, strerror(errno), errno);
158 if (ver.manufacturer != 37 && ver.manufacturer != 48) {
159 fprintf(stderr, "Can't find supported device hci%d: %s (%d)\n",
160 dev, strerror(ENOSYS), ENOSYS);
165 if (ericsson_write_events(dd, 0x03) < 0) {
166 fprintf(stderr, "Can't activate events for hci%d: %s (%d)\n",
167 dev, strerror(errno), errno);