Skip to contentSkip to conversation

Reset card

Bluez-devel Joshua Wright 4 participants 8 messages Aug 17, 2005 – Aug 22, 2005 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'd like to programatically reset my CSR USB dongle after running "bdaddr" from bluez-utils, but I haven't found a way to do that (short of manually removing and inserting the dongle).

I tried "hciconfig hci0 reset", but this does not reflect the changes from the bdaddr utility, even after hciconfig down/up. I also tried "hcitool -i hci0 cmd 0x03 0x0003" (OGF_HOST_CTL, OCF_RESET), but had the same results with "hciconfig hci0 reset".

I even tried to detach the device manually with libusb and usb_reset() and usb_detach_kernel_driver_np(). The former causes BlueZ to become intermittent with the USB dongle until I run a "hciconfig hci0 reset", but still no BD_ADDR change until I manually remove and reinsert the card. The latter causes the system to ignore the USB dongle until I manually remove and re-insert.

Any suggestions? Many thanks,

- -Josh
- --
- -Joshua Wright
[email protected]

2005-2006 pgpkey: http://802.11ninja.net/pgpkey.htm
fingerprint: F00E 7A42 8375 0C55 964F E5A4 4D2F 22F6 3658 A4BF

Today I stumbled across the world's largest hotspot. The SSID is "linksys". -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDA40LTS8i9jZYpL8RAjYoAKCITpoODWDNaJSgCQNbz7UqRk8tuQCfRR2R H1Dboc+GfktjC33pzhXxG0s=
=knrV
-----END PGP SIGNATURE-----

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#1 lore raw
Quoted 4 lines

I'd like to programatically reset my CSR USB dongle after running "bdaddr" from bluez-utils, but I haven't found a way to do that (short of manually removing and inserting the dongle).

Hi
This MAY perhaps be possible using a CSR proprietary BCCMD reset command. There is no support for it (yet) in BlueZ though since it's not widely asked for (what I know of).

Regards
/Ronny

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#2 lore raw

there's a little reset utility on my page, as I needed this as well:
http://www.soft.uni-linz.ac.at/_wiki/tiki-index.php?page=3DProjectBluezHa=
ndsfree
Look at the end of the page and use at your own risk :) Simon

Quoted 12 lines · Ronny L Nilsson
Quoted 3 lines

I'd like to programatically reset my CSR USB dongle after running "bdaddr" from bluez-utils, but I haven't found a way to do that (short of manually removing and inserting the dongle).

=20
=20
Hi
This MAY perhaps be possible using a CSR proprietary BCCMD reset=20 command. There is no support for it (yet) in BlueZ though since it's=20 not widely asked for (what I know of).
=20
Regards
/Ronny

Quoted 8 lines

=20
=20
=20
=20
=20
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Pract=

ices

Quoted 1 line

Agile & Plan-Driven Development * Managing Projects & Teams * Testing &=

QA

Quoted 1 line

Security * Process Improvement & Measurement * http://www.sqe.com/bsce5=

sf

Quoted 4 lines

_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

--=20
_______________________________________________________________________
Dr. Simon Vogl
ARC Seibersdorf research GmbH
Research Studios Austria, Studio Pervasive Computing Applications Altenberger Stra=DFe 69, A-4040 Linz, Austria

Tel: +43 732 2468-8517, Fax: +43 732 2468-8426
mailto: [email protected]

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#3 lore raw

Hi Simon,

Quoted 3 lines

there's a little reset utility on my page, as I needed this as well:
http://www.soft.uni-linz.ac.at/_wiki/tiki-index.php?page=ProjectBluezHandsfree
Look at the end of the page and use at your own risk :)

feel free to send me a patch for the bccmd tool that I can include into the bluez-utils distribution.

Regards

Marcel

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#4 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 2 lines · Marcel Holtmann

feel free to send me a patch for the bccmd tool that I can include into the bluez-utils distribution.

Thanks to all who replied. Simon's code was exactly what was needed, and the CSR BCCMD documentation was very helpful.

Attached is a patch to automatically reset CSR cards after changing the BD_ADDR with the bdaddr utility.

Thanks,

- -Josh
- --
- -Joshua Wright
[email protected]

2005-2006 pgpkey: http://802.11ninja.net/pgpkey.htm
fingerprint: F00E 7A42 8375 0C55 964F E5A4 4D2F 22F6 3658 A4BF

Today I stumbled across the world's largest hotspot. The SSID is "linksys". -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDBgb4TS8i9jZYpL8RAqOoAKCPXtduODADCFt6bOt2xofhVEG6oQCg8Bx6 2zYqq5VehC3FpOhPYwyiFgE=
=9B88
-----END PGP SIGNATURE-----

bdaddr-jlw.c renamed from bdaddr.c +44 -1
@@ -103,6 +103,40 @@
 }
 #endif
 
+static int csr_cold_reset(int dd)
+{
+	unsigned char cmd[] = { 0x02, 0x00, /* message type */
+				0x09, 0x00, /* message length */
+				0x00, 0x00, /* seqno for pairing response */
+				0x01, 0x40, /* varid for cold reset */
+				0x00, 0x00, /* status */
+				/* payload follows, must be at least at least
+				   4 uint16s in length accordind to BCCMD */
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+	unsigned char cp[254], rp[254];
+	struct hci_request rq;
+
+	memset(&cp, 0, sizeof(cp));
+	cp[0] = 0xc2;
+	memcpy(cp + 1, cmd, sizeof(cmd));
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf	= OGF_VENDOR_CMD;
+	rq.ocf	= 0x00;
+	rq.event  = EVT_VENDOR;
+	rq.cparam = cp;
+	rq.clen   = sizeof(cmd) + 1;
+	rq.rparam = rp;
+	rq.rlen   = sizeof(rp);
+
+	if (hci_send_req(dd, &rq, 2000) < 0)
+		return -1;
+
+	return 0;
+}
+
+
 static int csr_write_bd_addr(int dd, bdaddr_t *bdaddr)
 {
 	unsigned char cmd[] = { 0x02, 0x00, 0x0c, 0x00, 0x11, 0x47, 0x03, 0x70,
@@ -291,7 +325,16 @@
 				exit(1);
 			}
 
-			printf("Address changed - Reset device now\n");
+			if (ver.manufacturer == 10) { /* CSR devices */
+				if (csr_cold_reset(dd) != 0) {
+					fprintf(stderr, "Error resetting card, remove and insert manually.\n");
+					exit(1);
+				} else {
+					printf("Address changed - card reset successfully\n");
+				}
+			} else { /* non-CSR devices */
+				printf("Address changed - Reset device now\n");
+			}
 
 			//ioctl(dd, HCIDEVRESET, dev);
 			//ioctl(dd, HCIDEVDOWN, dev);
maintainer
#5 lore raw

Hi Joshua,

Quoted 8 lines
Quoted 2 lines

feel free to send me a patch for the bccmd tool that I can include into the bluez-utils distribution.

Thanks to all who replied. Simon's code was exactly what was needed, and the CSR BCCMD documentation was very helpful.

Attached is a patch to automatically reset CSR cards after changing the BD_ADDR with the bdaddr utility.

I modified it a little bit to make it more generic, but it is in the CVS now. Feel free to test it. Do I get also a patch for bccmd for a reset command and a patch for decoding this command in hcidump?

Regards

Marcel

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#6 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 3 lines · Marcel Holtmann

I modified it a little bit to make it more generic, but it is in the CVS now. Feel free to test it. Do I get also a patch for bccmd for a reset command and a patch for decoding this command in hcidump?

Why, yes! Attached is a patch to add decoding for hcidump, and a few extras for bccmd. I added "disabletx", "enabletx" and "rand", as well as "coldreset" to bccmd.

Note that coldreset will be decoded in hcidump properly, but hcidump dies shortly afterward when it isn't getting a response from the card during reset.

Thanks!

- -Josh
- --
- -Joshua Wright
[email protected]

2005-2006 pgpkey: http://802.11ninja.net/pgpkey.htm
fingerprint: F00E 7A42 8375 0C55 964F E5A4 4D2F 22F6 3658 A4BF

Today I stumbled across the world's largest hotspot. The SSID is "linksys". -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDCiV3TS8i9jZYpL8RAusWAKC6bYjtEyvQDTvzulJNWdH2h6gyyQCeNtrI L+FfgUfB+pCBKi8ZWfCYKDY=
=XBJy
-----END PGP SIGNATURE-----

tools/bccmd.c +41 -4
diff -ru bluez-utils-2.19/tools/bccmd.c bluez-utils-2.19-jlw/tools/bccmd.c
@@ -129,16 +129,53 @@
 	return 0;
 }
 
+static int cmd_disabletx(int dd, int argc, char *argv[])
+{
+	return csr_write_varid_uint16(dd, 0, CSR_VARID_DISABLE_TX, 0, 0);
+}
+	
+static int cmd_enabletx(int dd, int argc, char *argv[])
+{
+	return csr_write_varid_uint16(dd, 0, CSR_VARID_ENABLE_TX, 0, 0);
+}
+	
+static int cmd_coldreset(int dd, int argc, char *argv[])
+{
+	return csr_write_varid_uint16(dd, 0, CSR_VARID_COLD_RESET, 0, 0);
+}
+	
+static int cmd_rand(int dd, int argc, char *argv[])
+{
+	uint16_t error = 0;
+	int err;
+
+	err = csr_read_varid_uint16(dd, 5, CSR_VARID_RAND, &error);
+	if (err < 0) {
+		errno = -err;
+		return -1;
+	}
+
+	printf("Random number: 0x%02x (%d)\n", error, error);
+
+	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" },
-	{ "clock",    cmd_clock,    "",         "Get local Bluetooth clock"    },
-	{ "panicarg", cmd_panicarg, "",         "Get panic code argument"      },
-	{ "faultarg", cmd_faultarg, "",         "Get fault code argument"      },
+	{ "keylen",    cmd_keylen,    "<handle>", "Get current crypt key length" },
+	{ "clock",     cmd_clock,     "",         "Get local Bluetooth clock"    },
+	{ "panicarg",  cmd_panicarg,  "",         "Get panic code argument"      },
+	{ "faultarg",  cmd_faultarg,  "",         "Get fault code argument"      },
+    { "coldreset", cmd_coldreset, "",         "Perform cold reset"           },
+    { "disabletx", cmd_disabletx, "",         "Disable TX on the device"     },
+    { "enabletx",  cmd_enabletx,  "",         "Enable TX on the device"      },
+    { "rand",      cmd_rand,      "",         "Obtain a random number"       },
 	{ NULL },
 };
 
tools/csr.c +50 -0

53 lines not on this page · raw message

tools/csr.h +1 -0
diff -ru bluez-utils-2.19/tools/csr.h bluez-utils-2.19-jlw/tools/csr.h
@@ -81,3 +81,4 @@
 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);
+int csr_write_varid_uint16(int dd, uint16_t seqnum, uint16_t varid, uint16_t value, int chkresp);

Only in bluez-hcidump-1.24-jlw/: Makefile
Only in bluez-hcidump-1.24-jlw/: config.h
Only in bluez-hcidump-1.24-jlw/: config.log
Only in bluez-hcidump-1.24-jlw/: config.status
Only in bluez-hcidump-1.24-jlw/parser: .csr.c.swp
Only in bluez-hcidump-1.24-jlw/parser: Makefile

parser/csr.c +9 -0
diff -ru bluez-hcidump-1.24/parser/csr.c bluez-hcidump-1.24-jlw/parser/csr.c
@@ -214,6 +214,15 @@
 	case 0x3008:
 		handle_length_dump(level + 1, "CRYPT_KEY_LENGTH", frm);
 		break;
+	case 0x4001:
+		uint16_dump(level + 1, "COLD_RESET", frm);
+		break;
+	case 0x4007:
+		uint16_dump(level + 1, "ENABLE_TX", frm);
+		break;
+	case 0x4008:
+		uint16_dump(level + 1, "DISABLE_TX", frm);
+		break;
 	case 0x481c:
 		uint16_dump(level + 1, "MAP_SCO_PCM", frm);
 		break;

Only in bluez-hcidump-1.24-jlw/src: Makefile
Only in bluez-hcidump-1.24-jlw/: stamp-h1

maintainer
#7 lore raw

Hi Josh,

Quoted 11 lines
Quoted 3 lines

I modified it a little bit to make it more generic, but it is in the CVS now. Feel free to test it. Do I get also a patch for bccmd for a reset command and a patch for decoding this command in hcidump?

Why, yes! Attached is a patch to add decoding for hcidump, and a few extras for bccmd. I added "disabletx", "enabletx" and "rand", as well as "coldreset" to bccmd.

Note that coldreset will be decoded in hcidump properly, but hcidump dies shortly afterward when it isn't getting a response from the card during reset.

thanks for the patch, but always keep the coding style in mind and follow it.

The coldreset, disabletx and enabletx commands are valueless and so you must handle them like this.

I fixed that and added also the missing BCCMD variables to hcidump.

Regards

Marcel

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel