diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index bb6997ccecd2ce..09f8b1c6412c6b 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -543,11 +543,11 @@ void InitServer(AppDelegate * delegate) // Register to receive unsolicited legacy ZCL messages from the exchange manager. err = gExchangeMgr.RegisterUnsolicitedMessageHandlerForProtocol(Protocols::TempZCL::Id, &gCallbacks); - VerifyOrExit(err == CHIP_NO_ERROR, err = CHIP_ERROR_NO_UNSOLICITED_MESSAGE_HANDLER); + SuccessOrExit(err); // Register to receive unsolicited Service Provisioning messages from the exchange manager. err = gExchangeMgr.RegisterUnsolicitedMessageHandlerForProtocol(Protocols::ServiceProvisioning::Id, &gCallbacks); - VerifyOrExit(err == CHIP_NO_ERROR, err = CHIP_ERROR_NO_UNSOLICITED_MESSAGE_HANDLER); + SuccessOrExit(err); err = gCASEServer.ListenForSessionEstablishment(&gExchangeMgr, &gTransports, &gSessions, &GetGlobalAdminPairingTable(), &gSessionIDAllocator); diff --git a/src/ble/BLEEndPoint.cpp b/src/ble/BLEEndPoint.cpp index a303f11727b309..137c1ddf4e2ac1 100644 --- a/src/ble/BLEEndPoint.cpp +++ b/src/ble/BLEEndPoint.cpp @@ -1428,7 +1428,7 @@ bool BLEEndPoint::SendIndication(PacketBufferHandle && buf) CHIP_ERROR BLEEndPoint::StartConnectTimer() { const CHIP_ERROR timerErr = mBle->mSystemLayer->StartTimer(BLE_CONNECT_TIMEOUT_MS, HandleConnectTimeout, this); - VerifyOrReturnError(timerErr == CHIP_NO_ERROR, BLE_ERROR_START_TIMER_FAILED); + ReturnErrorOnFailure(timerErr); mTimerStateFlags.Set(TimerStateFlag::kConnectTimerRunning); return CHIP_NO_ERROR; @@ -1437,7 +1437,7 @@ CHIP_ERROR BLEEndPoint::StartConnectTimer() CHIP_ERROR BLEEndPoint::StartReceiveConnectionTimer() { const CHIP_ERROR timerErr = mBle->mSystemLayer->StartTimer(BLE_CONNECT_TIMEOUT_MS, HandleReceiveConnectionTimeout, this); - VerifyOrReturnError(timerErr == CHIP_NO_ERROR, BLE_ERROR_START_TIMER_FAILED); + ReturnErrorOnFailure(timerErr); mTimerStateFlags.Set(TimerStateFlag::kReceiveConnectionTimerRunning); return CHIP_NO_ERROR; @@ -1448,7 +1448,7 @@ CHIP_ERROR BLEEndPoint::StartAckReceivedTimer() if (!mTimerStateFlags.Has(TimerStateFlag::kAckReceivedTimerRunning)) { const CHIP_ERROR timerErr = mBle->mSystemLayer->StartTimer(BTP_ACK_RECEIVED_TIMEOUT_MS, HandleAckReceivedTimeout, this); - VerifyOrReturnError(timerErr == CHIP_NO_ERROR, BLE_ERROR_START_TIMER_FAILED); + ReturnErrorOnFailure(timerErr); mTimerStateFlags.Set(TimerStateFlag::kAckReceivedTimerRunning); } @@ -1473,7 +1473,7 @@ CHIP_ERROR BLEEndPoint::StartSendAckTimer() { ChipLogDebugBleEndPoint(Ble, "starting new SendAckTimer"); const CHIP_ERROR timerErr = mBle->mSystemLayer->StartTimer(BTP_ACK_SEND_TIMEOUT_MS, HandleSendAckTimeout, this); - VerifyOrReturnError(timerErr == CHIP_NO_ERROR, BLE_ERROR_START_TIMER_FAILED); + ReturnErrorOnFailure(timerErr); mTimerStateFlags.Set(TimerStateFlag::kSendAckTimerRunning); } @@ -1484,7 +1484,7 @@ CHIP_ERROR BLEEndPoint::StartSendAckTimer() CHIP_ERROR BLEEndPoint::StartUnsubscribeTimer() { const CHIP_ERROR timerErr = mBle->mSystemLayer->StartTimer(BLE_UNSUBSCRIBE_TIMEOUT_MS, HandleUnsubscribeTimeout, this); - VerifyOrReturnError(timerErr == CHIP_NO_ERROR, BLE_ERROR_START_TIMER_FAILED); + ReturnErrorOnFailure(timerErr); mTimerStateFlags.Set(TimerStateFlag::kUnsubscribeTimerRunning); return CHIP_NO_ERROR; diff --git a/src/ble/BtpEngine.cpp b/src/ble/BtpEngine.cpp index d222d15d8410f5..d243feb025029d 100644 --- a/src/ble/BtpEngine.cpp +++ b/src/ble/BtpEngine.cpp @@ -248,7 +248,8 @@ CHIP_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle && mRxCharCount++; // Get header flags, always in first byte. - VerifyOrExit(reader.Read8(rx_flags.RawStorage()).StatusCode() == CHIP_NO_ERROR, err = CHIP_ERROR_MESSAGE_INCOMPLETE); + err = reader.Read8(rx_flags.RawStorage()).StatusCode(); + SuccessOrExit(err); #if CHIP_ENABLE_CHIPOBLE_TEST if (rx_flags.Has(HeaderFlags::kCommandMessage)) SetRxPacketType(kType_Control); @@ -261,14 +262,16 @@ CHIP_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle && // Get ack number, if any. if (didReceiveAck) { - VerifyOrExit(reader.Read8(&receivedAck).StatusCode() == CHIP_NO_ERROR, err = CHIP_ERROR_MESSAGE_INCOMPLETE); + err = reader.Read8(&receivedAck).StatusCode(); + SuccessOrExit(err); err = HandleAckReceived(receivedAck); SuccessOrExit(err); } // Get sequence number. - VerifyOrExit(reader.Read8(&mRxNewestUnackedSeqNum).StatusCode() == CHIP_NO_ERROR, err = CHIP_ERROR_MESSAGE_INCOMPLETE); + err = reader.Read8(&mRxNewestUnackedSeqNum).StatusCode(); + SuccessOrExit(err); // Verify that received sequence number is the next one we'd expect. VerifyOrExit(mRxNewestUnackedSeqNum == mRxNextSeqNum, err = BLE_ERROR_INVALID_BTP_SEQUENCE_NUMBER); @@ -304,7 +307,8 @@ CHIP_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle && // Verify StartMessage header flag set. VerifyOrExit(rx_flags.Has(HeaderFlags::kStartMessage), err = BLE_ERROR_INVALID_BTP_HEADER_FLAGS); - VerifyOrExit(startReader.Read16(&mRxLength).StatusCode() == CHIP_NO_ERROR, err = CHIP_ERROR_MESSAGE_INCOMPLETE); + err = startReader.Read16(&mRxLength).StatusCode(); + SuccessOrExit(err); mRxState = kState_InProgress; diff --git a/src/controller/CHIPDevice.cpp b/src/controller/CHIPDevice.cpp index 5304bb37a74047..ab473927a42224 100644 --- a/src/controller/CHIPDevice.cpp +++ b/src/controller/CHIPDevice.cpp @@ -254,7 +254,7 @@ CHIP_ERROR Device::Deserialize(const SerializedDevice & input) #if CHIP_SYSTEM_CONFIG_USE_LWIP UNLOCK_TCPIP_CORE(); #endif - VerifyOrReturnError(CHIP_NO_ERROR == inetErr, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(inetErr); } static_assert(std::is_same::type, uint8_t>::value, diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 52c9a06e4cb06b..130638230b7119 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -345,8 +345,8 @@ CHIP_ERROR DeviceController::Shutdown() // ReturnErrorOnFailure(DeviceLayer::PlatformMgr().Shutdown()); #else - VerifyOrReturnError(mInetLayer->Shutdown() == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - VerifyOrReturnError(mSystemLayer->Shutdown() == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(mInetLayer->Shutdown()); + ReturnErrorOnFailure(mSystemLayer->Shutdown()); chip::Platform::Delete(mInetLayer); chip::Platform::Delete(mSystemLayer); #endif // CONFIG_DEVICE_LAYER @@ -894,13 +894,13 @@ CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, RendezvousParam // If the CSRNonce is passed in, using that else using a random one.. if (params.HasCSRNonce()) { - VerifyOrReturnError(device->SetCSRNonce(params.GetCSRNonce().Value()) == CHIP_NO_ERROR, CHIP_ERROR_INVALID_ARGUMENT); + ReturnErrorOnFailure(device->SetCSRNonce(params.GetCSRNonce().Value())); } else { uint8_t mCSRNonce[kOpCSRNonceLength]; Crypto::DRBG_get_bytes(mCSRNonce, sizeof(mCSRNonce)); - VerifyOrReturnError(device->SetCSRNonce(ByteSpan(mCSRNonce)) == CHIP_NO_ERROR, CHIP_ERROR_INVALID_ARGUMENT); + ReturnErrorOnFailure(device->SetCSRNonce(ByteSpan(mCSRNonce))); } mIsIPRendezvous = (params.GetPeerAddress().GetTransportType() != Transport::Type::kBle); diff --git a/src/credentials/CHIPCertFromX509.cpp b/src/credentials/CHIPCertFromX509.cpp index af60edf3027760..b99f813ce8b414 100644 --- a/src/credentials/CHIPCertFromX509.cpp +++ b/src/credentials/CHIPCertFromX509.cpp @@ -350,7 +350,7 @@ static CHIP_ERROR ConvertExtension(ASN1Reader & reader, TLVWriter & writer) ASN1_PARSE_ENTER_SEQUENCE { err = reader.Next(); - VerifyOrExit(err == CHIP_NO_ERROR, err = ASN1_ERROR_INVALID_ENCODING); + SuccessOrExit(err); // keyIdentifier [0] IMPLICIT KeyIdentifier, // KeyIdentifier ::= OCTET STRING diff --git a/src/crypto/CHIPCryptoPAL.cpp b/src/crypto/CHIPCryptoPAL.cpp index 32e63c30b07954..fa66c8de0b5a49 100644 --- a/src/crypto/CHIPCryptoPAL.cpp +++ b/src/crypto/CHIPCryptoPAL.cpp @@ -47,12 +47,10 @@ CHIP_ERROR Spake2p::InternalHash(const uint8_t * in, size_t in_len) lb[6] = static_cast((u64_len >> 48) & 0xff); lb[7] = static_cast((u64_len >> 56) & 0xff); - CHIP_ERROR error = Hash(lb, sizeof(lb)); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(Hash(lb, sizeof(lb))); if (in != nullptr) { - error = Hash(in, in_len); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(Hash(in, in_len)); } return CHIP_NO_ERROR; @@ -89,17 +87,10 @@ CHIP_ERROR Spake2p::Init(const uint8_t * context, size_t context_len) { state = CHIP_SPAKE2P_STATE::PREINIT; - CHIP_ERROR error = InitImpl(); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = PointLoad(spake2p_M_p256, sizeof(spake2p_M_p256), M); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = PointLoad(spake2p_N_p256, sizeof(spake2p_N_p256), N); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = InternalHash(context, context_len); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(InitImpl()); + ReturnErrorOnFailure(PointLoad(spake2p_M_p256, sizeof(spake2p_M_p256), M)); + ReturnErrorOnFailure(PointLoad(spake2p_N_p256, sizeof(spake2p_N_p256), N)); + ReturnErrorOnFailure(InternalHash(context, context_len)); state = CHIP_SPAKE2P_STATE::INIT; return CHIP_NO_ERROR; @@ -107,10 +98,8 @@ CHIP_ERROR Spake2p::Init(const uint8_t * context, size_t context_len) CHIP_ERROR Spake2p::WriteMN() { - CHIP_ERROR error = InternalHash(spake2p_M_p256, sizeof(spake2p_M_p256)); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - error = InternalHash(spake2p_N_p256, sizeof(spake2p_N_p256)); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(InternalHash(spake2p_M_p256, sizeof(spake2p_M_p256))); + ReturnErrorOnFailure(InternalHash(spake2p_N_p256, sizeof(spake2p_N_p256))); return CHIP_NO_ERROR; } @@ -119,27 +108,17 @@ CHIP_ERROR Spake2p::BeginVerifier(const uint8_t * my_identity, size_t my_identit size_t peer_identity_len, const uint8_t * w0in, size_t w0in_len, const uint8_t * Lin, size_t Lin_len) { - CHIP_ERROR error = CHIP_ERROR_INTERNAL; VerifyOrReturnError(state == CHIP_SPAKE2P_STATE::INIT, CHIP_ERROR_INTERNAL); - error = InternalHash(peer_identity, peer_identity_len); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = InternalHash(my_identity, my_identity_len); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = WriteMN(); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = FELoad(w0in, w0in_len, w0); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = PointLoad(Lin, Lin_len, L); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(InternalHash(peer_identity, peer_identity_len)); + ReturnErrorOnFailure(InternalHash(my_identity, my_identity_len)); + ReturnErrorOnFailure(WriteMN()); + ReturnErrorOnFailure(FELoad(w0in, w0in_len, w0)); + ReturnErrorOnFailure(PointLoad(Lin, Lin_len, L)); state = CHIP_SPAKE2P_STATE::STARTED; role = CHIP_SPAKE2P_ROLE::VERIFIER; - return error; + return CHIP_NO_ERROR; } CHIP_ERROR Spake2p::BeginProver(const uint8_t * my_identity, size_t my_identity_len, const uint8_t * peer_identity, @@ -148,20 +127,11 @@ CHIP_ERROR Spake2p::BeginProver(const uint8_t * my_identity, size_t my_identity_ { VerifyOrReturnError(state == CHIP_SPAKE2P_STATE::INIT, CHIP_ERROR_INTERNAL); - CHIP_ERROR error = InternalHash(my_identity, my_identity_len); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = InternalHash(peer_identity, peer_identity_len); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = WriteMN(); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = FELoad(w0in, w0in_len, w0); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = FELoad(w1in, w1in_len, w1); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(InternalHash(my_identity, my_identity_len)); + ReturnErrorOnFailure(InternalHash(peer_identity, peer_identity_len)); + ReturnErrorOnFailure(WriteMN()); + ReturnErrorOnFailure(FELoad(w0in, w0in_len, w0)); + ReturnErrorOnFailure(FELoad(w1in, w1in_len, w1)); state = CHIP_SPAKE2P_STATE::STARTED; role = CHIP_SPAKE2P_ROLE::PROVER; @@ -177,8 +147,7 @@ CHIP_ERROR Spake2p::ComputeRoundOne(const uint8_t * pab, size_t pab_len, uint8_t VerifyOrExit(state == CHIP_SPAKE2P_STATE::STARTED, error = CHIP_ERROR_INTERNAL); VerifyOrExit(*out_len >= point_size, error = CHIP_ERROR_INTERNAL); - error = FEGenerate(xy); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(FEGenerate(xy)); if (role == CHIP_SPAKE2P_ROLE::PROVER) { @@ -193,11 +162,8 @@ CHIP_ERROR Spake2p::ComputeRoundOne(const uint8_t * pab, size_t pab_len, uint8_t VerifyOrExit(MN != nullptr, error = CHIP_ERROR_INTERNAL); VerifyOrExit(XY != nullptr, error = CHIP_ERROR_INTERNAL); - error = PointAddMul(XY, G, xy, MN, w0); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - - error = PointWrite(XY, out, *out_len); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); + SuccessOrExit(error = PointAddMul(XY, G, xy, MN, w0)); + SuccessOrExit(error = PointWrite(XY, out, *out_len)); state = CHIP_SPAKE2P_STATE::R1; error = CHIP_NO_ERROR; @@ -220,14 +186,9 @@ CHIP_ERROR Spake2p::ComputeRoundTwo(const uint8_t * in, size_t in_len, uint8_t * if (role == CHIP_SPAKE2P_ROLE::PROVER) { - error = PointWrite(X, point_buffer, point_size); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - - error = InternalHash(point_buffer, point_size); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - - error = InternalHash(in, in_len); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); + SuccessOrExit(error = PointWrite(X, point_buffer, point_size)); + SuccessOrExit(error = InternalHash(point_buffer, point_size)); + SuccessOrExit(error = InternalHash(in, in_len)); MN = N; XY = Y; @@ -235,14 +196,9 @@ CHIP_ERROR Spake2p::ComputeRoundTwo(const uint8_t * in, size_t in_len, uint8_t * } else if (role == CHIP_SPAKE2P_ROLE::VERIFIER) { - error = InternalHash(in, in_len); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - - error = PointWrite(Y, point_buffer, point_size); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - - error = InternalHash(point_buffer, point_size); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); + SuccessOrExit(error = InternalHash(in, in_len)); + SuccessOrExit(error = PointWrite(Y, point_buffer, point_size)); + SuccessOrExit(error = InternalHash(point_buffer, point_size)); MN = M; XY = X; @@ -251,59 +207,36 @@ CHIP_ERROR Spake2p::ComputeRoundTwo(const uint8_t * in, size_t in_len, uint8_t * VerifyOrExit(MN != nullptr, error = CHIP_ERROR_INTERNAL); VerifyOrExit(XY != nullptr, error = CHIP_ERROR_INTERNAL); - error = PointLoad(in, in_len, XY); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - error = PointIsValid(XY); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - - error = FEMul(tempbn, xy, w0); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - - error = PointInvert(MN); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - - error = PointAddMul(Z, XY, xy, MN, tempbn); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - - error = PointCofactorMul(Z); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); + SuccessOrExit(error = PointLoad(in, in_len, XY)); + SuccessOrExit(error = PointIsValid(XY)); + SuccessOrExit(error = FEMul(tempbn, xy, w0)); + SuccessOrExit(error = PointInvert(MN)); + SuccessOrExit(error = PointAddMul(Z, XY, xy, MN, tempbn)); + SuccessOrExit(error = PointCofactorMul(Z)); if (role == CHIP_SPAKE2P_ROLE::PROVER) { - error = FEMul(tempbn, w1, w0); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - error = PointAddMul(V, XY, w1, MN, tempbn); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); + SuccessOrExit(error = FEMul(tempbn, w1, w0)); + SuccessOrExit(error = PointAddMul(V, XY, w1, MN, tempbn)); } else if (role == CHIP_SPAKE2P_ROLE::VERIFIER) { - error = PointMul(V, L, xy); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); + SuccessOrExit(error = PointMul(V, L, xy)); } - error = PointCofactorMul(V); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); + SuccessOrExit(error = PointCofactorMul(V)); + SuccessOrExit(error = PointWrite(Z, point_buffer, point_size)); + SuccessOrExit(error = InternalHash(point_buffer, point_size)); - error = PointWrite(Z, point_buffer, point_size); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - error = InternalHash(point_buffer, point_size); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); + SuccessOrExit(error = PointWrite(V, point_buffer, point_size)); + SuccessOrExit(error = InternalHash(point_buffer, point_size)); - error = PointWrite(V, point_buffer, point_size); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - error = InternalHash(point_buffer, point_size); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); + SuccessOrExit(error = FEWrite(w0, point_buffer, fe_size)); + SuccessOrExit(error = InternalHash(point_buffer, fe_size)); - error = FEWrite(w0, point_buffer, fe_size); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - error = InternalHash(point_buffer, fe_size); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); + SuccessOrExit(error = GenerateKeys()); - error = GenerateKeys(); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - - error = Mac(Kcaorb, hash_size / 2, in, in_len, out); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); + SuccessOrExit(error = Mac(Kcaorb, hash_size / 2, in, in_len, out)); state = CHIP_SPAKE2P_STATE::R2; error = CHIP_NO_ERROR; @@ -316,11 +249,8 @@ CHIP_ERROR Spake2p::GenerateKeys() { static const uint8_t info_keyconfirm[16] = { 'C', 'o', 'n', 'f', 'i', 'r', 'm', 'a', 't', 'i', 'o', 'n', 'K', 'e', 'y', 's' }; - CHIP_ERROR error = HashFinalize(Kae); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = KDF(Ka, hash_size / 2, nullptr, 0, info_keyconfirm, sizeof(info_keyconfirm), Kcab, hash_size); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(HashFinalize(Kae)); + ReturnErrorOnFailure(KDF(Ka, hash_size / 2, nullptr, 0, info_keyconfirm, sizeof(info_keyconfirm), Kcab, hash_size)); return CHIP_NO_ERROR; } @@ -346,11 +276,8 @@ CHIP_ERROR Spake2p::KeyConfirm(const uint8_t * in, size_t in_len) VerifyOrReturnError(XY != nullptr, CHIP_ERROR_INTERNAL); VerifyOrReturnError(Kcaorb != nullptr, CHIP_ERROR_INTERNAL); - CHIP_ERROR error = PointWrite(XY, point_buffer, point_size); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = MacVerify(Kcaorb, hash_size / 2, in, in_len, point_buffer, point_size); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(PointWrite(XY, point_buffer, point_size)); + ReturnErrorOnFailure(MacVerify(Kcaorb, hash_size / 2, in, in_len, point_buffer, point_size)); state = CHIP_SPAKE2P_STATE::KC; return CHIP_NO_ERROR; @@ -372,28 +299,20 @@ CHIP_ERROR Spake2p::GetKeys(uint8_t * out, size_t * out_len) CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::InitImpl() { - CHIP_ERROR error = sha256_hash_ctx.Begin(); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = InitInternal(); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - + ReturnErrorOnFailure(sha256_hash_ctx.Begin()); + ReturnErrorOnFailure(InitInternal()); return CHIP_NO_ERROR; } CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::Hash(const uint8_t * in, size_t in_len) { - CHIP_ERROR error = sha256_hash_ctx.AddData(in, in_len); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - + ReturnErrorOnFailure(sha256_hash_ctx.AddData(in, in_len)); return CHIP_NO_ERROR; } CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::HashFinalize(uint8_t * out) { - CHIP_ERROR error = sha256_hash_ctx.Finish(out); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - + ReturnErrorOnFailure(sha256_hash_ctx.Finish(out)); return CHIP_NO_ERROR; } @@ -403,8 +322,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::KDF(const uint8_t * ikm, const size_t { HKDF_sha_crypto mHKDF; - CHIP_ERROR error = mHKDF.HKDF_SHA256(ikm, ikm_len, salt, salt_len, info, info_len, out, out_len); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(mHKDF.HKDF_SHA256(ikm, ikm_len, salt, salt_len, info, info_len, out, out_len)); return CHIP_NO_ERROR; } diff --git a/src/crypto/CHIPCryptoPALOpenSSL.cpp b/src/crypto/CHIPCryptoPALOpenSSL.cpp index 466c4ae7271ee0..c1fc84b90236dc 100644 --- a/src/crypto/CHIPCryptoPALOpenSSL.cpp +++ b/src/crypto/CHIPCryptoPALOpenSSL.cpp @@ -1341,8 +1341,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::MacVerify(const uint8_t * key, size_t VerifyOrReturnError(mac_len == kSHA256_Hash_Length, CHIP_ERROR_INVALID_ARGUMENT); uint8_t computed_mac[kSHA256_Hash_Length]; - const CHIP_ERROR error = Mac(key, key_len, in, in_len, computed_mac); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(Mac(key, key_len, in, in_len, computed_mac)); VerifyOrReturnError(CRYPTO_memcmp(mac, computed_mac, mac_len) == 0, CHIP_ERROR_INTERNAL); @@ -1436,11 +1435,8 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::PointAddMul(void * R, const void * P1, scratch = EC_POINT_new(context->curve); VerifyOrExit(scratch != nullptr, error = CHIP_ERROR_INTERNAL); - error = PointMul(scratch, P1, fe1); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - - error = PointMul(R, P2, fe2); - VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); + SuccessOrExit(error = PointMul(scratch, P1, fe1)); + SuccessOrExit(error = PointMul(R, P2, fe2)); error_openssl = EC_POINT_add(context->curve, static_cast(R), static_cast(R), static_cast(scratch), context->bn_ctx); diff --git a/src/crypto/hsm/nxp/CHIPCryptoPALHsm_SE05X_Spake2p.cpp b/src/crypto/hsm/nxp/CHIPCryptoPALHsm_SE05X_Spake2p.cpp index 967e1338662807..9ca62a74c92b1e 100644 --- a/src/crypto/hsm/nxp/CHIPCryptoPALHsm_SE05X_Spake2p.cpp +++ b/src/crypto/hsm/nxp/CHIPCryptoPALHsm_SE05X_Spake2p.cpp @@ -91,12 +91,12 @@ CHIP_ERROR create_init_crypto_obj(chip::Crypto::CHIP_SPAKE2P_ROLE role, hsm_pake se05x_delete_key(m_id); error = se05x_set_key(m_id, chip::Crypto::spake2p_M_p256, sizeof(chip::Crypto::spake2p_M_p256), kSSS_KeyPart_Public, kSSS_CipherType_EC_NIST_P); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(error); se05x_delete_key(n_id); error = se05x_set_key(n_id, chip::Crypto::spake2p_N_p256, sizeof(chip::Crypto::spake2p_N_p256), kSSS_KeyPart_Public, kSSS_CipherType_EC_NIST_P); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(error); VerifyOrReturnError(gex_sss_chip_ctx.ks.session != NULL, CHIP_ERROR_INTERNAL); @@ -307,37 +307,29 @@ CHIP_ERROR Spake2pHSM_P256_SHA256_HKDF_HMAC::BeginVerifier(const uint8_t * my_id ChipLogProgress(Crypto, "HSM - BeginVerifier \n"); - error = FELoad(w0in, w0in_len, w0); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = FEWrite(w0, w0in_mod, w0in_mod_len); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = create_init_crypto_obj(chip::Crypto::CHIP_SPAKE2P_ROLE::VERIFIER, &hsm_pake_context); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(FELoad(w0in, w0in_len, w0)); + ReturnErrorOnFailure(FEWrite(w0, w0in_mod, w0in_mod_len)); + ReturnErrorOnFailure(create_init_crypto_obj(chip::Crypto::CHIP_SPAKE2P_ROLE::VERIFIER, &hsm_pake_context)); #if SSS_HAVE_SE05X_VER_GTE_16_02 smstatus = Se05x_API_PAKEConfigDevice(&((sss_se05x_session_t *) &gex_sss_chip_ctx.session)->s_ctx, SE05x_SPAKEDevice_B, hsm_pake_context.spake_objId); - VerifyOrReturnError(smstatus == SM_OK, CHIP_ERROR_INTERNAL); + VerifyOrReturnError(smstatus == SM_OK, chip::ChipError::Encapsulate(chip::ChipError::Range::kPlatform, smstatus)); smstatus = Se05x_API_PAKEInitDevice(&((sss_se05x_session_t *) &gex_sss_chip_ctx.session)->s_ctx, hsm_pake_context.spake_objId, (uint8_t *) hsm_pake_context.spake_context, hsm_pake_context.spake_context_len, (uint8_t *) peer_identity, peer_identity_len, (uint8_t *) my_identity, my_identity_len); - VerifyOrReturnError(smstatus == SM_OK, CHIP_ERROR_INTERNAL); + VerifyOrReturnError(smstatus == SM_OK, chip::ChipError::Encapsulate(chip::ChipError::Range::kPlatform, smstatus)); #else smstatus = Se05x_API_PAKEConfigDevice(&((sss_se05x_session_t *) &gex_sss_chip_ctx.session)->s_ctx, SE05x_SPAKEDevice_B, hsm_pake_context.spake_objId, (uint8_t *) hsm_pake_context.spake_context, hsm_pake_context.spake_context_len, (uint8_t *) peer_identity, peer_identity_len, (uint8_t *) my_identity, my_identity_len); - VerifyOrReturnError(smstatus == SM_OK, CHIP_ERROR_INTERNAL); + VerifyOrReturnError(smstatus == SM_OK, chip::ChipError::Encapsulate(chip::ChipError::Range::kPlatform, smstatus)); #endif - error = se05x_set_key(w0in_id_v, w0in_mod, w0in_mod_len, kSSS_KeyPart_Default, kSSS_CipherType_AES); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = se05x_set_key(Lin_id_v, Lin, Lin_len, kSSS_KeyPart_Public, kSSS_CipherType_EC_NIST_P); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(se05x_set_key(w0in_id_v, w0in_mod, w0in_mod_len, kSSS_KeyPart_Default, kSSS_CipherType_AES)); + ReturnErrorOnFailure(se05x_set_key(Lin_id_v, Lin, Lin_len, kSSS_KeyPart_Public, kSSS_CipherType_EC_NIST_P)); #if SSS_HAVE_SE05X_VER_GTE_16_02 smstatus = Se05x_API_PAKEInitCredentials(&((sss_se05x_session_t *) &gex_sss_chip_ctx.session)->s_ctx, @@ -346,7 +338,7 @@ CHIP_ERROR Spake2pHSM_P256_SHA256_HKDF_HMAC::BeginVerifier(const uint8_t * my_id smstatus = Se05x_API_PAKEInitDevice(&((sss_se05x_session_t *) &gex_sss_chip_ctx.session)->s_ctx, hsm_pake_context.spake_objId, w0in_id_v, 0, Lin_id_v); #endif - VerifyOrReturnError(smstatus == SM_OK, CHIP_ERROR_INTERNAL); + VerifyOrReturnError(smstatus == SM_OK, chip::ChipError::Encapsulate(chip::ChipError::Range::kPlatform, smstatus)); state = CHIP_SPAKE2P_STATE::STARTED; role = CHIP_SPAKE2P_ROLE::VERIFIER; @@ -387,43 +379,31 @@ CHIP_ERROR Spake2pHSM_P256_SHA256_HKDF_HMAC::BeginProver(const uint8_t * my_iden ChipLogProgress(Crypto, "HSM - BeginProver \n"); - error = FELoad(w0in, w0in_len, w0); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = FEWrite(w0, w0in_mod, w0in_mod_len); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = FELoad(w1in, w1in_len, w1); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = FEWrite(w1, w1in_mod, w1in_mod_len); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = create_init_crypto_obj(chip::Crypto::CHIP_SPAKE2P_ROLE::PROVER, &hsm_pake_context); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(FELoad(w0in, w0in_len, w0)); + ReturnErrorOnFailure(FEWrite(w0, w0in_mod, w0in_mod_len)); + ReturnErrorOnFailure(FELoad(w1in, w1in_len, w1)); + ReturnErrorOnFailure(FEWrite(w1, w1in_mod, w1in_mod_len)); + ReturnErrorOnFailure(create_init_crypto_obj(chip::Crypto::CHIP_SPAKE2P_ROLE::PROVER, &hsm_pake_context)); #if SSS_HAVE_SE05X_VER_GTE_16_02 smstatus = Se05x_API_PAKEConfigDevice(&((sss_se05x_session_t *) &gex_sss_chip_ctx.session)->s_ctx, SE05x_SPAKEDevice_A, hsm_pake_context.spake_objId); - VerifyOrReturnError(smstatus == SM_OK, CHIP_ERROR_INTERNAL); + VerifyOrReturnError(smstatus == SM_OK, chip::ChipError::Encapsulate(chip::ChipError::Range::kPlatform, smstatus)); smstatus = Se05x_API_PAKEInitDevice(&((sss_se05x_session_t *) &gex_sss_chip_ctx.session)->s_ctx, hsm_pake_context.spake_objId, (uint8_t *) hsm_pake_context.spake_context, hsm_pake_context.spake_context_len, (uint8_t *) my_identity, my_identity_len, (uint8_t *) peer_identity, peer_identity_len); - VerifyOrReturnError(smstatus == SM_OK, CHIP_ERROR_INTERNAL); + VerifyOrReturnError(smstatus == SM_OK, chip::ChipError::Encapsulate(chip::ChipError::Range::kPlatform, smstatus)); #else smstatus = Se05x_API_PAKEConfigDevice(&((sss_se05x_session_t *) &gex_sss_chip_ctx.session)->s_ctx, SE05x_SPAKEDevice_A, hsm_pake_context.spake_objId, (uint8_t *) hsm_pake_context.spake_context, hsm_pake_context.spake_context_len, (uint8_t *) peer_identity, peer_identity_len, (uint8_t *) my_identity, my_identity_len); - VerifyOrReturnError(smstatus == SM_OK, CHIP_ERROR_INTERNAL); + VerifyOrReturnError(smstatus == SM_OK, chip::ChipError::Encapsulate(chip::ChipError::Range::kPlatform, smstatus)); #endif - error = se05x_set_key(w0in_id_p, w0in_mod, w0in_mod_len, kSSS_KeyPart_Default, kSSS_CipherType_AES); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); - - error = se05x_set_key(w1in_id_p, w1in_mod, w1in_mod_len, kSSS_KeyPart_Default, kSSS_CipherType_AES); - VerifyOrReturnError(error == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL); + ReturnErrorOnFailure(se05x_set_key(w0in_id_p, w0in_mod, w0in_mod_len, kSSS_KeyPart_Default, kSSS_CipherType_AES)); + ReturnErrorOnFailure(se05x_set_key(w1in_id_p, w1in_mod, w1in_mod_len, kSSS_KeyPart_Default, kSSS_CipherType_AES)); #if SSS_HAVE_SE05X_VER_GTE_16_02 smstatus = Se05x_API_PAKEInitCredentials(&((sss_se05x_session_t *) &gex_sss_chip_ctx.session)->s_ctx, @@ -432,7 +412,7 @@ CHIP_ERROR Spake2pHSM_P256_SHA256_HKDF_HMAC::BeginProver(const uint8_t * my_iden smstatus = Se05x_API_PAKEInitDevice(&((sss_se05x_session_t *) &gex_sss_chip_ctx.session)->s_ctx, hsm_pake_context.spake_objId, w0in_id_p, w1in_id_p, 0); #endif - VerifyOrReturnError(smstatus == SM_OK, CHIP_ERROR_INTERNAL); + VerifyOrReturnError(smstatus == SM_OK, chip::ChipError::Encapsulate(chip::ChipError::Range::kPlatform, smstatus)); state = CHIP_SPAKE2P_STATE::STARTED; role = CHIP_SPAKE2P_ROLE::PROVER; diff --git a/src/platform/mbed/BLEManagerImpl.cpp b/src/platform/mbed/BLEManagerImpl.cpp index a57c82d6495fed..8cdbeb3ab1e539 100644 --- a/src/platform/mbed/BLEManagerImpl.cpp +++ b/src/platform/mbed/BLEManagerImpl.cpp @@ -563,7 +563,6 @@ static SecurityManagerEventHandler sSecurityManagerEventHandler; */ CHIP_ERROR BLEManagerImpl::_Init() { - CHIP_ERROR err = CHIP_NO_ERROR; ble_error_t mbed_err = BLE_ERROR_NONE; mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled; @@ -573,8 +572,7 @@ CHIP_ERROR BLEManagerImpl::_Init() ble::BLE & ble_interface = ble::BLE::Instance(); ble_interface.gap().setEventHandler(&sMbedGapEventHandler); - err = sCHIPService.init(ble_interface); - SuccessOrExit(err); + ReturnErrorOnFailure(sCHIPService.init(ble_interface)); ble_interface.onEventsToProcess(FunctionPointerWithContext{ [](ble::BLE::OnEventsToProcessCallbackContext * context) { PlatformMgr().ScheduleWork(DoBLEProcessing, 0); } }); @@ -582,10 +580,9 @@ CHIP_ERROR BLEManagerImpl::_Init() mbed_err = ble_interface.init([](ble::BLE::InitializationCompleteCallbackContext * context) { BLEMgrImpl().HandleInitComplete(context->error == BLE_ERROR_NONE); }); - VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR_INTERNAL); + VerifyOrReturnError(mbed_err == BLE_ERROR_NONE, chip::ChipError::Encapsulate(chip::ChipError::Range::kOS, mbed_err)); -exit: - return err; + return CHIP_NO_ERROR; } /* Process all the events from the mbed-os BLE subsystem. @@ -624,10 +621,10 @@ void BLEManagerImpl::HandleInitComplete(bool no_error) /*const Passkey_t passkey */ nullptr, /*bool signing */ true, /*const char *dbFilepath */ nullptr); - VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR_INTERNAL); + VerifyOrExit(mbed_err == BLE_ERROR_NONE, chip::ChipError::Encapsulate(chip::ChipError::Range::kOS, mbed_err)); mbed_err = security_mgr.setPairingRequestAuthorisation(true); - VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR_INTERNAL); + VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = chip::ChipError::Encapsulate(chip::ChipError::Range::kOS, mbed_err)); security_mgr.setSecurityManagerEventHandler(&sSecurityManagerEventHandler); err = BleLayer::Init(this, this, &SystemLayer); @@ -754,16 +751,16 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) if (gap.isAdvertisingActive(ble::LEGACY_ADVERTISING_HANDLE)) { mbed_err = gap.stopAdvertising(ble::LEGACY_ADVERTISING_HANDLE); - VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR_INTERNAL); + VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = chip::ChipError::Encapsulate(chip::ChipError::Range::kOS, mbed_err)); ChipLogDetail(DeviceLayer, "Advertising already active. Restarting."); } mbed_err = gap.setAdvertisingParameters(ble::LEGACY_ADVERTISING_HANDLE, adv_params); - VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR_INTERNAL); + VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = chip::ChipError::Encapsulate(chip::ChipError::Range::kOS, mbed_err)); mbed_err = adv_data_builder.setFlags(ble::adv_data_flags_t::BREDR_NOT_SUPPORTED | ble::adv_data_flags_t::LE_GENERAL_DISCOVERABLE); - VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR_INTERNAL); + VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = chip::ChipError::Encapsulate(chip::ChipError::Range::kOS, mbed_err)); if (!mFlags.Has(kFlag_UseCustomDeviceName)) { @@ -773,24 +770,24 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) snprintf(mDeviceName, kMaxDeviceNameLength, "%s%04u", CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, discriminator); } mbed_err = adv_data_builder.setName(mDeviceName); - VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR_INTERNAL); + VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = chip::ChipError::Encapsulate(chip::ChipError::Range::kOS, mbed_err)); dev_id_info.Init(); SuccessOrExit(ConfigurationMgr().GetBLEDeviceIdentificationInfo(dev_id_info)); mbed_err = adv_data_builder.setServiceData( ShortUUID_CHIPoBLEService, mbed::make_Span(reinterpret_cast(&dev_id_info), sizeof dev_id_info)); - VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR_INTERNAL); + VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = chip::ChipError::Encapsulate(chip::ChipError::Range::kOS, mbed_err)); mbed_err = gap.setAdvertisingPayload(ble::LEGACY_ADVERTISING_HANDLE, adv_data_builder.getAdvertisingData()); - VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR_INTERNAL); + VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = chip::ChipError::Encapsulate(chip::ChipError::Range::kOS, mbed_err)); adv_data_builder.clear(); adv_data_builder.setLocalServiceList(mbed::make_Span(&ShortUUID_CHIPoBLEService, 1)); mbed_err = gap.setAdvertisingScanResponse(ble::LEGACY_ADVERTISING_HANDLE, adv_data_builder.getAdvertisingData()); - VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR_INTERNAL); + VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = chip::ChipError::Encapsulate(chip::ChipError::Range::kOS, mbed_err)); mbed_err = gap.startAdvertising(ble::LEGACY_ADVERTISING_HANDLE); - VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR_INTERNAL); + VerifyOrExit(mbed_err == BLE_ERROR_NONE, chip::ChipError::Encapsulate(chip::ChipError::Range::kOS, mbed_err)); ChipLogDetail(DeviceLayer, "Advertising started, type: 0x%x (%sconnectable), interval: [%lu:%lu] ms, device name: %s)", adv_params.getType().value(), connectable ? "" : "non-", adv_params.getMinPrimaryInterval().valueInMs(), @@ -817,7 +814,7 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void) return err; } mbed_err = gap.stopAdvertising(ble::LEGACY_ADVERTISING_HANDLE); - VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR_INTERNAL); + VerifyOrExit(mbed_err == BLE_ERROR_NONE, chip::ChipError::Encapsulate(chip::ChipError::Range::kOS, mbed_err)); exit: if (mbed_err != BLE_ERROR_NONE) @@ -1031,7 +1028,7 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUU conId, att_handle, pBuf->DataLength()); mbed_err = gatt_server.write(att_handle, pBuf->Start(), pBuf->DataLength(), false); - VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR_INTERNAL); + VerifyOrExit(mbed_err == BLE_ERROR_NONE, chip::ChipError::Encapsulate(chip::ChipError::Range::kOS, mbed_err)); exit: if (mbed_err != BLE_ERROR_NONE)