From: Ronny L Nilsson <bb@arbetsmyra.dyndns.org>
To: bluez-devel@lists.sourceforge.net
Subject: [Bluez-devel] bccmd reading clock
Date: Tue, 28 Jun 2005 00:37:06 +0200 [thread overview]
Message-ID: <20050627223919.793D83BC@arbetsmyra.dyndns.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 431 bytes --]
Hi
I was in the need for an enhancement of the bccmd tool and thus made a
small change. The supplied patch adds a command for reading the the
BT-clock of local device. In the process I also made some minor changes
to utils/tools/csr.c to reuse existing code. Besided reading 16-bit
variables it can now also read 32- and 8-bits alike.
No changes has (yet) been made to hcidump. Should it be done?
Regards
/Ronny Nilsson
[-- Attachment #2: bccmd-clock.patch --]
[-- Type: text/x-diff, Size: 3921 bytes --]
Index: utils/tools/bccmd.c
===================================================================
RCS file: /cvsroot/bluez/utils/tools/bccmd.c,v
retrieving revision 1.1
diff -u -p -r1.1 bccmd.c
--- utils/tools/bccmd.c 16 May 2005 11:51:27 -0000 1.1
+++ utils/tools/bccmd.c 27 Jun 2005 22:30:05 -0000
@@ -79,13 +79,33 @@ static int cmd_keylen(int dd, int argc,
return 0;
}
+
+static int cmd_clock(int dd, int argc, char *argv[])
+{
+ uint32_t clk=0;
+ int err;
+
+ err = csr_read_varid_uint32(dd, 0x2143, CSR_VARID_BT_CLOCK, &clk);
+ if (err < 0) {
+ errno = -err;
+ return -1;
+ }
+
+ printf("Device local BT-clock: 0x%x\n", clk);
+
+ return 0;
+}
+
+
+
static struct {
char *str;
int (*func)(int dd, int argc, char **argv);
char *arg;
char *doc;
} commands[] = {
- { "keylen", cmd_keylen, "<handle>", "Get current crypt key length" },
+ { "keylen", cmd_keylen, "<handle>", "Get current crypt key length" },
+ { "clock", cmd_clock, " ", "Get local BT-clock" },
{ NULL },
};
Index: utils/tools/csr.c
===================================================================
RCS file: /cvsroot/bluez/utils/tools/csr.c,v
retrieving revision 1.27
diff -u -p -r1.27 csr.c
--- utils/tools/csr.c 10 Jun 2005 06:59:27 -0000 1.27
+++ utils/tools/csr.c 27 Jun 2005 22:30:06 -0000
@@ -464,7 +464,8 @@ int csr_read_varid_complex(int dd, uint1
return 0;
}
-int csr_read_varid_uint16(int dd, uint16_t seqnum, uint16_t varid, uint16_t *value)
+
+int csr_read_varid_uint32(int dd, uint16_t seqnum, uint16_t varid, uint32_t *value)
{
unsigned char cmd[] = { 0x00, 0x00, 0x09, 0x00,
seqnum & 0xff, seqnum >> 8, varid & 0xff, varid >> 8, 0x00, 0x00,
@@ -488,22 +489,56 @@ int csr_read_varid_uint16(int dd, uint16
if (hci_send_req(dd, &rq, 2000) < 0)
return -1;
-
- if (rp[0] != 0xc2) {
+
+ if (rp[0] != 0xc2 || rp[5] != (seqnum & 0xff) ||
+ rp[6] != (seqnum >> 8)) {
errno = EIO;
return -1;
}
- if ((rp[9] + (rp[10] << 8)) != 0) {
+ if (rp[9] || rp[10]) {
errno = ENXIO;
return -1;
}
- *value = rp[11] + (rp[12] << 8);
+ *value = rp[12];
+ *value <<= 8;
+ *value |= rp[11];
+ *value <<= 8;
+ *value |= rp[14];
+ *value <<= 8;
+ *value |= rp[13];
return 0;
}
+
+int csr_read_varid_uint16(int dd, uint16_t seqnum, uint16_t varid, uint16_t *value)
+{
+ uint32_t val32;
+
+ if(csr_read_varid_uint32(dd, seqnum, varid, &val32)==0) {
+ *value = (uint16_t) (val32 >> 16);
+ return 0;
+ }
+
+ return -1;
+}
+
+
+int csr_read_varid_uint8(int dd, uint16_t seqnum, uint16_t varid, uint8_t *value)
+{
+ uint16_t val16;
+
+ if(csr_read_varid_uint16(dd, seqnum, varid, &val16)==0) {
+ *value = (uint8_t) val16;
+ return 0;
+ }
+
+ return -1;
+}
+
+
int csr_read_pskey_complex(int dd, uint16_t seqnum, uint16_t pskey, uint8_t *value, uint16_t length)
{
unsigned char cmd[] = { 0x00, 0x00, ((length / 2) + 8) & 0xff, ((length / 2) + 8) >> 8,
Index: utils/tools/csr.h
===================================================================
RCS file: /cvsroot/bluez/utils/tools/csr.h,v
retrieving revision 1.12
diff -u -p -r1.12 csr.h
--- utils/tools/csr.h 10 Jun 2005 05:30:28 -0000 1.12
+++ utils/tools/csr.h 27 Jun 2005 22:30:06 -0000
@@ -76,7 +76,9 @@ char *csr_chipvertostr(uint16_t ver, uin
char *csr_pskeytostr(uint16_t pskey);
int csr_read_varid_complex(int dd, uint16_t seqnum, uint16_t varid, uint8_t *value, uint16_t length);
+int csr_read_varid_uint32(int dd, uint16_t seqnum, uint16_t varid, uint32_t *value);
int csr_read_varid_uint16(int dd, uint16_t seqnum, uint16_t varid, uint16_t *value);
+int csr_read_varid_uint8(int dd, uint16_t seqnum, uint16_t varid, uint8_t *value);
int csr_read_pskey_complex(int dd, uint16_t seqnum, uint16_t pskey, uint8_t *value, uint16_t length);
int csr_read_pskey_uint16(int dd, uint16_t seqnum, uint16_t pskey, uint16_t *value);
int csr_write_pskey_uint16(int dd, uint16_t seqnum, uint16_t pskey, uint16_t value);
next reply other threads:[~2005-06-27 22:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-27 22:37 Ronny L Nilsson [this message]
2005-06-28 15:42 ` [Bluez-devel] bccmd reading clock Marcel Holtmann
2005-06-29 8:26 ` Ronny L Nilsson
2005-07-01 8:43 ` Ronny L Nilsson
2005-07-03 10:16 ` Marcel Holtmann
2005-07-03 16:33 ` Ronny L Nilsson
2005-07-03 16:56 ` Marcel Holtmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050627223919.793D83BC@arbetsmyra.dyndns.org \
--to=bb@arbetsmyra.dyndns.org \
--cc=bluez-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox