Check length is larger than 0 before sending data to Bluetooth services

This commit is contained in:
Kristian Lauszus 2013-12-11 11:56:05 +01:00
parent 6909ecd6b8
commit c1f82e9e47

32
BTD.cpp
View file

@ -372,20 +372,19 @@ uint8_t BTD::Poll() {
return 0; return 0;
if (qNextPollTime <= millis()) { // Don't poll if shorter than polling interval if (qNextPollTime <= millis()) { // Don't poll if shorter than polling interval
qNextPollTime = millis() + pollInterval; // Set new poll time qNextPollTime = millis() + pollInterval; // Set new poll time
HCI_event_task(); // poll the HCI event pipe HCI_event_task(); // Poll the HCI event pipe
ACL_event_task(); // start polling the ACL input pipe too, though discard data until connected HCI_task(); // HCI state machine
ACL_event_task(); // Poll the ACL input pipe too
} }
return 0; return 0;
} }
void BTD::HCI_event_task() { void BTD::HCI_event_task() {
/* check the event pipe*/ uint16_t length = BULK_MAXPKTSIZE; // Request more than 16 bytes anyway, the inTransfer routine will take care of this
uint16_t MAX_BUFFER_SIZE = BULK_MAXPKTSIZE; // Request more than 16 bytes anyway, the inTransfer routine will take care of this uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_EVENT_PIPE ].epAddr, &length, hcibuf); // Input on endpoint 1
uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_EVENT_PIPE ].epAddr, &MAX_BUFFER_SIZE, hcibuf); // input on endpoint 1
if (!rcode || rcode == hrNAK) // Check for errors if (!rcode || rcode == hrNAK) { // Check for errors
{ switch (hcibuf[0]) { // Switch on event type
switch (hcibuf[0]) //switch on event type
{
case EV_COMMAND_COMPLETE: case EV_COMMAND_COMPLETE:
if (!hcibuf[5]) { // Check if command succeeded if (!hcibuf[5]) { // Check if command succeeded
hci_set_flag(HCI_FLAG_CMD_COMPLETE); // Set command complete flag hci_set_flag(HCI_FLAG_CMD_COMPLETE); // Set command complete flag
@ -607,7 +606,6 @@ void BTD::HCI_event_task() {
D_PrintHex<uint8_t > (rcode, 0x80); D_PrintHex<uint8_t > (rcode, 0x80);
} }
#endif #endif
HCI_task();
} }
/* Poll Bluetooth and print result */ /* Poll Bluetooth and print result */
@ -878,12 +876,16 @@ void BTD::HCI_task() {
} }
void BTD::ACL_event_task() { void BTD::ACL_event_task() {
uint16_t MAX_BUFFER_SIZE = BULK_MAXPKTSIZE; uint16_t length = BULK_MAXPKTSIZE;
uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_DATAIN_PIPE ].epAddr, &MAX_BUFFER_SIZE, l2capinbuf); // input on endpoint 2 uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_DATAIN_PIPE ].epAddr, &length, l2capinbuf); // Input on endpoint 2
if (!rcode) { // Check for errors if (!rcode) { // Check for errors
for (uint8_t i = 0; i < BTD_NUMSERVICES; i++) if (length > 0) { // Check if any data was read
if (btService[i]) for (uint8_t i = 0; i < BTD_NUMSERVICES; i++) {
btService[i]->ACLData(l2capinbuf); if (btService[i])
btService[i]->ACLData(l2capinbuf);
}
}
} }
#ifdef EXTRADEBUG #ifdef EXTRADEBUG
else if (rcode != hrNAK) { else if (rcode != hrNAK) {