aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Friesen <jeremy.friesen@thisisant.com>2013-05-07 14:44:01 -0600
committerJeremy Friesen <jeremy.friesen@thisisant.com>2013-05-07 14:44:01 -0600
commitbc43659899dbd271078397e966aca9d39c7d6b00 (patch)
treedb99754803d55779c0a7560e7dab0901c0fe8d4c
parent2d96a12078c6f9131e8b3c3907b4803111197efc (diff)
downloadandroid_external_ant-wireless_ant_native-bc43659899dbd271078397e966aca9d39c7d6b00.tar.gz
android_external_ant-wireless_ant_native-bc43659899dbd271078397e966aca9d39c7d6b00.tar.bz2
android_external_ant-wireless_ant_native-bc43659899dbd271078397e966aca9d39c7d6b00.zip
Fixed bug with partial packet processing in multiple transport channel scenario
Usage of buffers did not allow partial packet processing to function correctly if multiple ANT transport channels exist. A buffer is now allocated for each transport channel so no message mixing occurs.
-rw-r--r--src/vfs/ant_rx_chardev.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/vfs/ant_rx_chardev.c b/src/vfs/ant_rx_chardev.c
index d6262e5..2f0cc33 100644
--- a/src/vfs/ant_rx_chardev.c
+++ b/src/vfs/ant_rx_chardev.c
@@ -45,6 +45,14 @@ extern ANTStatus ant_tx_message_flowcontrol_none(ant_channel_type eTxPath, ANT_U
#define ANT_POLL_TIMEOUT ((int)30000)
+static ANT_U8 aucRxBuffer[NUM_ANT_CHANNELS][ANT_HCI_MAX_MSG_SIZE];
+
+#ifdef ANT_DEVICE_NAME // Single transport path
+ static int iRxBufferLength[NUM_ANT_CHANNELS] = {0};
+#else
+ static int iRxBufferLength[NUM_ANT_CHANNELS] = {0, 0};
+#endif //
+
int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo);
/*
@@ -232,15 +240,13 @@ int setFlowControl(ant_channel_info_t *pstChnlInfo, ANT_U8 ucFlowSetting)
int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo)
{
int iRet = -1;
- static ANT_U8 aucRxBuffer[ANT_HCI_MAX_MSG_SIZE];
- static int iRxBufferLength = 0;
int iRxLenRead;
int iCurrentHciPacketOffset;
int iHciDataSize;
ANT_FUNC_START();
// Keep trying to read while there is an error, and that error is EAGAIN
- while (((iRxLenRead = read(pstChnlInfo->iFd, &aucRxBuffer[iRxBufferLength], (sizeof(aucRxBuffer) - iRxBufferLength))) < 0)
+ while (((iRxLenRead = read(pstChnlInfo->iFd, &aucRxBuffer[eChannel][iRxBufferLength[eChannel]], (sizeof(aucRxBuffer[eChannel]) - iRxBufferLength[eChannel]))) < 0)
&& errno == EAGAIN)
;
@@ -262,21 +268,21 @@ int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo)
goto out;
}
} else {
- ANT_SERIAL(aucRxBuffer, iRxLenRead, 'R');
+ ANT_SERIAL(aucRxBuffer[eChannel], iRxLenRead, 'R');
- iRxLenRead += iRxBufferLength; // add existing data on
+ iRxLenRead += iRxBufferLength[eChannel]; // add existing data on
// if we didn't get a full packet, then just exit
- if (iRxLenRead < (aucRxBuffer[ANT_HCI_SIZE_OFFSET] + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE)) {
- iRxBufferLength = iRxLenRead;
+ if (iRxLenRead < (aucRxBuffer[eChannel][ANT_HCI_SIZE_OFFSET] + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE)) {
+ iRxBufferLength[eChannel] = iRxLenRead;
iRet = 0;
goto out;
}
- iRxBufferLength = 0; // reset buffer length here since we should have a full packet
+ iRxBufferLength[eChannel] = 0; // reset buffer length here since we should have a full packet
#if ANT_HCI_OPCODE_SIZE == 1 // Check the different message types by opcode
- ANT_U8 opcode = aucRxBuffer[ANT_HCI_OPCODE_OFFSET];
+ ANT_U8 opcode = aucRxBuffer[eChannel][ANT_HCI_OPCODE_OFFSET];
if(ANT_HCI_OPCODE_COMMAND_COMPLETE == opcode) {
// Command Complete, so signal a FLOW_GO
@@ -304,21 +310,21 @@ int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo)
// TODO Allow HCI Packet Size value to be larger than 1 byte
// This currently works as no size value is greater than 255, and little endian
- iHciDataSize = aucRxBuffer[iCurrentHciPacketOffset + ANT_HCI_SIZE_OFFSET];
+ iHciDataSize = aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_SIZE_OFFSET];
if ((iHciDataSize + ANT_HCI_HEADER_SIZE + ANT_HCI_FOOTER_SIZE + iCurrentHciPacketOffset) >
iRxLenRead) {
// we don't have a whole packet
- iRxBufferLength = iRxLenRead - iCurrentHciPacketOffset;
- memcpy(aucRxBuffer, &aucRxBuffer[iCurrentHciPacketOffset], iRxBufferLength);
+ iRxBufferLength[eChannel] = iRxLenRead - iCurrentHciPacketOffset;
+ memcpy(aucRxBuffer[eChannel], &aucRxBuffer[eChannel][iCurrentHciPacketOffset], iRxBufferLength[eChannel]);
// the increment at the end should push us out of the while loop
} else
#ifdef ANT_MESG_FLOW_CONTROL
- if (aucRxBuffer[iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_ID_OFFSET] ==
+ if (aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_ID_OFFSET] ==
ANT_MESG_FLOW_CONTROL) {
// This is a flow control packet, not a standard ANT message
if(setFlowControl(pstChnlInfo, \
- aucRxBuffer[iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_DATA_OFFSET])) {
+ aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET + ANT_MSG_DATA_OFFSET])) {
goto out;
}
} else
@@ -328,7 +334,7 @@ int readChannelMsg(ant_channel_type eChannel, ant_channel_info_t *pstChnlInfo)
// Loop through read data until all HCI packets are written to callback
pstChnlInfo->fnRxCallback(iHciDataSize, \
- &aucRxBuffer[iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET]);
+ &aucRxBuffer[eChannel][iCurrentHciPacketOffset + ANT_HCI_DATA_OFFSET]);
} else {
ANT_WARN("%s rx callback is null", pstChnlInfo->pcDevicePath);
}