#ifndef CLI_COAP_HPP_
#define CLI_COAP_HPP_
#include "openthread-core-config.h"
#if OPENTHREAD_CONFIG_COAP_API_ENABLE
#include "coap/coap_message.hpp"
namespace ot {
namespace Cli {
class Interpreter;
class Coap
{
public:
explicit Coap(Interpreter &aInterpreter);
otError Process(uint8_t aArgsLength, char *aArgs[]);
private:
enum
{
kMaxUriLength = 32,
kMaxBufferSize = 16
};
struct Command
{
const char *mName;
otError (Coap::*mCommand)(uint8_t aArgsLength, char *aArgs[]);
};
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
otError CancelResourceSubscription(void);
void CancelSubscriber(void);
#endif
void PrintPayload(otMessage *aMessage) const;
otError ProcessHelp(uint8_t aArgsLength, char *aArgs[]);
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
otError ProcessCancel(uint8_t aArgsLength, char *aArgs[]);
#endif
otError ProcessParameters(uint8_t aArgsLength, char *aArgs[]);
otError ProcessRequest(uint8_t aArgsLength, char *aArgs[]);
otError ProcessResource(uint8_t aArgsLength, char *aArgs[]);
otError ProcessSet(uint8_t aArgsLength, char *aArgs[]);
otError ProcessStart(uint8_t aArgsLength, char *aArgs[]);
otError ProcessStop(uint8_t aArgsLength, char *aArgs[]);
static void HandleRequest(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
void HandleRequest(otMessage *aMessage, const otMessageInfo *aMessageInfo);
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
static void HandleNotificationResponse(void * aContext,
otMessage * aMessage,
const otMessageInfo *aMessageInfo,
otError aError);
void HandleNotificationResponse(otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aError);
#endif
static void HandleResponse(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aError);
void HandleResponse(otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aError);
const otCoapTxParameters *GetRequestTxParameters(void) const
{
return mUseDefaultRequestTxParameters ? NULL : &mRequestTxParameters;
}
const otCoapTxParameters *GetResponseTxParameters(void) const
{
return mUseDefaultResponseTxParameters ? NULL : &mResponseTxParameters;
}
static const Command sCommands[];
Interpreter & mInterpreter;
bool mUseDefaultRequestTxParameters;
bool mUseDefaultResponseTxParameters;
otCoapTxParameters mRequestTxParameters;
otCoapTxParameters mResponseTxParameters;
otCoapResource mResource;
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
otIp6Address mRequestAddr;
otSockAddr mSubscriberSock;
char mRequestUri[kMaxUriLength];
uint8_t mRequestToken[OT_COAP_MAX_TOKEN_LENGTH];
uint8_t mSubscriberToken[OT_COAP_MAX_TOKEN_LENGTH];
#endif
char mUriPath[kMaxUriLength];
char mResourceContent[kMaxBufferSize];
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
uint32_t mObserveSerial;
uint8_t mRequestTokenLength;
uint8_t mSubscriberTokenLength;
bool mSubscriberConfirmableNotifications;
#endif
};
} }
#endif
#endif