From: Chan-Yeol Park <chanyeol.park@samsung.com>
To: bluez-devel@lists.sourceforge.net
Subject: [Bluez-devel] bccmd(csr_bcsp.c) bug Report
Date: Mon, 30 Jun 2008 15:08:54 +0900 [thread overview]
Message-ID: <004b01c8da77$c65e95b0$531bc110$%park@samsung.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 835 bytes --]
Dear all
Recently I found the bccmd bug.
I think that do_command function (csr_bcsp.c) could have a problem
if we receive both UBCSP_PACKET_SENT and UBCSP_PACKET_RECEIVED
simultaneously from ubcsp_poll function.
An expected scenario is that UBCSP_PACKET_SENT comes earlier than
UBCSP_PACKET_RECEIVED.
But if we get them at the same time this could be a problem because
“sent=1” is located after checking “sent==1”.
It means that this program doesn’t know UBCSP_PACKET_SENT even if we
already receive it.
I there anyone who know this bug?
If you let me know how to check-in code,
I would like to do it!
Regards.
Chan-Yeol Park (박 찬 열)
Engineer
Mobile S/W Platform Lab.
Telecommunication R&D Center
SAMSUNG ELECTRONICS CO., LTD.
[-- Attachment #1.2: Type: text/html, Size: 6775 bytes --]
[-- Attachment #2: csr_bcsp_modified.c --]
[-- Type: application/octet-stream, Size: 1939 bytes --]
static int do_command(uint16_t command, uint16_t seqnum, uint16_t varid, uint8_t *value, uint16_t length)
{
unsigned char cp[254], rp[254];
uint8_t cmd[10];
uint16_t size;
uint8_t delay, activity = 0x00;
int timeout = 0, sent = 0;
size = (length < 8) ? 9 : ((length + 1) / 2) + 5;
cmd[0] = command & 0xff;
cmd[1] = command >> 8;
cmd[2] = size & 0xff;
cmd[3] = size >> 8;
cmd[4] = seqnum & 0xff;
cmd[5] = seqnum >> 8;
cmd[6] = varid & 0xff;
cmd[7] = varid >> 8;
cmd[8] = 0x00;
cmd[9] = 0x00;
memset(cp, 0, sizeof(cp));
cp[0] = 0x00;
cp[1] = 0xfc;
cp[2] = (size * 2) + 1;
cp[3] = 0xc2;
memcpy(cp + 4, cmd, sizeof(cmd));
memcpy(cp + 14, value, length);
receive_packet.length = 512;
ubcsp_receive_packet(&receive_packet);
send_packet.channel = 5;
send_packet.reliable = 1;
send_packet.length = (size * 2) + 4;
memcpy(send_packet.payload, cp, (size * 2) + 4);
ubcsp_send_packet(&send_packet);
while (1) {
delay = ubcsp_poll(&activity);
if (activity & UBCSP_PACKET_SENT) {
switch (varid) {
case CSR_VARID_COLD_RESET:
case CSR_VARID_WARM_RESET:
case CSR_VARID_COLD_HALT:
case CSR_VARID_WARM_HALT:
return 0;
}
sent = 1;
timeout = 0;
}
if (activity & UBCSP_PACKET_RECEIVED) {
if (sent && receive_packet.channel == 5 &&
receive_packet.payload[0] == 0xff) {
memcpy(rp, receive_packet.payload,
receive_packet.length);
break;
}
receive_packet.length = 512;
ubcsp_receive_packet(&receive_packet);
timeout = 0;
}
if (delay) {
usleep(delay * 100);
if (timeout++ > 100) {
fprintf(stderr, "Operation timed out\n");
return -1;
}
}
}
if (rp[0] != 0xff || rp[2] != 0xc2) {
errno = EIO;
return -1;
}
if ((rp[11] + (rp[12] << 8)) != 0) {
errno = ENXIO;
return -1;
}
memcpy(value, rp + 13, length);
return 0;
}
[-- Attachment #3: csr_bcsp_original.c --]
[-- Type: application/octet-stream, Size: 1941 bytes --]
static int do_command(uint16_t command, uint16_t seqnum, uint16_t varid, uint8_t *value, uint16_t length)
{
unsigned char cp[254], rp[254];
uint8_t cmd[10];
uint16_t size;
uint8_t delay, activity = 0x00;
int timeout = 0, sent = 0;
size = (length < 8) ? 9 : ((length + 1) / 2) + 5;
cmd[0] = command & 0xff;
cmd[1] = command >> 8;
cmd[2] = size & 0xff;
cmd[3] = size >> 8;
cmd[4] = seqnum & 0xff;
cmd[5] = seqnum >> 8;
cmd[6] = varid & 0xff;
cmd[7] = varid >> 8;
cmd[8] = 0x00;
cmd[9] = 0x00;
memset(cp, 0, sizeof(cp));
cp[0] = 0x00;
cp[1] = 0xfc;
cp[2] = (size * 2) + 1;
cp[3] = 0xc2;
memcpy(cp + 4, cmd, sizeof(cmd));
memcpy(cp + 14, value, length);
receive_packet.length = 512;
ubcsp_receive_packet(&receive_packet);
send_packet.channel = 5;
send_packet.reliable = 1;
send_packet.length = (size * 2) + 4;
memcpy(send_packet.payload, cp, (size * 2) + 4);
ubcsp_send_packet(&send_packet);
while (1) {
delay = ubcsp_poll(&activity);
if (activity & UBCSP_PACKET_RECEIVED) {
if (sent && receive_packet.channel == 5 &&
receive_packet.payload[0] == 0xff) {
memcpy(rp, receive_packet.payload,
receive_packet.length);
break;
}
receive_packet.length = 512;
ubcsp_receive_packet(&receive_packet);
timeout = 0;
}
if (activity & UBCSP_PACKET_SENT) {
switch (varid) {
case CSR_VARID_COLD_RESET:
case CSR_VARID_WARM_RESET:
case CSR_VARID_COLD_HALT:
case CSR_VARID_WARM_HALT:
return 0;
}
sent = 1;
timeout = 0;
}
if (delay) {
usleep(delay * 100);
if (timeout++ > 100) {
fprintf(stderr, "Operation timed out\n");
return -1;
}
}
}
if (rp[0] != 0xff || rp[2] != 0xc2) {
errno = EIO;
return -1;
}
if ((rp[11] + (rp[12] << 8)) != 0) {
errno = ENXIO;
return -1;
}
memcpy(value, rp + 13, length);
return 0;
}
[-- Attachment #4: Type: text/plain, Size: 247 bytes --]
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
[-- Attachment #5: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
next reply other threads:[~2008-06-30 6:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-30 6:08 Chan-Yeol Park [this message]
2008-06-30 6:15 ` [Bluez-devel] bccmd(csr_bcsp.c) bug Report Marcel Holtmann
2008-07-02 18:47 ` Frank Mandarino
2008-07-11 6:49 ` 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='004b01c8da77$c65e95b0$531bc110$%park@samsung.com' \
--to=chanyeol.park@samsung.com \
--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