Skip to content

Commit 1da2994

Browse files
authored
Merge pull request #59 from pan-apple/platform-layer
Import software update manager generic code
2 parents 608aba1 + 58641f2 commit 1da2994

27 files changed

+2427
-214
lines changed

src/ble/BLEEndPoint.cpp

+67-67
Large diffs are not rendered by default.

src/ble/BleLayer.cpp

+19-19
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ BLE_ERROR BleLayer::NewBleEndPoint(BLEEndPoint ** retEndPoint, BLE_CONNECTION_OB
376376
*retEndPoint = sBLEEndPointPool.GetFree();
377377
if (*retEndPoint == NULL)
378378
{
379-
chipLogError(Ble, "%s endpoint pool FULL", "Ble");
379+
ChipLogError(Ble, "%s endpoint pool FULL", "Ble");
380380
return BLE_ERROR_NO_ENDPOINTS;
381381
}
382382

@@ -421,7 +421,7 @@ BLE_ERROR BleLayer::HandleBleTransportConnectionInitiated(BLE_CONNECTION_OBJECT
421421

422422
if (err != BLE_NO_ERROR)
423423
{
424-
chipLogError(Ble, "HandlechipConnectionReceived failed, err = %d", err);
424+
ChipLogError(Ble, "HandlechipConnectionReceived failed, err = %d", err);
425425
}
426426

427427
return err;
@@ -432,15 +432,15 @@ bool BleLayer::HandleWriteReceived(BLE_CONNECTION_OBJECT connObj, const chipBleU
432432
{
433433
if (!UUIDsMatch(&CHIP_BLE_SVC_ID, svcId))
434434
{
435-
chipLogError(Ble, "ble write rcvd on unknown svc id");
435+
ChipLogError(Ble, "ble write rcvd on unknown svc id");
436436
ExitNow();
437437
}
438438

439439
if (UUIDsMatch(&CHIP_BLE_CHAR_1_ID, charId))
440440
{
441441
if (pBuf == NULL)
442442
{
443-
chipLogError(Ble, "rcvd null ble write");
443+
ChipLogError(Ble, "rcvd null ble write");
444444
ExitNow();
445445
}
446446

@@ -453,7 +453,7 @@ bool BleLayer::HandleWriteReceived(BLE_CONNECTION_OBJECT connObj, const chipBleU
453453
pBuf = NULL;
454454
if (status != BLE_NO_ERROR)
455455
{
456-
chipLogError(Ble, "BLEEndPoint rcv failed, err = %d", status);
456+
ChipLogError(Ble, "BLEEndPoint rcv failed, err = %d", status);
457457
}
458458
}
459459
else
@@ -462,13 +462,13 @@ bool BleLayer::HandleWriteReceived(BLE_CONNECTION_OBJECT connObj, const chipBleU
462462
pBuf = NULL;
463463
if (status != BLE_NO_ERROR)
464464
{
465-
chipLogError(Ble, "failed handle new chip BLE connection, status = %d", status);
465+
ChipLogError(Ble, "failed handle new chip BLE connection, status = %d", status);
466466
}
467467
}
468468
}
469469
else
470470
{
471-
chipLogError(Ble, "ble write rcvd on unknown char");
471+
ChipLogError(Ble, "ble write rcvd on unknown char");
472472
}
473473

474474
exit:
@@ -492,7 +492,7 @@ bool BleLayer::HandleIndicationReceived(BLE_CONNECTION_OBJECT connObj, const chi
492492
{
493493
if (pBuf == NULL)
494494
{
495-
chipLogError(Ble, "rcvd null ble indication");
495+
ChipLogError(Ble, "rcvd null ble indication");
496496
ExitNow();
497497
}
498498

@@ -505,17 +505,17 @@ bool BleLayer::HandleIndicationReceived(BLE_CONNECTION_OBJECT connObj, const chi
505505
pBuf = NULL;
506506
if (status != BLE_NO_ERROR)
507507
{
508-
chipLogError(Ble, "BLEEndPoint rcv failed, err = %d", status);
508+
ChipLogError(Ble, "BLEEndPoint rcv failed, err = %d", status);
509509
}
510510
}
511511
else
512512
{
513-
chipLogDetail(Ble, "no endpoint for rcvd indication");
513+
ChipLogDetail(Ble, "no endpoint for rcvd indication");
514514
}
515515
}
516516
else
517517
{
518-
chipLogError(Ble, "ble ind rcvd on unknown char");
518+
ChipLogError(Ble, "ble ind rcvd on unknown char");
519519
}
520520

521521
exit:
@@ -540,7 +540,7 @@ bool BleLayer::HandleWriteConfirmation(BLE_CONNECTION_OBJECT connObj, const chip
540540
}
541541
else
542542
{
543-
chipLogError(Ble, "ble write con rcvd on unknown char");
543+
ChipLogError(Ble, "ble write con rcvd on unknown char");
544544
}
545545

546546
return true;
@@ -559,7 +559,7 @@ bool BleLayer::HandleIndicationConfirmation(BLE_CONNECTION_OBJECT connObj, const
559559
}
560560
else
561561
{
562-
chipLogError(Ble, "ble ind con rcvd on unknown char");
562+
ChipLogError(Ble, "ble ind con rcvd on unknown char");
563563
}
564564

565565
return true;
@@ -576,12 +576,12 @@ void BleLayer::HandleAckReceived(BLE_CONNECTION_OBJECT connObj)
576576

577577
if (status != BLE_NO_ERROR)
578578
{
579-
chipLogError(Ble, "endpoint conf recvd failed, err = %d", status);
579+
ChipLogError(Ble, "endpoint conf recvd failed, err = %d", status);
580580
}
581581
}
582582
else
583583
{
584-
chipLogError(Ble, "no endpoint for BLE sent data ack");
584+
ChipLogError(Ble, "no endpoint for BLE sent data ack");
585585
}
586586
}
587587

@@ -603,7 +603,7 @@ bool BleLayer::HandleSubscribeReceived(BLE_CONNECTION_OBJECT connObj, const chip
603603
}
604604
else
605605
{
606-
chipLogError(Ble, "no endpoint for sub recvd");
606+
ChipLogError(Ble, "no endpoint for sub recvd");
607607
}
608608
}
609609

@@ -627,7 +627,7 @@ bool BleLayer::HandleSubscribeComplete(BLE_CONNECTION_OBJECT connObj, const chip
627627
}
628628
else
629629
{
630-
chipLogError(Ble, "no endpoint for sub complete");
630+
ChipLogError(Ble, "no endpoint for sub complete");
631631
}
632632
}
633633

@@ -652,7 +652,7 @@ bool BleLayer::HandleUnsubscribeReceived(BLE_CONNECTION_OBJECT connObj, const ch
652652
}
653653
else
654654
{
655-
chipLogError(Ble, "no endpoint for unsub recvd");
655+
ChipLogError(Ble, "no endpoint for unsub recvd");
656656
}
657657
}
658658

@@ -677,7 +677,7 @@ bool BleLayer::HandleUnsubscribeComplete(BLE_CONNECTION_OBJECT connObj, const ch
677677
}
678678
else
679679
{
680-
chipLogError(Ble, "no endpoint for unsub complete");
680+
ChipLogError(Ble, "no endpoint for unsub complete");
681681
}
682682
}
683683

src/ble/CHIPoBle.cpp

+37-37
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
#undef CHIP_BTP_PROTOCOL_ENGINE_DEBUG_LOGGING_ENABLED
4141

4242
#ifdef CHIP_BTP_PROTOCOL_ENGINE_DEBUG_LOGGING_ENABLED
43-
#define chipLogDebugBtpEngine(MOD, MSG, ...) chipLogError(MOD, MSG, ##__VA_ARGS__)
43+
#define ChipLogDebugBtpEngine(MOD, MSG, ...) ChipLogError(MOD, MSG, ##__VA_ARGS__)
4444
#else
45-
#define chipLogDebugBtpEngine(MOD, MSG, ...)
45+
#define ChipLogDebugBtpEngine(MOD, MSG, ...)
4646
#endif
4747

4848
#define CHIP_BLE_TRANSFER_PROTOCOL_HEADER_FLAGS_SIZE 1 // Size in bytes of enocded BTP fragment header flag bits
@@ -83,7 +83,7 @@ static void PrintBufDebug(PacketBuffer * buf)
8383

8484
for (int i = 0; i < buf->DataLength(); i++)
8585
{
86-
chipLogError(Ble, "\t%02x", b[i]);
86+
ChipLogError(Ble, "\t%02x", b[i]);
8787
}
8888
#endif
8989
}
@@ -166,13 +166,13 @@ bool CHIPoBle::HasUnackedData() const
166166

167167
bool CHIPoBle::IsValidAck(SequenceNumber_t ack_num) const
168168
{
169-
chipLogDebugBtpEngine(Ble, "entered IsValidAck, ack = %u, oldest = %u, newest = %u", ack_num, mTxOldestUnackedSeqNum,
169+
ChipLogDebugBtpEngine(Ble, "entered IsValidAck, ack = %u, oldest = %u, newest = %u", ack_num, mTxOldestUnackedSeqNum,
170170
mTxNewestUnackedSeqNum);
171171

172172
// Return false if not awaiting any ack.
173173
if (!mExpectingAck)
174174
{
175-
chipLogDebugBtpEngine(Ble, "unexpected ack is invalid");
175+
ChipLogDebugBtpEngine(Ble, "unexpected ack is invalid");
176176
return false;
177177
}
178178

@@ -192,7 +192,7 @@ BLE_ERROR CHIPoBle::HandleAckReceived(SequenceNumber_t ack_num)
192192
{
193193
BLE_ERROR err = BLE_NO_ERROR;
194194

195-
chipLogDebugBtpEngine(Ble, "entered HandleAckReceived, ack_num = %u", ack_num);
195+
ChipLogDebugBtpEngine(Ble, "entered HandleAckReceived, ack_num = %u", ack_num);
196196

197197
// Ensure ack_num falls within range of ack values we're expecting.
198198
VerifyOrExit(IsValidAck(ack_num), err = BLE_ERROR_INVALID_ACK);
@@ -234,7 +234,7 @@ BLE_ERROR CHIPoBle::EncodeStandAloneAck(PacketBuffer * data)
234234

235235
// Acknowledge most recently received sequence number.
236236
characteristic[1] = GetAndRecordRxAckSeqNum();
237-
chipLogDebugBtpEngine(Ble, "===> encoded stand-alone ack = %u", characteristic[1]);
237+
ChipLogDebugBtpEngine(Ble, "===> encoded stand-alone ack = %u", characteristic[1]);
238238

239239
// Include sequence number for stand-alone ack itself.
240240
characteristic[2] = GetAndIncrementNextTxSeqNum();
@@ -313,7 +313,7 @@ BLE_ERROR CHIPoBle::HandleCharacteristicReceived(PacketBuffer * data, SequenceNu
313313
// mRxFragnentSize may be smaller than the characteristic size.
314314
data->SetDataLength(chip::min(data->DataLength(), mRxFragmentSize));
315315

316-
chipLogDebugBtpEngine(Ble, ">>> BTP reassembler received data:");
316+
ChipLogDebugBtpEngine(Ble, ">>> BTP reassembler received data:");
317317
PrintBufDebug(data);
318318

319319
if (mRxState == kState_Idle)
@@ -386,14 +386,14 @@ BLE_ERROR CHIPoBle::HandleCharacteristicReceived(PacketBuffer * data, SequenceNu
386386
mRxState = kState_Error;
387387

388388
// Dump protocol engine state, plus header flags and received data length.
389-
chipLogError(Ble, "HandleCharacteristicReceived failed, err = %d, rx_flags = %u", err, rx_flags);
389+
ChipLogError(Ble, "HandleCharacteristicReceived failed, err = %d, rx_flags = %u", err, rx_flags);
390390
if (didReceiveAck)
391391
{
392-
chipLogError(Ble, "With rx'd ack = %u", receivedAck);
392+
ChipLogError(Ble, "With rx'd ack = %u", receivedAck);
393393
}
394394
if (mRxBuf != NULL)
395395
{
396-
chipLogError(Ble, "With rx buf data length = %u", mRxBuf->DataLength());
396+
ChipLogError(Ble, "With rx buf data length = %u", mRxBuf->DataLength());
397397
}
398398
LogState();
399399

@@ -442,7 +442,7 @@ bool CHIPoBle::HandleCharacteristicSend(PacketBuffer * data, bool send_ack)
442442

443443
if (send_ack && !HasUnackedData())
444444
{
445-
chipLogError(Ble, "HandleCharacteristicSend: send_ack true, but nothing to acknowledge.");
445+
ChipLogError(Ble, "HandleCharacteristicSend: send_ack true, but nothing to acknowledge.");
446446
return false;
447447
}
448448

@@ -457,7 +457,7 @@ bool CHIPoBle::HandleCharacteristicSend(PacketBuffer * data, bool send_ack)
457457
mTxState = kState_InProgress;
458458
mTxLength = mTxBuf->DataLength();
459459

460-
chipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send whole message:");
460+
ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send whole message:");
461461
PrintBufDebug(data);
462462

463463
// Determine fragment header size.
@@ -468,7 +468,7 @@ bool CHIPoBle::HandleCharacteristicSend(PacketBuffer * data, bool send_ack)
468468
if (!mTxBuf->EnsureReservedSize(header_size + CHIP_CONFIG_BLE_PKT_RESERVED_SIZE))
469469
{
470470
// handle error
471-
chipLogError(Ble, "HandleCharacteristicSend: not enough headroom");
471+
ChipLogError(Ble, "HandleCharacteristicSend: not enough headroom");
472472
mTxState = kState_Error;
473473
mTxBuf = NULL; // Avoid double-free after assignment above, as caller frees data on error.
474474

@@ -492,7 +492,7 @@ bool CHIPoBle::HandleCharacteristicSend(PacketBuffer * data, bool send_ack)
492492
{
493493
SetFlag(characteristic[0], kHeaderFlag_FragmentAck, true);
494494
characteristic[cursor++] = GetAndRecordRxAckSeqNum();
495-
chipLogDebugBtpEngine(Ble, "===> encoded piggybacked ack, ack_num = %u", characteristic[cursor - 1]);
495+
ChipLogDebugBtpEngine(Ble, "===> encoded piggybacked ack, ack_num = %u", characteristic[cursor - 1]);
496496
}
497497

498498
characteristic[cursor++] = GetAndIncrementNextTxSeqNum();
@@ -513,7 +513,7 @@ bool CHIPoBle::HandleCharacteristicSend(PacketBuffer * data, bool send_ack)
513513
mTxLength -= mTxFragmentSize - cursor;
514514
}
515515

516-
chipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send first fragment:");
516+
ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send first fragment:");
517517
PrintBufDebug(data);
518518
}
519519
else if (mTxState == kState_InProgress)
@@ -545,7 +545,7 @@ bool CHIPoBle::HandleCharacteristicSend(PacketBuffer * data, bool send_ack)
545545
{
546546
SetFlag(characteristic[0], kHeaderFlag_FragmentAck, true);
547547
characteristic[cursor++] = GetAndRecordRxAckSeqNum();
548-
chipLogDebugBtpEngine(Ble, "===> encoded piggybacked ack, ack_num = %u", characteristic[cursor - 1]);
548+
ChipLogDebugBtpEngine(Ble, "===> encoded piggybacked ack, ack_num = %u", characteristic[cursor - 1]);
549549
}
550550

551551
characteristic[cursor++] = GetAndIncrementNextTxSeqNum();
@@ -564,7 +564,7 @@ bool CHIPoBle::HandleCharacteristicSend(PacketBuffer * data, bool send_ack)
564564
mTxLength -= mTxFragmentSize - cursor;
565565
}
566566

567-
chipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send additional fragment:");
567+
ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send additional fragment:");
568568
PrintBufDebug(mTxBuf);
569569
}
570570
else
@@ -596,25 +596,25 @@ bool CHIPoBle::ClearTxPacket()
596596

597597
void CHIPoBle::LogState() const
598598
{
599-
chipLogError(Ble, "mAppState: %p", mAppState);
600-
601-
chipLogError(Ble, "mRxFragmentSize: %d", mRxFragmentSize);
602-
chipLogError(Ble, "mRxState: %d", mRxState);
603-
chipLogError(Ble, "mRxBuf: %p", mRxBuf);
604-
chipLogError(Ble, "mRxNextSeqNum: %d", mRxNextSeqNum);
605-
chipLogError(Ble, "mRxNewestUnackedSeqNum: %d", mRxNewestUnackedSeqNum);
606-
chipLogError(Ble, "mRxOldestUnackedSeqNum: %d", mRxOldestUnackedSeqNum);
607-
chipLogError(Ble, "mRxCharCount: %d", mRxCharCount);
608-
chipLogError(Ble, "mRxPacketCount: %d", mRxPacketCount);
609-
610-
chipLogError(Ble, "mTxFragmentSize: %d", mTxFragmentSize);
611-
chipLogError(Ble, "mTxState: %d", mTxState);
612-
chipLogError(Ble, "mTxBuf: %p", mTxBuf);
613-
chipLogError(Ble, "mTxNextSeqNum: %d", mTxNextSeqNum);
614-
chipLogError(Ble, "mTxNewestUnackedSeqNum: %d", mTxNewestUnackedSeqNum);
615-
chipLogError(Ble, "mTxOldestUnackedSeqNum: %d", mTxOldestUnackedSeqNum);
616-
chipLogError(Ble, "mTxCharCount: %d", mTxCharCount);
617-
chipLogError(Ble, "mTxPacketCount: %d", mTxPacketCount);
599+
ChipLogError(Ble, "mAppState: %p", mAppState);
600+
601+
ChipLogError(Ble, "mRxFragmentSize: %d", mRxFragmentSize);
602+
ChipLogError(Ble, "mRxState: %d", mRxState);
603+
ChipLogError(Ble, "mRxBuf: %p", mRxBuf);
604+
ChipLogError(Ble, "mRxNextSeqNum: %d", mRxNextSeqNum);
605+
ChipLogError(Ble, "mRxNewestUnackedSeqNum: %d", mRxNewestUnackedSeqNum);
606+
ChipLogError(Ble, "mRxOldestUnackedSeqNum: %d", mRxOldestUnackedSeqNum);
607+
ChipLogError(Ble, "mRxCharCount: %d", mRxCharCount);
608+
ChipLogError(Ble, "mRxPacketCount: %d", mRxPacketCount);
609+
610+
ChipLogError(Ble, "mTxFragmentSize: %d", mTxFragmentSize);
611+
ChipLogError(Ble, "mTxState: %d", mTxState);
612+
ChipLogError(Ble, "mTxBuf: %p", mTxBuf);
613+
ChipLogError(Ble, "mTxNextSeqNum: %d", mTxNextSeqNum);
614+
ChipLogError(Ble, "mTxNewestUnackedSeqNum: %d", mTxNewestUnackedSeqNum);
615+
ChipLogError(Ble, "mTxOldestUnackedSeqNum: %d", mTxOldestUnackedSeqNum);
616+
ChipLogError(Ble, "mTxCharCount: %d", mTxCharCount);
617+
ChipLogError(Ble, "mTxPacketCount: %d", mTxPacketCount);
618618
}
619619

620620
void CHIPoBle::LogStateDebug() const

0 commit comments

Comments
 (0)