mirror of
https://github.com/espressif/openthread.git
synced 2026-10-04 14:57:38 +00:00
[api] update message API to create message with priority (#3199)
This commit is contained in:
committed by
Jonathan Hui
parent
f5fdf506ad
commit
f8909593a9
@@ -904,7 +904,7 @@ otLwfEventWorkerThread(
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
// Create a new message
|
||||
otMessage *message = otIp6NewMessage(pFilter->otCtx, TRUE);
|
||||
otMessage *message = otIp6NewMessage(pFilter->otCtx, NULL);
|
||||
if (message)
|
||||
{
|
||||
// Write to the message
|
||||
|
||||
@@ -485,13 +485,17 @@ const otCoapOption *otCoapHeaderGetNextOption(otCoapHeader *aHeader);
|
||||
/**
|
||||
* This function creates a new message with a CoAP header.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aHeader A pointer to a CoAP header that is used to create the message.
|
||||
* @note If @p aSettings is 'NULL', the link layer security is enabled and the message priority is set to
|
||||
* OT_MESSAGE_PRIORITY_NORMAL by default.
|
||||
*
|
||||
* @returns A pointer to the message or NULL if failed to allocate message.
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aHeader A pointer to a CoAP header that is used to create the message.
|
||||
* @param[in] aSettings A pointer to the message settings or NULL to set default settings.
|
||||
*
|
||||
* @returns A pointer to the message buffer or NULL if no message buffers are available or parameters are invalid.
|
||||
*
|
||||
*/
|
||||
otMessage *otCoapNewMessage(otInstance *aInstance, const otCoapHeader *aHeader);
|
||||
otMessage *otCoapNewMessage(otInstance *aInstance, const otCoapHeader *aHeader, const otMessageSettings *aSettings);
|
||||
|
||||
/**
|
||||
* This function sends a CoAP request.
|
||||
|
||||
@@ -370,14 +370,17 @@ otError otIp6CreateSemanticallyOpaqueIid(otInstance *aInstance, otNetifAddress *
|
||||
/**
|
||||
* Allocate a new message buffer for sending an IPv6 message.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aLinkSecurityEnabled TRUE if the message should be secured at Layer 2
|
||||
* @note If @p aSettings is 'NULL', the link layer security is enabled and the message priority is set to
|
||||
* OT_MESSAGE_PRIORITY_NORMAL by default.
|
||||
*
|
||||
* @returns A pointer to the message buffer or NULL if no message buffers are available.
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aSettings A pointer to the message settings or NULL to set default settings.
|
||||
*
|
||||
* @returns A pointer to the message buffer or NULL if no message buffers are available or parameters are invalid.
|
||||
*
|
||||
* @sa otFreeMessage
|
||||
*/
|
||||
otMessage *otIp6NewMessage(otInstance *aInstance, bool aLinkSecurityEnabled);
|
||||
otMessage *otIp6NewMessage(otInstance *aInstance, const otMessageSettings *aSettings);
|
||||
|
||||
/**
|
||||
* This function pointer is called when an IPv6 datagram is received.
|
||||
|
||||
@@ -88,6 +88,27 @@ typedef struct otBufferInfo
|
||||
uint16_t mApplicationCoapBuffers; ///< The number of buffers in the application CoAP send queue.
|
||||
} otBufferInfo;
|
||||
|
||||
/**
|
||||
* This enumeration defines the Openthread message priority levels.
|
||||
*
|
||||
*/
|
||||
typedef enum otMessagePriority
|
||||
{
|
||||
OT_MESSAGE_PRIORITY_LOW = 0, ///< Low priority level.
|
||||
OT_MESSAGE_PRIORITY_NORMAL = 1, ///< Normal priority level.
|
||||
OT_MESSAGE_PRIORITY_HIGH = 2, ///< High priority level.
|
||||
} otMessagePriority;
|
||||
|
||||
/**
|
||||
* This structure represents a message settings.
|
||||
*
|
||||
*/
|
||||
typedef struct otMessageSettings
|
||||
{
|
||||
bool mLinkSecurityEnabled; ///< TRUE if the message should be secured at Layer 2.
|
||||
otMessagePriority mPriority; ///< The message priority level.
|
||||
} otMessageSettings;
|
||||
|
||||
/**
|
||||
* Free an allocated message buffer.
|
||||
*
|
||||
|
||||
@@ -96,15 +96,18 @@ typedef struct otUdpSocket
|
||||
/**
|
||||
* Allocate a new message buffer for sending a UDP message.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aLinkSecurityEnabled TRUE if the message should be secured at Layer 2.
|
||||
* @note If @p aSettings is 'NULL', the link layer security is enabled and the message priority is set to
|
||||
* OT_MESSAGE_PRIORITY_NORMAL by default.
|
||||
*
|
||||
* @returns A pointer to the message buffer or NULL if no message buffers are available.
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aSettings A pointer to the message settings or NULL to set default settings.
|
||||
*
|
||||
* @returns A pointer to the message buffer or NULL if no message buffers are available or parameters are invalid.
|
||||
*
|
||||
* @sa otFreeMessage
|
||||
*
|
||||
*/
|
||||
otMessage *otUdpNewMessage(otInstance *aInstance, bool aLinkSecurityEnabled);
|
||||
otMessage *otUdpNewMessage(otInstance *aInstance, const otMessageSettings *aSettings);
|
||||
|
||||
/**
|
||||
* Open a UDP/IPv6 socket.
|
||||
|
||||
+1
-1
@@ -1849,7 +1849,7 @@ void Interpreter::HandlePingTimer()
|
||||
otMessage * message;
|
||||
const otMessageInfo *messageInfo = static_cast<const otMessageInfo *>(&mMessageInfo);
|
||||
|
||||
VerifyOrExit((message = otIp6NewMessage(mInstance, true)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = otIp6NewMessage(mInstance, NULL)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
SuccessOrExit(error = otMessageAppend(message, ×tamp, sizeof(timestamp)));
|
||||
SuccessOrExit(error = otMessageSetLength(message, mLength));
|
||||
SuccessOrExit(error = otIcmp6SendEchoRequest(mInstance, message, messageInfo, 1));
|
||||
|
||||
@@ -183,7 +183,7 @@ void Coap::HandleServerResponse(otCoapHeader *aHeader, otMessage *aMessage, cons
|
||||
otCoapHeaderSetPayloadMarker(&responseHeader);
|
||||
}
|
||||
|
||||
responseMessage = otCoapNewMessage(mInterpreter.mInstance, &responseHeader);
|
||||
responseMessage = otCoapNewMessage(mInterpreter.mInstance, &responseHeader, NULL);
|
||||
VerifyOrExit(responseMessage != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
if (otCoapHeaderGetCode(aHeader) == OT_COAP_CODE_GET)
|
||||
@@ -292,7 +292,7 @@ otError Coap::ProcessRequest(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
message = otCoapNewMessage(mInterpreter.mInstance, &header);
|
||||
message = otCoapNewMessage(mInterpreter.mInstance, &header, NULL);
|
||||
VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
// Embed content into message if given
|
||||
|
||||
@@ -416,7 +416,7 @@ void CoapSecure::HandleServerResponse(otCoapHeader *aHeader, otMessage *aMessage
|
||||
otCoapHeaderSetPayloadMarker(&responseHeader);
|
||||
}
|
||||
|
||||
responseMessage = otCoapNewMessage(mInterpreter.mInstance, &responseHeader);
|
||||
responseMessage = otCoapNewMessage(mInterpreter.mInstance, &responseHeader, NULL);
|
||||
VerifyOrExit(responseMessage != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
if (otCoapHeaderGetCode(aHeader) == OT_COAP_CODE_GET)
|
||||
@@ -530,7 +530,7 @@ otError CoapSecure::ProcessRequest(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
message = otCoapNewMessage(mInterpreter.mInstance, &header);
|
||||
message = otCoapNewMessage(mInterpreter.mInstance, &header, NULL);
|
||||
VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
// add payload
|
||||
@@ -618,7 +618,7 @@ void CoapSecure::DefaultHandle(otCoapHeader *aHeader, otMessage *aMessage, const
|
||||
otCoapHeaderSetMessageId(&responseHeader, otCoapHeaderGetMessageId(aHeader));
|
||||
otCoapHeaderSetToken(&responseHeader, otCoapHeaderGetToken(aHeader), otCoapHeaderGetTokenLength(aHeader));
|
||||
|
||||
responseMessage = otCoapNewMessage(mInterpreter.mInstance, &responseHeader);
|
||||
responseMessage = otCoapNewMessage(mInterpreter.mInstance, &responseHeader, NULL);
|
||||
VerifyOrExit(responseMessage != NULL, error = OT_ERROR_NO_BUFS);
|
||||
SuccessOrExit(error = otCoapSecureSendResponse(mInterpreter.mInstance, responseMessage, aMessageInfo));
|
||||
}
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ int Udp::Output(const char *aBuf, uint16_t aBufLength)
|
||||
otError error = OT_ERROR_NONE;
|
||||
otMessage *message;
|
||||
|
||||
VerifyOrExit((message = otUdpNewMessage(mInstance, true)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = otUdpNewMessage(mInstance, NULL)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
SuccessOrExit(error = otMessageSetLength(message, aBufLength));
|
||||
otMessageWrite(message, 0, aBuf, aBufLength);
|
||||
SuccessOrExit(error = otUdpSend(&mSocket, message, &mPeer));
|
||||
|
||||
@@ -158,7 +158,7 @@ otError UdpExample::ProcessSend(int argc, char *argv[])
|
||||
messageInfo.mInterfaceId = OT_NETIF_INTERFACE_ID_THREAD;
|
||||
}
|
||||
|
||||
message = otUdpNewMessage(mInterpreter.mInstance, true);
|
||||
message = otUdpNewMessage(mInterpreter.mInstance, NULL);
|
||||
VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
error = otMessageAppend(message, argv[curArg], static_cast<uint16_t>(strlen(argv[curArg])));
|
||||
|
||||
@@ -148,13 +148,20 @@ const otCoapOption *otCoapHeaderGetNextOption(otCoapHeader *aHeader)
|
||||
return static_cast<const otCoapOption *>(static_cast<Coap::Header *>(aHeader)->GetNextOption());
|
||||
}
|
||||
|
||||
otMessage *otCoapNewMessage(otInstance *aInstance, const otCoapHeader *aHeader)
|
||||
otMessage *otCoapNewMessage(otInstance *aInstance, const otCoapHeader *aHeader, const otMessageSettings *aSettings)
|
||||
{
|
||||
Message * message;
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
VerifyOrExit(aHeader != NULL, message = NULL);
|
||||
message = instance.GetApplicationCoap().NewMessage(*(static_cast<const Coap::Header *>(aHeader)));
|
||||
|
||||
if (aSettings != NULL)
|
||||
{
|
||||
VerifyOrExit(aSettings->mPriority <= OT_MESSAGE_PRIORITY_HIGH, message = NULL);
|
||||
}
|
||||
|
||||
message = instance.GetApplicationCoap().NewMessage(*(static_cast<const Coap::Header *>(aHeader)), aSettings);
|
||||
|
||||
exit:
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -194,16 +194,19 @@ otError otIp6Send(otInstance *aInstance, otMessage *aMessage)
|
||||
return error;
|
||||
}
|
||||
|
||||
otMessage *otIp6NewMessage(otInstance *aInstance, bool aLinkSecurityEnabled)
|
||||
otMessage *otIp6NewMessage(otInstance *aInstance, const otMessageSettings *aSettings)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
Message * message = instance.GetMessagePool().New(Message::kTypeIp6, 0);
|
||||
Message * message;
|
||||
|
||||
if (message)
|
||||
if (aSettings != NULL)
|
||||
{
|
||||
message->SetLinkSecurityEnabled(aLinkSecurityEnabled);
|
||||
VerifyOrExit(aSettings->mPriority <= OT_MESSAGE_PRIORITY_HIGH, message = NULL);
|
||||
}
|
||||
|
||||
message = instance.GetMessagePool().New(Message::kTypeIp6, 0, aSettings);
|
||||
|
||||
exit:
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,16 +40,19 @@
|
||||
|
||||
using namespace ot;
|
||||
|
||||
otMessage *otUdpNewMessage(otInstance *aInstance, bool aLinkSecurityEnabled)
|
||||
otMessage *otUdpNewMessage(otInstance *aInstance, const otMessageSettings *aSettings)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
Message * message = instance.GetIp6().GetUdp().NewMessage(0);
|
||||
Message * message;
|
||||
|
||||
if (message)
|
||||
if (aSettings != NULL)
|
||||
{
|
||||
message->SetLinkSecurityEnabled(aLinkSecurityEnabled);
|
||||
VerifyOrExit(aSettings->mPriority <= OT_MESSAGE_PRIORITY_HIGH, message = NULL);
|
||||
}
|
||||
|
||||
message = instance.GetMessagePool().New(Message::kTypeIp6, 0, aSettings);
|
||||
|
||||
exit:
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
@@ -142,14 +142,14 @@ void CoapBase::SetDefaultHandler(otCoapRequestHandler aHandler, void *aContext)
|
||||
mDefaultHandlerContext = aContext;
|
||||
}
|
||||
|
||||
Message *CoapBase::NewMessage(const Header &aHeader, uint8_t aPriority)
|
||||
Message *CoapBase::NewMessage(const Header &aHeader, const otMessageSettings *aSettings)
|
||||
{
|
||||
Message *message = NULL;
|
||||
|
||||
// Ensure that header has minimum required length.
|
||||
VerifyOrExit(aHeader.GetLength() >= Header::kMinHeaderLength);
|
||||
|
||||
VerifyOrExit((message = mSocket.NewMessage(aHeader.GetLength(), aPriority)) != NULL);
|
||||
VerifyOrExit((message = mSocket.NewMessage(aHeader.GetLength(), aSettings)) != NULL);
|
||||
message->Prepend(aHeader.GetBytes(), aHeader.GetLength());
|
||||
message->SetOffset(0);
|
||||
|
||||
|
||||
@@ -514,13 +514,16 @@ public:
|
||||
/**
|
||||
* This method creates a new message with a CoAP header.
|
||||
*
|
||||
* @param[in] aHeader A reference to a CoAP header that is used to create the message.
|
||||
* @param[in] aPriority The message priority level.
|
||||
* @note If @p aSettings is 'NULL', the link layer security is enabled and the message priority is set to
|
||||
* OT_MESSAGE_PRIORITY_NORMAL by default.
|
||||
*
|
||||
* @param[in] aHeader A reference to a CoAP header that is used to create the message.
|
||||
* @param[in] aSettings A pointer to the message settings or NULL to set default settings.
|
||||
*
|
||||
* @returns A pointer to the message or NULL if failed to allocate message.
|
||||
*
|
||||
*/
|
||||
Message *NewMessage(const Header &aHeader, uint8_t aPriority = kDefaultCoapMessagePriority);
|
||||
Message *NewMessage(const Header &aHeader, const otMessageSettings *aSettings = NULL);
|
||||
|
||||
/**
|
||||
* This method sends a CoAP message.
|
||||
@@ -717,11 +720,6 @@ protected:
|
||||
Ip6::UdpSocket mSocket;
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
kDefaultCoapMessagePriority = Message::kPriorityNormal,
|
||||
};
|
||||
|
||||
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
||||
|
||||
Message *CopyAndEnqueueMessage(const Message &aMessage, uint16_t aCopyLength, const CoapMetadata &aCoapMetadata);
|
||||
|
||||
@@ -91,6 +91,32 @@ exit:
|
||||
return message;
|
||||
}
|
||||
|
||||
Message *MessagePool::New(uint8_t aType, uint16_t aReserved, const otMessageSettings *aSettings)
|
||||
{
|
||||
Message *message;
|
||||
bool linkSecurityEnabled;
|
||||
uint8_t priority;
|
||||
|
||||
if (aSettings == NULL)
|
||||
{
|
||||
linkSecurityEnabled = true;
|
||||
priority = OT_MESSAGE_PRIORITY_NORMAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
linkSecurityEnabled = aSettings->mLinkSecurityEnabled;
|
||||
priority = aSettings->mPriority;
|
||||
}
|
||||
|
||||
message = New(aType, aReserved, priority);
|
||||
if (message)
|
||||
{
|
||||
message->SetLinkSecurityEnabled(linkSecurityEnabled);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
void MessagePool::Free(Message *aMessage)
|
||||
{
|
||||
assert(aMessage->Next(MessageInfo::kListAll) == NULL && aMessage->Prev(MessageInfo::kListAll) == NULL);
|
||||
|
||||
@@ -229,10 +229,10 @@ public:
|
||||
|
||||
enum
|
||||
{
|
||||
kPriorityLow = 0, ///< Low priority level.
|
||||
kPriorityNormal = 1, ///< Normal priority level.
|
||||
kPriorityHigh = 2, ///< High priority level.
|
||||
kPriorityNet = 3, ///< Network Control priority level.
|
||||
kPriorityLow = OT_MESSAGE_PRIORITY_LOW, ///< Low priority level.
|
||||
kPriorityNormal = OT_MESSAGE_PRIORITY_NORMAL, ///< Normal priority level.
|
||||
kPriorityHigh = OT_MESSAGE_PRIORITY_HIGH, ///< High priority level.
|
||||
kPriorityNet = OT_MESSAGE_PRIORITY_HIGH + 1, ///< Network Control priority level.
|
||||
|
||||
kNumPriorities = 4, ///< Number of priority levels.
|
||||
};
|
||||
@@ -1250,6 +1250,21 @@ public:
|
||||
*/
|
||||
Message *New(uint8_t aType, uint16_t aReserveHeader, uint8_t aPriority = kDefaultMessagePriority);
|
||||
|
||||
/**
|
||||
* This method is used to obtain a new message with specified settings.
|
||||
*
|
||||
* @note If @p aSettings is 'NULL', the link layer security is enabled and the message priority is set to
|
||||
* OT_MESSAGE_PRIORITY_NORMAL by default.
|
||||
*
|
||||
* @param[in] aType The message type.
|
||||
* @param[in] aReserveHeader The number of header bytes to reserve.
|
||||
* @param[in] aSettings A pointer to the message settings or NULL to set default settings.
|
||||
*
|
||||
* @returns A pointer to the message or NULL if no message buffers are available.
|
||||
*
|
||||
*/
|
||||
Message *New(uint8_t aType, uint16_t aReserveHeader, const otMessageSettings *aSettings);
|
||||
|
||||
/**
|
||||
* This method is used to free a message and return all message buffers to the buffer pool.
|
||||
*
|
||||
|
||||
@@ -227,7 +227,8 @@ void JoinerRouter::HandleRelayTransmit(Coap::Header &aHeader, Message &aMessage,
|
||||
JoinerRouterKekTlv kek;
|
||||
uint16_t offset;
|
||||
uint16_t length;
|
||||
Message * message = NULL;
|
||||
Message * message = NULL;
|
||||
otMessageSettings settings = {false, static_cast<otMessagePriority>(kMeshCoPMessagePriority)};
|
||||
Ip6::MessageInfo messageInfo;
|
||||
|
||||
VerifyOrExit(aHeader.GetType() == OT_COAP_TYPE_NON_CONFIRMABLE && aHeader.GetCode() == OT_COAP_CODE_POST,
|
||||
@@ -243,8 +244,7 @@ void JoinerRouter::HandleRelayTransmit(Coap::Header &aHeader, Message &aMessage,
|
||||
|
||||
SuccessOrExit(error = Tlv::GetValueOffset(aMessage, Tlv::kJoinerDtlsEncapsulation, offset, length));
|
||||
|
||||
VerifyOrExit((message = mSocket.NewMessage(0, kMeshCoPMessagePriority)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
message->SetLinkSecurityEnabled(false);
|
||||
VerifyOrExit((message = mSocket.NewMessage(0, &settings)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
while (length)
|
||||
{
|
||||
|
||||
@@ -57,7 +57,8 @@ enum
|
||||
*/
|
||||
inline Message *NewMeshCoPMessage(Coap::CoapBase &aCoap, const Coap::Header &aHeader)
|
||||
{
|
||||
return aCoap.NewMessage(aHeader, kMeshCoPMessagePriority);
|
||||
otMessageSettings settings = {true, static_cast<otMessagePriority>(kMeshCoPMessagePriority)};
|
||||
return aCoap.NewMessage(aHeader, &settings);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -67,10 +67,10 @@ Ip6::Ip6(Instance &aInstance)
|
||||
{
|
||||
}
|
||||
|
||||
Message *Ip6::NewMessage(uint16_t aReserved, uint8_t aPriority)
|
||||
Message *Ip6::NewMessage(uint16_t aReserved, const otMessageSettings *aSettings)
|
||||
{
|
||||
return GetInstance().GetMessagePool().New(
|
||||
Message::kTypeIp6, sizeof(Header) + sizeof(HopByHopHeader) + sizeof(OptionMpl) + aReserved, aPriority);
|
||||
Message::kTypeIp6, sizeof(Header) + sizeof(HopByHopHeader) + sizeof(OptionMpl) + aReserved, aSettings);
|
||||
}
|
||||
|
||||
uint16_t Ip6::UpdateChecksum(uint16_t aChecksum, const Address &aAddress)
|
||||
|
||||
@@ -110,13 +110,16 @@ public:
|
||||
/**
|
||||
* This method allocates a new message buffer from the buffer pool.
|
||||
*
|
||||
* @note If @p aSettings is 'NULL', the link layer security is enabled and the message priority is set to
|
||||
* OT_MESSAGE_PRIORITY_NORMAL by default.
|
||||
*
|
||||
* @param[in] aReserved The number of header bytes to reserve following the IPv6 header.
|
||||
* @param[in] aPriority The priority level of the message.
|
||||
* @param[in] aSettings A pointer to the message settings or NULL to set default settings.
|
||||
*
|
||||
* @returns A pointer to the message or NULL if insufficient message buffers are available.
|
||||
*
|
||||
*/
|
||||
Message *NewMessage(uint16_t aReserved, uint8_t aPriority = kDefaultIp6MessagePriority);
|
||||
Message *NewMessage(uint16_t aReserved, const otMessageSettings *aSettings = NULL);
|
||||
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
|
||||
@@ -69,9 +69,9 @@ Udp &UdpSocket::GetUdp(void)
|
||||
return GetInstance().GetIp6().GetUdp();
|
||||
}
|
||||
|
||||
Message *UdpSocket::NewMessage(uint16_t aReserved, uint8_t aPriority)
|
||||
Message *UdpSocket::NewMessage(uint16_t aReserved, const otMessageSettings *aSettings)
|
||||
{
|
||||
return GetUdp().NewMessage(aReserved, aPriority);
|
||||
return GetUdp().NewMessage(aReserved, aSettings);
|
||||
}
|
||||
|
||||
otError UdpSocket::Open(otUdpReceive aHandler, void *aContext)
|
||||
@@ -299,9 +299,9 @@ uint16_t Udp::GetEphemeralPort(void)
|
||||
return rval;
|
||||
}
|
||||
|
||||
Message *Udp::NewMessage(uint16_t aReserved, uint8_t aPriority)
|
||||
Message *Udp::NewMessage(uint16_t aReserved, const otMessageSettings *aSettings)
|
||||
{
|
||||
return GetIp6().NewMessage(sizeof(UdpHeader) + aReserved, aPriority);
|
||||
return GetIp6().NewMessage(sizeof(UdpHeader) + aReserved, aSettings);
|
||||
}
|
||||
|
||||
otError Udp::SendDatagram(Message &aMessage, MessageInfo &aMessageInfo, IpProto aIpProto)
|
||||
|
||||
+6
-13
@@ -109,13 +109,16 @@ public:
|
||||
/**
|
||||
* This method returns a new UDP message with sufficient header space reserved.
|
||||
*
|
||||
* @note If @p aSettings is 'NULL', the link layer security is enabled and the message priority is set to
|
||||
* OT_MESSAGE_PRIORITY_NORMAL by default.
|
||||
*
|
||||
* @param[in] aReserved The number of header bytes to reserve after the UDP header.
|
||||
* @param[in] aPriority A reference to the priority of the message.
|
||||
* @param[in] aSettings A pointer to the message settings or NULL to set default settings.
|
||||
*
|
||||
* @returns A pointer to the message or NULL if no buffers are available.
|
||||
*
|
||||
*/
|
||||
Message *NewMessage(uint16_t aReserved, uint8_t aPriority = kDefaultSocketMessagePriority);
|
||||
Message *NewMessage(uint16_t aReserved, const otMessageSettings *aSettings = NULL);
|
||||
|
||||
/**
|
||||
* This method opens the UDP socket.
|
||||
@@ -186,11 +189,6 @@ public:
|
||||
SockAddr &GetPeerName(void) { return *static_cast<SockAddr *>(&mPeerName); }
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
kDefaultSocketMessagePriority = Message::kPriorityNormal,
|
||||
};
|
||||
|
||||
UdpSocket *GetNext(void) { return static_cast<UdpSocket *>(mNext); }
|
||||
void SetNext(UdpSocket *socket) { mNext = static_cast<otUdpSocket *>(socket); }
|
||||
|
||||
@@ -276,7 +274,7 @@ public:
|
||||
* @returns A pointer to the message or NULL if no buffers are available.
|
||||
*
|
||||
*/
|
||||
Message *NewMessage(uint16_t aReserved, uint8_t aPriority = kDefaultUdpMessagePriority);
|
||||
Message *NewMessage(uint16_t aReserved, const otMessageSettings *aSettings = NULL);
|
||||
|
||||
/**
|
||||
* This method sends an IPv6 datagram.
|
||||
@@ -344,11 +342,6 @@ public:
|
||||
#endif // OPENTHREAD_ENABLE_UDP_PROXY
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
kDefaultUdpMessagePriority = Message::kPriorityNormal,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
kDynamicPortMin = 49152, ///< Service Name and Transport Protocol Port Number Registry
|
||||
|
||||
@@ -1079,13 +1079,13 @@ void Mle::GenerateNonce(const Mac::ExtAddress &aMacAddr,
|
||||
|
||||
Message *Mle::NewMleMessage(void)
|
||||
{
|
||||
Message *message;
|
||||
Message * message;
|
||||
otMessageSettings settings = {false, static_cast<otMessagePriority>(kMleMessagePriority)};
|
||||
|
||||
message = mSocket.NewMessage(0, kMleMessagePriority);
|
||||
message = mSocket.NewMessage(0, &settings);
|
||||
VerifyOrExit(message != NULL);
|
||||
|
||||
message->SetSubType(Message::kSubTypeMleGeneral);
|
||||
message->SetLinkSecurityEnabled(false);
|
||||
|
||||
exit:
|
||||
return message;
|
||||
|
||||
+12
-10
@@ -1420,7 +1420,7 @@ template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_STREAM_NET>(void)
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
// STREAM_NET requires layer 2 security.
|
||||
message = otIp6NewMessage(mInstance, true);
|
||||
message = otIp6NewMessage(mInstance, NULL);
|
||||
VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
SuccessOrExit(error = mDecoder.ReadDataWithLen(framePtr, frameLen));
|
||||
@@ -2255,15 +2255,16 @@ template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NET_REQUIRE_JOIN_EXIS
|
||||
|
||||
template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_STREAM_NET_INSECURE>(void)
|
||||
{
|
||||
const uint8_t *framePtr = NULL;
|
||||
uint16_t frameLen = 0;
|
||||
const uint8_t *metaPtr = NULL;
|
||||
uint16_t metaLen = 0;
|
||||
otMessage * message = NULL;
|
||||
otError error = OT_ERROR_NONE;
|
||||
const uint8_t * framePtr = NULL;
|
||||
uint16_t frameLen = 0;
|
||||
const uint8_t * metaPtr = NULL;
|
||||
uint16_t metaLen = 0;
|
||||
otMessage * message = NULL;
|
||||
otError error = OT_ERROR_NONE;
|
||||
otMessageSettings msgSettings = {false, OT_MESSAGE_PRIORITY_NORMAL};
|
||||
|
||||
// STREAM_NET_INSECURE packets are not secured at layer 2.
|
||||
message = otIp6NewMessage(mInstance, false);
|
||||
message = otIp6NewMessage(mInstance, &msgSettings);
|
||||
VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
SuccessOrExit(mDecoder.ReadDataWithLen(framePtr, frameLen));
|
||||
@@ -2850,9 +2851,10 @@ template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_UDP_PROXY_STRE
|
||||
uint16_t peerPort;
|
||||
uint16_t sockPort;
|
||||
otMessage * message;
|
||||
otError error = OT_ERROR_NONE;
|
||||
otError error = OT_ERROR_NONE;
|
||||
otMessageSettings msgSettings = {false, OT_MESSAGE_PRIORITY_NORMAL};
|
||||
|
||||
message = otIp6NewMessage(mInstance, false);
|
||||
message = otIp6NewMessage(mInstance, &msgSettings);
|
||||
VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
SuccessOrExit(error = mDecoder.ReadDataWithLen(framePtr, frameLen));
|
||||
|
||||
@@ -392,6 +392,8 @@ void platformUdpInit(void)
|
||||
|
||||
void platformUdpProcess(otInstance *aInstance, const fd_set *aReadFdSet)
|
||||
{
|
||||
otMessageSettings msgSettings = {false, OT_MESSAGE_PRIORITY_NORMAL};
|
||||
|
||||
VerifyOrExit(sPlatNetifIndex != 0);
|
||||
|
||||
for (otUdpSocket *socket = otUdpGetSockets(aInstance); socket != NULL; socket = socket->mNext)
|
||||
@@ -413,7 +415,7 @@ void platformUdpProcess(otInstance *aInstance, const fd_set *aReadFdSet)
|
||||
continue;
|
||||
}
|
||||
|
||||
message = otUdpNewMessage(aInstance, false);
|
||||
message = otUdpNewMessage(aInstance, &msgSettings);
|
||||
|
||||
if (message == NULL)
|
||||
{
|
||||
|
||||
@@ -43,10 +43,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
const otPanId panId = 0xdead;
|
||||
|
||||
otInstance *instance = NULL;
|
||||
otMessage * message = NULL;
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool isSecure;
|
||||
otInstance * instance = NULL;
|
||||
otMessage * message = NULL;
|
||||
otError error = OT_ERROR_NONE;
|
||||
otMessageSettings settings;
|
||||
|
||||
VerifyOrExit(size > 0);
|
||||
|
||||
@@ -58,9 +58,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
otThreadSetEnabled(instance, true);
|
||||
otThreadBecomeLeader(instance);
|
||||
|
||||
isSecure = (data[0] & 0x1) != 0;
|
||||
settings.mLinkSecurityEnabled = (data[0] & 0x1) != 0;
|
||||
settings.mPriority = OT_MESSAGE_PRIORITY_NORMAL;
|
||||
|
||||
message = otIp6NewMessage(instance, isSecure);
|
||||
message = otIp6NewMessage(instance, &settings);
|
||||
VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
error = otMessageAppend(message, data + 1, static_cast<uint16_t>(size - 1));
|
||||
|
||||
@@ -236,7 +236,7 @@ void TestMessageQueueOtApis(void)
|
||||
|
||||
for (int i = 0; i < kNumTestMessages; i++)
|
||||
{
|
||||
msg[i] = otIp6NewMessage(sInstance, true);
|
||||
msg[i] = otIp6NewMessage(sInstance, NULL);
|
||||
VerifyOrQuit(msg[i] != NULL, "otIp6NewMessage() failed.\n");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user