Lines Matching refs:aMessage
149 Message *CoapBase::InitMessage(Message *aMessage, Type aType, Uri aUri) in InitMessage() argument
153 VerifyOrExit(aMessage != nullptr); in InitMessage()
155 SuccessOrExit(error = aMessage->Init(aType, kCodePost, aUri)); in InitMessage()
156 SuccessOrExit(error = aMessage->SetPayloadMarker()); in InitMessage()
159 FreeAndNullMessageOnError(aMessage, error); in InitMessage()
160 return aMessage; in InitMessage()
163 Message *CoapBase::InitResponse(Message *aMessage, const Message &aResponse) in InitResponse() argument
167 VerifyOrExit(aMessage != nullptr); in InitResponse()
169 SuccessOrExit(error = aMessage->SetDefaultResponseHeader(aResponse)); in InitResponse()
170 SuccessOrExit(error = aMessage->SetPayloadMarker()); in InitResponse()
173 FreeAndNullMessageOnError(aMessage, error); in InitResponse()
174 return aMessage; in InitResponse()
177 Error CoapBase::Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) in Send() argument
182 Get<Utils::Otns>().EmitCoapSend(AsCoapMessage(&aMessage), aMessageInfo); in Send()
185 error = mSender(*this, aMessage, aMessageInfo); in Send()
190 Get<Utils::Otns>().EmitCoapSendFailure(error, AsCoapMessage(&aMessage), aMessageInfo); in Send()
197 Error CoapBase::SendMessage(Message &aMessage, in SendMessage() argument
205 Error CoapBase::SendMessage(Message &aMessage, in SendMessage()
221 switch (aMessage.GetType()) in SendMessage()
226 … if ((aTransmitHook != nullptr) && (aMessage.ReadBlockOptionValues(kOptionBlock2) == kErrorNone) && in SendMessage()
227 (aMessage.GetBlockWiseBlockNumber() == 0)) in SendMessage()
230 …VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlock… in SendMessage()
232 …SuccessOrExit(error = aTransmitHook(aContext, buf, aMessage.GetBlockWiseBlockNumber() * bufLen, &b… in SendMessage()
234 SuccessOrExit(error = aMessage.AppendBytes(buf, bufLen)); in SendMessage()
236 SuccessOrExit(error = CacheLastBlockResponse(&aMessage)); in SendMessage()
240 mResponsesQueue.EnqueueResponse(aMessage, aMessageInfo, aTxParameters); in SendMessage()
243 OT_ASSERT(aMessage.GetCode() == kCodeEmpty); in SendMessage()
248 … if ((aTransmitHook != nullptr) && (aMessage.ReadBlockOptionValues(kOptionBlock1) == kErrorNone) && in SendMessage()
249 (aMessage.GetBlockWiseBlockNumber() == 0)) in SendMessage()
252 …VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlock… in SendMessage()
254 …SuccessOrExit(error = aTransmitHook(aContext, buf, aMessage.GetBlockWiseBlockNumber() * bufLen, &b… in SendMessage()
256 SuccessOrExit(error = aMessage.AppendBytes(buf, bufLen)); in SendMessage()
259 if (aMessage.IsNonConfirmable()) in SendMessage()
261 aMessage.SetType(kTypeConfirmable); in SendMessage()
266 aMessage.SetMessageId(mMessageId++); in SendMessage()
270 aMessage.Finish(); in SendMessage()
272 if (aMessage.IsConfirmable()) in SendMessage()
274 copyLength = aMessage.GetLength(); in SendMessage()
276 else if (aMessage.IsNonConfirmable() && (aHandler != nullptr)) in SendMessage()
280 copyLength = aMessage.GetOptionStart(); in SendMessage()
292 SuccessOrExit(error = iterator.Init(aMessage, kOptionObserve)); in SendMessage()
296 if (observe && aMessage.IsGetRequest()) in SendMessage()
311 Message *origRequest = FindRelatedRequest(aMessage, aMessageInfo, handlerMetadata); in SendMessage()
329 metadata.mConfirmable = aMessage.IsConfirmable(); in SendMessage()
345 storedCopy = CopyAndEnqueueMessage(aMessage, copyLength, metadata); in SendMessage()
349 SuccessOrExit(error = Send(aMessage, aMessageInfo)); in SendMessage()
361 Error CoapBase::SendMessage(Message &aMessage, const Ip6::MessageInfo &aMessageInfo, const TxParame… in SendMessage() argument
363 return SendMessage(aMessage, aMessageInfo, aTxParameters, nullptr, nullptr); in SendMessage()
366 Error CoapBase::SendMessage(Message &aMessage, in SendMessage() argument
372 …return SendMessage(aMessage, aMessageInfo, TxParameters::GetDefault(), aHandler, aContext, nullptr… in SendMessage()
374 return SendMessage(aMessage, aMessageInfo, TxParameters::GetDefault(), aHandler, aContext); in SendMessage()
378 Error CoapBase::SendMessage(Message &aMessage, const Ip6::MessageInfo &aMessageInfo) in SendMessage() argument
380 return SendMessage(aMessage, aMessageInfo, nullptr, nullptr); in SendMessage()
557 Message *CoapBase::CopyAndEnqueueMessage(const Message &aMessage, uint16_t aCopyLength, const Metad… in CopyAndEnqueueMessage() argument
562 VerifyOrExit((messageCopy = aMessage.Clone(aCopyLength)) != nullptr, error = kErrorNoBufs); in CopyAndEnqueueMessage()
575 void CoapBase::DequeueMessage(Message &aMessage) in DequeueMessage() argument
577 mPendingRequests.Dequeue(aMessage); in DequeueMessage()
584 aMessage.Free(); in DequeueMessage()
618 Message &aMessage) in PrepareNextBlockRequest() argument
642 …SuccessOrExit(error = aRequest.AppendBlockOption(aType, aMessage.GetBlockWiseBlockNumber() + 1, aM… in PrepareNextBlockRequest()
643 aMessage.GetBlockWiseBlockSize())); in PrepareNextBlockRequest()
644 aRequest.SetBlockWiseBlockNumber(aMessage.GetBlockWiseBlockNumber() + 1); in PrepareNextBlockRequest()
645 aRequest.SetBlockWiseBlockSize(aMessage.GetBlockWiseBlockSize()); in PrepareNextBlockRequest()
665 …SuccessOrExit(error = aRequest.AppendBlockOption(aType, aMessage.GetBlockWiseBlockNumber() + 1, aM… in PrepareNextBlockRequest()
666 aMessage.GetBlockWiseBlockSize())); in PrepareNextBlockRequest()
667 aRequest.SetBlockWiseBlockNumber(aMessage.GetBlockWiseBlockNumber() + 1); in PrepareNextBlockRequest()
668 aRequest.SetBlockWiseBlockSize(aMessage.GetBlockWiseBlockSize()); in PrepareNextBlockRequest()
677 Message &aMessage, in SendNextBlock1Request() argument
688 SuccessOrExit(error = aMessage.ReadBlockOptionValues(kOptionBlock1)); in SendNextBlock1Request()
693 FinalizeCoapTransaction(aRequest, aCoapMetadata, &aMessage, &aMessageInfo, kErrorNone); in SendNextBlock1Request()
698 …VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlock… in SendNextBlock1Request()
703 … otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) * in SendNextBlock1Request()
704 (aMessage.GetBlockWiseBlockNumber() + 1), in SendNextBlock1Request()
708 …VerifyOrExit(bufLen <= otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()), error = kErr… in SendNextBlock1Request()
712 …t(error = PrepareNextBlockRequest(Message::kBlockType1, moreBlocks, aRequest, *request, aMessage)); in SendNextBlock1Request()
734 Message &aMessage, in SendNextBlock2Request() argument
745 SuccessOrExit(error = aMessage.ReadBlockOptionValues(kOptionBlock2)); in SendNextBlock2Request()
748 VerifyOrExit((aMessage.GetLength() - aMessage.GetOffset()) <= in SendNextBlock2Request()
749 otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) && in SendNextBlock2Request()
750 (aMessage.GetLength() - aMessage.GetOffset()) <= kMaxBlockLength, in SendNextBlock2Request()
754 …bufLen = aMessage.ReadBytes(aMessage.GetOffset(), buf, aMessage.GetLength() - aMessage.GetOffset()… in SendNextBlock2Request()
757 … otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) * in SendNextBlock2Request()
758 aMessage.GetBlockWiseBlockNumber(), in SendNextBlock2Request()
759 … bufLen, aMessage.IsMoreBlocksFlagSet(), aTotalLength)); in SendNextBlock2Request()
762 …LogInfo("Received Block2 Nr. %d , Size: %d bytes, More Blocks Flag: %d", aMessage.GetBlockWiseBloc… in SendNextBlock2Request()
763 … otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()), aMessage.IsMoreBlocksFlagSet()); in SendNextBlock2Request()
766 if (!aMessage.IsMoreBlocksFlagSet()) in SendNextBlock2Request()
768 FinalizeCoapTransaction(aRequest, aCoapMetadata, &aMessage, &aMessageInfo, kErrorNone); in SendNextBlock2Request()
774 …SuccessOrExit(error = PrepareNextBlockRequest(Message::kBlockType2, aMessage.IsMoreBlocksFlagSet()… in SendNextBlock2Request()
775 *request, aMessage)); in SendNextBlock2Request()
795 Error CoapBase::ProcessBlock1Request(Message &aMessage, in ProcessBlock1Request() argument
805 SuccessOrExit(error = aMessage.ReadBlockOptionValues(kOptionBlock1)); in ProcessBlock1Request()
808 …VerifyOrExit((aMessage.GetLength() - aMessage.GetOffset()) <= kMaxBlockLength, error = kErrorNoBuf… in ProcessBlock1Request()
809 …bufLen = aMessage.ReadBytes(aMessage.GetOffset(), buf, aMessage.GetLength() - aMessage.GetOffset()… in ProcessBlock1Request()
811 … otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) * in ProcessBlock1Request()
812 aMessage.GetBlockWiseBlockNumber(), in ProcessBlock1Request()
813 … bufLen, aMessage.IsMoreBlocksFlagSet(), aTotalLength)); in ProcessBlock1Request()
815 if (aMessage.IsMoreBlocksFlagSet()) in ProcessBlock1Request()
820 response->SetMessageId(aMessage.GetMessageId()); in ProcessBlock1Request()
821 … IgnoreReturnValue(response->SetToken(AsConst(aMessage).GetToken(), aMessage.GetTokenLength())); in ProcessBlock1Request()
823 response->SetBlockWiseBlockNumber(aMessage.GetBlockWiseBlockNumber()); in ProcessBlock1Request()
824 response->SetMoreBlocksFlag(aMessage.IsMoreBlocksFlagSet()); in ProcessBlock1Request()
825 response->SetBlockWiseBlockSize(aMessage.GetBlockWiseBlockSize()); in ProcessBlock1Request()
856 Error CoapBase::ProcessBlock2Request(Message &aMessage, in ProcessBlock2Request() argument
868 SuccessOrExit(error = aMessage.ReadBlockOptionValues(kOptionBlock2)); in ProcessBlock2Request()
870 … LogInfo("Request for Block2 Nr. %d, Size: %d bytes received", aMessage.GetBlockWiseBlockNumber(), in ProcessBlock2Request()
871 otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())); in ProcessBlock2Request()
873 if (aMessage.GetBlockWiseBlockNumber() == 0) in ProcessBlock2Request()
875 aResource.HandleRequest(aMessage, aMessageInfo); in ProcessBlock2Request()
882 response->SetMessageId(aMessage.GetMessageId()); in ProcessBlock2Request()
884 SuccessOrExit(error = response->SetTokenFromMessage(aMessage)); in ProcessBlock2Request()
886 …VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlock… in ProcessBlock2Request()
889 … otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) * in ProcessBlock2Request()
890 aMessage.GetBlockWiseBlockNumber(), in ProcessBlock2Request()
928 VerifyOrExit(bufLen <= otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()), in ProcessBlock2Request()
930 response->SetBlockWiseBlockSize(aMessage.GetBlockWiseBlockSize()); in ProcessBlock2Request()
934 …(otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) * aMessage.GetBlockWiseBlockNumber(… in ProcessBlock2Request()
984 void CoapBase::SendCopy(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo) in SendCopy() argument
990 messageCopy = aMessage.Clone(aMessage.GetLength() - sizeof(Metadata)); in SendCopy()
1048 void CoapBase::Receive(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) in Receive() argument
1050 Message &message = AsCoapMessage(&aMessage); in Receive()
1075 void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo &aMessageInfo) in ProcessReceivedResponse() argument
1088 request = FindRelatedRequest(aMessage, aMessageInfo, metadata); in ProcessReceivedResponse()
1097 SuccessOrExit(error = iterator.Init(aMessage, kOptionObserve)); in ProcessReceivedResponse()
1102 switch (aMessage.GetType()) in ProcessReceivedResponse()
1105 if (aMessage.IsEmpty()) in ProcessReceivedResponse()
1114 if (aMessage.IsEmpty()) in ProcessReceivedResponse()
1123 FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, kErrorNone); in ProcessReceivedResponse()
1144 else if (aMessage.IsResponse() && aMessage.IsTokenEqual(*request)) in ProcessReceivedResponse()
1154 … metadata.mResponseHandler(metadata.mResponseContext, &aMessage, &aMessageInfo, kErrorNone); in ProcessReceivedResponse()
1169 SuccessOrExit(error = iterator.Init(aMessage)); in ProcessReceivedResponse()
1198 … FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, kErrorNone); in ProcessReceivedResponse()
1201 … if (aMessage.GetCode() == kCodeContinue && metadata.mBlockwiseTransmitHook != nullptr) in ProcessReceivedResponse()
1203 error = SendNextBlock1Request(*request, aMessage, aMessageInfo, metadata); in ProcessReceivedResponse()
1206 … if (aMessage.GetCode() != kCodeContinue || metadata.mBlockwiseTransmitHook == nullptr || in ProcessReceivedResponse()
1209 … FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error); in ProcessReceivedResponse()
1213 … if (aMessage.GetCode() < kCodeBadRequest && metadata.mBlockwiseReceiveHook != nullptr) in ProcessReceivedResponse()
1216 … SendNextBlock2Request(*request, aMessage, aMessageInfo, metadata, totalTransferSize, false); in ProcessReceivedResponse()
1219 … if (aMessage.GetCode() >= kCodeBadRequest || metadata.mBlockwiseReceiveHook == nullptr || in ProcessReceivedResponse()
1222 … FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error); in ProcessReceivedResponse()
1226 … if (aMessage.GetCode() < kCodeBadRequest && metadata.mBlockwiseReceiveHook != nullptr) in ProcessReceivedResponse()
1229 … SendNextBlock2Request(*request, aMessage, aMessageInfo, metadata, totalTransferSize, true); in ProcessReceivedResponse()
1232 FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error); in ProcessReceivedResponse()
1236 FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error); in ProcessReceivedResponse()
1242 … FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, kErrorNone); in ProcessReceivedResponse()
1253 IgnoreError(SendAck(aMessage, aMessageInfo)); in ProcessReceivedResponse()
1268 … metadata.mResponseHandler(metadata.mResponseContext, &aMessage, &aMessageInfo, kErrorNone); in ProcessReceivedResponse()
1272 FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, kErrorNone); in ProcessReceivedResponse()
1282 if (aMessage.IsConfirmable() || aMessage.IsNonConfirmable()) in ProcessReceivedResponse()
1286 IgnoreError(SendReset(aMessage, aMessageInfo)); in ProcessReceivedResponse()
1291 void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo &aMessageInfo) in ProcessReceivedRequest() argument
1305 SuccessOrExit(error = mInterceptor.Invoke(aMessage, aMessageInfo)); in ProcessReceivedRequest()
1308 switch (mResponsesQueue.GetMatchedResponseCopy(aMessage, aMessageInfo, &cachedResponse)) in ProcessReceivedRequest()
1325 SuccessOrExit(error = iterator.Init(aMessage)); in ProcessReceivedRequest()
1379 … switch (ProcessBlock1Request(aMessage, aMessageInfo, resource, totalTransferSize)) in ProcessReceivedRequest()
1382 resource.HandleRequest(aMessage, aMessageInfo); in ProcessReceivedRequest()
1388 … IgnoreReturnValue(SendHeaderResponse(kCodeRequestTooLarge, aMessage, aMessageInfo)); in ProcessReceivedRequest()
1392 … IgnoreReturnValue(SendHeaderResponse(kCodeRequestIncomplete, aMessage, aMessageInfo)); in ProcessReceivedRequest()
1396 … IgnoreReturnValue(SendHeaderResponse(kCodeInternalError, aMessage, aMessageInfo)); in ProcessReceivedRequest()
1405 … if ((error = ProcessBlock2Request(aMessage, aMessageInfo, resource)) != kErrorNone) in ProcessReceivedRequest()
1407 … IgnoreReturnValue(SendHeaderResponse(kCodeInternalError, aMessage, aMessageInfo)); in ProcessReceivedRequest()
1417 resource.HandleRequest(aMessage, aMessageInfo); in ProcessReceivedRequest()
1423 SuccessOrExit(error = aMessage.ReadUriPathOptions(uriPath)); in ProcessReceivedRequest()
1426 if ((mResourceHandler != nullptr) && mResourceHandler(*this, uriPath, aMessage, aMessageInfo)) in ProcessReceivedRequest()
1436 resource.HandleRequest(aMessage, aMessageInfo); in ProcessReceivedRequest()
1444 mDefaultHandler.Invoke(&aMessage, &aMessageInfo); in ProcessReceivedRequest()
1459 IgnoreError(SendNotFound(aMessage, aMessageInfo)); in ProcessReceivedRequest()
1466 void CoapBase::Metadata::ReadFrom(const Message &aMessage) in ReadFrom() argument
1468 uint16_t length = aMessage.GetLength(); in ReadFrom()
1471 IgnoreError(aMessage.Read(length - sizeof(*this), *this)); in ReadFrom()
1474 void CoapBase::Metadata::UpdateIn(Message &aMessage) const in UpdateIn()
1476 aMessage.Write(aMessage.GetLength() - sizeof(*this), *this); in UpdateIn()
1525 void ResponsesQueue::EnqueueResponse(Message &aMessage, in EnqueueResponse() argument
1535 VerifyOrExit(FindMatchedResponse(aMessage, aMessageInfo) == nullptr); in EnqueueResponse()
1539 VerifyOrExit((responseCopy = aMessage.Clone()) != nullptr); in EnqueueResponse()
1582 void ResponsesQueue::DequeueResponse(Message &aMessage) { mQueue.DequeueAndFree(aMessage); } in DequeueResponse() argument
1617 void ResponsesQueue::ResponseMetadata::ReadFrom(const Message &aMessage) in ReadFrom() argument
1619 uint16_t length = aMessage.GetLength(); in ReadFrom()
1622 IgnoreError(aMessage.Read(length - sizeof(*this), *this)); in ReadFrom()
1742 void Coap::HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo) in HandleUdpReceive() argument
1744 static_cast<Coap *>(aContext)->Receive(AsCoapMessage(aMessage), AsCoreType(aMessageInfo)); in HandleUdpReceive()
1747 Error Coap::Send(CoapBase &aCoapBase, ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) in Send() argument
1749 return static_cast<Coap &>(aCoapBase).Send(aMessage, aMessageInfo); in Send()
1752 Error Coap::Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) in Send() argument
1754 return mSocket.IsBound() ? mSocket.SendTo(aMessage, aMessageInfo) : kErrorInvalidState; in Send()