mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-25 07:43:38 +00:00
MISRAC2012-Rule-12.1: add suggested parentheses
This commit is contained in:
parent
15a2796783
commit
c1ab6cc1be
4
3rd-party/bluedroid/decoder/srce/alloc.c
vendored
4
3rd-party/bluedroid/decoder/srce/alloc.c
vendored
@ -35,11 +35,11 @@ PRIVATE OI_STATUS OI_CODEC_SBC_Alloc(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||
size_t subdataSize;
|
||||
OI_BYTE *codecData = (OI_BYTE*)codecDataAligned;
|
||||
|
||||
if (maxChannels < 1 || maxChannels > 2) {
|
||||
if ((maxChannels < 1) || (maxChannels > 2)) {
|
||||
return OI_STATUS_INVALID_PARAMETERS;
|
||||
}
|
||||
|
||||
if (pcmStride < 1 || pcmStride > maxChannels) {
|
||||
if ((pcmStride < 1) || (pcmStride > maxChannels)) {
|
||||
return OI_STATUS_INVALID_PARAMETERS;
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ OI_UINT16 OI_CODEC_SBC_CalculateBitpool(OI_CODEC_SBC_FRAME_INFO *frame,
|
||||
nrof_blocks *= 2;
|
||||
}
|
||||
}
|
||||
bits = 8 * (frameLen - SBC_HEADER_LEN) - hdr;
|
||||
bits = (8 * (frameLen - SBC_HEADER_LEN)) - hdr;
|
||||
return DIVIDE(bits, nrof_blocks);
|
||||
}
|
||||
|
||||
|
6
3rd-party/bluedroid/decoder/srce/bitalloc.c
vendored
6
3rd-party/bluedroid/decoder/srce/bitalloc.c
vendored
@ -68,7 +68,7 @@ PRIVATE OI_UINT16 internal_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO *frame)
|
||||
if (frame->mode == SBC_DUAL_CHANNEL) { result += nbits; }
|
||||
if (frame->mode == SBC_MONO) { result += 4*nrof_subbands; } else { result += 8*nrof_subbands; }
|
||||
}
|
||||
return SBC_HEADER_LEN + (result + 7) / 8;
|
||||
return SBC_HEADER_LEN + ((result + 7) / 8);
|
||||
}
|
||||
|
||||
|
||||
@ -83,7 +83,7 @@ PRIVATE OI_UINT32 internal_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO *frame)
|
||||
|
||||
INLINE OI_UINT16 OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *frame, OI_UINT *headerLen_)
|
||||
{
|
||||
OI_UINT headerLen = SBC_HEADER_LEN + frame->nrof_subbands * frame->nrof_channels/2;
|
||||
OI_UINT headerLen = SBC_HEADER_LEN + (frame->nrof_subbands * frame->nrof_channels/2);
|
||||
|
||||
if (frame->mode == SBC_JOINT_STEREO) { headerLen++; }
|
||||
|
||||
@ -266,7 +266,7 @@ OI_INT adjustToFitBitpool(const OI_UINT bitpool,
|
||||
adjust4 |= (adjust4 << 8);
|
||||
adjust4 |= (adjust4 << 16);
|
||||
|
||||
for (i = (subbands / 4 - 1); i >= 0; --i) {
|
||||
for (i = ((subbands / 4) - 1); i >= 0; --i) {
|
||||
OI_UINT32 mask;
|
||||
OI_UINT32 n = bitneeds[i] + adjust4;
|
||||
mask = 0x7F7F7F7F + ((n & 0x40404040) >> 6);
|
||||
|
@ -177,7 +177,7 @@ PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||
OI_INT8 *scale_factor = common->scale_factor;
|
||||
OI_UINT f;
|
||||
|
||||
if (common->frameInfo.nrof_subbands == 8 || common->frameInfo.mode != SBC_JOINT_STEREO) {
|
||||
if ((common->frameInfo.nrof_subbands == 8) || (common->frameInfo.mode != SBC_JOINT_STEREO)) {
|
||||
if (common->frameInfo.mode == SBC_JOINT_STEREO) {
|
||||
common->frameInfo.join = *b++;
|
||||
} else {
|
||||
|
10
3rd-party/bluedroid/decoder/srce/decoder-sbc.c
vendored
10
3rd-party/bluedroid/decoder/srce/decoder-sbc.c
vendored
@ -174,10 +174,10 @@ static OI_STATUS DecodeBody(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
/*
|
||||
* When decoding mono into a stride-2 array, copy pcm data to second channel
|
||||
*/
|
||||
if (context->common.frameInfo.nrof_channels == 1 && context->common.pcmStride == 2) {
|
||||
if ((context->common.frameInfo.nrof_channels == 1) && (context->common.pcmStride == 2)) {
|
||||
OI_UINT i;
|
||||
for (i = 0; i < frameSamples; ++i) {
|
||||
pcmData[2*i+1] = pcmData[2*i];
|
||||
pcmData[(2*i)+1] = pcmData[2*i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,7 +226,7 @@ PRIVATE OI_STATUS internal_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
* tones.
|
||||
*/
|
||||
status = DecodeBody(context, *frameData, pcmData, pcmBytes, TRUE);
|
||||
if (OI_SUCCESS(status) || status == OI_CODEC_SBC_PARTIAL_DECODE) {
|
||||
if (OI_SUCCESS(status) || (status == OI_CODEC_SBC_PARTIAL_DECODE)) {
|
||||
*frameData += bodyLen;
|
||||
*frameBytes -= bodyLen;
|
||||
}
|
||||
@ -303,7 +303,7 @@ OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
return OI_STATUS_INVALID_PARAMETERS;
|
||||
}
|
||||
|
||||
if (context->common.pcmStride < 1 || context->common.pcmStride > 2) {
|
||||
if ((context->common.pcmStride < 1) || (context->common.pcmStride > 2)) {
|
||||
ERROR(("PCM stride not set correctly during reset"));
|
||||
return OI_STATUS_INVALID_PARAMETERS;
|
||||
}
|
||||
@ -443,7 +443,7 @@ OI_UINT8 OI_CODEC_SBC_FrameCount(OI_BYTE *frameData,
|
||||
}
|
||||
|
||||
frameCount++;
|
||||
frameLen = SBC_HEADER_LEN + (frameLen + 7) / 8;
|
||||
frameLen = SBC_HEADER_LEN + ((frameLen + 7) / 8);
|
||||
if (frameBytes > frameLen){
|
||||
frameBytes -= frameLen;
|
||||
frameData += frameLen;
|
||||
|
4
3rd-party/bluedroid/decoder/srce/framing.c
vendored
4
3rd-party/bluedroid/decoder/srce/framing.c
vendored
@ -205,7 +205,7 @@ PRIVATE OI_UINT8 OI_SBC_CalculateChecksum(OI_CODEC_SBC_FRAME_INFO *frame, OI_BYT
|
||||
|
||||
OI_UINT count = (frame->nrof_subbands * frame->nrof_channels / 2u) + 4;
|
||||
|
||||
if (frame->mode == SBC_JOINT_STEREO && frame->nrof_subbands == 8) {
|
||||
if ((frame->mode == SBC_JOINT_STEREO) && (frame->nrof_subbands == 8)) {
|
||||
count++;
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ PRIVATE OI_UINT8 OI_SBC_CalculateChecksum(OI_CODEC_SBC_FRAME_INFO *frame, OI_BYT
|
||||
}
|
||||
}
|
||||
|
||||
if (frame->mode == SBC_JOINT_STEREO && frame->nrof_subbands == 4) {
|
||||
if ((frame->mode == SBC_JOINT_STEREO) && (frame->nrof_subbands == 4)) {
|
||||
crc = crc_iterate_top4(crc, data[i]);
|
||||
}
|
||||
|
||||
|
@ -69,11 +69,11 @@ INLINE OI_INT32 default_mul_32s_32s_hi(OI_INT32 u, OI_INT32 v)
|
||||
u0 = u & 0xFFFF; u1 = u >> 16;
|
||||
v0 = v & 0xFFFF; v1 = v >> 16;
|
||||
t = u0*v0;
|
||||
t = u1*v0 + ((OI_UINT32)t >> 16);
|
||||
t = (u1*v0) + ((OI_UINT32)t >> 16);
|
||||
w1 = t & 0xFFFF;
|
||||
w2 = t >> 16;
|
||||
w1 = u0*v1 + w1;
|
||||
return u1*v1 + w2 + (w1 >> 16);
|
||||
w1 = (u0*v1) + w1;
|
||||
return (u1*v1) + w2 + (w1 >> 16);
|
||||
}
|
||||
|
||||
#define MUL_32S_32S_HI(_x, _y) default_mul_32s_32s_hi(_x, _y)
|
||||
|
@ -262,9 +262,9 @@ PRIVATE void OI_SBC_SynthFrame_80(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT1
|
||||
OI_UINT blk;
|
||||
OI_UINT ch;
|
||||
OI_UINT nrof_channels = context->common.frameInfo.nrof_channels;
|
||||
OI_UINT pcmStrideShift = context->common.pcmStride == 1 ? 0 : 1;
|
||||
OI_UINT pcmStrideShift = (context->common.pcmStride == 1) ? 0 : 1;
|
||||
OI_UINT offset = context->common.filterBufferOffset;
|
||||
OI_INT32 *s = context->common.subdata + 8 * nrof_channels * blkstart;
|
||||
OI_INT32 *s = context->common.subdata + (8 * nrof_channels * blkstart);
|
||||
OI_UINT blkstop = blkstart + blkcount;
|
||||
|
||||
for (blk = blkstart; blk < blkstop; blk++) {
|
||||
@ -294,9 +294,9 @@ PRIVATE void OI_SBC_SynthFrame_4SB(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT
|
||||
OI_UINT blk;
|
||||
OI_UINT ch;
|
||||
OI_UINT nrof_channels = context->common.frameInfo.nrof_channels;
|
||||
OI_UINT pcmStrideShift = context->common.pcmStride == 1 ? 0 : 1;
|
||||
OI_UINT pcmStrideShift = (context->common.pcmStride == 1) ? 0 : 1;
|
||||
OI_UINT offset = context->common.filterBufferOffset;
|
||||
OI_INT32 *s = context->common.subdata + 8 * nrof_channels * blkstart;
|
||||
OI_INT32 *s = context->common.subdata + (8 * nrof_channels * blkstart);
|
||||
OI_UINT blkstop = blkstart + blkcount;
|
||||
|
||||
for (blk = blkstart; blk < blkstop; blk++) {
|
||||
|
@ -963,7 +963,7 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
|
||||
}
|
||||
for (s32Ch=0;s32Ch<s32NumOfChannels;s32Ch++)
|
||||
{
|
||||
ChOffset=s32Ch*Offset2+Offset;
|
||||
ChOffset=(s32Ch*Offset2)+Offset;
|
||||
|
||||
WINDOW_PARTIAL_4
|
||||
|
||||
@ -1066,7 +1066,7 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
|
||||
}
|
||||
for (s32Ch=0;s32Ch<s32NumOfChannels;s32Ch++)
|
||||
{
|
||||
ChOffset=s32Ch*Offset2+Offset;
|
||||
ChOffset=(s32Ch*Offset2)+Offset;
|
||||
|
||||
WINDOW_PARTIAL_8
|
||||
|
||||
|
@ -61,18 +61,18 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
|
||||
for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++)
|
||||
{
|
||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*SBC_MAX_NUM_OF_SUBBANDS;
|
||||
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+(s32Ch*SBC_MAX_NUM_OF_SUBBANDS);
|
||||
|
||||
/* bitneed values are derived from scale factor */
|
||||
if (pstrCodecParams->s16AllocationMethod == SBC_SNR)
|
||||
{
|
||||
ps16BitNeed = pstrCodecParams->as16ScaleFactor;
|
||||
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
|
||||
ps16GenBufPtr = ps16BitNeed + (s32Ch * s32NumOfSubBands);
|
||||
}
|
||||
else
|
||||
{
|
||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
||||
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
|
||||
if(s32NumOfSubBands == 4)
|
||||
{
|
||||
ps16GenTabPtr = (SINT16 *)
|
||||
@ -85,12 +85,12 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
}
|
||||
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
|
||||
{
|
||||
if(pstrCodecParams->as16ScaleFactor[s32Ch*s32NumOfSubBands+s32Sb] == 0)
|
||||
if(pstrCodecParams->as16ScaleFactor[(s32Ch*s32NumOfSubBands)+s32Sb] == 0)
|
||||
*(ps16GenBufPtr) = -5;
|
||||
else
|
||||
{
|
||||
s32Loudness =
|
||||
(SINT32)(pstrCodecParams->as16ScaleFactor[s32Ch*s32NumOfSubBands+s32Sb]
|
||||
(SINT32)(pstrCodecParams->as16ScaleFactor[(s32Ch*s32NumOfSubBands)+s32Sb]
|
||||
- *ps16GenTabPtr);
|
||||
if(s32Loudness > 0)
|
||||
*(ps16GenBufPtr) = (SINT16)(s32Loudness >>1);
|
||||
@ -105,7 +105,7 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
|
||||
/* max bitneed index is searched*/
|
||||
s32MaxBitNeed = 0;
|
||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
||||
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
|
||||
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
|
||||
{
|
||||
if( *(ps16GenBufPtr) > s32MaxBitNeed)
|
||||
@ -113,7 +113,7 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
|
||||
ps16GenBufPtr++;
|
||||
}
|
||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
||||
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
|
||||
/*iterative process to find hwo many bitslices fit into the bitpool*/
|
||||
s32BitSlice = s32MaxBitNeed + 1;
|
||||
s32BitCount = pstrCodecParams->s16BitPool;
|
||||
@ -126,7 +126,7 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
|
||||
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
|
||||
{
|
||||
if( (((*ps16GenBufPtr-s32BitSlice)< 16) && (*ps16GenBufPtr-s32BitSlice) >= 1))
|
||||
if( (((*ps16GenBufPtr-s32BitSlice)< 16) && ((*ps16GenBufPtr-s32BitSlice) >= 1)))
|
||||
{
|
||||
if((*ps16GenBufPtr-s32BitSlice) == 1)
|
||||
s32SliceCount+=2;
|
||||
@ -136,8 +136,8 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
ps16GenBufPtr++;
|
||||
|
||||
}/*end of for*/
|
||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
||||
}while(s32BitCount-s32SliceCount>0);
|
||||
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
|
||||
}while((s32BitCount-s32SliceCount)>0);
|
||||
|
||||
if(s32BitCount == 0)
|
||||
{
|
||||
@ -146,11 +146,11 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
}
|
||||
|
||||
/*Bits are distributed until the last bitslice is reached*/
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands;
|
||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+(s32Ch*s32NumOfSubBands);
|
||||
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
|
||||
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
|
||||
{
|
||||
if(*(ps16GenBufPtr) < s32BitSlice+2)
|
||||
if(*(ps16GenBufPtr) < (s32BitSlice+2))
|
||||
*(ps16GenArrPtr) = 0;
|
||||
else
|
||||
*(ps16GenArrPtr) = ((*(ps16GenBufPtr)-s32BitSlice)<16) ?
|
||||
@ -159,8 +159,8 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
ps16GenBufPtr++;
|
||||
ps16GenArrPtr++;
|
||||
}
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands;
|
||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+(s32Ch*s32NumOfSubBands);
|
||||
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
|
||||
/*the remaining bits are allocated starting at subband 0*/
|
||||
s32Sb=0;
|
||||
while( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) )
|
||||
@ -170,7 +170,7 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
(*(ps16GenArrPtr))++;
|
||||
s32BitCount--;
|
||||
}
|
||||
else if( (*(ps16GenBufPtr) == s32BitSlice+1) &&
|
||||
else if( (*(ps16GenBufPtr) == (s32BitSlice+1)) &&
|
||||
(s32BitCount > 1) )
|
||||
{
|
||||
*(ps16GenArrPtr) = 2;
|
||||
@ -180,7 +180,7 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
ps16GenArrPtr++;
|
||||
ps16GenBufPtr++;
|
||||
}
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands;
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+(s32Ch*s32NumOfSubBands);
|
||||
|
||||
|
||||
s32Sb=0;
|
||||
|
@ -113,20 +113,20 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
s32SliceCount = 0;
|
||||
ps16GenBufPtr = ps16BitNeed;
|
||||
|
||||
for (s32Sb = 0; s32Sb < 2*s32NumOfSubBands; s32Sb++)
|
||||
for (s32Sb = 0; s32Sb < (2*s32NumOfSubBands); s32Sb++)
|
||||
{
|
||||
if ( (*ps16GenBufPtr >= s32BitSlice + 1) && (*ps16GenBufPtr < s32BitSlice + 16) )
|
||||
if ( (*ps16GenBufPtr >= (s32BitSlice + 1)) && (*ps16GenBufPtr < (s32BitSlice + 16)) )
|
||||
{
|
||||
if (*(ps16GenBufPtr) == s32BitSlice+1)
|
||||
if (*(ps16GenBufPtr) == (s32BitSlice+1))
|
||||
s32SliceCount += 2;
|
||||
else
|
||||
s32SliceCount++;
|
||||
}
|
||||
ps16GenBufPtr++;
|
||||
}
|
||||
} while (s32BitCount-s32SliceCount>0);
|
||||
} while ((s32BitCount-s32SliceCount)>0);
|
||||
|
||||
if (s32BitCount-s32SliceCount == 0)
|
||||
if ((s32BitCount-s32SliceCount) == 0)
|
||||
{
|
||||
s32BitCount -= s32SliceCount;
|
||||
s32BitSlice --;
|
||||
@ -139,7 +139,7 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
{
|
||||
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
|
||||
{
|
||||
if (*ps16GenBufPtr < s32BitSlice+2)
|
||||
if (*ps16GenBufPtr < (s32BitSlice+2))
|
||||
*ps16GenArrPtr = 0;
|
||||
else
|
||||
*ps16GenArrPtr = ((*(ps16GenBufPtr)-s32BitSlice) < 16) ?
|
||||
@ -162,7 +162,7 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
(*(ps16GenArrPtr))++;
|
||||
s32BitCount--;
|
||||
}
|
||||
else if ((*ps16GenBufPtr == s32BitSlice+1) && (s32BitCount > 1))
|
||||
else if ((*ps16GenBufPtr == (s32BitSlice+1)) && (s32BitCount > 1))
|
||||
{
|
||||
*(ps16GenArrPtr) = 2;
|
||||
s32BitCount -= 2;
|
||||
|
12
3rd-party/bluedroid/encoder/srce/sbc_encoder.c
vendored
12
3rd-party/bluedroid/encoder/srce/sbc_encoder.c
vendored
@ -187,7 +187,7 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
|
||||
/* Calculate sum and differance scale factors for making JS decision */
|
||||
ps16ScfL = pstrEncParams->as16ScaleFactor ;
|
||||
/* calculate the scale factor of Joint stereo max sum and diff */
|
||||
for (s32Sb = 0; s32Sb < s32NumOfSubBands-1; s32Sb++)
|
||||
for (s32Sb = 0; s32Sb < (s32NumOfSubBands-1); s32Sb++)
|
||||
{
|
||||
SbBuffer=pstrEncParams->s32SbBuffer+s32Sb;
|
||||
s32MaxValue2=0;
|
||||
@ -393,16 +393,16 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
|
||||
if (pstrEncParams->s16NumOfSubBands==4)
|
||||
{
|
||||
if (pstrEncParams->s16NumOfChannels==1)
|
||||
EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-4*10)>>2)<<2;
|
||||
EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-(4*10))>>2)<<2;
|
||||
else
|
||||
EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-4*10*2)>>3)<<2;
|
||||
EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-(4*10*2))>>3)<<2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pstrEncParams->s16NumOfChannels==1)
|
||||
EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-8*10)>>3)<<3;
|
||||
EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-(8*10))>>3)<<3;
|
||||
else
|
||||
EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-8*10*2)>>4)<<3;
|
||||
EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-(8*10*2))>>4)<<3;
|
||||
}
|
||||
|
||||
// APPL_TRACE_EVENT("SBC_Encoder_Init : bitrate %d, bitpool %d",
|
||||
@ -411,5 +411,5 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
|
||||
SbcAnalysisInit();
|
||||
|
||||
memset(&sbc_prtc_cb, 0, sizeof(tSBC_PRTC_CB));
|
||||
sbc_prtc_cb.base = 6 + pstrEncParams->s16NumOfChannels*pstrEncParams->s16NumOfSubBands/2;
|
||||
sbc_prtc_cb.base = 6 + (pstrEncParams->s16NumOfChannels*pstrEncParams->s16NumOfSubBands/2);
|
||||
}
|
||||
|
12
3rd-party/yxml/yxml.c
vendored
12
3rd-party/yxml/yxml.c
vendored
@ -188,14 +188,14 @@ static inline yxml_ret_t yxml_datacd2(yxml_t *x, unsigned ch) {
|
||||
|
||||
static inline yxml_ret_t yxml_dataattr(yxml_t *x, unsigned ch) {
|
||||
/* Normalize attribute values according to the XML spec section 3.3.3. */
|
||||
yxml_setchar(x->data, ch == 0x9 || ch == 0xa ? 0x20 : ch);
|
||||
yxml_setchar(x->data, (ch == 0x9) || (ch == 0xa) ? 0x20 : ch);
|
||||
x->data[1] = 0;
|
||||
return YXML_ATTRVAL;
|
||||
}
|
||||
|
||||
|
||||
static yxml_ret_t yxml_pushstack(yxml_t *x, char **res, unsigned ch) {
|
||||
if(x->stacklen+2 >= x->stacksize)
|
||||
if((x->stacklen+2) >= x->stacksize)
|
||||
return YXML_ESTACK;
|
||||
x->stacklen++;
|
||||
*res = (char *)x->stack+x->stacklen;
|
||||
@ -207,7 +207,7 @@ static yxml_ret_t yxml_pushstack(yxml_t *x, char **res, unsigned ch) {
|
||||
|
||||
|
||||
static yxml_ret_t yxml_pushstackc(yxml_t *x, unsigned ch) {
|
||||
if(x->stacklen+1 >= x->stacksize)
|
||||
if((x->stacklen+1) >= x->stacksize)
|
||||
return YXML_ESTACK;
|
||||
x->stack[x->stacklen] = ch;
|
||||
x->stacklen++;
|
||||
@ -270,7 +270,7 @@ static inline yxml_ret_t yxml_pistart (yxml_t *x, unsigned ch) { return yxml_pu
|
||||
static inline yxml_ret_t yxml_piname (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
|
||||
static inline yxml_ret_t yxml_piabort (yxml_t *x, unsigned ch) { (void) x; (void) ch; yxml_popstack(x); return YXML_OK; }
|
||||
static inline yxml_ret_t yxml_pinameend(yxml_t *x, unsigned ch) { (void) ch;
|
||||
return (x->pi[0]|32) == 'x' && (x->pi[1]|32) == 'm' && (x->pi[2]|32) == 'l' && !x->pi[3] ? YXML_ESYN : YXML_PISTART;
|
||||
return ((x->pi[0]|32) == 'x') && ((x->pi[1]|32) == 'm') && ((x->pi[2]|32) == 'l') && !x->pi[3] ? YXML_ESYN : YXML_PISTART;
|
||||
}
|
||||
static inline yxml_ret_t yxml_pivalend (yxml_t *x, unsigned ch) { (void) ch; yxml_popstack(x); x->pi = (char *)x->stack; return YXML_PIEND; }
|
||||
|
||||
@ -298,7 +298,7 @@ static yxml_ret_t yxml_refend(yxml_t *x, yxml_ret_t ret) {
|
||||
if(*r == '#') {
|
||||
if(r[1] == 'x')
|
||||
for(r += 2; yxml_isHex((unsigned)*r); r++)
|
||||
ch = (ch<<4) + (*r <= '9' ? *r-'0' : (*r|32)-'a' + 10);
|
||||
ch = (ch<<4) + ((*r <= '9') ? (*r-'0') : ((*r|32)-'a' + 10));
|
||||
else
|
||||
for(r++; yxml_isNum((unsigned)*r); r++)
|
||||
ch = (ch*10) + (*r-'0');
|
||||
@ -354,7 +354,7 @@ yxml_ret_t yxml_parse(yxml_t *x, int _ch) {
|
||||
return YXML_OK;
|
||||
}
|
||||
x->ignore = (ch == 0xd) * 0xa;
|
||||
if(ch == 0xa || ch == 0xd) {
|
||||
if((ch == 0xa) || (ch == 0xd)) {
|
||||
ch = 0xa;
|
||||
x->line++;
|
||||
x->byte = 0;
|
||||
|
@ -72,7 +72,7 @@ int ad_iterator_has_more(const ad_context_t * context){
|
||||
if (chunk_len == 0) return 0;
|
||||
|
||||
// assert complete chunk fits into buffer
|
||||
if (context->offset + 1 + chunk_len > context->length) return 0;
|
||||
if ((context->offset + 1 + chunk_len) > context->length) return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
|
||||
}
|
||||
break;
|
||||
case TC_SUBSCRIBED:
|
||||
if (hci_event_packet_get_type(packet) != GATT_EVENT_NOTIFICATION && hci_event_packet_get_type(packet) != GATT_EVENT_INDICATION ) break;
|
||||
if ((hci_event_packet_get_type(packet) != GATT_EVENT_NOTIFICATION) && (hci_event_packet_get_type(packet) != GATT_EVENT_INDICATION) ) break;
|
||||
|
||||
value_handle = little_endian_read_16(packet, 4);
|
||||
value_length = little_endian_read_16(packet, 6);
|
||||
|
@ -249,13 +249,13 @@ static void att_prepare_write_reset(void){
|
||||
|
||||
static void att_prepare_write_update_errors(uint8_t error_code, uint16_t handle){
|
||||
// first ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LENGTH has highest priority
|
||||
if (error_code == ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LENGTH && error_code != att_prepare_write_error_code){
|
||||
if ((error_code == ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LENGTH) && (error_code != att_prepare_write_error_code)){
|
||||
att_prepare_write_error_code = error_code;
|
||||
att_prepare_write_error_handle = handle;
|
||||
return;
|
||||
}
|
||||
// first ATT_ERROR_INVALID_OFFSET is next
|
||||
if (error_code == ATT_ERROR_INVALID_OFFSET && att_prepare_write_error_code == 0){
|
||||
if ((error_code == ATT_ERROR_INVALID_OFFSET) && (att_prepare_write_error_code == 0)){
|
||||
att_prepare_write_error_code = error_code;
|
||||
att_prepare_write_error_handle = handle;
|
||||
return;
|
||||
@ -324,7 +324,7 @@ static uint8_t att_validate_security(att_connection_t * att_connection, att_oper
|
||||
log_debug("att_validate_security. flags 0x%04x (=> security level %u, key size %u) authorized %u, authenticated %u, encryption_key_size %u, secure connection %u",
|
||||
it->flags, required_security_level, required_encryption_size, att_connection->authorized, att_connection->authenticated, att_connection->encryption_key_size, att_connection->secure_connection);
|
||||
|
||||
int sc_missing = requires_secure_connection && att_connection->secure_connection == 0;
|
||||
int sc_missing = requires_secure_connection && (att_connection->secure_connection == 0);
|
||||
switch (required_security_level){
|
||||
case ATT_SECURITY_AUTHORIZED:
|
||||
if ((att_connection->authorized == 0) || sc_missing){
|
||||
@ -386,7 +386,7 @@ static uint16_t handle_find_information_request2(att_connection_t * att_connecti
|
||||
log_info("ATT_FIND_INFORMATION_REQUEST: from %04X to %04X", start_handle, end_handle);
|
||||
uint8_t request_type = ATT_FIND_INFORMATION_REQUEST;
|
||||
|
||||
if (start_handle > end_handle || start_handle == 0){
|
||||
if ((start_handle > end_handle) || (start_handle == 0)){
|
||||
return setup_error_invalid_handle(response_buffer, request_type, start_handle);
|
||||
}
|
||||
|
||||
@ -421,7 +421,7 @@ static uint16_t handle_find_information_request2(att_connection_t * att_connecti
|
||||
}
|
||||
|
||||
// space?
|
||||
if (offset + 2 + uuid_len > response_buffer_size) break;
|
||||
if ((offset + 2 + uuid_len) > response_buffer_size) break;
|
||||
|
||||
// store
|
||||
little_endian_store_16(response_buffer, offset, it.handle);
|
||||
@ -467,7 +467,7 @@ static uint16_t handle_find_by_type_value_request2(att_connection_t * att_connec
|
||||
log_info_hexdump(attribute_value, attribute_len);
|
||||
uint8_t request_type = ATT_FIND_BY_TYPE_VALUE_REQUEST;
|
||||
|
||||
if (start_handle > end_handle || start_handle == 0){
|
||||
if ((start_handle > end_handle) || (start_handle == 0)){
|
||||
return setup_error_invalid_handle(response_buffer, request_type, start_handle);
|
||||
}
|
||||
|
||||
@ -480,12 +480,12 @@ static uint16_t handle_find_by_type_value_request2(att_connection_t * att_connec
|
||||
while (att_iterator_has_next(&it)){
|
||||
att_iterator_fetch_next(&it);
|
||||
|
||||
if (it.handle && it.handle < start_handle) continue;
|
||||
if (it.handle && (it.handle < start_handle)) continue;
|
||||
if (it.handle > end_handle) break; // (1)
|
||||
|
||||
// close current tag, if within a group and a new service definition starts or we reach end of att db
|
||||
if (in_group &&
|
||||
(it.handle == 0 || att_iterator_match_uuid16(&it, GATT_PRIMARY_SERVICE_UUID) || att_iterator_match_uuid16(&it, GATT_SECONDARY_SERVICE_UUID))){
|
||||
((it.handle == 0) || att_iterator_match_uuid16(&it, GATT_PRIMARY_SERVICE_UUID) || att_iterator_match_uuid16(&it, GATT_SECONDARY_SERVICE_UUID))){
|
||||
|
||||
log_info("End of group, handle 0x%04x", prev_handle);
|
||||
little_endian_store_16(response_buffer, offset, prev_handle);
|
||||
@ -493,7 +493,7 @@ static uint16_t handle_find_by_type_value_request2(att_connection_t * att_connec
|
||||
in_group = 0;
|
||||
|
||||
// check if space for another handle pair available
|
||||
if (offset + 4 > response_buffer_size){
|
||||
if ((offset + 4) > response_buffer_size){
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -502,7 +502,7 @@ static uint16_t handle_find_by_type_value_request2(att_connection_t * att_connec
|
||||
prev_handle = it.handle;
|
||||
|
||||
// does current attribute match
|
||||
if (it.handle && att_iterator_match_uuid16(&it, attribute_type) && attribute_len == it.value_len && memcmp(attribute_value, it.value, it.value_len) == 0){
|
||||
if (it.handle && att_iterator_match_uuid16(&it, attribute_type) && (attribute_len == it.value_len) && memcmp(attribute_value, it.value, it.value_len) == 0){
|
||||
log_info("Begin of group, handle 0x%04x", it.handle);
|
||||
little_endian_store_16(response_buffer, offset, it.handle);
|
||||
offset += 2;
|
||||
@ -536,7 +536,7 @@ static uint16_t handle_read_by_type_request2(att_connection_t * att_connection,
|
||||
log_info_hexdump(attribute_type, attribute_type_len);
|
||||
uint8_t request_type = ATT_READ_BY_TYPE_REQUEST;
|
||||
|
||||
if (start_handle > end_handle || start_handle == 0){
|
||||
if ((start_handle > end_handle) || (start_handle == 0)){
|
||||
return setup_error_invalid_handle(response_buffer, request_type, start_handle);
|
||||
}
|
||||
|
||||
@ -599,7 +599,7 @@ static uint16_t handle_read_by_type_request2(att_connection_t * att_connection,
|
||||
}
|
||||
|
||||
// space?
|
||||
if (offset + pair_len > response_buffer_size) {
|
||||
if ((offset + pair_len) > response_buffer_size) {
|
||||
if (offset > 2) break;
|
||||
it.value_len = response_buffer_size - 4;
|
||||
response_buffer[1] = 2 + it.value_len;
|
||||
@ -680,7 +680,7 @@ static uint16_t handle_read_request2(att_connection_t * att_connection, uint8_t
|
||||
|
||||
uint16_t offset = 1;
|
||||
// limit data
|
||||
if (offset + it.value_len > response_buffer_size) {
|
||||
if ((offset + it.value_len) > response_buffer_size) {
|
||||
it.value_len = response_buffer_size - 1;
|
||||
}
|
||||
|
||||
@ -734,7 +734,7 @@ static uint16_t handle_read_blob_request2(att_connection_t * att_connection, uin
|
||||
|
||||
// limit data
|
||||
uint16_t offset = 1;
|
||||
if (offset + it.value_len - value_offset > response_buffer_size) {
|
||||
if ((offset + it.value_len - value_offset) > response_buffer_size) {
|
||||
it.value_len = response_buffer_size - 1 + value_offset;
|
||||
}
|
||||
|
||||
@ -808,7 +808,7 @@ static uint16_t handle_read_multiple_request2(att_connection_t * att_connection,
|
||||
#endif
|
||||
|
||||
// limit data
|
||||
if (offset + it.value_len > response_buffer_size) {
|
||||
if ((offset + it.value_len) > response_buffer_size) {
|
||||
it.value_len = response_buffer_size - 1;
|
||||
}
|
||||
|
||||
@ -856,13 +856,13 @@ static uint16_t handle_read_by_group_type_request2(att_connection_t * att_connec
|
||||
log_info_hexdump(attribute_type, attribute_type_len);
|
||||
uint8_t request_type = ATT_READ_BY_GROUP_TYPE_REQUEST;
|
||||
|
||||
if (start_handle > end_handle || start_handle == 0){
|
||||
if ((start_handle > end_handle) || (start_handle == 0)){
|
||||
return setup_error_invalid_handle(response_buffer, request_type, start_handle);
|
||||
}
|
||||
|
||||
// assert UUID is primary or secondary service uuid
|
||||
uint16_t uuid16 = uuid16_from_uuid(attribute_type_len, attribute_type);
|
||||
if (uuid16 != GATT_PRIMARY_SERVICE_UUID && uuid16 != GATT_SECONDARY_SERVICE_UUID){
|
||||
if ((uuid16 != GATT_PRIMARY_SERVICE_UUID) && (uuid16 != GATT_SECONDARY_SERVICE_UUID)){
|
||||
return setup_error(response_buffer, request_type, start_handle, ATT_ERROR_UNSUPPORTED_GROUP_TYPE);
|
||||
}
|
||||
|
||||
@ -878,14 +878,14 @@ static uint16_t handle_read_by_group_type_request2(att_connection_t * att_connec
|
||||
while (att_iterator_has_next(&it)){
|
||||
att_iterator_fetch_next(&it);
|
||||
|
||||
if (it.handle && it.handle < start_handle) continue;
|
||||
if (it.handle && (it.handle < start_handle)) continue;
|
||||
if (it.handle > end_handle) break; // (1)
|
||||
|
||||
// log_info("Handle 0x%04x", it.handle);
|
||||
|
||||
// close current tag, if within a group and a new service definition starts or we reach end of att db
|
||||
if (in_group &&
|
||||
(it.handle == 0 || att_iterator_match_uuid16(&it, GATT_PRIMARY_SERVICE_UUID) || att_iterator_match_uuid16(&it, GATT_SECONDARY_SERVICE_UUID))){
|
||||
((it.handle == 0) || att_iterator_match_uuid16(&it, GATT_PRIMARY_SERVICE_UUID) || att_iterator_match_uuid16(&it, GATT_SECONDARY_SERVICE_UUID))){
|
||||
// log_info("End of group, handle 0x%04x, val_len: %u", prev_handle, pair_len - 4);
|
||||
|
||||
little_endian_store_16(response_buffer, offset, group_start_handle);
|
||||
@ -897,7 +897,7 @@ static uint16_t handle_read_by_group_type_request2(att_connection_t * att_connec
|
||||
in_group = 0;
|
||||
|
||||
// check if space for another handle pair available
|
||||
if (offset + pair_len > response_buffer_size){
|
||||
if ((offset + pair_len) > response_buffer_size){
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1111,7 +1111,7 @@ static uint16_t prepare_handle_value(att_connection_t * att_connection,
|
||||
uint16_t value_len,
|
||||
uint8_t * response_buffer){
|
||||
little_endian_store_16(response_buffer, 1, handle);
|
||||
if (value_len > att_connection->mtu - 3){
|
||||
if (value_len > (att_connection->mtu - 3)){
|
||||
value_len = att_connection->mtu - 3;
|
||||
}
|
||||
memcpy(&response_buffer[3], value, value_len);
|
||||
@ -1215,7 +1215,7 @@ int gatt_server_get_get_handle_range_for_service_with_uuid16(uint16_t uuid16, ui
|
||||
|
||||
// close current tag, if within a group and a new service definition starts or we reach end of att db
|
||||
if (in_group &&
|
||||
(it.handle == 0 || new_service_started)){
|
||||
((it.handle == 0) || new_service_started)){
|
||||
*end_handle = prev_handle;
|
||||
return 1;
|
||||
}
|
||||
@ -1224,7 +1224,7 @@ int gatt_server_get_get_handle_range_for_service_with_uuid16(uint16_t uuid16, ui
|
||||
prev_handle = it.handle;
|
||||
|
||||
// check if found
|
||||
if (it.handle && new_service_started && attribute_len == it.value_len && memcmp(attribute_value, it.value, it.value_len) == 0){
|
||||
if (it.handle && new_service_started && (attribute_len == it.value_len) && memcmp(attribute_value, it.value, it.value_len) == 0){
|
||||
*start_handle = it.handle;
|
||||
in_group = 1;
|
||||
}
|
||||
@ -1238,7 +1238,7 @@ uint16_t gatt_server_get_value_handle_for_characteristic_with_uuid16(uint16_t st
|
||||
att_iterator_init(&it);
|
||||
while (att_iterator_has_next(&it)){
|
||||
att_iterator_fetch_next(&it);
|
||||
if (it.handle && it.handle < start_handle) continue;
|
||||
if (it.handle && (it.handle < start_handle)) continue;
|
||||
if (it.handle > end_handle) break; // (1)
|
||||
if (it.handle == 0) break;
|
||||
if (att_iterator_match_uuid16(&it, uuid16)) return it.handle;
|
||||
@ -1252,7 +1252,7 @@ uint16_t gatt_server_get_descriptor_handle_for_characteristic_with_uuid16(uint16
|
||||
int characteristic_found = 0;
|
||||
while (att_iterator_has_next(&it)){
|
||||
att_iterator_fetch_next(&it);
|
||||
if (it.handle && it.handle < start_handle) continue;
|
||||
if (it.handle && (it.handle < start_handle)) continue;
|
||||
if (it.handle > end_handle) break; // (1)
|
||||
if (it.handle == 0) break;
|
||||
if (att_iterator_match_uuid16(&it, characteristic_uuid16)){
|
||||
@ -1299,7 +1299,7 @@ int gatt_server_get_get_handle_range_for_service_with_uuid128(const uint8_t * uu
|
||||
|
||||
// close current tag, if within a group and a new service definition starts or we reach end of att db
|
||||
if (in_group &&
|
||||
(it.handle == 0 || new_service_started)){
|
||||
((it.handle == 0) || new_service_started)){
|
||||
*end_handle = prev_handle;
|
||||
return 1;
|
||||
}
|
||||
@ -1308,7 +1308,7 @@ int gatt_server_get_get_handle_range_for_service_with_uuid128(const uint8_t * uu
|
||||
prev_handle = it.handle;
|
||||
|
||||
// check if found
|
||||
if (it.handle && new_service_started && attribute_len == it.value_len && memcmp(attribute_value, it.value, it.value_len) == 0){
|
||||
if (it.handle && new_service_started && (attribute_len == it.value_len) && memcmp(attribute_value, it.value, it.value_len) == 0){
|
||||
*start_handle = it.handle;
|
||||
in_group = 1;
|
||||
}
|
||||
@ -1324,7 +1324,7 @@ uint16_t gatt_server_get_value_handle_for_characteristic_with_uuid128(uint16_t s
|
||||
att_iterator_init(&it);
|
||||
while (att_iterator_has_next(&it)){
|
||||
att_iterator_fetch_next(&it);
|
||||
if (it.handle && it.handle < start_handle) continue;
|
||||
if (it.handle && (it.handle < start_handle)) continue;
|
||||
if (it.handle > end_handle) break; // (1)
|
||||
if (it.handle == 0) break;
|
||||
if (att_iterator_match_uuid(&it, attribute_value, 16)) return it.handle;
|
||||
@ -1341,7 +1341,7 @@ uint16_t gatt_server_get_client_configuration_handle_for_characteristic_with_uui
|
||||
int characteristic_found = 0;
|
||||
while (att_iterator_has_next(&it)){
|
||||
att_iterator_fetch_next(&it);
|
||||
if (it.handle && it.handle < start_handle) continue;
|
||||
if (it.handle && (it.handle < start_handle)) continue;
|
||||
if (it.handle > end_handle) break; // (1)
|
||||
if (it.handle == 0) break;
|
||||
if (att_iterator_match_uuid(&it, attribute_value, 16)){
|
||||
|
@ -88,7 +88,7 @@ void att_db_util_init(void){
|
||||
*/
|
||||
static int att_db_util_assert_space(uint16_t size){
|
||||
size += 2; // for end tag
|
||||
if (att_db_size + size <= att_db_max_size) return 1;
|
||||
if ((att_db_size + size) <= att_db_max_size) return 1;
|
||||
#ifdef HAVE_MALLOC
|
||||
int new_size = att_db_size + att_db_size / 2;
|
||||
uint8_t * new_db = (uint8_t*) realloc(att_db, new_size);
|
||||
|
@ -516,7 +516,7 @@ static int att_server_process_validated_request(att_server_t * att_server){
|
||||
uint16_t att_response_size = att_handle_request(&att_server->connection, att_server->request_buffer, att_server->request_size, att_response_buffer);
|
||||
|
||||
#ifdef ENABLE_ATT_DELAYED_RESPONSE
|
||||
if (att_response_size == ATT_READ_RESPONSE_PENDING || att_response_size == ATT_INTERNAL_WRITE_RESPONSE_PENDING){
|
||||
if ((att_response_size == ATT_READ_RESPONSE_PENDING) || (att_response_size == ATT_INTERNAL_WRITE_RESPONSE_PENDING)){
|
||||
// update state
|
||||
att_server->state = ATT_SERVER_RESPONSE_PENDING;
|
||||
|
||||
@ -659,7 +659,7 @@ static int att_server_data_ready_for_phase(att_server_t * att_server, att_serve
|
||||
case ATT_SERVER_RUN_PHASE_1_REQUESTS:
|
||||
return att_server->state == ATT_SERVER_REQUEST_RECEIVED_AND_VALIDATED;
|
||||
case ATT_SERVER_RUN_PHASE_2_INDICATIONS:
|
||||
return (!btstack_linked_list_empty(&att_server->indication_requests) && att_server->value_indication_handle == 0);
|
||||
return (!btstack_linked_list_empty(&att_server->indication_requests) && (att_server->value_indication_handle == 0));
|
||||
case ATT_SERVER_RUN_PHASE_3_NOTIFICATIONS:
|
||||
return (!btstack_linked_list_empty(&att_server->notification_requests));
|
||||
}
|
||||
@ -759,7 +759,7 @@ static void att_server_handle_can_send_now(void){
|
||||
static void att_server_handle_att_pdu(att_server_t * att_server, uint8_t * packet, uint16_t size){
|
||||
|
||||
// handle value indication confirms
|
||||
if (packet[0] == ATT_HANDLE_VALUE_CONFIRMATION && att_server->value_indication_handle){
|
||||
if ((packet[0] == ATT_HANDLE_VALUE_CONFIRMATION) && att_server->value_indication_handle){
|
||||
btstack_run_loop_remove_timer(&att_server->value_indication_timer);
|
||||
uint16_t att_handle = att_server->value_indication_handle;
|
||||
att_server->value_indication_handle = 0;
|
||||
@ -840,7 +840,7 @@ static void att_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *pa
|
||||
// ---------------------
|
||||
// persistent CCC writes
|
||||
static uint32_t att_server_persistent_ccc_tag_for_index(uint8_t index){
|
||||
return 'B' << 24 | 'T' << 16 | 'C' << 8 | index;
|
||||
return ('B' << 24) | ('T' << 16) | ('C' << 8) | index;
|
||||
}
|
||||
|
||||
static void att_server_persistent_ccc_write(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t value){
|
||||
@ -1065,7 +1065,7 @@ static int att_server_write_callback(hci_con_handle_t con_handle, uint16_t attri
|
||||
}
|
||||
|
||||
// track CCC writes
|
||||
if (att_is_persistent_ccc(attribute_handle) && offset == 0 && buffer_size == 2){
|
||||
if (att_is_persistent_ccc(attribute_handle) && (offset == 0) && (buffer_size == 2)){
|
||||
att_server_persistent_ccc_write(con_handle, attribute_handle, little_endian_read_16(buffer, 0));
|
||||
}
|
||||
|
||||
|
@ -226,42 +226,42 @@ static uint16_t cycling_power_service_read_callback(hci_con_handle_t con_handle,
|
||||
cycling_power_t * instance = &cycling_power;
|
||||
|
||||
if (attribute_handle == instance->measurement_client_configuration_descriptor_handle){
|
||||
if (buffer && buffer_size >= 2){
|
||||
if (buffer && (buffer_size >= 2)){
|
||||
little_endian_store_16(buffer, 0, instance->measurement_client_configuration_descriptor_notify);
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (attribute_handle == instance->measurement_server_configuration_descriptor_handle){
|
||||
if (buffer && buffer_size >= 2){
|
||||
if (buffer && (buffer_size >= 2)){
|
||||
little_endian_store_16(buffer, 0, instance->measurement_server_configuration_descriptor_broadcast);
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (attribute_handle == instance->vector_client_configuration_descriptor_handle){
|
||||
if (buffer && buffer_size >= 2){
|
||||
if (buffer && (buffer_size >= 2)){
|
||||
little_endian_store_16(buffer, 0, instance->vector_client_configuration_descriptor_notify);
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (attribute_handle == instance->control_point_client_configuration_descriptor_handle){
|
||||
if (buffer && buffer_size >= 2){
|
||||
if (buffer && (buffer_size >= 2)){
|
||||
little_endian_store_16(buffer, 0, instance->control_point_client_configuration_descriptor_indicate);
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (attribute_handle == instance->feature_value_handle){
|
||||
if (buffer && buffer_size >= 4){
|
||||
if (buffer && (buffer_size >= 4)){
|
||||
little_endian_store_32(buffer, 0, instance->feature_flags);
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
|
||||
if (attribute_handle == instance->sensor_location_value_handle){
|
||||
if (buffer && buffer_size >= 1){
|
||||
if (buffer && (buffer_size >= 1)){
|
||||
buffer[0] = instance->sensor_location;
|
||||
}
|
||||
return 1;
|
||||
@ -364,10 +364,10 @@ static void cycling_power_service_vector_can_send_now(void * context){
|
||||
case CP_VECTOR_FLAG_INSTANTANEOUS_FORCE_MAGNITUDE_ARRAY_PRESENT:{
|
||||
uint16_t att_mtu = att_server_get_mtu(instance->con_handle);
|
||||
uint16_t bytes_left = 0;
|
||||
if (att_mtu > pos + 3){
|
||||
if (att_mtu > (pos + 3)){
|
||||
bytes_left = btstack_min(sizeof(value), att_mtu - 3 - pos);
|
||||
}
|
||||
while (bytes_left > 2 && instance->force_magnitude_count){
|
||||
while ((bytes_left > 2) && instance->force_magnitude_count){
|
||||
little_endian_store_16(value, pos, instance->vector_instantaneous_force_magnitude_newton_array[0]);
|
||||
pos += 2;
|
||||
bytes_left -= 2;
|
||||
@ -379,11 +379,11 @@ static void cycling_power_service_vector_can_send_now(void * context){
|
||||
case CP_VECTOR_FLAG_INSTANTANEOUS_TORQUE_MAGNITUDE_ARRAY_PRESENT:{
|
||||
uint16_t att_mtu = att_server_get_mtu(instance->con_handle);
|
||||
uint16_t bytes_left = 0;
|
||||
if (att_mtu > pos + 3){
|
||||
if (att_mtu > (pos + 3)){
|
||||
bytes_left = btstack_min(sizeof(value), att_mtu - 3 - pos);
|
||||
}
|
||||
|
||||
while (bytes_left > 2 && instance->torque_magnitude_count){
|
||||
while ((bytes_left > 2) && instance->torque_magnitude_count){
|
||||
little_endian_store_16(value, pos, instance->vector_instantaneous_torque_magnitude_newton_per_m_array[0]);
|
||||
pos += 2;
|
||||
bytes_left -= 2;
|
||||
@ -652,7 +652,7 @@ static void cycling_power_service_response_can_send_now(void * context){
|
||||
if (instance->request_opcode == CP_OPCODE_START_OFFSET_COMPENSATION) break;
|
||||
little_endian_store_16(value, pos, instance->manufacturer_company_id);
|
||||
pos += 2;
|
||||
int data_len = instance->num_manufacturer_specific_data < CYCLING_POWER_MANUFACTURER_SPECIFIC_DATA_MAX_SIZE ? instance->num_manufacturer_specific_data : (CYCLING_POWER_MANUFACTURER_SPECIFIC_DATA_MAX_SIZE - 1);
|
||||
int data_len = (instance->num_manufacturer_specific_data < CYCLING_POWER_MANUFACTURER_SPECIFIC_DATA_MAX_SIZE) ? instance->num_manufacturer_specific_data : (CYCLING_POWER_MANUFACTURER_SPECIFIC_DATA_MAX_SIZE - 1);
|
||||
value[pos++] = data_len;
|
||||
memcpy(&value[pos], instance->manufacturer_specific_data, data_len);
|
||||
pos += data_len;
|
||||
@ -733,7 +733,7 @@ static int cycling_power_service_write_callback(hci_con_handle_t con_handle, uin
|
||||
|
||||
case CP_CONNECTION_INTERVAL_STATUS_ACCEPTED:
|
||||
case CP_CONNECTION_INTERVAL_STATUS_RECEIVED:
|
||||
if (instance->con_interval > instance->con_interval_max || instance->con_interval < instance->con_interval_min){
|
||||
if ((instance->con_interval > instance->con_interval_max) || (instance->con_interval < instance->con_interval_min)){
|
||||
instance->con_interval_status = CP_CONNECTION_INTERVAL_STATUS_W4_L2CAP_RESPONSE;
|
||||
gap_request_connection_parameter_update(instance->con_handle, instance->con_interval_min, instance->con_interval_max, 4, 100); // 15 ms, 4, 1s
|
||||
return ATT_ERROR_WRITE_RESPONSE_PENDING;
|
||||
@ -884,7 +884,7 @@ static int cycling_power_service_write_callback(hci_con_handle_t con_handle, uin
|
||||
uint16_t index = 0;
|
||||
|
||||
for (i = 0; i < CP_MASK_BIT_RESERVED; i++){
|
||||
uint8_t clear_bit = mask_bitmap & (1 << i) ? 1 : 0;
|
||||
uint8_t clear_bit = (mask_bitmap & (1 << i)) ? 1 : 0;
|
||||
|
||||
masked_measurement_flags &= ~(clear_bit << index);
|
||||
index++;
|
||||
@ -940,7 +940,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
||||
if (instance->con_interval_status != CP_CONNECTION_INTERVAL_STATUS_W4_UPDATE) return;
|
||||
|
||||
if (instance->con_interval > instance->con_interval_max || instance->con_interval < instance->con_interval_min){
|
||||
if ((instance->con_interval > instance->con_interval_max) || (instance->con_interval < instance->con_interval_min)){
|
||||
instance->con_interval = hci_subevent_le_connection_update_complete_get_conn_interval(packet);
|
||||
// printf("Updated Connection Interval: %u, %u.%02u ms\n", instance->con_interval, instance->con_interval * 125 / 100, 25 * (instance->con_interval & 3));
|
||||
// printf("Updated Connection Latency: %u\n", hci_subevent_le_connection_update_complete_get_conn_latency(packet));
|
||||
@ -1104,7 +1104,7 @@ void cycling_power_service_server_add_crank_revolution(uint16_t crank_revolution
|
||||
|
||||
void cycling_power_service_add_energy(uint16_t energy_kJ){
|
||||
cycling_power_t * instance = &cycling_power;
|
||||
if (instance->accumulated_energy_kJ <= 0xffff - energy_kJ){
|
||||
if (instance->accumulated_energy_kJ <= (0xffff - energy_kJ)){
|
||||
instance->accumulated_energy_kJ += energy_kJ;
|
||||
} else {
|
||||
instance->accumulated_energy_kJ = 0xffff;
|
||||
@ -1173,9 +1173,9 @@ void cycling_power_service_server_set_bottom_dead_spot_angle(uint16_t bottom_dea
|
||||
}
|
||||
|
||||
static int gatt_date_is_valid(gatt_date_time_t date){
|
||||
if (date.year != 0 && (date.year < 1582 || date.year > 9999)) return 0;
|
||||
if (date.month != 0 && date.month > 12) return 0;
|
||||
if (date.day != 0 && date.day > 31) return 0;
|
||||
if ((date.year != 0) && ((date.year < 1582) || (date.year > 9999))) return 0;
|
||||
if ((date.month != 0) && (date.month > 12)) return 0;
|
||||
if ((date.day != 0) && (date.day > 31)) return 0;
|
||||
|
||||
if (date.hours > 23) return 0;
|
||||
if (date.minutes > 59) return 0;
|
||||
|
@ -103,21 +103,21 @@ static uint16_t cycling_speed_and_cadence_service_read_callback(hci_con_handle_t
|
||||
cycling_speed_and_cadence_t * instance = &cycling_speed_and_cadence;
|
||||
|
||||
if (attribute_handle == instance->measurement_client_configuration_descriptor_handle){
|
||||
if (buffer && buffer_size >= 2){
|
||||
if (buffer && (buffer_size >= 2)){
|
||||
little_endian_store_16(buffer, 0, instance->measurement_client_configuration_descriptor_notify);
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (attribute_handle == instance->control_point_client_configuration_descriptor_handle){
|
||||
if (buffer && buffer_size >= 2){
|
||||
if (buffer && (buffer_size >= 2)){
|
||||
little_endian_store_16(buffer, 0, instance->control_point_client_configuration_descriptor_indicate);
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (attribute_handle == instance->feature_handle){
|
||||
if (buffer && buffer_size >= 2){
|
||||
if (buffer && (buffer_size >= 2)){
|
||||
uint16_t feature = (instance->wheel_revolution_data_supported << CSC_FLAG_WHEEL_REVOLUTION_DATA_SUPPORTED);
|
||||
feature |= (instance->crank_revolution_data_supported << CSC_FLAG_CRANK_REVOLUTION_DATA_SUPPORTED);
|
||||
feature |= (instance->multiple_sensor_locations_supported << CSC_FLAG_MULTIPLE_SENSOR_LOCATIONS_SUPPORTED);
|
||||
@ -127,7 +127,7 @@ static uint16_t cycling_speed_and_cadence_service_read_callback(hci_con_handle_t
|
||||
}
|
||||
|
||||
if (attribute_handle == instance->sensor_location_value_handle){
|
||||
if (buffer && buffer_size >= 1){
|
||||
if (buffer && (buffer_size >= 1)){
|
||||
buffer[0] = instance->sensor_location;
|
||||
}
|
||||
return 1;
|
||||
@ -181,7 +181,7 @@ static void cycling_speed_and_cadence_service_response_can_send_now(void * conte
|
||||
switch (instance->request_opcode){
|
||||
case CSC_OPCODE_REQUEST_SUPPORTED_SENSOR_LOCATIONS:{
|
||||
int loc;
|
||||
for (loc = CSC_SERVICE_SENSOR_LOCATION_OTHER; loc < CSC_SERVICE_SENSOR_LOCATION_RESERVED-1; loc++){
|
||||
for (loc = CSC_SERVICE_SENSOR_LOCATION_OTHER; loc < (CSC_SERVICE_SENSOR_LOCATION_RESERVED-1); loc++){
|
||||
if (instance->supported_sensor_locations & (1 << loc)){
|
||||
value[pos++] = loc;
|
||||
}
|
||||
@ -360,7 +360,7 @@ static void cycling_speed_and_cadence_service_calculate_cumulative_wheel_revolut
|
||||
static void cycling_speed_and_cadence_service_calculate_cumulative_crank_revolutions(uint16_t revolutions_change){
|
||||
cycling_speed_and_cadence_t * instance = &cycling_speed_and_cadence;
|
||||
|
||||
if (instance->cumulative_crank_revolutions <= 0xffff - revolutions_change){
|
||||
if (instance->cumulative_crank_revolutions <= (0xffff - revolutions_change)){
|
||||
instance->cumulative_crank_revolutions += revolutions_change;
|
||||
} else {
|
||||
instance->cumulative_crank_revolutions = 0xffff;
|
||||
|
@ -95,14 +95,14 @@ static uint16_t heart_rate_service_read_callback(hci_con_handle_t con_handle, ui
|
||||
UNUSED(buffer_size);
|
||||
|
||||
if (attribute_handle == heart_rate.measurement_client_configuration_descriptor_handle){
|
||||
if (buffer && buffer_size >= 2){
|
||||
if (buffer && (buffer_size >= 2)){
|
||||
little_endian_store_16(buffer, 0, heart_rate.measurement_client_configuration_descriptor_notify);
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (attribute_handle == heart_rate.sensor_location_value_handle){
|
||||
if (buffer && buffer_size >= 1){
|
||||
if (buffer && (buffer_size >= 1)){
|
||||
buffer[0] = heart_rate.sensor_location;
|
||||
}
|
||||
return 1;
|
||||
@ -208,7 +208,7 @@ static void heart_rate_service_can_send_now(void * context){
|
||||
// TODO: get actual MTU from ATT server
|
||||
uint16_t bytes_left = btstack_min(sizeof(value), l2cap_max_mtu() - 3 - pos);
|
||||
|
||||
while (bytes_left > 2 && instance->rr_interval_count){
|
||||
while ((bytes_left > 2) && instance->rr_interval_count){
|
||||
little_endian_store_16(value, pos, instance->rr_intervals[0]);
|
||||
pos +=2;
|
||||
bytes_left -= 2;
|
||||
@ -229,7 +229,7 @@ static void heart_rate_service_can_send_now(void * context){
|
||||
void heart_rate_service_add_energy_expended(uint16_t energy_expended_kJ){
|
||||
heart_rate_t * instance = &heart_rate;
|
||||
// limit energy expended to 0xffff
|
||||
if (instance->energy_expended_kJ <= 0xffff - energy_expended_kJ){
|
||||
if (instance->energy_expended_kJ <= (0xffff - energy_expended_kJ)){
|
||||
instance->energy_expended_kJ += energy_expended_kJ;
|
||||
} else {
|
||||
instance->energy_expended_kJ = 0xffff;
|
||||
|
@ -197,7 +197,7 @@ static uint16_t att_read_callback(hci_con_handle_t con_handle, uint16_t att_hand
|
||||
}
|
||||
|
||||
if (att_handle == instance->hid_control_point_value_handle){
|
||||
if (buffer && buffer_size >= 1){
|
||||
if (buffer && (buffer_size >= 1)){
|
||||
buffer[0] = instance->hid_control_point_suspend;
|
||||
}
|
||||
return 1;
|
||||
|
@ -868,7 +868,7 @@ static int gatt_client_run_for_peripheral( gatt_client_t * peripheral){
|
||||
switch (peripheral->gatt_client_state){
|
||||
case P_W2_SEND_WRITE_CHARACTERISTIC_VALUE:
|
||||
case P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR:
|
||||
if (peripheral->attribute_length <= peripheral_mtu(peripheral) - 3) break;
|
||||
if (peripheral->attribute_length <= (peripheral_mtu(peripheral) - 3)) break;
|
||||
log_error("gatt_client_run: value len %u > MTU %u - 3\n", peripheral->attribute_length, peripheral_mtu(peripheral));
|
||||
gatt_client_handle_transaction_complete(peripheral);
|
||||
emit_gatt_complete_event(peripheral, ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LENGTH);
|
||||
@ -1196,7 +1196,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
|
||||
{
|
||||
uint16_t remote_rx_mtu = little_endian_read_16(packet, 1);
|
||||
uint16_t local_rx_mtu = l2cap_max_le_mtu();
|
||||
peripheral->mtu = remote_rx_mtu < local_rx_mtu ? remote_rx_mtu : local_rx_mtu;
|
||||
peripheral->mtu = (remote_rx_mtu < local_rx_mtu) ? remote_rx_mtu : local_rx_mtu;
|
||||
peripheral->mtu_state = MTU_EXCHANGED;
|
||||
emit_gatt_mtu_exchanged_result_event(peripheral, peripheral->mtu);
|
||||
break;
|
||||
|
@ -207,7 +207,7 @@ int le_device_db_add(int addr_type, bd_addr_t addr, sm_key_t irk){
|
||||
le_device_db_entry_t entry;
|
||||
le_device_db_tlv_fetch(i, &entry);
|
||||
// found addr?
|
||||
if ((memcmp(addr, entry.addr, 6) == 0) && addr_type == entry.addr_type){
|
||||
if ((memcmp(addr, entry.addr, 6) == 0) && (addr_type == entry.addr_type)){
|
||||
index_for_addr = i;
|
||||
}
|
||||
// update highest seq nr
|
||||
|
22
src/ble/sm.c
22
src/ble/sm.c
@ -1133,7 +1133,7 @@ static int sm_stk_generation_init(sm_connection_t * sm_conn){
|
||||
sm_setup_key_distribution(remote_key_request);
|
||||
|
||||
// JUST WORKS doens't provide authentication
|
||||
sm_conn->sm_connection_authenticated = setup->sm_stk_generation_method == JUST_WORKS ? 0 : 1;
|
||||
sm_conn->sm_connection_authenticated = (setup->sm_stk_generation_method == JUST_WORKS) ? 0 : 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1271,7 +1271,7 @@ static void sm_key_distribution_handle_all_received(sm_connection_t * sm_conn){
|
||||
|
||||
// if not found, lookup via public address if possible
|
||||
log_info("sm peer addr type %u, peer addres %s", setup->sm_peer_addr_type, bd_addr_to_str(setup->sm_peer_address));
|
||||
if (le_db_index < 0 && setup->sm_peer_addr_type == BD_ADDR_TYPE_LE_PUBLIC){
|
||||
if ((le_db_index < 0) && (setup->sm_peer_addr_type == BD_ADDR_TYPE_LE_PUBLIC)){
|
||||
int i;
|
||||
for (i=0; i < le_device_db_max_count(); i++){
|
||||
bd_addr_t address;
|
||||
@ -1280,7 +1280,7 @@ static void sm_key_distribution_handle_all_received(sm_connection_t * sm_conn){
|
||||
// skip unused entries
|
||||
if (address_type == BD_ADDR_TYPE_UNKNOWN) continue;
|
||||
log_info("device %u, sm peer addr type %u, peer addres %s", i, address_type, bd_addr_to_str(address));
|
||||
if (address_type == BD_ADDR_TYPE_LE_PUBLIC && memcmp(address, setup->sm_peer_address, 6) == 0){
|
||||
if ((address_type == BD_ADDR_TYPE_LE_PUBLIC) && memcmp(address, setup->sm_peer_address, 6) == 0){
|
||||
log_info("sm: device found for public address, updating");
|
||||
le_db_index = i;
|
||||
break;
|
||||
@ -1927,7 +1927,7 @@ static void sm_run(void){
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sm_address_resolution_addr_type == addr_type && memcmp(addr, sm_address_resolution_address, 6) == 0){
|
||||
if ((sm_address_resolution_addr_type == addr_type) && memcmp(addr, sm_address_resolution_address, 6) == 0){
|
||||
log_info("LE Device Lookup: found CSRK by { addr_type, address} ");
|
||||
sm_address_resolution_handle_event(ADDRESS_RESOLUTION_SUCEEDED);
|
||||
break;
|
||||
@ -2085,7 +2085,7 @@ static void sm_run(void){
|
||||
// start using context by loading security info
|
||||
sm_reset_setup();
|
||||
sm_load_security_info(sm_connection);
|
||||
if (setup->sm_peer_ediv == 0 && sm_is_null_random(setup->sm_peer_rand) && !sm_is_null_key(setup->sm_peer_ltk)){
|
||||
if ((setup->sm_peer_ediv == 0) && sm_is_null_random(setup->sm_peer_rand) && !sm_is_null_key(setup->sm_peer_ltk)){
|
||||
memcpy(setup->sm_ltk, setup->sm_peer_ltk, 16);
|
||||
sm_connection->sm_engine_state = SM_RESPONDER_PH4_SEND_LTK_REPLY;
|
||||
break;
|
||||
@ -2376,7 +2376,7 @@ static void sm_run(void){
|
||||
buffer[0] = SM_CODE_PAIRING_RANDOM;
|
||||
reverse_128(setup->sm_local_nonce, &buffer[1]);
|
||||
log_info("stk method %u, num bits %u", setup->sm_stk_generation_method, setup->sm_passkey_bit);
|
||||
if (sm_passkey_entry(setup->sm_stk_generation_method) && setup->sm_passkey_bit < 20){
|
||||
if (sm_passkey_entry(setup->sm_stk_generation_method) && (setup->sm_passkey_bit < 20)){
|
||||
log_info("SM_SC_SEND_PAIRING_RANDOM A");
|
||||
if (IS_RESPONDER(connection->sm_role)){
|
||||
// responder
|
||||
@ -2452,7 +2452,7 @@ static void sm_run(void){
|
||||
l2cap_send_connectionless(connection->sm_handle, L2CAP_CID_SECURITY_MANAGER_PROTOCOL, (uint8_t*) &setup->sm_s_pres, sizeof(sm_pairing_packet_t));
|
||||
sm_timeout_reset(connection);
|
||||
// SC Numeric Comparison will trigger user response after public keys & nonces have been exchanged
|
||||
if (!setup->sm_use_secure_connections || setup->sm_stk_generation_method == JUST_WORKS){
|
||||
if (!setup->sm_use_secure_connections || (setup->sm_stk_generation_method == JUST_WORKS)){
|
||||
sm_trigger_user_response(connection);
|
||||
}
|
||||
return;
|
||||
@ -3185,7 +3185,7 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint
|
||||
|
||||
// For Legacy Pairing (<=> EDIV != 0 || RAND != NULL), we need to recalculated our LTK as a
|
||||
// potentially stored LTK is from the master
|
||||
if (sm_conn->sm_local_ediv != 0 || !sm_is_null_random(sm_conn->sm_local_rand)){
|
||||
if ((sm_conn->sm_local_ediv != 0) || !sm_is_null_random(sm_conn->sm_local_rand)){
|
||||
if (sm_reconstruct_ltk_without_le_device_db_entry){
|
||||
sm_conn->sm_engine_state = SM_RESPONDER_PH0_RECEIVED_LTK_REQUEST;
|
||||
break;
|
||||
@ -3314,9 +3314,9 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint
|
||||
if (!sm_conn) break;
|
||||
|
||||
// delete stored bonding on disconnect with authentication failure in ph0
|
||||
if (sm_conn->sm_role == 0
|
||||
if ((sm_conn->sm_role == 0)
|
||||
&& sm_conn->sm_engine_state == SM_INITIATOR_PH0_W4_CONNECTION_ENCRYPTED
|
||||
&& packet[2] == ERROR_CODE_AUTHENTICATION_FAILURE){
|
||||
&& (packet[2] == ERROR_CODE_AUTHENTICATION_FAILURE)){
|
||||
le_device_db_remove(sm_conn->sm_le_db_index);
|
||||
}
|
||||
|
||||
@ -3437,7 +3437,7 @@ static const uint8_t sm_pdu_size[] = {
|
||||
|
||||
static void sm_pdu_handler(uint8_t packet_type, hci_con_handle_t con_handle, uint8_t *packet, uint16_t size){
|
||||
|
||||
if (packet_type == HCI_EVENT_PACKET && packet[0] == L2CAP_EVENT_CAN_SEND_NOW){
|
||||
if ((packet_type == HCI_EVENT_PACKET) && (packet[0] == L2CAP_EVENT_CAN_SEND_NOW)){
|
||||
sm_run();
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ int btstack_base64_decoder_process_byte(btstack_base64_decoder_t * context, uin
|
||||
|
||||
// handle '='
|
||||
if (c == '='){
|
||||
if (context->pos == 2 || context->pos == 3){
|
||||
if ((context->pos == 2) || (context->pos == 3)){
|
||||
context->pos++;
|
||||
return BTSTACK_BASE64_DECODER_MORE;
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ static void btstack_crypto_cmac_handle_aes_engine_ready(btstack_crypto_aes128_cm
|
||||
int j;
|
||||
sm_key_t y;
|
||||
for (j=0;j<16;j++){
|
||||
y[j] = btstack_crypto_cmac_x[j] ^ btstack_crypto_cmac_get_byte(btstack_crypto_cmac, btstack_crypto_cmac_block_current*16 + j);
|
||||
y[j] = btstack_crypto_cmac_x[j] ^ btstack_crypto_cmac_get_byte(btstack_crypto_cmac, (btstack_crypto_cmac_block_current*16) + j);
|
||||
}
|
||||
btstack_crypto_cmac_block_current++;
|
||||
btstack_crypto_cmac_next_state();
|
||||
@ -220,7 +220,7 @@ static void btstack_crypto_cmac_shift_left_by_one_bit_inplace(int len, uint8_t *
|
||||
int carry = 0;
|
||||
for (i=len-1; i >= 0 ; i--){
|
||||
int new_carry = data[i] >> 7;
|
||||
data[i] = data[i] << 1 | carry;
|
||||
data[i] = (data[i] << 1) | carry;
|
||||
carry = new_carry;
|
||||
}
|
||||
}
|
||||
@ -267,12 +267,12 @@ static void btstack_crypto_cmac_handle_encryption_result(btstack_crypto_aes128_c
|
||||
}
|
||||
|
||||
// next
|
||||
btstack_crypto_cmac_state = btstack_crypto_cmac_block_current < btstack_crypto_cmac_block_count - 1 ? CMAC_CALC_MI : CMAC_CALC_MLAST;
|
||||
btstack_crypto_cmac_state = (btstack_crypto_cmac_block_current < (btstack_crypto_cmac_block_count - 1)) ? CMAC_CALC_MI : CMAC_CALC_MLAST;
|
||||
break;
|
||||
}
|
||||
case CMAC_W4_MI:
|
||||
memcpy(btstack_crypto_cmac_x, data, 16);
|
||||
btstack_crypto_cmac_state = btstack_crypto_cmac_block_current < btstack_crypto_cmac_block_count - 1 ? CMAC_CALC_MI : CMAC_CALC_MLAST;
|
||||
btstack_crypto_cmac_state = (btstack_crypto_cmac_block_current < (btstack_crypto_cmac_block_count - 1)) ? CMAC_CALC_MI : CMAC_CALC_MLAST;
|
||||
break;
|
||||
case CMAC_W4_MLAST:
|
||||
// done
|
||||
|
@ -158,7 +158,7 @@ void btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8
|
||||
item->item_type = (item_header & 0x0c) >> 2;
|
||||
item->item_tag = (item_header & 0xf0) >> 4;
|
||||
// long item
|
||||
if (item->data_size == 2 && item->item_tag == 0x0f && item->item_type == 3){
|
||||
if ((item->data_size == 2) && item->item_tag == 0x0f && (item->item_type == 3)){
|
||||
if (hid_descriptor_len < 3) return;
|
||||
item->data_size = hid_descriptor[pos++];
|
||||
item->item_tag = hid_descriptor[pos++];
|
||||
@ -170,14 +170,14 @@ void btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8
|
||||
if (hid_descriptor_len < item->item_size) return;
|
||||
if (item->data_size > 4) return;
|
||||
int i;
|
||||
int sgnd = item->item_type == Global && item->item_tag > 0 && item->item_tag < 5;
|
||||
int sgnd = item->item_type == Global && (item->item_tag > 0) && (item->item_tag < 5);
|
||||
int32_t value = 0;
|
||||
uint8_t latest_byte = 0;
|
||||
for (i=0;i<item->data_size;i++){
|
||||
latest_byte = hid_descriptor[pos++];
|
||||
value = (latest_byte << (8*i)) | value;
|
||||
}
|
||||
if (sgnd && item->data_size > 0){
|
||||
if (sgnd && (item->data_size > 0)){
|
||||
if (latest_byte & 0x80) {
|
||||
value -= 1 << (item->data_size*8);
|
||||
}
|
||||
@ -200,7 +200,7 @@ static void btstack_hid_handle_global_item(btstack_hid_parser_t * parser, hid_de
|
||||
parser->global_report_size = item->item_value;
|
||||
break;
|
||||
case ReportID:
|
||||
if (parser->active_record && parser->global_report_id != item->item_value){
|
||||
if (parser->active_record && (parser->global_report_id != item->item_value)){
|
||||
// log_debug("New report, don't match anymore");
|
||||
parser->active_record = 0;
|
||||
}
|
||||
@ -216,15 +216,15 @@ static void btstack_hid_handle_global_item(btstack_hid_parser_t * parser, hid_de
|
||||
}
|
||||
|
||||
static void hid_find_next_usage(btstack_hid_parser_t * parser){
|
||||
while (parser->available_usages == 0 && parser->usage_pos < parser->descriptor_pos){
|
||||
while ((parser->available_usages == 0) && (parser->usage_pos < parser->descriptor_pos)){
|
||||
hid_descriptor_item_t usage_item;
|
||||
// parser->usage_pos < parser->descriptor_pos < parser->descriptor_len
|
||||
btstack_hid_parse_descriptor_item(&usage_item, &parser->descriptor[parser->usage_pos], parser->descriptor_len - parser->usage_pos);
|
||||
if (usage_item.item_type == Global && usage_item.item_tag == UsagePage){
|
||||
if (usage_item.item_type == Global && (usage_item.item_tag == UsagePage)){
|
||||
parser->usage_page = usage_item.item_value;
|
||||
}
|
||||
if (usage_item.item_type == Local){
|
||||
uint32_t usage_value = (usage_item.data_size > 2) ? usage_item.item_value : (parser->usage_page << 16) | usage_item.item_value;
|
||||
uint32_t usage_value = (usage_item.data_size > 2) ? usage_item.item_value : ((parser->usage_page << 16) | usage_item.item_value);
|
||||
switch (usage_item.item_tag){
|
||||
case Usage:
|
||||
parser->available_usages = 1;
|
||||
|
@ -61,7 +61,7 @@ uint16_t btstack_resample_block(btstack_resample_t * context, const int16_t * in
|
||||
for (i=0;i<context->num_channels;i++){
|
||||
int s1 = context->last_sample[i];
|
||||
int s2 = input_buffer[i];
|
||||
int os = (s1*(0x10000 - t) + s2*t) >> 16;
|
||||
int os = ((s1*(0x10000 - t)) + (s2*t)) >> 16;
|
||||
output_buffer[dest_samples++] = os;
|
||||
}
|
||||
dest_frames++;
|
||||
@ -85,7 +85,7 @@ uint16_t btstack_resample_block(btstack_resample_t * context, const int16_t * in
|
||||
for (i=0;i<context->num_channels;i++){
|
||||
int s1 = input_buffer[index];
|
||||
int s2 = input_buffer[index+context->num_channels];
|
||||
int os = (s1*(0x10000 - t) + s2*t) >> 16;
|
||||
int os = ((s1*(0x10000 - t)) + (s2*t)) >> 16;
|
||||
output_buffer[dest_samples++] = os;
|
||||
index++;
|
||||
}
|
||||
|
@ -159,11 +159,11 @@ void reverse_bd_addr(const bd_addr_t src, bd_addr_t dest){
|
||||
}
|
||||
|
||||
uint32_t btstack_min(uint32_t a, uint32_t b){
|
||||
return a < b ? a : b;
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
uint32_t btstack_max(uint32_t a, uint32_t b){
|
||||
return a > b ? a : b;
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -194,9 +194,9 @@ static inline char char_for_low_nibble(int value){
|
||||
|
||||
|
||||
int nibble_for_char(char c){
|
||||
if (c >= '0' && c <= '9') return c - '0';
|
||||
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
||||
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
||||
if ((c >= '0') && (c <= '9')) return c - '0';
|
||||
if ((c >= 'a') && (c <= 'f')) return c - 'a' + 10;
|
||||
if ((c >= 'A') && (c <= 'F')) return c - 'A' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -226,7 +226,7 @@ static void log_hexdump(int level, const void * data, int size){
|
||||
for (i=0; i<size;i++){
|
||||
|
||||
// help static analyzer proof that j stays within bounds
|
||||
if (j > BYTES_PER_BYTE * (ITEMS_PER_LINE-1)){
|
||||
if (j > (BYTES_PER_BYTE * (ITEMS_PER_LINE-1))){
|
||||
j = 0;
|
||||
}
|
||||
|
||||
@ -238,7 +238,7 @@ static void log_hexdump(int level, const void * data, int size){
|
||||
buffer[j++] = ',';
|
||||
buffer[j++] = ' ';
|
||||
|
||||
if (j >= BYTES_PER_BYTE * ITEMS_PER_LINE ){
|
||||
if (j >= (BYTES_PER_BYTE * ITEMS_PER_LINE) ){
|
||||
buffer[j] = 0;
|
||||
HCI_DUMP_LOG(level, "%s", buffer);
|
||||
j = 0;
|
||||
@ -354,13 +354,13 @@ int sscanf_bd_addr(const char * addr_string, bd_addr_t addr){
|
||||
addr_string += 2;
|
||||
buffer[i] = (uint8_t)single_byte;
|
||||
// don't check seperator after last byte
|
||||
if (i == BD_ADDR_LEN - 1) {
|
||||
if (i == (BD_ADDR_LEN - 1)) {
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
// skip supported separators
|
||||
char next_char = *addr_string;
|
||||
if (next_char == ':' || next_char == '-' || next_char == ' ') {
|
||||
if ((next_char == ':') || (next_char == '-') || next_char == ' ') {
|
||||
addr_string++;
|
||||
}
|
||||
}
|
||||
@ -375,7 +375,7 @@ uint32_t btstack_atoi(const char *str){
|
||||
uint32_t val = 0;
|
||||
while (1){
|
||||
char chr = *str;
|
||||
if (!chr || chr < '0' || chr > '9')
|
||||
if (!chr || (chr < '0') || (chr > '9'))
|
||||
return val;
|
||||
val = (val * 10) + (uint8_t)(chr - '0');
|
||||
str++;
|
||||
|
@ -954,7 +954,7 @@ uint8_t avdtp_discover_stream_endpoints(uint16_t avdtp_cid, avdtp_context_t * co
|
||||
return AVDTP_CONNECTION_DOES_NOT_EXIST;
|
||||
}
|
||||
if (connection->state != AVDTP_SIGNALING_CONNECTION_OPENED ||
|
||||
connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE) {
|
||||
(connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE)) {
|
||||
return AVDTP_CONNECTION_IN_WRONG_STATE;
|
||||
}
|
||||
|
||||
@ -971,7 +971,7 @@ uint8_t avdtp_get_capabilities(uint16_t avdtp_cid, uint8_t remote_seid, avdtp_co
|
||||
return AVDTP_CONNECTION_DOES_NOT_EXIST;
|
||||
}
|
||||
if (connection->state != AVDTP_SIGNALING_CONNECTION_OPENED ||
|
||||
connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE) {
|
||||
(connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE)) {
|
||||
return AVDTP_CONNECTION_IN_WRONG_STATE;
|
||||
}
|
||||
|
||||
@ -989,7 +989,7 @@ uint8_t avdtp_get_all_capabilities(uint16_t avdtp_cid, uint8_t remote_seid, avdt
|
||||
return AVDTP_CONNECTION_DOES_NOT_EXIST;
|
||||
}
|
||||
if (connection->state != AVDTP_SIGNALING_CONNECTION_OPENED ||
|
||||
connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE) {
|
||||
(connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE)) {
|
||||
return AVDTP_CONNECTION_IN_WRONG_STATE;
|
||||
}
|
||||
|
||||
@ -1006,7 +1006,7 @@ uint8_t avdtp_get_configuration(uint16_t avdtp_cid, uint8_t remote_seid, avdtp_c
|
||||
return AVDTP_CONNECTION_DOES_NOT_EXIST;
|
||||
}
|
||||
if (connection->state != AVDTP_SIGNALING_CONNECTION_OPENED ||
|
||||
connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE) {
|
||||
(connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE)) {
|
||||
return AVDTP_CONNECTION_IN_WRONG_STATE;
|
||||
}
|
||||
|
||||
@ -1023,7 +1023,7 @@ uint8_t avdtp_set_configuration(uint16_t avdtp_cid, uint8_t local_seid, uint8_t
|
||||
return AVDTP_CONNECTION_DOES_NOT_EXIST;
|
||||
}
|
||||
if (connection->state != AVDTP_SIGNALING_CONNECTION_OPENED ||
|
||||
connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE) {
|
||||
(connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE)) {
|
||||
log_error("connection in wrong state, %d, initiator state %d", connection->state, connection->initiator_connection_state);
|
||||
return AVDTP_CONNECTION_IN_WRONG_STATE;
|
||||
}
|
||||
@ -1065,7 +1065,7 @@ uint8_t avdtp_reconfigure(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote
|
||||
}
|
||||
//TODO: if opened only app capabilities, enable reconfigure for not opened
|
||||
if (connection->state != AVDTP_SIGNALING_CONNECTION_OPENED ||
|
||||
connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE) {
|
||||
(connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE)) {
|
||||
return AVDTP_CONNECTION_IN_WRONG_STATE;
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ static int avdtp_acceptor_send_accept_response(uint16_t cid, uint8_t transactio
|
||||
static int avdtp_acceptor_process_chunk(avdtp_signaling_packet_t * signaling_packet, uint8_t * packet, uint16_t size){
|
||||
memcpy(signaling_packet->command + signaling_packet->size, packet, size);
|
||||
signaling_packet->size += size;
|
||||
return signaling_packet->packet_type == AVDTP_SINGLE_PACKET || signaling_packet->packet_type == AVDTP_END_PACKET;
|
||||
return (signaling_packet->packet_type == AVDTP_SINGLE_PACKET) || signaling_packet->packet_type == AVDTP_END_PACKET;
|
||||
}
|
||||
|
||||
static int avdtp_acceptor_validate_msg_length(avdtp_signal_identifier_t signal_identifier, uint16_t msg_size){
|
||||
@ -498,7 +498,7 @@ void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avd
|
||||
l2cap_reserve_packet_buffer();
|
||||
out_buffer = l2cap_get_outgoing_buffer();
|
||||
pos = avdtp_signaling_create_fragment(cid, &connection->signaling_packet, out_buffer);
|
||||
if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
if ((connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET) && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
stream_endpoint->acceptor_config_state = acceptor_config_state;
|
||||
log_info("ACP: fragmented");
|
||||
} else {
|
||||
@ -515,7 +515,7 @@ void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avd
|
||||
l2cap_reserve_packet_buffer();
|
||||
out_buffer = l2cap_get_outgoing_buffer();
|
||||
pos = avdtp_signaling_create_fragment(cid, &connection->signaling_packet, out_buffer);
|
||||
if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
if ((connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET) && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
stream_endpoint->acceptor_config_state = acceptor_config_state;
|
||||
log_info("ACP: fragmented");
|
||||
} else {
|
||||
@ -542,7 +542,7 @@ void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avd
|
||||
l2cap_reserve_packet_buffer();
|
||||
out_buffer = l2cap_get_outgoing_buffer();
|
||||
pos = avdtp_signaling_create_fragment(cid, &connection->signaling_packet, out_buffer);
|
||||
if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
if ((connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET) && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
stream_endpoint->acceptor_config_state = acceptor_config_state;
|
||||
log_info("ACP: fragmented");
|
||||
} else {
|
||||
@ -597,7 +597,7 @@ void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avd
|
||||
}
|
||||
avdtp_signaling_emit_accept(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), connection->signaling_packet.signal_identifier);
|
||||
// check fragmentation
|
||||
if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
if ((connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET) && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
avdtp_request_can_send_now_acceptor(connection, connection->l2cap_signaling_cid);
|
||||
}
|
||||
}
|
||||
|
@ -399,7 +399,7 @@ void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t * connection, av
|
||||
l2cap_reserve_packet_buffer();
|
||||
uint8_t * out_buffer = l2cap_get_outgoing_buffer();
|
||||
uint16_t pos = avdtp_signaling_create_fragment(connection->l2cap_signaling_cid, &connection->signaling_packet, out_buffer);
|
||||
if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
if ((connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET) && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
stream_endpoint->initiator_config_state = AVDTP_INITIATOR_FRAGMENTATED_COMMAND;
|
||||
log_info("INT: fragmented");
|
||||
}
|
||||
@ -410,7 +410,7 @@ void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t * connection, av
|
||||
l2cap_reserve_packet_buffer();
|
||||
uint8_t * out_buffer = l2cap_get_outgoing_buffer();
|
||||
uint16_t pos = avdtp_signaling_create_fragment(connection->l2cap_signaling_cid, &connection->signaling_packet, out_buffer);
|
||||
if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
if ((connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET) && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
stream_endpoint->initiator_config_state = AVDTP_INITIATOR_FRAGMENTATED_COMMAND;
|
||||
log_info("INT: fragmented");
|
||||
}
|
||||
@ -434,7 +434,7 @@ void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t * connection, av
|
||||
}
|
||||
|
||||
// check fragmentation
|
||||
if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
if ((connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET) && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
|
||||
avdtp_request_can_send_now_initiator(connection, connection->l2cap_signaling_cid);
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ uint8_t avdtp_sink_delay_report(uint16_t avdtp_cid, uint8_t local_seid, uint16_t
|
||||
}
|
||||
|
||||
if (connection->state != AVDTP_SIGNALING_CONNECTION_OPENED ||
|
||||
connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE) {
|
||||
(connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE)) {
|
||||
log_error("delay_report: connection in wrong state, state %d, initiator state %d", connection->state, connection->initiator_connection_state);
|
||||
return AVDTP_CONNECTION_IN_WRONG_STATE;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ static const char * avdtp_si_name[] = {
|
||||
"AVDTP_SI_DELAY_REPORT"
|
||||
};
|
||||
const char * avdtp_si2str(uint16_t index){
|
||||
if (index <= 0 || index > sizeof(avdtp_si_name)) return avdtp_si_name[0];
|
||||
if ((index <= 0) || (index > sizeof(avdtp_si_name))) return avdtp_si_name[0];
|
||||
return avdtp_si_name[index];
|
||||
}
|
||||
|
||||
@ -506,7 +506,7 @@ int avdtp_signaling_create_fragment(uint16_t cid, avdtp_signaling_packet_t * sig
|
||||
uint16_t pos = 1;
|
||||
|
||||
if (offset == 0){
|
||||
if (signaling_packet->size <= mtu - 2){
|
||||
if (signaling_packet->size <= (mtu - 2)){
|
||||
signaling_packet->packet_type = AVDTP_SINGLE_PACKET;
|
||||
out_buffer[pos++] = signaling_packet->signal_identifier;
|
||||
data_len = signaling_packet->size;
|
||||
@ -519,7 +519,7 @@ int avdtp_signaling_create_fragment(uint16_t cid, avdtp_signaling_packet_t * sig
|
||||
}
|
||||
} else {
|
||||
int remaining_bytes = signaling_packet->size - offset;
|
||||
if (remaining_bytes <= mtu - 1){
|
||||
if (remaining_bytes <= (mtu - 1)){
|
||||
signaling_packet->packet_type = AVDTP_END_PACKET;
|
||||
data_len = remaining_bytes;
|
||||
signaling_packet->offset = 0;
|
||||
|
@ -108,7 +108,7 @@ static const char * avrcp_media_attribute_id_name[] = {
|
||||
"NONE", "TITLE", "ARTIST", "ALBUM", "TRACK", "TOTAL TRACKS", "GENRE", "SONG LENGTH"
|
||||
};
|
||||
const char * avrcp_attribute2str(uint8_t index){
|
||||
if (index >= 1 && index <= 7) return avrcp_media_attribute_id_name[index];
|
||||
if ((index >= 1) && (index <= 7)) return avrcp_media_attribute_id_name[index];
|
||||
return avrcp_media_attribute_id_name[0];
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ static const char * avrcp_play_status_name[] = {
|
||||
"ERROR" // 0xFF
|
||||
};
|
||||
const char * avrcp_play_status2str(uint8_t index){
|
||||
if (index >= 1 && index <= 4) return avrcp_play_status_name[index];
|
||||
if ((index >= 1) && (index <= 4)) return avrcp_play_status_name[index];
|
||||
return avrcp_play_status_name[5];
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ static const char * avrcp_shuffle_mode_name[] = {
|
||||
};
|
||||
|
||||
const char * avrcp_shuffle2str(uint8_t index){
|
||||
if (index >= 1 && index <= 3) return avrcp_shuffle_mode_name[index-1];
|
||||
if ((index >= 1) && (index <= 3)) return avrcp_shuffle_mode_name[index-1];
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ static const char * avrcp_repeat_mode_name[] = {
|
||||
};
|
||||
|
||||
const char * avrcp_repeat2str(uint8_t index){
|
||||
if (index >= 1 && index <= 4) return avrcp_repeat_mode_name[index-1];
|
||||
if ((index >= 1) && (index <= 4)) return avrcp_repeat_mode_name[index-1];
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
@ -348,7 +348,7 @@ avrcp_connection_t * get_avrcp_connection_for_browsing_l2cap_cid(avrcp_role_t ro
|
||||
while (btstack_linked_list_iterator_has_next(&it)){
|
||||
avrcp_connection_t * connection = (avrcp_connection_t *)btstack_linked_list_iterator_next(&it);
|
||||
if (connection->role != role) continue;
|
||||
if (connection->browsing_connection && connection->browsing_connection->l2cap_browsing_cid != browsing_l2cap_cid) continue;
|
||||
if (connection->browsing_connection && (connection->browsing_connection->l2cap_browsing_cid != browsing_l2cap_cid)) continue;
|
||||
return connection;
|
||||
}
|
||||
return NULL;
|
||||
@ -360,7 +360,7 @@ avrcp_browsing_connection_t * get_avrcp_browsing_connection_for_l2cap_cid(avrcp_
|
||||
while (btstack_linked_list_iterator_has_next(&it)){
|
||||
avrcp_connection_t * connection = (avrcp_connection_t *)btstack_linked_list_iterator_next(&it);
|
||||
if (connection->role != role) continue;
|
||||
if (connection->browsing_connection && connection->browsing_connection->l2cap_browsing_cid != l2cap_cid) continue;
|
||||
if (connection->browsing_connection && (connection->browsing_connection->l2cap_browsing_cid != l2cap_cid)) continue;
|
||||
return connection->browsing_connection;
|
||||
}
|
||||
return NULL;
|
||||
|
@ -248,7 +248,7 @@ static int avrcp_browsing_controller_send_get_folder_items_cmd(uint16_t cid, avr
|
||||
attributes_to_copy = attribute_count;
|
||||
break;
|
||||
}
|
||||
big_endian_store_16(command, pos, 9 + 1 + attribute_count*4);
|
||||
big_endian_store_16(command, pos, 9 + 1 + (attribute_count*4));
|
||||
pos += 2;
|
||||
|
||||
command[pos++] = connection->scope;
|
||||
@ -296,7 +296,7 @@ static int avrcp_browsing_controller_send_get_item_attributes_cmd(uint16_t cid,
|
||||
break;
|
||||
}
|
||||
|
||||
big_endian_store_16(command, pos, 12 + attribute_count*4);
|
||||
big_endian_store_16(command, pos, 12 + (attribute_count*4));
|
||||
pos += 2;
|
||||
|
||||
command[pos++] = connection->scope;
|
||||
@ -490,7 +490,7 @@ static void avrcp_browsing_parser_process_byte(uint8_t byte, avrcp_browsing_conn
|
||||
}
|
||||
case AVRCP_PARSER_GET_ATTRIBUTE_VALUE:{
|
||||
connection->parsed_attribute_value[connection->parsed_attribute_value_offset++] = byte;
|
||||
if (connection->parsed_attribute_value_offset < connection->parsed_attribute_value_len + prepended_header_size){
|
||||
if (connection->parsed_attribute_value_offset < (connection->parsed_attribute_value_len + prepended_header_size)){
|
||||
break;
|
||||
}
|
||||
if (connection->parsed_attribute_value_offset < big_endian_read_16(connection->parser_attribute_header, 1)){
|
||||
@ -567,7 +567,7 @@ static void avrcp_browsing_controller_packet_handler(uint8_t packet_type, uint16
|
||||
if (avctp_packet_type == AVRCP_START_PACKET){
|
||||
browsing_connection->num_packets = packet[pos++];
|
||||
}
|
||||
if (pos + 4 > size){
|
||||
if ((pos + 4) > size){
|
||||
browsing_connection->state = AVCTP_CONNECTION_OPENED;
|
||||
avrcp_browsing_controller_emit_failed(avrcp_controller_context.browsing_avrcp_callback, channel, AVRCP_BROWSING_ERROR_CODE_INVALID_COMMAND, ERROR_CODE_SUCCESS);
|
||||
return;
|
||||
@ -910,7 +910,7 @@ uint8_t avrcp_browsing_controller_search(uint16_t avrcp_browsing_cid, uint16_t s
|
||||
log_error("avrcp_browsing_controller_change_path: no browsed player set.");
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
if (!search_str || search_str_len == 0){
|
||||
if (!search_str || (search_str_len == 0)){
|
||||
return AVRCP_BROWSING_ERROR_CODE_INVALID_COMMAND;
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ static int avrcp_send_cmd(avrcp_connection_t * connection, avrcp_packet_type_t p
|
||||
max_bytes -= 3;
|
||||
}
|
||||
|
||||
if (packet_type == AVRCP_SINGLE_PACKET || packet_type == AVRCP_START_PACKET){
|
||||
if ((packet_type == AVRCP_SINGLE_PACKET) || packet_type == AVRCP_START_PACKET){
|
||||
// Profile IDentifier (PID)
|
||||
command[pos++] = BLUETOOTH_SERVICE_CLASS_AV_REMOTE_CONTROL >> 8;
|
||||
command[pos++] = BLUETOOTH_SERVICE_CLASS_AV_REMOTE_CONTROL & 0x00FF;
|
||||
@ -504,13 +504,13 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
|
||||
memcpy(operands, packet+pos, 5);
|
||||
uint8_t unit_type = operands[1] >> 3;
|
||||
uint8_t unit = operands[1] & 0x07;
|
||||
uint32_t company_id = operands[2] << 16 | operands[3] << 8 | operands[4];
|
||||
uint32_t company_id = (operands[2] << 16) | (operands[3] << 8) | operands[4];
|
||||
log_info(" UNIT INFO response: ctype 0x%02x (0C), subunit_type 0x%02x (1F), subunit_id 0x%02x (07), opcode 0x%02x (30), unit_type 0x%02x, unit %d, company_id 0x%06" PRIx32,
|
||||
ctype, subunit_type, subunit_id, opcode, unit_type, unit, company_id);
|
||||
break;
|
||||
}
|
||||
case AVRCP_CMD_OPCODE_VENDOR_DEPENDENT:
|
||||
if (size - pos < 7) {
|
||||
if ((size - pos) < 7) {
|
||||
log_error("avrcp: wrong packet size");
|
||||
return;
|
||||
};
|
||||
@ -890,7 +890,7 @@ static void avrcp_controller_handle_can_send_now(avrcp_connection_t * connection
|
||||
avrcp_send_cmd(connection, AVRCP_START_PACKET);
|
||||
avrcp_request_can_send_now(connection, connection->l2cap_signaling_cid);
|
||||
} else {
|
||||
if (connection->cmd_operands_fragmented_len - connection->cmd_operands_fragmented_pos > avrcp_get_max_payload_size_for_packet_type(AVRCP_CONTINUE_PACKET)){
|
||||
if ((connection->cmd_operands_fragmented_len - connection->cmd_operands_fragmented_pos) > avrcp_get_max_payload_size_for_packet_type(AVRCP_CONTINUE_PACKET)){
|
||||
avrcp_send_cmd(connection, AVRCP_CONTINUE_PACKET);
|
||||
avrcp_request_can_send_now(connection, connection->l2cap_signaling_cid);
|
||||
} else {
|
||||
|
@ -126,7 +126,7 @@ static uint16_t avrcp_target_pack_single_element_attribute_string(uint8_t * pack
|
||||
}
|
||||
memcpy(packet+pos, attr_value, attr_value_to_copy);
|
||||
pos += attr_value_size;
|
||||
return header * 8 + attr_value_size;
|
||||
return (header * 8) + attr_value_size;
|
||||
}
|
||||
|
||||
static int avrcp_target_abort_continue_response(uint16_t cid, avrcp_connection_t * connection){
|
||||
@ -207,7 +207,7 @@ static int avrcp_target_send_now_playing_info(uint16_t cid, avrcp_connection_t *
|
||||
int num_free_bytes = size - pos - 2;
|
||||
uint8_t MAX_NUMBER_ATTR_LEN = 10;
|
||||
|
||||
while (!fragmented && num_free_bytes > 0 && connection->next_attr_id <= AVRCP_MEDIA_ATTR_SONG_LENGTH_MS){
|
||||
while (!fragmented && (num_free_bytes > 0) && connection->next_attr_id <= AVRCP_MEDIA_ATTR_SONG_LENGTH_MS){
|
||||
avrcp_media_attribute_id_t attr_id = connection->next_attr_id;
|
||||
int attr_index = attr_id - 1;
|
||||
|
||||
@ -250,7 +250,7 @@ static int avrcp_target_send_now_playing_info(uint16_t cid, avrcp_connection_t *
|
||||
uint8_t * attr_value = (uint8_t *) (connection->now_playing_info[attr_index].value + connection->attribute_value_offset);
|
||||
uint16_t attr_value_len = connection->now_playing_info[attr_index].len - connection->attribute_value_offset;
|
||||
|
||||
num_bytes_to_write = attr_value_len + header * AVRCP_ATTR_HEADER_LEN;
|
||||
num_bytes_to_write = attr_value_len + (header * AVRCP_ATTR_HEADER_LEN);
|
||||
if (num_bytes_to_write <= num_free_bytes){
|
||||
connection->attribute_value_offset = 0;
|
||||
num_written_bytes = num_bytes_to_write;
|
||||
@ -259,7 +259,7 @@ static int avrcp_target_send_now_playing_info(uint16_t cid, avrcp_connection_t *
|
||||
}
|
||||
fragmented = 1;
|
||||
num_written_bytes = num_free_bytes;
|
||||
attr_value_len = num_free_bytes - header * AVRCP_ATTR_HEADER_LEN;
|
||||
attr_value_len = num_free_bytes - (header * AVRCP_ATTR_HEADER_LEN);
|
||||
avrcp_target_pack_single_element_attribute_string(packet, pos, RFC2978_CHARSET_MIB_UTF8, attr_id, attr_value, attr_value_len, connection->now_playing_info[attr_index].len, header);
|
||||
connection->attribute_value_offset += attr_value_len;
|
||||
break;
|
||||
@ -411,7 +411,7 @@ static uint8_t avrcp_target_response_vendor_dependent_interim(avrcp_connection_t
|
||||
big_endian_store_16(connection->cmd_operands, pos, 1 + value_len);
|
||||
pos += 2;
|
||||
connection->cmd_operands[pos++] = event_id;
|
||||
if (value && value_len > 0){
|
||||
if (value && (value_len > 0)){
|
||||
memcpy(connection->cmd_operands + pos, value, value_len);
|
||||
pos += value_len;
|
||||
}
|
||||
@ -548,7 +548,7 @@ static uint8_t avrcp_target_unit_info(avrcp_connection_t * connection){
|
||||
|
||||
static uint8_t avrcp_target_subunit_info(avrcp_connection_t * connection, uint8_t offset){
|
||||
if (connection->state != AVCTP_CONNECTION_OPENED) return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
if (offset - 4 > connection->subunit_info_data_size) return AVRCP_STATUS_INVALID_PARAMETER;
|
||||
if ((offset - 4) > connection->subunit_info_data_size) return AVRCP_STATUS_INVALID_PARAMETER;
|
||||
|
||||
connection->command_opcode = AVRCP_CMD_OPCODE_SUBUNIT_INFO;
|
||||
connection->command_type = AVRCP_CTYPE_RESPONSE_IMPLEMENTED_STABLE;
|
||||
|
@ -826,7 +826,7 @@ static int bnep_handle_connection_request(bnep_channel_t *channel, uint8_t *pack
|
||||
bnep_service_t * service;
|
||||
|
||||
/* Sanity check packet size */
|
||||
if (size < 1 + 1 + 2 * uuid_size) {
|
||||
if (size < 1 + 1 + (2 * uuid_size)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -890,7 +890,7 @@ static int bnep_handle_connection_request(bnep_channel_t *channel, uint8_t *pack
|
||||
l2cap_request_can_send_now_event(channel->l2cap_cid);
|
||||
|
||||
/* Return the number of processed package bytes = BNEP Type, BNEP Control Type, UUID-Size + 2 * UUID */
|
||||
return 1 + 1 + 2 * uuid_size;
|
||||
return 1 + 1 + (2 * uuid_size);
|
||||
}
|
||||
|
||||
static int bnep_handle_connection_response(bnep_channel_t *channel, uint8_t *packet, uint16_t size)
|
||||
@ -898,7 +898,7 @@ static int bnep_handle_connection_response(bnep_channel_t *channel, uint8_t *pac
|
||||
uint16_t response_code;
|
||||
|
||||
/* Sanity check packet size */
|
||||
if (size < 1 + 2) {
|
||||
if (size < (1 + 2)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -946,7 +946,7 @@ static int bnep_handle_filter_net_type_set(bnep_channel_t *channel, uint8_t *pac
|
||||
|
||||
list_length = big_endian_read_16(packet, 1);
|
||||
/* Sanity check packet size again with known package size */
|
||||
if (size < 3 + list_length) {
|
||||
if (size < (3 + list_length)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -964,9 +964,9 @@ static int bnep_handle_filter_net_type_set(bnep_channel_t *channel, uint8_t *pac
|
||||
channel->net_filter_count = 0;
|
||||
/* There is still enough space, copy the filters to our filter list */
|
||||
/* There is still enough space, copy the filters to our filter list */
|
||||
for (i = 0; i < list_length / (2 * 2); i ++) {
|
||||
channel->net_filter[channel->net_filter_count].range_start = big_endian_read_16(packet, 1 + 2 + i * 4);
|
||||
channel->net_filter[channel->net_filter_count].range_end = big_endian_read_16(packet, 1 + 2 + i * 4 + 2);
|
||||
for (i = 0; i < (list_length / (2 * 2)); i ++) {
|
||||
channel->net_filter[channel->net_filter_count].range_start = big_endian_read_16(packet, 1 + 2 + (i * 4));
|
||||
channel->net_filter[channel->net_filter_count].range_end = big_endian_read_16(packet, 1 + 2 + (i * 4) + 2);
|
||||
if (channel->net_filter[channel->net_filter_count].range_start > channel->net_filter[channel->net_filter_count].range_end) {
|
||||
/* Invalid filter range, ignore this filter rule */
|
||||
log_error("BNEP_FILTER_NET_TYPE_SET: Invalid filter: start: %d, end: %d",
|
||||
@ -998,7 +998,7 @@ static int bnep_handle_filter_net_type_response(bnep_channel_t *channel, uint8_t
|
||||
// TODO: Currently we do not support setting a network filter.
|
||||
|
||||
/* Sanity check packet size */
|
||||
if (size < 1 + 2) {
|
||||
if (size < (1 + 2)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1030,7 +1030,7 @@ static int bnep_handle_multi_addr_set(bnep_channel_t *channel, uint8_t *packet,
|
||||
|
||||
list_length = big_endian_read_16(packet, 1);
|
||||
/* Sanity check packet size again with known package size */
|
||||
if (size < 3 + list_length) {
|
||||
if (size < (3 + list_length)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1047,9 +1047,9 @@ static int bnep_handle_multi_addr_set(bnep_channel_t *channel, uint8_t *packet,
|
||||
unsigned int i;
|
||||
channel->multicast_filter_count = 0;
|
||||
/* There is enough space, copy the filters to our filter list */
|
||||
for (i = 0; i < list_length / (2 * ETHER_ADDR_LEN); i ++) {
|
||||
bd_addr_copy(channel->multicast_filter[channel->multicast_filter_count].addr_start, packet + 1 + 2 + i * ETHER_ADDR_LEN * 2);
|
||||
bd_addr_copy(channel->multicast_filter[channel->multicast_filter_count].addr_end, packet + 1 + 2 + i * ETHER_ADDR_LEN * 2 + ETHER_ADDR_LEN);
|
||||
for (i = 0; i < (list_length / (2 * ETHER_ADDR_LEN)); i ++) {
|
||||
bd_addr_copy(channel->multicast_filter[channel->multicast_filter_count].addr_start, packet + 1 + 2 + (i * ETHER_ADDR_LEN * 2));
|
||||
bd_addr_copy(channel->multicast_filter[channel->multicast_filter_count].addr_end, packet + 1 + 2 + (i * ETHER_ADDR_LEN * 2) + ETHER_ADDR_LEN);
|
||||
|
||||
if (memcmp(channel->multicast_filter[channel->multicast_filter_count].addr_start,
|
||||
channel->multicast_filter[channel->multicast_filter_count].addr_end, ETHER_ADDR_LEN) > 0) {
|
||||
@ -1084,7 +1084,7 @@ static int bnep_handle_multi_addr_response(bnep_channel_t *channel, uint8_t *pac
|
||||
// TODO: Currently we do not support setting multicast address filter.
|
||||
|
||||
/* Sanity check packet size */
|
||||
if (size < 1 + 2) {
|
||||
if (size < (1 + 2)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1418,7 +1418,7 @@ static int bnep_l2cap_packet_handler(uint16_t l2cap_cid, uint8_t *packet, uint16
|
||||
ext_len = packet[pos];
|
||||
pos ++;
|
||||
|
||||
if (size - pos < ext_len) {
|
||||
if ((size - pos) < ext_len) {
|
||||
log_error("BNEP pkt handler: Invalid extension length! Packet ignored");
|
||||
/* Invalid packet size! */
|
||||
return 0;
|
||||
@ -1447,7 +1447,7 @@ static int bnep_l2cap_packet_handler(uint16_t l2cap_cid, uint8_t *packet, uint16
|
||||
} while (bnep_header_has_ext);
|
||||
}
|
||||
|
||||
if (bnep_type != BNEP_PKT_TYPE_CONTROL && network_protocol_type != 0xffff) {
|
||||
if ((bnep_type != BNEP_PKT_TYPE_CONTROL) && (network_protocol_type != 0xffff)) {
|
||||
if (channel->state == BNEP_CHANNEL_STATE_CONNECTED) {
|
||||
rc = bnep_handle_ethernet_packet(channel, addr_dest, addr_source, network_protocol_type, packet + pos, size - pos);
|
||||
} else {
|
||||
|
@ -79,8 +79,8 @@ static float sqrt3(const float x){
|
||||
// Two Babylonian Steps (simplified from:)
|
||||
// u.x = 0.5f * (u.x + x/u.x);
|
||||
// u.x = 0.5f * (u.x + x/u.x);
|
||||
u.x = u.x + x/u.x;
|
||||
u.x = 0.25f*u.x + x/u.x;
|
||||
u.x = u.x + (x/u.x);
|
||||
u.x = (0.25f*u.x) + (x/u.x);
|
||||
|
||||
return u.x;
|
||||
}
|
||||
@ -334,18 +334,18 @@ void btstack_cvsd_plc_bad_frame(btstack_cvsd_plc_state_t *plc_state, uint16_t nu
|
||||
plc_state->hist[CVSD_LHIST+i] = btstack_cvsd_plc_crop_sample(val);
|
||||
}
|
||||
|
||||
for (;i<num_samples+CVSD_OLAL;i++){
|
||||
for (;i<(num_samples+CVSD_OLAL);i++){
|
||||
float left = sf*plc_state->hist[plc_state->bestlag+i];
|
||||
float right = plc_state->hist[plc_state->bestlag+i];
|
||||
val = left*rcos[i-num_samples] + right*rcos[CVSD_OLAL-1-i+num_samples];
|
||||
val = (left*rcos[i-num_samples]) + (right*rcos[CVSD_OLAL-1-i+num_samples]);
|
||||
plc_state->hist[CVSD_LHIST+i] = btstack_cvsd_plc_crop_sample(val);
|
||||
}
|
||||
|
||||
for (;i<num_samples+CVSD_RT+CVSD_OLAL;i++){
|
||||
for (;i<(num_samples+CVSD_RT+CVSD_OLAL);i++){
|
||||
plc_state->hist[CVSD_LHIST+i] = plc_state->hist[plc_state->bestlag+i];
|
||||
}
|
||||
} else {
|
||||
for (;i<num_samples+CVSD_RT+CVSD_OLAL;i++){
|
||||
for (;i<(num_samples+CVSD_RT+CVSD_OLAL);i++){
|
||||
plc_state->hist[CVSD_LHIST+i] = plc_state->hist[plc_state->bestlag+i];
|
||||
}
|
||||
}
|
||||
@ -384,10 +384,10 @@ void btstack_cvsd_plc_good_frame(btstack_cvsd_plc_state_t *plc_state, uint16_t n
|
||||
out[i] = plc_state->hist[CVSD_LHIST+i];
|
||||
}
|
||||
|
||||
for (i=CVSD_RT;i<CVSD_RT+CVSD_OLAL;i++){
|
||||
for (i=CVSD_RT;i<(CVSD_RT+CVSD_OLAL);i++){
|
||||
float left = plc_state->hist[CVSD_LHIST+i];
|
||||
float right = in[i];
|
||||
val = left * rcos[i-CVSD_RT] + right *rcos[CVSD_OLAL+CVSD_RT-1-i];
|
||||
val = (left * rcos[i-CVSD_RT]) + (right *rcos[CVSD_OLAL+CVSD_RT-1-i]);
|
||||
out[i] = btstack_cvsd_plc_crop_sample((BTSTACK_CVSD_PLC_SAMPLE_FORMAT)val);
|
||||
}
|
||||
}
|
||||
@ -417,7 +417,7 @@ static int count_equal_samples(BTSTACK_CVSD_PLC_SAMPLE_FORMAT * packet, uint16_t
|
||||
int count = 0;
|
||||
int temp_count = 1;
|
||||
int i;
|
||||
for (i = 0; i < size-1; i++){
|
||||
for (i = 0; i < (size-1); i++){
|
||||
if (packet[i] == packet[i+1]){
|
||||
temp_count++;
|
||||
continue;
|
||||
@ -427,7 +427,7 @@ static int count_equal_samples(BTSTACK_CVSD_PLC_SAMPLE_FORMAT * packet, uint16_t
|
||||
}
|
||||
temp_count = 1;
|
||||
}
|
||||
if (temp_count > count + 1){
|
||||
if (temp_count > (count + 1)){
|
||||
count = temp_count;
|
||||
}
|
||||
return count;
|
||||
@ -436,7 +436,7 @@ static int count_equal_samples(BTSTACK_CVSD_PLC_SAMPLE_FORMAT * packet, uint16_t
|
||||
static int count_zeros(BTSTACK_CVSD_PLC_SAMPLE_FORMAT * frame, uint16_t size){
|
||||
int nr_zeros = 0;
|
||||
int i;
|
||||
for (i = 0; i < size-1; i++){
|
||||
for (i = 0; i < (size-1); i++){
|
||||
if (frame[i] == 0){
|
||||
nr_zeros++;
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ void OI_AssertFail(const char* file, int line, const char* reason){
|
||||
#endif
|
||||
|
||||
void btstack_sbc_decoder_init(btstack_sbc_decoder_state_t * state, btstack_sbc_mode_t mode, void (*callback)(int16_t * data, int num_samples, int num_channels, int sample_rate, void * context), void * context){
|
||||
if (sbc_decoder_state_singleton && sbc_decoder_state_singleton != state ){
|
||||
if (sbc_decoder_state_singleton && (sbc_decoder_state_singleton != state) ){
|
||||
log_error("SBC decoder: different sbc decoder state is allready registered");
|
||||
}
|
||||
OI_STATUS status = OI_STATUS_SUCCESS;
|
||||
@ -239,7 +239,7 @@ static void btstack_sbc_decoder_process_sbc_data(btstack_sbc_decoder_state_t * s
|
||||
if (corrupt_frame_period > 0){
|
||||
frame_count++;
|
||||
|
||||
if (frame_count % corrupt_frame_period == 0){
|
||||
if ((frame_count % corrupt_frame_period) == 0){
|
||||
*(uint8_t*)&frame_data[5] = 0;
|
||||
frame_count = 0;
|
||||
}
|
||||
@ -326,7 +326,7 @@ static void btstack_sbc_decoder_process_msbc_data(btstack_sbc_decoder_state_t *
|
||||
while (input_bytes_to_process > 0){
|
||||
|
||||
// Use PLC to insert missing frames (after first sync found)
|
||||
while (decoder_state->first_good_frame_found && decoder_state->msbc_bad_bytes >= MSBC_FRAME_SIZE){
|
||||
while (decoder_state->first_good_frame_found && (decoder_state->msbc_bad_bytes >= MSBC_FRAME_SIZE)){
|
||||
|
||||
decoder_state->msbc_bad_bytes -= MSBC_FRAME_SIZE;
|
||||
state->bad_frames_nr++;
|
||||
@ -384,7 +384,7 @@ static void btstack_sbc_decoder_process_msbc_data(btstack_sbc_decoder_state_t *
|
||||
if (corrupt_frame_period > 0){
|
||||
frame_count++;
|
||||
|
||||
if (frame_count % corrupt_frame_period == 0){
|
||||
if ((frame_count % corrupt_frame_period) == 0){
|
||||
*(uint8_t*)&frame_data[5] = 0;
|
||||
frame_count = 0;
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ static bludroid_encoder_state_t bd_encoder_state;
|
||||
void btstack_sbc_encoder_init(btstack_sbc_encoder_state_t * state, btstack_sbc_mode_t mode,
|
||||
int blocks, int subbands, int allmethod, int sample_rate, int bitpool, int channel_mode){
|
||||
|
||||
if (sbc_encoder_state_singleton && sbc_encoder_state_singleton != state ){
|
||||
if (sbc_encoder_state_singleton && (sbc_encoder_state_singleton != state) ){
|
||||
log_error("SBC encoder: different sbc decoder state is allready registered");
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,8 @@ static float sqrt3(const float x){
|
||||
// Two Babylonian Steps (simplified from:)
|
||||
// u.x = 0.5f * (u.x + x/u.x);
|
||||
// u.x = 0.5f * (u.x + x/u.x);
|
||||
u.x = u.x + x/u.x;
|
||||
u.x = 0.25f*u.x + x/u.x;
|
||||
u.x = u.x + (x/u.x);
|
||||
u.x = (0.25f*u.x) + (x/u.x);
|
||||
|
||||
return u.x;
|
||||
}
|
||||
@ -337,7 +337,7 @@ void btstack_sbc_plc_bad_frame(btstack_sbc_plc_state_t *plc_state, SAMPLE_FORMAT
|
||||
for (i=0;i<SBC_OLAL;i++){
|
||||
float left = ZIRbuf[i];
|
||||
float right = sf*plc_state->hist[plc_state->bestlag+i];
|
||||
val = left*rcos[i] + right*rcos[SBC_OLAL-1-i];
|
||||
val = (left*rcos[i]) + (right*rcos[SBC_OLAL-1-i]);
|
||||
// val = sf*plc_state->hist[plc_state->bestlag+i];
|
||||
plc_state->hist[SBC_LHIST+i] = crop_sample(val);
|
||||
}
|
||||
@ -347,19 +347,19 @@ void btstack_sbc_plc_bad_frame(btstack_sbc_plc_state_t *plc_state, SAMPLE_FORMAT
|
||||
plc_state->hist[SBC_LHIST+i] = crop_sample(val);
|
||||
}
|
||||
|
||||
for (;i<SBC_FS+SBC_OLAL;i++){
|
||||
for (;i<(SBC_FS+SBC_OLAL);i++){
|
||||
float left = sf*plc_state->hist[plc_state->bestlag+i];
|
||||
float right = plc_state->hist[plc_state->bestlag+i];
|
||||
val = left*rcos[i-SBC_FS]+right*rcos[SBC_OLAL-1-i+SBC_FS];
|
||||
val = (left*rcos[i-SBC_FS])+(right*rcos[SBC_OLAL-1-i+SBC_FS]);
|
||||
plc_state->hist[SBC_LHIST+i] = crop_sample(val);
|
||||
}
|
||||
|
||||
for (;i<SBC_FS+SBC_RT+SBC_OLAL;i++){
|
||||
for (;i<(SBC_FS+SBC_RT+SBC_OLAL);i++){
|
||||
plc_state->hist[SBC_LHIST+i] = plc_state->hist[plc_state->bestlag+i];
|
||||
}
|
||||
} else {
|
||||
// printf("succesive bad frame nr %d\n", plc_state->nbf);
|
||||
for (;i<SBC_FS+SBC_RT+SBC_OLAL;i++){
|
||||
for (;i<(SBC_FS+SBC_RT+SBC_OLAL);i++){
|
||||
plc_state->hist[SBC_LHIST+i] = plc_state->hist[plc_state->bestlag+i];
|
||||
}
|
||||
}
|
||||
@ -401,10 +401,10 @@ void btstack_sbc_plc_good_frame(btstack_sbc_plc_state_t *plc_state, SAMPLE_FORMA
|
||||
out[i] = plc_state->hist[SBC_LHIST+i];
|
||||
}
|
||||
|
||||
for (i = SBC_RT;i<SBC_RT+SBC_OLAL;i++){
|
||||
for (i = SBC_RT;i<(SBC_RT+SBC_OLAL);i++){
|
||||
float left = plc_state->hist[SBC_LHIST+i];
|
||||
float right = in[i];
|
||||
val = left*rcos[i-SBC_RT] + right*rcos[SBC_OLAL+SBC_RT-1-i];
|
||||
val = (left*rcos[i-SBC_RT]) + (right*rcos[SBC_OLAL+SBC_RT-1-i]);
|
||||
out[i] = crop_sample(val);
|
||||
}
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ static void goep_client_handle_sdp_query_event(uint8_t packet_type, uint16_t cha
|
||||
goep_client_emit_connected_event(goep_client, status);
|
||||
break;
|
||||
}
|
||||
if (context->rfcomm_port == 0 && context->l2cap_psm == 0){
|
||||
if ((context->rfcomm_port == 0) && (context->l2cap_psm == 0)){
|
||||
log_info("No GOEP RFCOMM or L2CAP server found");
|
||||
context->state = GOEP_INIT;
|
||||
goep_client_emit_connected_event(goep_client, ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
|
||||
|
@ -184,7 +184,7 @@ int send_str_over_rfcomm(uint16_t cid, char * command){
|
||||
int hfp_supports_codec(uint8_t codec, int codecs_nr, uint8_t * codecs){
|
||||
|
||||
// mSBC requires support for eSCO connections
|
||||
if (codec == HFP_CODEC_MSBC && !hci_extended_sco_link_supported()) return 0;
|
||||
if ((codec == HFP_CODEC_MSBC) && !hci_extended_sco_link_supported()) return 0;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < codecs_nr; i++){
|
||||
@ -222,10 +222,10 @@ int store_bit(uint32_t bitmap, int position, uint8_t value){
|
||||
}
|
||||
|
||||
int join(char * buffer, int buffer_size, uint8_t * values, int values_nr){
|
||||
if (buffer_size < values_nr * 3) return 0;
|
||||
if (buffer_size < (values_nr * 3)) return 0;
|
||||
int i;
|
||||
int offset = 0;
|
||||
for (i = 0; i < values_nr-1; i++) {
|
||||
for (i = 0; i < (values_nr-1); i++) {
|
||||
offset += snprintf(buffer+offset, buffer_size-offset, "%d,", values[i]); // puts string into buffer
|
||||
}
|
||||
if (i<values_nr){
|
||||
@ -235,11 +235,11 @@ int join(char * buffer, int buffer_size, uint8_t * values, int values_nr){
|
||||
}
|
||||
|
||||
int join_bitmap(char * buffer, int buffer_size, uint32_t values, int values_nr){
|
||||
if (buffer_size < values_nr * 3) return 0;
|
||||
if (buffer_size < (values_nr * 3)) return 0;
|
||||
|
||||
int i;
|
||||
int offset = 0;
|
||||
for (i = 0; i < values_nr-1; i++) {
|
||||
for (i = 0; i < (values_nr-1); i++) {
|
||||
offset += snprintf(buffer+offset, buffer_size-offset, "%d,", get_bit(values,i)); // puts string into buffer
|
||||
}
|
||||
|
||||
@ -316,7 +316,7 @@ void hfp_emit_string_event(hfp_connection_t * hfp_connection, uint8_t event_subt
|
||||
event[0] = HCI_EVENT_HFP_META;
|
||||
event[1] = sizeof(event) - 2;
|
||||
event[2] = event_subtype;
|
||||
int size = ( strlen(value) < sizeof(event) - 4) ? (int) strlen(value) : (int) sizeof(event) - 4;
|
||||
int size = ( strlen(value) < (sizeof(event) - 4)) ? (int) strlen(value) : ((int) sizeof(event) - 4);
|
||||
strncpy((char*)&event[3], value, size);
|
||||
event[3 + size] = 0;
|
||||
hfp_emit_event_for_context(hfp_connection, event, sizeof(event));
|
||||
@ -343,7 +343,7 @@ hfp_connection_t * get_hfp_connection_context_for_bd_addr(bd_addr_t bd_addr, hfp
|
||||
btstack_linked_list_iterator_init(&it, hfp_get_connections());
|
||||
while (btstack_linked_list_iterator_has_next(&it)){
|
||||
hfp_connection_t * hfp_connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
|
||||
if (memcmp(hfp_connection->remote_addr, bd_addr, 6) == 0 && hfp_connection->local_role == hfp_role) {
|
||||
if (memcmp(hfp_connection->remote_addr, bd_addr, 6) == 0 && (hfp_connection->local_role == hfp_role)) {
|
||||
return hfp_connection;
|
||||
}
|
||||
}
|
||||
@ -355,7 +355,7 @@ hfp_connection_t * get_hfp_connection_context_for_sco_handle(uint16_t handle, hf
|
||||
btstack_linked_list_iterator_init(&it, hfp_get_connections());
|
||||
while (btstack_linked_list_iterator_has_next(&it)){
|
||||
hfp_connection_t * hfp_connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
|
||||
if (hfp_connection->sco_handle == handle && hfp_connection->local_role == hfp_role){
|
||||
if ((hfp_connection->sco_handle == handle) && (hfp_connection->local_role == hfp_role)){
|
||||
return hfp_connection;
|
||||
}
|
||||
}
|
||||
@ -367,7 +367,7 @@ hfp_connection_t * get_hfp_connection_context_for_acl_handle(uint16_t handle, hf
|
||||
btstack_linked_list_iterator_init(&it, hfp_get_connections());
|
||||
while (btstack_linked_list_iterator_has_next(&it)){
|
||||
hfp_connection_t * hfp_connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it);
|
||||
if (hfp_connection->acl_handle == handle && hfp_connection->local_role == hfp_role){
|
||||
if ((hfp_connection->acl_handle == handle) && (hfp_connection->local_role == hfp_role)){
|
||||
return hfp_connection;
|
||||
}
|
||||
}
|
||||
@ -574,7 +574,7 @@ static int hfp_handle_failed_sco_connection(uint8_t status){
|
||||
}
|
||||
log_info("(e)SCO Connection failed status 0x%02x", status);
|
||||
// invalid params / unspecified error
|
||||
if (status != 0x11 && status != 0x1f && status != 0x0D) return 0;
|
||||
if ((status != 0x11) && (status != 0x1f) && status != 0x0D) return 0;
|
||||
|
||||
switch (sco_establishment_active->link_setting){
|
||||
case HFP_LINK_SETTINGS_D0:
|
||||
@ -1035,19 +1035,19 @@ static int hfp_parser_is_buffer_empty(hfp_connection_t * hfp_connection){
|
||||
}
|
||||
|
||||
static int hfp_parser_is_end_of_line(uint8_t byte){
|
||||
return byte == '\n' || byte == '\r';
|
||||
return (byte == '\n') || (byte == '\r');
|
||||
}
|
||||
|
||||
static int hfp_parser_is_end_of_header(uint8_t byte){
|
||||
return hfp_parser_is_end_of_line(byte) || byte == ':' || byte == '?';
|
||||
return hfp_parser_is_end_of_line(byte) || (byte == ':') || (byte == '?');
|
||||
}
|
||||
|
||||
static int hfp_parser_found_separator(hfp_connection_t * hfp_connection, uint8_t byte){
|
||||
if (hfp_connection->keep_byte == 1) return 1;
|
||||
|
||||
int found_separator = byte == ',' || byte == '\n'|| byte == '\r'||
|
||||
byte == ')' || byte == '(' || byte == ':' ||
|
||||
byte == '-' || byte == '"' || byte == '?'|| byte == '=';
|
||||
int found_separator = (byte == ',') || (byte == '\n')|| (byte == '\r')||
|
||||
(byte == ')') || (byte == '(') || (byte == ':') ||
|
||||
(byte == '-') || (byte == '"') || (byte == '?')|| (byte == '=');
|
||||
return found_separator;
|
||||
}
|
||||
static void hfp_parser_next_state(hfp_connection_t * hfp_connection, uint8_t byte){
|
||||
@ -1099,7 +1099,7 @@ void hfp_parse(hfp_connection_t * hfp_connection, uint8_t byte, int isHandsFree)
|
||||
// handle ATD<dial_string>;
|
||||
if (strncmp((const char*)hfp_connection->line_buffer, HFP_CALL_PHONE_NUMBER, strlen(HFP_CALL_PHONE_NUMBER)) == 0){
|
||||
// check for end-of-line or ';'
|
||||
if (byte == ';' || hfp_parser_is_end_of_line(byte)){
|
||||
if ((byte == ';') || hfp_parser_is_end_of_line(byte)){
|
||||
hfp_connection->line_buffer[hfp_connection->line_size] = 0;
|
||||
hfp_connection->line_size = 0;
|
||||
hfp_connection->command = HFP_CMD_CALL_PHONE_NUMBER;
|
||||
@ -1110,9 +1110,9 @@ void hfp_parse(hfp_connection_t * hfp_connection, uint8_t byte, int isHandsFree)
|
||||
}
|
||||
|
||||
// TODO: handle space inside word
|
||||
if (byte == ' ' && hfp_connection->parser_state > HFP_PARSER_CMD_HEADER) return;
|
||||
if (byte == ' ' && (hfp_connection->parser_state > HFP_PARSER_CMD_HEADER)) return;
|
||||
|
||||
if (byte == ',' && hfp_connection->command == HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE){
|
||||
if ((byte == ',') && hfp_connection->command == HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE){
|
||||
if (hfp_connection->line_size == 0){
|
||||
hfp_connection->line_buffer[0] = 0;
|
||||
hfp_connection->ignore_value = 1;
|
||||
@ -1152,7 +1152,7 @@ void hfp_parse(hfp_connection_t * hfp_connection, uint8_t byte, int isHandsFree)
|
||||
}
|
||||
|
||||
// printf(" parse header 2 %s, keep separator $ %d\n", hfp_connection->line_buffer, hfp_connection->keep_byte);
|
||||
if (hfp_parser_is_end_of_header(byte) || hfp_connection->keep_byte == 1){
|
||||
if (hfp_parser_is_end_of_header(byte) || (hfp_connection->keep_byte == 1)){
|
||||
// printf(" parse header 3 %s, keep separator $ %d\n", hfp_connection->line_buffer, hfp_connection->keep_byte);
|
||||
char * line_buffer = (char *)hfp_connection->line_buffer;
|
||||
hfp_connection->command = parse_command(line_buffer, isHandsFree);
|
||||
|
@ -297,7 +297,7 @@ static void hfp_ag_indicators_string_store(hfp_connection_t * hfp_connection, in
|
||||
static int hfp_ag_indicators_cmd_generator_num_segments(hfp_connection_t * hfp_connection){
|
||||
int num_indicators = hfp_ag_get_ag_indicators_nr(hfp_connection);
|
||||
if (!num_indicators) return 2;
|
||||
return 3 + (num_indicators-1) * 2;
|
||||
return 3 + ((num_indicators-1) * 2);
|
||||
}
|
||||
|
||||
// get size of individual segment for hfp_ag_retrieve_indicators_cmd
|
||||
@ -311,7 +311,7 @@ static int hfp_ag_indicators_cmd_generator_get_segment_len(hfp_connection_t * hf
|
||||
if ((index & 1) == 0){
|
||||
return hfp_ag_indicators_string_size(hfp_connection, indicator_index);
|
||||
}
|
||||
if (indicator_index == num_indicators - 1){
|
||||
if (indicator_index == (num_indicators - 1)){
|
||||
return 8; // "\r\n\r\nOK\r\n"
|
||||
}
|
||||
return 1; // comma
|
||||
@ -334,7 +334,7 @@ static void hgp_ag_indicators_cmd_generator_store_segment(hfp_connection_t * hfp
|
||||
hfp_ag_indicators_string_store(hfp_connection, indicator_index, buffer);
|
||||
return;
|
||||
}
|
||||
if (indicator_index == num_indicators-1){
|
||||
if (indicator_index == (num_indicators-1)){
|
||||
memcpy(buffer, "\r\n\r\nOK\r\n", 8);
|
||||
return;
|
||||
}
|
||||
@ -342,10 +342,10 @@ static void hgp_ag_indicators_cmd_generator_store_segment(hfp_connection_t * hfp
|
||||
}
|
||||
|
||||
static int hfp_hf_indicators_join(char * buffer, int buffer_size){
|
||||
if (buffer_size < hfp_ag_indicators_nr * 3) return 0;
|
||||
if (buffer_size < (hfp_ag_indicators_nr * 3)) return 0;
|
||||
int i;
|
||||
int offset = 0;
|
||||
for (i = 0; i < hfp_generic_status_indicators_nr-1; i++) {
|
||||
for (i = 0; i < (hfp_generic_status_indicators_nr-1); i++) {
|
||||
offset += snprintf(buffer+offset, buffer_size-offset, "%d,", hfp_generic_status_indicators[i].uuid);
|
||||
}
|
||||
if (i < hfp_generic_status_indicators_nr){
|
||||
@ -355,7 +355,7 @@ static int hfp_hf_indicators_join(char * buffer, int buffer_size){
|
||||
}
|
||||
|
||||
static int hfp_hf_indicators_initial_status_join(char * buffer, int buffer_size){
|
||||
if (buffer_size < hfp_generic_status_indicators_nr * 3) return 0;
|
||||
if (buffer_size < (hfp_generic_status_indicators_nr * 3)) return 0;
|
||||
int i;
|
||||
int offset = 0;
|
||||
for (i = 0; i < hfp_generic_status_indicators_nr; i++) {
|
||||
@ -365,10 +365,10 @@ static int hfp_hf_indicators_initial_status_join(char * buffer, int buffer_size)
|
||||
}
|
||||
|
||||
static int hfp_ag_indicators_status_join(char * buffer, int buffer_size){
|
||||
if (buffer_size < hfp_ag_indicators_nr * 3) return 0;
|
||||
if (buffer_size < (hfp_ag_indicators_nr * 3)) return 0;
|
||||
int i;
|
||||
int offset = 0;
|
||||
for (i = 0; i < hfp_ag_indicators_nr-1; i++) {
|
||||
for (i = 0; i < (hfp_ag_indicators_nr-1); i++) {
|
||||
offset += snprintf(buffer+offset, buffer_size-offset, "%d,", hfp_ag_indicators[i].status);
|
||||
}
|
||||
if (i<hfp_ag_indicators_nr){
|
||||
@ -378,10 +378,10 @@ static int hfp_ag_indicators_status_join(char * buffer, int buffer_size){
|
||||
}
|
||||
|
||||
static int hfp_ag_call_services_join(char * buffer, int buffer_size){
|
||||
if (buffer_size < hfp_ag_call_hold_services_nr * 3) return 0;
|
||||
if (buffer_size < (hfp_ag_call_hold_services_nr * 3)) return 0;
|
||||
int i;
|
||||
int offset = snprintf(buffer, buffer_size, "(");
|
||||
for (i = 0; i < hfp_ag_call_hold_services_nr-1; i++) {
|
||||
for (i = 0; i < (hfp_ag_call_hold_services_nr-1); i++) {
|
||||
offset += snprintf(buffer+offset, buffer_size-offset, "%s,", hfp_ag_call_hold_services[i]);
|
||||
}
|
||||
if (i<hfp_ag_call_hold_services_nr){
|
||||
@ -405,7 +405,7 @@ static int hfp_ag_send_cmd_via_generator(uint16_t cid, hfp_connection_t * hfp_co
|
||||
int segment = start_segment;
|
||||
while (segment < num_segments){
|
||||
int segment_len = get_segment_len(hfp_connection, segment);
|
||||
if (offset + segment_len > mtu) break;
|
||||
if ((offset + segment_len) > mtu) break;
|
||||
// append segement
|
||||
store_segment(hfp_connection, segment, data+offset);
|
||||
offset += segment_len;
|
||||
@ -580,7 +580,7 @@ static int codecs_exchange_state_machine(hfp_connection_t * hfp_connection){
|
||||
}
|
||||
hfp_connection->negotiated_codec = hfp_connection->codec_confirmed;
|
||||
hfp_connection->codecs_state = HFP_CODECS_EXCHANGED;
|
||||
log_info("hfp: codec confirmed: %s", hfp_connection->negotiated_codec == HFP_CODEC_MSBC ? "mSBC" : "CVSD");
|
||||
log_info("hfp: codec confirmed: %s", (hfp_connection->negotiated_codec == HFP_CODEC_MSBC) ? "mSBC" : "CVSD");
|
||||
hfp_ag_send_ok(hfp_connection->rfcomm_cid);
|
||||
// now, pick link settings
|
||||
|
||||
@ -601,7 +601,7 @@ static void hfp_ag_slc_established(hfp_connection_t * hfp_connection){
|
||||
hfp_connection->call_state = HFP_CALL_W4_AUDIO_CONNECTION_FOR_ACTIVE;
|
||||
}
|
||||
// if AG is ringing, also start ringing on the HF
|
||||
if (hfp_gsm_call_status() == HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS &&
|
||||
if ((hfp_gsm_call_status() == HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS) &&
|
||||
hfp_gsm_callsetup_status() == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS){
|
||||
hfp_ag_hf_start_ringing(hfp_connection);
|
||||
}
|
||||
@ -1775,7 +1775,7 @@ static void hfp_ag_run_for_context(hfp_connection_t *hfp_connection){
|
||||
log_info("trigger codec, command %u, codec state %u", hfp_connection->command, hfp_connection->codecs_state);
|
||||
}
|
||||
|
||||
if (hfp_connection->trigger_codec_exchange && hfp_connection->command == HFP_CMD_NONE){
|
||||
if (hfp_connection->trigger_codec_exchange && (hfp_connection->command == HFP_CMD_NONE)){
|
||||
switch (hfp_connection->codecs_state){
|
||||
case HFP_CODECS_IDLE:
|
||||
case HFP_CODECS_RECEIVED_LIST:
|
||||
@ -1805,7 +1805,7 @@ static void hfp_ag_run_for_context(hfp_connection_t *hfp_connection){
|
||||
cmd_sent = hfp_ag_run_for_audio_connection(hfp_connection);
|
||||
}
|
||||
|
||||
if (hfp_connection->command == HFP_CMD_NONE && !cmd_sent){
|
||||
if ((hfp_connection->command == HFP_CMD_NONE) && !cmd_sent){
|
||||
// log_info("hfp_connection->command == HFP_CMD_NONE");
|
||||
switch(hfp_connection->state){
|
||||
case HFP_W2_DISCONNECT_RFCOMM:
|
||||
@ -1835,7 +1835,7 @@ static hfp_generic_status_indicator_t *get_hf_indicator_by_number(int number){
|
||||
}
|
||||
|
||||
static int hfp_parser_is_end_of_line(uint8_t byte){
|
||||
return byte == '\n' || byte == '\r';
|
||||
return (byte == '\n') || (byte == '\r');
|
||||
}
|
||||
|
||||
static void hfp_ag_handle_rfcomm_data(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
|
@ -226,7 +226,7 @@ static void hfp_gsm_set_clip(int index_in_table, uint8_t type, const char * numb
|
||||
|
||||
gsm_calls[index_in_table].clip_type = type;
|
||||
|
||||
int clip_number_size = strlen(number) < HFP_GSM_MAX_CALL_NUMBER_SIZE ? (int) strlen(number) : HFP_GSM_MAX_CALL_NUMBER_SIZE-1;
|
||||
int clip_number_size = (strlen(number) < HFP_GSM_MAX_CALL_NUMBER_SIZE) ? (int) strlen(number) : (HFP_GSM_MAX_CALL_NUMBER_SIZE-1);
|
||||
strncpy(gsm_calls[index_in_table].clip_number, number, clip_number_size);
|
||||
gsm_calls[index_in_table].clip_number[clip_number_size] = '\0';
|
||||
strncpy(last_dialed_number, number, clip_number_size);
|
||||
@ -521,7 +521,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty
|
||||
break;
|
||||
|
||||
case HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:
|
||||
if (index != 0 && index <= HFP_GSM_MAX_NR_CALLS ){
|
||||
if ((index != 0) && (index <= HFP_GSM_MAX_NR_CALLS) ){
|
||||
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
|
||||
if (gsm_calls[i].index == index){
|
||||
delete_call(i);
|
||||
@ -547,7 +547,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty
|
||||
|
||||
case HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:
|
||||
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
|
||||
if (is_enhanced_call_status_active(i) && gsm_calls[i].index != index){
|
||||
if (is_enhanced_call_status_active(i) && (gsm_calls[i].index != index)){
|
||||
set_enhanced_call_status_held(i);
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ static void hfp_hf_emit_subscriber_information(btstack_packet_handler_t callback
|
||||
event[2] = event_subtype;
|
||||
event[3] = status;
|
||||
event[4] = bnip_type;
|
||||
int size = (strlen(bnip_number) < sizeof(event) - 6) ? (int) strlen(bnip_number) : (int) sizeof(event) - 6;
|
||||
int size = (strlen(bnip_number) < (sizeof(event) - 6)) ? (int) strlen(bnip_number) : ((int) sizeof(event) - 6);
|
||||
strncpy((char*)&event[5], bnip_number, size);
|
||||
event[5 + size] = 0;
|
||||
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
@ -130,7 +130,7 @@ static void hfp_hf_emit_type_and_number(btstack_packet_handler_t callback, uint8
|
||||
event[1] = sizeof(event) - 2;
|
||||
event[2] = event_subtype;
|
||||
event[3] = bnip_type;
|
||||
int size = (strlen(bnip_number) < sizeof(event) - 5) ? (int) strlen(bnip_number) : (int) sizeof(event) - 5;
|
||||
int size = (strlen(bnip_number) < (sizeof(event) - 5)) ? (int) strlen(bnip_number) : ((int) sizeof(event) - 5);
|
||||
strncpy((char*)&event[4], bnip_number, size);
|
||||
event[4 + size] = 0;
|
||||
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
@ -151,7 +151,7 @@ static void hfp_hf_emit_enhanced_call_status(btstack_packet_handler_t callback,
|
||||
event[pos++] = clcc_mode;
|
||||
event[pos++] = clcc_mpty;
|
||||
event[pos++] = bnip_type;
|
||||
int size = (strlen(bnip_number) < sizeof(event) - pos) ? (int) strlen(bnip_number) : (int) sizeof(event) - pos;
|
||||
int size = (strlen(bnip_number) < (sizeof(event) - pos)) ? (int) strlen(bnip_number) : ((int) sizeof(event) - pos);
|
||||
strncpy((char*)&event[pos], bnip_number, size);
|
||||
pos += size;
|
||||
event[pos++] = 0;
|
||||
@ -526,7 +526,7 @@ static int codecs_exchange_state_machine(hfp_connection_t * hfp_connection){
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_connection->codecs_state = HFP_CODECS_HF_CONFIRMED_CODEC;
|
||||
hfp_connection->negotiated_codec = hfp_connection->suggested_codec;
|
||||
log_info("hfp: codec confirmed: %s", hfp_connection->negotiated_codec == HFP_CODEC_MSBC ? "mSBC" : "CVSD");
|
||||
log_info("hfp: codec confirmed: %s", (hfp_connection->negotiated_codec == HFP_CODEC_MSBC) ? "mSBC" : "CVSD");
|
||||
hfp_hf_cmd_confirm_codec(hfp_connection->rfcomm_cid, hfp_connection->codec_confirmed);
|
||||
} else {
|
||||
hfp_connection->codec_confirmed = 0;
|
||||
@ -994,7 +994,7 @@ static void hfp_hf_switch_on_ok(hfp_connection_t *hfp_connection){
|
||||
}
|
||||
|
||||
static int hfp_parser_is_end_of_line(uint8_t byte){
|
||||
return byte == '\n' || byte == '\r';
|
||||
return (byte == '\n') || (byte == '\r');
|
||||
}
|
||||
|
||||
static void hfp_hf_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
@ -1592,7 +1592,7 @@ void hfp_hf_set_microphone_gain(hci_con_handle_t acl_handle, int gain){
|
||||
}
|
||||
|
||||
if (hfp_connection->microphone_gain == gain) return;
|
||||
if (gain < 0 || gain > 15){
|
||||
if ((gain < 0) || (gain > 15)){
|
||||
log_info("Valid range for a gain is [0..15]. Currently sent: %d", gain);
|
||||
return;
|
||||
}
|
||||
@ -1609,7 +1609,7 @@ void hfp_hf_set_speaker_gain(hci_con_handle_t acl_handle, int gain){
|
||||
}
|
||||
|
||||
if (hfp_connection->speaker_gain == gain) return;
|
||||
if (gain < 0 || gain > 15){
|
||||
if ((gain < 0) || (gain > 15)){
|
||||
log_info("Valid range for a gain is [0..15]. Currently sent: %d", gain);
|
||||
return;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ void hfp_msbc_init(void){
|
||||
}
|
||||
|
||||
int hfp_msbc_can_encode_audio_frame_now(void){
|
||||
return sizeof(msbc_buffer) - msbc_buffer_offset >= MSBC_FRAME_SIZE + MSBC_EXTRA_SIZE;
|
||||
return (sizeof(msbc_buffer) - msbc_buffer_offset) >= MSBC_FRAME_SIZE + MSBC_EXTRA_SIZE;
|
||||
}
|
||||
|
||||
void hfp_msbc_encode_audio_frame(int16_t * pcm_samples){
|
||||
|
@ -127,7 +127,7 @@ static uint16_t hid_device_get_next_cid(void){
|
||||
|
||||
// TODO: store hid device connection into list
|
||||
static hid_device_t * hid_device_get_instance_for_l2cap_cid(uint16_t cid){
|
||||
if (_hid_device.control_cid == cid || _hid_device.interrupt_cid == cid){
|
||||
if ((_hid_device.control_cid == cid) || (_hid_device.interrupt_cid == cid)){
|
||||
return &_hid_device;
|
||||
}
|
||||
return NULL;
|
||||
@ -370,7 +370,7 @@ static int hid_report_size_valid(uint16_t cid, int report_id, hid_report_type_t
|
||||
}
|
||||
} else {
|
||||
int size = btstack_hid_get_report_size_for_id(report_id, report_type, hid_descriptor_len, hid_descriptor);
|
||||
if (size == 0 || size != report_size) return 0;
|
||||
if ((size == 0) || (size != report_size)) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -504,7 +504,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * pack
|
||||
device->expected_report_size = hid_get_report_size_for_id(device->cid, device->report_id, device->report_type, hid_descriptor_len, hid_descriptor);
|
||||
report_size = device->expected_report_size + pos; // add 1 for header size and report id
|
||||
|
||||
if ((packet[0] & 0x08) && packet_size >= pos + 1){
|
||||
if ((packet[0] & 0x08) && packet_size >= (pos + 1)){
|
||||
device->report_size = btstack_min(btstack_min(little_endian_read_16(packet, pos), report_size), sizeof(report));
|
||||
} else {
|
||||
device->report_size = btstack_min(btstack_min(l2cap_max_mtu(), report_size), sizeof(report));
|
||||
@ -570,7 +570,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * pack
|
||||
break;
|
||||
}
|
||||
param = packet[0] & 0x01;
|
||||
if (param == HID_PROTOCOL_MODE_BOOT && !hid_boot_protocol_mode_supported){
|
||||
if ((param == HID_PROTOCOL_MODE_BOOT) && !hid_boot_protocol_mode_supported){
|
||||
device->report_status = HID_HANDSHAKE_PARAM_TYPE_ERR_INVALID_PARAMETER;
|
||||
break;
|
||||
}
|
||||
@ -643,7 +643,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * pack
|
||||
l2cap_decline_connection(channel);
|
||||
break;
|
||||
}
|
||||
if (device->con_handle == HCI_CON_HANDLE_INVALID || l2cap_event_incoming_connection_get_handle(packet) == device->con_handle){
|
||||
if ((device->con_handle == HCI_CON_HANDLE_INVALID) || (l2cap_event_incoming_connection_get_handle(packet) == device->con_handle)){
|
||||
device->con_handle = l2cap_event_incoming_connection_get_handle(packet);
|
||||
device->incoming = 1;
|
||||
l2cap_event_incoming_connection_get_address(packet, device->bd_addr);
|
||||
@ -704,7 +704,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * pack
|
||||
}
|
||||
|
||||
// connect HID Interrupt for outgoing
|
||||
if (device->incoming == 0 && psm == PSM_HID_CONTROL){
|
||||
if ((device->incoming == 0) && (psm == PSM_HID_CONTROL)){
|
||||
// printf("Create outgoing HID Interrupt\n");
|
||||
status = l2cap_create_channel(packet_handler, device->bd_addr, PSM_HID_INTERRUPT, 48, &device->interrupt_cid);
|
||||
break;
|
||||
|
@ -542,7 +542,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
UNUSED(channel); // ok: no channel for HCI_EVENT_PACKET and only single active RFCOMM channel
|
||||
|
||||
if (packet_type == RFCOMM_DATA_PACKET){
|
||||
while (size > 0 && (packet[0] == '\n' || packet[0] == '\r')){
|
||||
while ((size > 0) && ((packet[0] == '\n') || (packet[0] == '\r'))){
|
||||
size--;
|
||||
packet++;
|
||||
}
|
||||
|
@ -483,7 +483,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
if (packet_type == RFCOMM_DATA_PACKET){
|
||||
// printf("packet_handler type RFCOMM_DATA_PACKET %u, packet[0] %x\n", packet_type, packet[0]);
|
||||
// skip over leading newline
|
||||
while (size > 0 && (packet[0] == '\n' || packet[0] == '\r')){
|
||||
while ((size > 0) && ((packet[0] == '\n') || (packet[0] == '\r'))){
|
||||
size--;
|
||||
packet++;
|
||||
}
|
||||
@ -501,7 +501,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
} else {
|
||||
if (!hsp_hs_callback) return;
|
||||
// strip trailing newline
|
||||
while (size > 0 && (packet[size-1] == '\n' || packet[size-1] == '\r')){
|
||||
while ((size > 0) && ((packet[size-1] == '\n') || (packet[size-1] == '\r'))){
|
||||
size--;
|
||||
}
|
||||
// add trailing \0
|
||||
|
@ -75,7 +75,7 @@ void obex_iterator_init_with_request_packet(obex_iterator_t *context, const uint
|
||||
}
|
||||
|
||||
void obex_iterator_init_with_response_packet(obex_iterator_t *context, uint8_t request_opcode, const uint8_t * packet_data, uint16_t packet_len){
|
||||
int header_offset = request_opcode == OBEX_OPCODE_CONNECT ? 7 : 3;
|
||||
int header_offset = (request_opcode == OBEX_OPCODE_CONNECT) ? 7 : 3;
|
||||
obex_iterator_init(context, header_offset, packet_data, packet_len);
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ const uint8_t * obex_iterator_get_data(const obex_iterator_t * context){
|
||||
void obex_dump_packet(uint8_t request_opcode, uint8_t * packet, uint16_t size){
|
||||
obex_iterator_t it;
|
||||
printf("OBEX Opcode: 0x%02x\n", request_opcode);
|
||||
int header_offset = request_opcode == OBEX_OPCODE_CONNECT ? 7 : 3;
|
||||
int header_offset = (request_opcode == OBEX_OPCODE_CONNECT) ? 7 : 3;
|
||||
printf("OBEX Header: ");
|
||||
printf_hexdump(packet, header_offset);
|
||||
for (obex_iterator_init_with_response_packet(&it, request_opcode, packet, size); obex_iterator_has_more(&it) ; obex_iterator_next(&it)){
|
||||
|
@ -220,8 +220,8 @@ static void pbap_client_emit_phonebook_size_event(pbap_client_t * context, uint8
|
||||
|
||||
static void pbap_client_emit_authentication_event(pbap_client_t * context, uint8_t options){
|
||||
// split options
|
||||
uint8_t user_id_required = options & 1 ? 1 : 0;
|
||||
uint8_t full_access = options & 2 ? 1 : 0;
|
||||
uint8_t user_id_required = (options & 1) ? 1 : 0;
|
||||
uint8_t full_access = (options & 2) ? 1 : 0;
|
||||
|
||||
uint8_t event[7];
|
||||
int pos = 0;
|
||||
@ -448,8 +448,8 @@ static void pbap_handle_can_send_now(void){
|
||||
case PBAP_W2_SET_PATH_ELEMENT:
|
||||
// find '/' or '\0'
|
||||
path_element_start = pbap_client->set_path_offset;
|
||||
while (pbap_client->current_folder[pbap_client->set_path_offset] != '\0' &&
|
||||
pbap_client->current_folder[pbap_client->set_path_offset] != '/'){
|
||||
while ((pbap_client->current_folder[pbap_client->set_path_offset] != '\0') &&
|
||||
(pbap_client->current_folder[pbap_client->set_path_offset] != '/')){
|
||||
pbap_client->set_path_offset++;
|
||||
}
|
||||
path_element_len = pbap_client->set_path_offset-path_element_start;
|
||||
@ -576,8 +576,8 @@ static void pbap_client_process_vcard_listing(uint8_t *packet, uint16_t size){
|
||||
obex_iterator_t it;
|
||||
for (obex_iterator_init_with_response_packet(&it, goep_client_get_request_opcode(pbap_client->goep_cid), packet, size); obex_iterator_has_more(&it) ; obex_iterator_next(&it)){
|
||||
uint8_t hi = obex_iterator_get_hi(&it);
|
||||
if (hi == OBEX_HEADER_END_OF_BODY ||
|
||||
hi == OBEX_HEADER_BODY){
|
||||
if ((hi == OBEX_HEADER_END_OF_BODY) ||
|
||||
(hi == OBEX_HEADER_BODY)){
|
||||
uint16_t data_len = obex_iterator_get_data_len(&it);
|
||||
const uint8_t * data = obex_iterator_get_data(&it);
|
||||
// now try parsing it
|
||||
@ -615,13 +615,13 @@ static void pbap_client_process_vcard_listing(uint8_t *packet, uint16_t size){
|
||||
case YXML_ATTRVAL:
|
||||
if (name_found) {
|
||||
// "In UTF-8, characters from the U+0000..U+10FFFF range (the UTF-16 accessible range) are encoded using sequences of 1 to 4 octets."
|
||||
if (strlen(name) + 4 + 1 >= sizeof(name)) break;
|
||||
if ((strlen(name) + 4 + 1) >= sizeof(name)) break;
|
||||
strcat(name, pbap_client->xml_parser.data);
|
||||
break;
|
||||
}
|
||||
if (handle_found) {
|
||||
// "In UTF-8, characters from the U+0000..U+10FFFF range (the UTF-16 accessible range) are encoded using sequences of 1 to 4 octets."
|
||||
if (strlen(handle) + 4 + 1 >= sizeof(handle)) break;
|
||||
if ((strlen(handle) + 4 + 1) >= sizeof(handle)) break;
|
||||
strcat(handle, pbap_client->xml_parser.data);
|
||||
break;
|
||||
}
|
||||
@ -795,7 +795,7 @@ static void pbap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *
|
||||
while (i<data_len){
|
||||
uint8_t tag = data[i++];
|
||||
uint8_t len = data[i++];
|
||||
if (tag == PBAP_APPLICATION_PARAMETER_PHONEBOOK_SIZE && len == 2){
|
||||
if ((tag == PBAP_APPLICATION_PARAMETER_PHONEBOOK_SIZE) && (len == 2)){
|
||||
have_size = 1;
|
||||
phonebook_size = big_endian_read_16(data, i);
|
||||
}
|
||||
@ -854,8 +854,8 @@ static void pbap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *
|
||||
case OBEX_RESP_SUCCESS:
|
||||
for (obex_iterator_init_with_response_packet(&it, goep_client_get_request_opcode(pbap_client->goep_cid), packet, size); obex_iterator_has_more(&it) ; obex_iterator_next(&it)){
|
||||
uint8_t hi = obex_iterator_get_hi(&it);
|
||||
if (hi == OBEX_HEADER_END_OF_BODY ||
|
||||
hi == OBEX_HEADER_BODY){
|
||||
if ((hi == OBEX_HEADER_END_OF_BODY) ||
|
||||
(hi == OBEX_HEADER_BODY)){
|
||||
// uint16_t data_len = obex_iterator_get_data_len(&it);
|
||||
// const uint8_t * data = obex_iterator_get_data(&it);
|
||||
// now try parsing it
|
||||
|
@ -527,7 +527,7 @@ static rfcomm_channel_t * rfcomm_channel_for_multiplexer_and_dlci(rfcomm_multipl
|
||||
btstack_linked_item_t *it;
|
||||
for (it = (btstack_linked_item_t *) rfcomm_channels; it ; it = it->next){
|
||||
rfcomm_channel_t * channel = ((rfcomm_channel_t *) it);
|
||||
if (channel->dlci == dlci && channel->multiplexer == multiplexer) {
|
||||
if ((channel->dlci == dlci) && (channel->multiplexer == multiplexer)) {
|
||||
return channel;
|
||||
};
|
||||
}
|
||||
@ -1444,7 +1444,7 @@ static void rfcomm_channel_packet_handler_uih(rfcomm_multiplexer_t *multiplexer,
|
||||
}
|
||||
|
||||
// contains payload?
|
||||
if (size - 1 > payload_offset){
|
||||
if ((size - 1) > payload_offset){
|
||||
|
||||
// log_info( "RFCOMM data UIH_PF, size %u, channel %p", size-payload_offset-1, rfChannel->connection);
|
||||
|
||||
@ -1459,7 +1459,7 @@ static void rfcomm_channel_packet_handler_uih(rfcomm_multiplexer_t *multiplexer,
|
||||
}
|
||||
|
||||
// automatically provide new credits to remote device, if no incoming flow control
|
||||
if (!channel->incoming_flow_control && channel->credits_incoming < 5){
|
||||
if (!channel->incoming_flow_control && (channel->credits_incoming < 5)){
|
||||
channel->new_credits_incoming = RFCOMM_CREDITS;
|
||||
request_can_send_now = 1;
|
||||
}
|
||||
@ -1737,7 +1737,7 @@ static void rfcomm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t
|
||||
// rfcomm: (0) addr [76543 server channel] [2 direction: initiator uses 1] [1 C/R: CMD by initiator = 1] [0 EA=1]
|
||||
const uint8_t frame_dlci = packet[0] >> 2;
|
||||
|
||||
if (frame_dlci && (packet[1] == BT_RFCOMM_UIH || packet[1] == BT_RFCOMM_UIH_PF)) {
|
||||
if (frame_dlci && ((packet[1] == BT_RFCOMM_UIH) || (packet[1] == BT_RFCOMM_UIH_PF))) {
|
||||
rfcomm_channel_packet_handler_uih(multiplexer, packet, size);
|
||||
return;
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ static void sdp_parser_process_byte(uint8_t eventByte){
|
||||
record_offset = 0;
|
||||
// log_debug("parser: List offset %u, list size %u", list_offset, list_size);
|
||||
|
||||
if (list_size > 0 && list_offset != list_size){
|
||||
if ((list_size > 0) && (list_offset != list_size)){
|
||||
record_counter++;
|
||||
state = GET_RECORD_LENGTH;
|
||||
log_debug("parser: END_OF_RECORD");
|
||||
@ -359,10 +359,10 @@ static void sdp_client_send_request(uint16_t channel){
|
||||
static void sdp_client_parse_service_search_attribute_response(uint8_t* packet, uint16_t size){
|
||||
|
||||
uint16_t offset = 3;
|
||||
if (offset + 2 + 2 > size) return; // parameterLength + attributeListByteCount
|
||||
if ((offset + 2 + 2) > size) return; // parameterLength + attributeListByteCount
|
||||
uint16_t parameterLength = big_endian_read_16(packet,offset);
|
||||
offset+=2;
|
||||
if (offset + parameterLength > size) return;
|
||||
if ((offset + parameterLength) > size) return;
|
||||
|
||||
// AttributeListByteCount <= mtu
|
||||
uint16_t attributeListByteCount = big_endian_read_16(packet,offset);
|
||||
@ -373,12 +373,12 @@ static void sdp_client_parse_service_search_attribute_response(uint8_t* packet,
|
||||
}
|
||||
|
||||
// AttributeLists
|
||||
if (offset + attributeListByteCount > size) return;
|
||||
if ((offset + attributeListByteCount) > size) return;
|
||||
sdp_client_parse_attribute_lists(packet+offset, attributeListByteCount);
|
||||
offset+=attributeListByteCount;
|
||||
|
||||
// continuation state len
|
||||
if (offset + 1 > size) return;
|
||||
if ((offset + 1) > size) return;
|
||||
continuationStateLen = packet[offset];
|
||||
offset++;
|
||||
if (continuationStateLen > 16){
|
||||
@ -388,7 +388,7 @@ static void sdp_client_parse_service_search_attribute_response(uint8_t* packet,
|
||||
}
|
||||
|
||||
// continuation state
|
||||
if (offset + continuationStateLen > size) return;
|
||||
if ((offset + continuationStateLen) > size) return;
|
||||
memcpy(continuationState, packet+offset, continuationStateLen);
|
||||
// offset+=continuationStateLen;
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ static void sdp_client_query_rfcomm_handle_service_name_data(uint32_t attribute_
|
||||
}
|
||||
|
||||
// notify on last char
|
||||
if (data_offset == attribute_value_length - 1 && sdp_rfcomm_channel_nr!=0){
|
||||
if (data_offset == (attribute_value_length - 1) && (sdp_rfcomm_channel_nr!=0)){
|
||||
sdp_rfcomm_query_emit_service();
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ int sdp_handle_service_search_request(uint8_t * packet, uint16_t remote_mtu){
|
||||
if (param_len < 1) return 0;
|
||||
uint8_t * continuationState = &packet[5+serviceSearchPatternLen+2];
|
||||
// assert continuation state is contained in param_len
|
||||
if (1 + continuationState[0] > param_len) return 0;
|
||||
if ((1 + continuationState[0]) > param_len) return 0;
|
||||
|
||||
// calc maximumServiceRecordCount based on remote MTU
|
||||
uint16_t maxNrServiceRecordsPerResponse = (remote_mtu - (9+3))/4;
|
||||
@ -283,7 +283,7 @@ int sdp_handle_service_attribute_request(uint8_t * packet, uint16_t remote_mtu){
|
||||
if (param_len < 1) return 0;
|
||||
uint8_t * continuationState = &packet[11+attributeIDListLen];
|
||||
// assert continuation state is contained in param_len
|
||||
if (1 + continuationState[0] > param_len) return 0;
|
||||
if ((1 + continuationState[0]) > param_len) return 0;
|
||||
|
||||
// calc maximumAttributeByteCount based on remote MTU
|
||||
uint16_t maximumAttributeByteCount2 = remote_mtu - (7+3);
|
||||
@ -383,7 +383,7 @@ int sdp_handle_service_search_attribute_request(uint8_t * packet, uint16_t remot
|
||||
if (param_len < 1) return 0;
|
||||
uint8_t * continuationState = &packet[5+serviceSearchPatternLen+2+attributeIDListLen];
|
||||
// assert continuation state is contained in param_len
|
||||
if (1 + continuationState[0] > param_len) return 0;
|
||||
if ((1 + continuationState[0]) > param_len) return 0;
|
||||
|
||||
// calc maximumAttributeByteCount based on remote MTU, SDP header and reserved Continuation block
|
||||
uint16_t maximumAttributeByteCount2 = remote_mtu - 12;
|
||||
@ -406,7 +406,7 @@ int sdp_handle_service_search_attribute_request(uint8_t * packet, uint16_t remot
|
||||
uint16_t pos = 7;
|
||||
|
||||
// add DES with total size for first request
|
||||
if (continuation_service_index == 0 && continuation_offset == 0){
|
||||
if ((continuation_service_index == 0) && (continuation_offset == 0)){
|
||||
uint16_t total_response_size = sdp_get_size_for_service_search_attribute_response(serviceSearchPattern, attributeIDList);
|
||||
de_store_descriptor_with_len(&sdp_response_buffer[pos], DE_DES, DE_SIZE_VAR_16, total_response_size);
|
||||
// log_info("total response size %u", total_response_size);
|
||||
@ -431,7 +431,7 @@ int sdp_handle_service_search_attribute_request(uint8_t * packet, uint16_t remot
|
||||
uint16_t filtered_attributes_size = spd_get_filtered_size(item->service_record, attributeIDList);
|
||||
|
||||
// stop if complete record doesn't fits into response but we already have a partial response
|
||||
if ((filtered_attributes_size + 3 > maximumAttributeByteCount) && !first_answer) {
|
||||
if (((filtered_attributes_size + 3) > maximumAttributeByteCount) && !first_answer) {
|
||||
continuation = 1;
|
||||
break;
|
||||
}
|
||||
@ -527,7 +527,7 @@ static void sdp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
|
||||
remote_mtu = SDP_RESPONSE_BUFFER_SIZE;
|
||||
}
|
||||
// validate parm_len against packet size
|
||||
if (param_len + 5 > size) {
|
||||
if ((param_len + 5) > size) {
|
||||
// just clear pdu_id
|
||||
pdu_id = SDP_ErrorResponse;
|
||||
}
|
||||
|
@ -397,7 +397,7 @@ static int sdp_traversal_append_attributes(uint16_t attributeID, uint8_t * attri
|
||||
// DES_HEADER(3) + DES_DATA + (UINT16(3) + attribute)
|
||||
uint16_t data_size = big_endian_read_16(context->buffer, 1);
|
||||
int attribute_len = de_get_len(attributeValue);
|
||||
if (3 + data_size + (3 + attribute_len) <= context->maxBytes) {
|
||||
if ((3 + data_size + (3 + attribute_len)) <= context->maxBytes) {
|
||||
// copy Attribute
|
||||
de_add_number(context->buffer, DE_UINT, DE_SIZE_16, attributeID);
|
||||
data_size += 3; // 3 bytes
|
||||
|
@ -340,7 +340,7 @@ static void hci_connection_timeout_handler(btstack_timer_source_t *timer){
|
||||
hci_emit_l2cap_check_timeout(connection);
|
||||
}
|
||||
#else
|
||||
if (btstack_run_loop_get_time_ms() > connection->timestamp + HCI_CONNECTION_TIMEOUT_MS){
|
||||
if (btstack_run_loop_get_time_ms() > (connection->timestamp + HCI_CONNECTION_TIMEOUT_MS)){
|
||||
// connections might be timed out
|
||||
hci_emit_l2cap_check_timeout(connection);
|
||||
}
|
||||
|
@ -636,10 +636,10 @@ static void hci_transport_h5_process_frame(uint16_t frame_size){
|
||||
}
|
||||
|
||||
// Process ACKs in reliable packet and explicit ack packets
|
||||
if (reliable_packet || link_packet_type == LINK_ACKNOWLEDGEMENT_TYPE){
|
||||
if (reliable_packet || (link_packet_type == LINK_ACKNOWLEDGEMENT_TYPE)){
|
||||
// our packet is good if the remote expects our seq nr + 1
|
||||
int next_seq_nr = hci_transport_link_inc_seq_nr(link_seq_nr);
|
||||
if (hci_transport_link_have_outgoing_packet() && next_seq_nr == ack_nr){
|
||||
if (hci_transport_link_have_outgoing_packet() && (next_seq_nr == ack_nr)){
|
||||
log_debug("outoing packet with seq %u ack'ed", link_seq_nr);
|
||||
link_seq_nr = next_seq_nr;
|
||||
hci_transport_link_clear_queue();
|
||||
@ -742,7 +742,7 @@ static void hci_transport_h5_block_received(){
|
||||
if (hci_transport_h5_active == 0) return;
|
||||
|
||||
// track start time when receiving first byte // a bit hackish
|
||||
if (hci_transport_h5_receive_start == 0 && hci_transport_link_read_byte != BTSTACK_SLIP_SOF){
|
||||
if ((hci_transport_h5_receive_start == 0) && (hci_transport_link_read_byte != BTSTACK_SLIP_SOF)){
|
||||
hci_transport_h5_receive_start = btstack_run_loop_get_time_ms();
|
||||
}
|
||||
btstack_slip_decoder_process(hci_transport_link_read_byte);
|
||||
|
20
src/l2cap.c
20
src/l2cap.c
@ -1038,7 +1038,7 @@ void l2cap_emit_channel_opened(l2cap_channel_t *channel, uint8_t status) {
|
||||
little_endian_store_16(event, 17, channel->local_mtu);
|
||||
little_endian_store_16(event, 19, channel->remote_mtu);
|
||||
little_endian_store_16(event, 21, channel->flush_timeout);
|
||||
event[23] = channel->state_var & L2CAP_CHANNEL_STATE_VAR_INCOMING ? 1 : 0;
|
||||
event[23] = (channel->state_var & L2CAP_CHANNEL_STATE_VAR_INCOMING) ? 1 : 0;
|
||||
#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
|
||||
log_info("ERTM mode %u, fcs enabled %u", channel->mode, channel->fcs_option);
|
||||
event[24] = channel->mode;
|
||||
@ -1820,7 +1820,7 @@ static void l2cap_run(void){
|
||||
hci_connections_get_iterator(&it);
|
||||
while(btstack_linked_list_iterator_has_next(&it)){
|
||||
hci_connection_t * connection = (hci_connection_t *) btstack_linked_list_iterator_next(&it);
|
||||
if (connection->address_type != BD_ADDR_TYPE_LE_PUBLIC && connection->address_type != BD_ADDR_TYPE_LE_RANDOM) continue;
|
||||
if ((connection->address_type != BD_ADDR_TYPE_LE_PUBLIC) && (connection->address_type != BD_ADDR_TYPE_LE_RANDOM)) continue;
|
||||
if (!hci_can_send_acl_packet_now(connection->con_handle)) continue;
|
||||
switch (connection->le_con_parameter_update_state){
|
||||
case CON_PARAMETER_UPDATE_SEND_REQUEST:
|
||||
@ -2515,7 +2515,7 @@ static void l2cap_signaling_handle_configure_request(l2cap_channel_t *channel, u
|
||||
pos++;
|
||||
uint8_t length = command[pos++];
|
||||
// MTU { type(8): 1, len(8):2, MTU(16) }
|
||||
if (option_type == L2CAP_CONFIG_OPTION_TYPE_MAX_TRANSMISSION_UNIT && length == 2){
|
||||
if ((option_type == L2CAP_CONFIG_OPTION_TYPE_MAX_TRANSMISSION_UNIT) && (length == 2)){
|
||||
channel->remote_mtu = little_endian_read_16(command, pos);
|
||||
log_info("Remote MTU %u", channel->remote_mtu);
|
||||
if (channel->remote_mtu > l2cap_max_mtu()){
|
||||
@ -2525,7 +2525,7 @@ static void l2cap_signaling_handle_configure_request(l2cap_channel_t *channel, u
|
||||
channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_MTU);
|
||||
}
|
||||
// Flush timeout { type(8):2, len(8): 2, Flush Timeout(16)}
|
||||
if (option_type == L2CAP_CONFIG_OPTION_TYPE_FLUSH_TIMEOUT && length == 2){
|
||||
if (option_type == L2CAP_CONFIG_OPTION_TYPE_FLUSH_TIMEOUT && (length == 2)){
|
||||
channel->flush_timeout = little_endian_read_16(command, pos);
|
||||
log_info("Flush timeout: %u ms", channel->flush_timeout);
|
||||
}
|
||||
@ -2580,7 +2580,7 @@ static void l2cap_signaling_handle_configure_request(l2cap_channel_t *channel, u
|
||||
}
|
||||
#endif
|
||||
// check for unknown options
|
||||
if (option_hint == 0 && (option_type < L2CAP_CONFIG_OPTION_TYPE_MAX_TRANSMISSION_UNIT || option_type > L2CAP_CONFIG_OPTION_TYPE_EXTENDED_WINDOW_SIZE)){
|
||||
if ((option_hint == 0) && ((option_type < L2CAP_CONFIG_OPTION_TYPE_MAX_TRANSMISSION_UNIT) || option_type > L2CAP_CONFIG_OPTION_TYPE_EXTENDED_WINDOW_SIZE)){
|
||||
log_info("l2cap cid %u, unknown options", channel->local_cid);
|
||||
channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_INVALID);
|
||||
}
|
||||
@ -2720,7 +2720,7 @@ static void l2cap_signaling_handler_channel(l2cap_channel_t *channel, uint8_t *c
|
||||
l2cap_handle_channel_open_failed(channel, L2CAP_CONNECTION_RESPONSE_RESULT_SUCCESSFUL + result);
|
||||
|
||||
// drop link key if security block
|
||||
if (L2CAP_CONNECTION_RESPONSE_RESULT_SUCCESSFUL + result == L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_SECURITY){
|
||||
if ((L2CAP_CONNECTION_RESPONSE_RESULT_SUCCESSFUL + result) == L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_SECURITY){
|
||||
gap_drop_link_key_for_bd_addr(channel->address);
|
||||
}
|
||||
|
||||
@ -2839,7 +2839,7 @@ static void l2cap_signaling_handler_dispatch(hci_con_handle_t handle, uint8_t *
|
||||
uint16_t cmd_len = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET);
|
||||
|
||||
// not for a particular channel, and not CONNECTION_REQUEST, ECHO_[REQUEST|RESPONSE], INFORMATION_RESPONSE
|
||||
if (code < 1 || code == ECHO_RESPONSE || code > INFORMATION_RESPONSE){
|
||||
if ((code < 1) || code == ECHO_RESPONSE || code > INFORMATION_RESPONSE){
|
||||
l2cap_register_signaling_response(handle, COMMAND_REJECT, sig_id, 0, L2CAP_REJ_CMD_UNKNOWN);
|
||||
return;
|
||||
}
|
||||
@ -3555,7 +3555,7 @@ static void l2cap_acl_le_handler(hci_con_handle_t handle, uint8_t *packet, uint1
|
||||
l2cap_channel->credits_incoming--;
|
||||
|
||||
// automatic credits
|
||||
if (l2cap_channel->credits_incoming < L2CAP_LE_DATA_CHANNELS_AUTOMATIC_CREDITS_WATERMARK && l2cap_channel->automatic_credits){
|
||||
if ((l2cap_channel->credits_incoming < L2CAP_LE_DATA_CHANNELS_AUTOMATIC_CREDITS_WATERMARK) && l2cap_channel->automatic_credits){
|
||||
l2cap_channel->new_credits_incoming = L2CAP_LE_DATA_CHANNELS_AUTOMATIC_CREDITS_INCREMENT;
|
||||
}
|
||||
|
||||
@ -3740,7 +3740,7 @@ static void l2cap_emit_le_channel_opened(l2cap_channel_t *channel, uint8_t statu
|
||||
event[3] = channel->address_type;
|
||||
reverse_bd_addr(channel->address, &event[4]);
|
||||
little_endian_store_16(event, 10, channel->con_handle);
|
||||
event[12] = channel->state_var & L2CAP_CHANNEL_STATE_VAR_INCOMING ? 1 : 0;
|
||||
event[12] = (channel->state_var & L2CAP_CHANNEL_STATE_VAR_INCOMING) ? 1 : 0;
|
||||
little_endian_store_16(event, 13, channel->psm);
|
||||
little_endian_store_16(event, 15, channel->local_cid);
|
||||
little_endian_store_16(event, 17, channel->remote_cid);
|
||||
@ -3787,7 +3787,7 @@ static void l2cap_le_send_pdu(l2cap_channel_t *channel){
|
||||
|
||||
hci_send_acl_packet_buffer(8 + pos);
|
||||
|
||||
if (channel->send_sdu_pos >= channel->send_sdu_len + 2){
|
||||
if (channel->send_sdu_pos >= (channel->send_sdu_len + 2)){
|
||||
channel->send_sdu_buffer = NULL;
|
||||
// send done event
|
||||
l2cap_emit_simple_event_with_cid(channel, L2CAP_EVENT_LE_PACKET_SENT);
|
||||
|
@ -82,7 +82,7 @@ static const unsigned int num_l2cap_commands = sizeof(l2cap_signaling_commands_f
|
||||
static uint16_t l2cap_create_signaling_internal(uint8_t * acl_buffer, hci_con_handle_t handle, uint16_t cid, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
|
||||
|
||||
const char *format = NULL;
|
||||
if (cmd > 0 && cmd <= num_l2cap_commands) {
|
||||
if ((cmd > 0) && (cmd <= num_l2cap_commands)) {
|
||||
format = l2cap_signaling_commands_format[cmd-1];
|
||||
}
|
||||
if (!format){
|
||||
|
Loading…
x
Reference in New Issue
Block a user