This is CoAP library with a focus on simplicity. It offers minimal CoAP PDU construction and decoding to and from byte buffers.

Dependents:   cantcoap_cellular_test yeswecancoap

Teaser

CoAP implementation that focuses on simplicity by offering a minimal set of functions and straightforward interface.

	CoapPDU *pdu = new CoapPDU();
	pdu->setType(CoapPDU::COAP_CONFIRMABLE);
	pdu->setCode(CoapPDU::COAP_GET);
	pdu->setToken((uint8_t*)"\3\2\1\0",4);
	pdu->setMessageID(0x0005);
	pdu->setURI((char*)"test",4);

	// send packet 
	ret = send(sockfd,pdu->getPDUPointer(),pdu->getPDULength(),0);

...

	// receive packet
	ret = recvfrom(sockfd,&buffer,BUF_LEN,0,(sockaddr*)&recvAddr,&recvAddrLen);
	CoapPDU *recvPDU = new CoapPDU((uint8_t*)buffer,ret);
	if(recvPDU->validate()) {
		recvPDU->getURI(uriBuffer,URI_BUF_LEN,&recvURILen);
		...
	}

Long description

This is a CoAP implementation with a focus on simplicity. The library only provides PDU construction and de-construction.

The user is expected to deal with retransmissions, timeouts, and message ID matching themselves. This isn’t as arduous as it sounds and makes a lot more sense on a constrained device.

Imagine for example a simple microcontroller sensor that only reports readings once every 15 minutes, and only sends a few packets each time. Do you really need a complicated framework to deal with acknowledgements and re-transmissions?

Since CoAP recommends you only send one packet at at time, this means you only need to keep track of one on-going transaction at a time. Yeah... I think you’re capable of this.

Furthermore, the timers and interrupt processes between different embedded processor architectures, vary quite a bit. So it often makes sense to write the packet sending processes yourself.

Finally, you might be sending the packets over odd transport bearers such as a SMS (woah dude, that's just totally wild) or a simple radio bearer. In which case, it’s easiest to deal with buffers. If I built retransmission handlers, they’d all be UDP/IP specific and would bloat the code for no reason.

Resources

Github page for the cantcoap library is here:

https://github.com/staropram/cantcoap

Doxygen for the library is here:

http://staropram.github.io/cantcoap/index.html

Examples

Construction

There are a couple of different ways to construct a PDU depending on whether you want the library to allocate memory for you, or whether you have an external buffer you want to use. You can also re-purpose existing objects.

Using a managed object

The simplest usage scenario hands control of memory allocation to the library:

CoapPDU *pdu = new CoapPDU();
...
pdu->setType(CoapPDU::COAP_CONFIRMABLE);
pdu->setCode(CoapPDU::COAP_GET);
pdu->addOption(11,5,(uint8_t*)"hello");
pdu->addOption(11,5,(uint8_t*)"there");
pdu->addOption(11,6,(uint8_t*)"server");

In this case you just call the default constructor. That's it. The library handles memory from there-on out. For example, when adding each of those options, the library will realloc the pdu to accomodate space for them. It will also shrink the PDU if something changes (like the token length) so that it always uses the minimum amount of memory.

When you free the PDU, all data including the buffer is deleted. The PDU can also be reused as shown below.

Using an external buffer for memory

There are two obvious reasons why you would do this:

1. The buffer contains a CoAP PDU and you want to access the data in the PDU. 2. Buffers cost space and allocating memory consumes processor resources. On embedded targets it is often simpler to reuse buffers where possible.

The first instance is a special case and requires some extra work. Just using an external buffer is as simple as follows:

uint8_t *buffer[100];
CoapPDU *pdu = new CoapPDU((uint8_t*)buffer,100,0);
...
pdu->setType(CoapPDU::COAP_CONFIRMABLE);
pdu->setCode(CoapPDU::COAP_GET);
pdu->addOption(11,5,(uint8_t*)"hello");
pdu->addOption(11,5,(uint8_t*)"there");
pdu->addOption(11,6,(uint8_t*)"server");

The PDU is constructed as normal except that the memory of your buffer is used instead of allocated memory.

A call such as this:

pdu->addOption(11,5,(uint8_t*)"hello");

Will fail if there is no space left in the buffer.

When you delete the object, the buffer is not freed. Hey, it's your buffer mannn!

Reusing an existing object

Regardless of whether you constructed a PDU using either of the above methods, you can always reuse it:

pdu->reset(); 
...
pdu->setType(CoapPDU::COAP_CONFIRMABLE);
pdu->setCode(CoapPDU::COAP_GET);
pdu->addOption(11,5,(uint8_t*)"hello");
pdu->addOption(11,5,(uint8_t*)"there");
pdu->addOption(11,6,(uint8_t*)"server");

The only difference is that if the PDU was initially constructed using managed-memory, then it will continue to have managed-memory. Whereas if the PDU was constructed with an external buffer, then you are limited in space by the size of the buffer you used.

Receving CoAP packets over a network or something

In this case you have a CoAP PDU in a buffer you just gobbled from a socket and want to read it:

uint8_t *buffer[100];
int ret = recvfrom(sockfd,&buffer,BUF_LEN,0,(sockaddr*)&recvAddr,&recvAddrLen);
CoapPDU *recvPDU = new CoapPDU((uint8_t*)buffer,ret,100);
if(recvPDU->validate()) {
	recvPDU->printHuman();
	// do your work
}

You must call CoapPDU::validate() and get a positive response before accessing any of the data members. This sets up some internal pionters and so on, so if you fail to do it, undefined behaviour will result.

Note that the constructor is just a shorthand for the external-buffer-constructor explained above, and you can use the long form if you want. For example. you might want to use the long form if you have a buffer bigger than the PDU and you expect to reuse it.

You can reuse this object by resetting it as above.

If you reuse such an object, you need to set the PDU length manually because there is no way to deduce the PDU length using validate():

	// earlier
	#define BUFLEN 500
	char buffer[BUFLEN];
	CoapPDU *recvPDU = new CoapPDU((uint8_t*)buffer,BUFLEN,BUFLEN);

	...

	while(1) {
		// receive packet
		ret = sockfd,&buffer,BUFLEN,0);
		if(ret==-1) {
			INFO("Error receiving data");
			// handle error
		}

		// validate packet
		// you should also check that ret doesn't exceed buffer length
		recvPDU->setPDULength(ret);
		if(recvPDU->validate()!=1) {
			INFO("Malformed CoAP packet");
			// handle error
		}
	}
Committer:
ashleymills
Date:
Tue Oct 08 14:36:01 2013 +0000
Revision:
0:3d62a105fd34
Child:
1:5eec2844ad47
CoAP library with a focus on simplicity. Init.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 0:3d62a105fd34 1 /// Copyright (c) 2013, Ashley Mills.
ashleymills 0:3d62a105fd34 2 #define MBED
ashleymills 0:3d62a105fd34 3 #ifndef MBED
ashleymills 0:3d62a105fd34 4 #include <unistd.h>
ashleymills 0:3d62a105fd34 5 #endif
ashleymills 0:3d62a105fd34 6 #include <stdint.h>
ashleymills 0:3d62a105fd34 7
ashleymills 0:3d62a105fd34 8 #define INFO(...) printf(__VA_ARGS__); printf("\r\n");
ashleymills 0:3d62a105fd34 9 #define INFOX(...); printf(__VA_ARGS__);
ashleymills 0:3d62a105fd34 10 #define ERR(...) printf(__VA_ARGS__); printf("\r\n");
ashleymills 0:3d62a105fd34 11
ashleymills 0:3d62a105fd34 12 #ifdef DEBUG
ashleymills 0:3d62a105fd34 13 #define DBG(...) fprintf(stderr,"%s:%d ",__FILE__,__LINE__); fprintf(stderr,__VA_ARGS__); fprintf(stderr,"\r\n");
ashleymills 0:3d62a105fd34 14 #define DBGX(...) fprintf(stderr,__VA_ARGS__);
ashleymills 0:3d62a105fd34 15 #define DBGLX(...) fprintf(stderr,"%s:%d ",__FILE__,__LINE__); fprintf(stderr,__VA_ARGS__);
ashleymills 0:3d62a105fd34 16 #define DBG_PDU() printBin();
ashleymills 0:3d62a105fd34 17 #else
ashleymills 0:3d62a105fd34 18 #define DBG(...) {};
ashleymills 0:3d62a105fd34 19 #define DBGX(...) {};
ashleymills 0:3d62a105fd34 20 #define DBGLX(...) {};
ashleymills 0:3d62a105fd34 21 #define DBG_PDU() {};
ashleymills 0:3d62a105fd34 22 #endif
ashleymills 0:3d62a105fd34 23
ashleymills 0:3d62a105fd34 24 #define COAP_HDR_SIZE 4
ashleymills 0:3d62a105fd34 25 #define COAP_OPTION_HDR_BYTE 1
ashleymills 0:3d62a105fd34 26
ashleymills 0:3d62a105fd34 27 // CoAP PDU format
ashleymills 0:3d62a105fd34 28
ashleymills 0:3d62a105fd34 29 // 0 1 2 3
ashleymills 0:3d62a105fd34 30 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
ashleymills 0:3d62a105fd34 31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ashleymills 0:3d62a105fd34 32 // |Ver| T | TKL | Code | Message ID |
ashleymills 0:3d62a105fd34 33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ashleymills 0:3d62a105fd34 34 // | Token (if any, TKL bytes) ...
ashleymills 0:3d62a105fd34 35 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ashleymills 0:3d62a105fd34 36 // | Options (if any) ...
ashleymills 0:3d62a105fd34 37 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ashleymills 0:3d62a105fd34 38 // |1 1 1 1 1 1 1 1| Payload (if any) ...
ashleymills 0:3d62a105fd34 39 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ashleymills 0:3d62a105fd34 40
ashleymills 0:3d62a105fd34 41 class CoapPDU {
ashleymills 0:3d62a105fd34 42
ashleymills 0:3d62a105fd34 43
ashleymills 0:3d62a105fd34 44 public:
ashleymills 0:3d62a105fd34 45 /// CoAP message types. Note, values only work as enum.
ashleymills 0:3d62a105fd34 46 enum Type {
ashleymills 0:3d62a105fd34 47 COAP_CONFIRMABLE=0x00,
ashleymills 0:3d62a105fd34 48 COAP_NON_CONFIRMABLE=0x10,
ashleymills 0:3d62a105fd34 49 COAP_ACKNOWLEDGEMENT=0x20,
ashleymills 0:3d62a105fd34 50 COAP_RESET=0x30
ashleymills 0:3d62a105fd34 51 };
ashleymills 0:3d62a105fd34 52
ashleymills 0:3d62a105fd34 53 // CoAP response codes.
ashleymills 0:3d62a105fd34 54 enum Code {
ashleymills 0:3d62a105fd34 55 COAP_EMPTY=0x00,
ashleymills 0:3d62a105fd34 56 COAP_GET,
ashleymills 0:3d62a105fd34 57 COAP_POST,
ashleymills 0:3d62a105fd34 58 COAP_PUT,
ashleymills 0:3d62a105fd34 59 COAP_DELETE,
ashleymills 0:3d62a105fd34 60 COAP_CREATED=0x41,
ashleymills 0:3d62a105fd34 61 COAP_DELETED,
ashleymills 0:3d62a105fd34 62 COAP_VALID,
ashleymills 0:3d62a105fd34 63 COAP_CHANGED,
ashleymills 0:3d62a105fd34 64 COAP_CONTENT,
ashleymills 0:3d62a105fd34 65 COAP_BAD_REQUEST=0x80,
ashleymills 0:3d62a105fd34 66 COAP_UNAUTHORIZED,
ashleymills 0:3d62a105fd34 67 COAP_BAD_OPTION,
ashleymills 0:3d62a105fd34 68 COAP_FORBIDDEN,
ashleymills 0:3d62a105fd34 69 COAP_NOT_FOUND,
ashleymills 0:3d62a105fd34 70 COAP_METHOD_NOT_ALLOWED,
ashleymills 0:3d62a105fd34 71 COAP_NOT_ACCEPTABLE,
ashleymills 0:3d62a105fd34 72 COAP_PRECONDITION_FAILED=0x8C,
ashleymills 0:3d62a105fd34 73 COAP_REQUEST_ENTITY_TOO_LARGE=0x8D,
ashleymills 0:3d62a105fd34 74 COAP_UNSUPPORTED_CONTENT_FORMAT=0x8F,
ashleymills 0:3d62a105fd34 75 COAP_INTERNAL_SERVER_ERROR=0xA0,
ashleymills 0:3d62a105fd34 76 COAP_NOT_IMPLEMENTED,
ashleymills 0:3d62a105fd34 77 COAP_BAD_GATEWAY,
ashleymills 0:3d62a105fd34 78 COAP_SERVICE_UNAVAILABLE,
ashleymills 0:3d62a105fd34 79 COAP_GATEWAY_TIMEOUT,
ashleymills 0:3d62a105fd34 80 COAP_PROXYING_NOT_SUPPORTED
ashleymills 0:3d62a105fd34 81 };
ashleymills 0:3d62a105fd34 82
ashleymills 0:3d62a105fd34 83 /// CoAP option numbers.
ashleymills 0:3d62a105fd34 84 enum Option {
ashleymills 0:3d62a105fd34 85 COAP_OPTION_IF_MATCH=1,
ashleymills 0:3d62a105fd34 86 COAP_OPTION_URI_HOST=3,
ashleymills 0:3d62a105fd34 87 COAP_OPTION_ETAG,
ashleymills 0:3d62a105fd34 88 COAP_OPTION_IF_NONE_MATCH,
ashleymills 0:3d62a105fd34 89 COAP_OPTION_OBSERVE,
ashleymills 0:3d62a105fd34 90 COAP_OPTION_URI_PORT,
ashleymills 0:3d62a105fd34 91 COAP_OPTION_LOCATION_PATH,
ashleymills 0:3d62a105fd34 92 COAP_OPTION_URI_PATH=11,
ashleymills 0:3d62a105fd34 93 COAP_OPTION_CONTENT_FORMAT,
ashleymills 0:3d62a105fd34 94 COAP_OPTION_MAX_AGE=14,
ashleymills 0:3d62a105fd34 95 COAP_OPTION_URI_QUERY,
ashleymills 0:3d62a105fd34 96 COAP_OPTION_ACCEPT=17,
ashleymills 0:3d62a105fd34 97 COAP_OPTION_LOCATION_QUERY=20,
ashleymills 0:3d62a105fd34 98 COAP_OPTION_BLOCK2=23,
ashleymills 0:3d62a105fd34 99 COAP_OPTION_BLOCK1=27,
ashleymills 0:3d62a105fd34 100 COAP_OPTION_SIZE2,
ashleymills 0:3d62a105fd34 101 COAP_OPTION_PROXY_URI=35,
ashleymills 0:3d62a105fd34 102 COAP_OPTION_PROXY_SCHEME=39,
ashleymills 0:3d62a105fd34 103 COAP_OPTION_SIZE1=60
ashleymills 0:3d62a105fd34 104 };
ashleymills 0:3d62a105fd34 105
ashleymills 0:3d62a105fd34 106 /// CoAP content-formats.
ashleymills 0:3d62a105fd34 107 enum ContentFormat {
ashleymills 0:3d62a105fd34 108 COAP_CONTENT_FORMAT_TEXT_PLAIN = 0,
ashleymills 0:3d62a105fd34 109 COAP_CONTENT_FORMAT_APP_LINK = 40,
ashleymills 0:3d62a105fd34 110 COAP_CONTENT_FORMAT_APP_XML,
ashleymills 0:3d62a105fd34 111 COAP_CONTENT_FORMAT_APP_OCTET,
ashleymills 0:3d62a105fd34 112 COAP_CONTENT_FORMAT_APP_EXI = 47,
ashleymills 0:3d62a105fd34 113 COAP_CONTENT_FORMAT_APP_JSON = 50
ashleymills 0:3d62a105fd34 114 };
ashleymills 0:3d62a105fd34 115
ashleymills 0:3d62a105fd34 116 /// Sequence of these is returned by CoapPDU::getOptions()
ashleymills 0:3d62a105fd34 117 struct CoapOption {
ashleymills 0:3d62a105fd34 118 uint16_t optionDelta;
ashleymills 0:3d62a105fd34 119 uint16_t optionNumber;
ashleymills 0:3d62a105fd34 120 uint16_t optionValueLength;
ashleymills 0:3d62a105fd34 121 int totalLength;
ashleymills 0:3d62a105fd34 122 uint8_t *optionPointer;
ashleymills 0:3d62a105fd34 123 uint8_t *optionValuePointer;
ashleymills 0:3d62a105fd34 124 };
ashleymills 0:3d62a105fd34 125
ashleymills 0:3d62a105fd34 126 // construction and destruction
ashleymills 0:3d62a105fd34 127 CoapPDU();
ashleymills 0:3d62a105fd34 128 CoapPDU(uint8_t *pdu, int pduLength);
ashleymills 0:3d62a105fd34 129 CoapPDU(uint8_t *buffer, int bufferLength, int pduLength);
ashleymills 0:3d62a105fd34 130 ~CoapPDU();
ashleymills 0:3d62a105fd34 131 int reset();
ashleymills 0:3d62a105fd34 132 int validate();
ashleymills 0:3d62a105fd34 133
ashleymills 0:3d62a105fd34 134 // version
ashleymills 0:3d62a105fd34 135 int setVersion(uint8_t version);
ashleymills 0:3d62a105fd34 136 uint8_t getVersion();
ashleymills 0:3d62a105fd34 137
ashleymills 0:3d62a105fd34 138 // message type
ashleymills 0:3d62a105fd34 139 void setType(CoapPDU::Type type);
ashleymills 0:3d62a105fd34 140 CoapPDU::Type getType();
ashleymills 0:3d62a105fd34 141
ashleymills 0:3d62a105fd34 142 // tokens
ashleymills 0:3d62a105fd34 143 int setTokenLength(uint8_t tokenLength);
ashleymills 0:3d62a105fd34 144 int getTokenLength();
ashleymills 0:3d62a105fd34 145 uint8_t* getTokenPointer();
ashleymills 0:3d62a105fd34 146 int setToken(uint8_t *token, uint8_t tokenLength);
ashleymills 0:3d62a105fd34 147
ashleymills 0:3d62a105fd34 148 // message code
ashleymills 0:3d62a105fd34 149 void setCode(CoapPDU::Code code);
ashleymills 0:3d62a105fd34 150 CoapPDU::Code getCode();
ashleymills 0:3d62a105fd34 151
ashleymills 0:3d62a105fd34 152 // message ID
ashleymills 0:3d62a105fd34 153 int setMessageID(uint16_t messageID);
ashleymills 0:3d62a105fd34 154 uint16_t getMessageID();
ashleymills 0:3d62a105fd34 155
ashleymills 0:3d62a105fd34 156 // options
ashleymills 0:3d62a105fd34 157 int addOption(uint16_t optionNumber, uint16_t optionLength, uint8_t *optionValue);
ashleymills 0:3d62a105fd34 158 // gets a list of all options
ashleymills 0:3d62a105fd34 159 CoapOption* getOptions();
ashleymills 0:3d62a105fd34 160 int getNumOptions();
ashleymills 0:3d62a105fd34 161 // shorthand helpers
ashleymills 0:3d62a105fd34 162 int setURI(char *uri, int urilen);
ashleymills 0:3d62a105fd34 163 int getURI(char *dst, int dstlen, int *outLen);
ashleymills 0:3d62a105fd34 164
ashleymills 0:3d62a105fd34 165 // content format helper
ashleymills 0:3d62a105fd34 166 int setContentFormat(CoapPDU::ContentFormat format);
ashleymills 0:3d62a105fd34 167
ashleymills 0:3d62a105fd34 168 // payload
ashleymills 0:3d62a105fd34 169 uint8_t* mallocPayload(int bytes);
ashleymills 0:3d62a105fd34 170 int setPayload(uint8_t *value, int len);
ashleymills 0:3d62a105fd34 171 uint8_t* getPayloadPointer();
ashleymills 0:3d62a105fd34 172 int getPayloadLength();
ashleymills 0:3d62a105fd34 173 uint8_t* getPayloadCopy();
ashleymills 0:3d62a105fd34 174
ashleymills 0:3d62a105fd34 175 // pdu
ashleymills 0:3d62a105fd34 176 int getPDULength();
ashleymills 0:3d62a105fd34 177 uint8_t* getPDUPointer();
ashleymills 0:3d62a105fd34 178 void setPDULength(int len);
ashleymills 0:3d62a105fd34 179
ashleymills 0:3d62a105fd34 180 // debugging
ashleymills 0:3d62a105fd34 181 static void printBinary(uint8_t b);
ashleymills 0:3d62a105fd34 182 void print();
ashleymills 0:3d62a105fd34 183 void printBin();
ashleymills 0:3d62a105fd34 184 void printHex();
ashleymills 0:3d62a105fd34 185 void printOptionHuman(uint8_t *option);
ashleymills 0:3d62a105fd34 186 void printHuman();
ashleymills 0:3d62a105fd34 187 void printPDUAsCArray();
ashleymills 0:3d62a105fd34 188
ashleymills 0:3d62a105fd34 189 private:
ashleymills 0:3d62a105fd34 190 // variables
ashleymills 0:3d62a105fd34 191 uint8_t *_pdu;
ashleymills 0:3d62a105fd34 192 int _pduLength;
ashleymills 0:3d62a105fd34 193
ashleymills 0:3d62a105fd34 194 int _constructedFromBuffer;
ashleymills 0:3d62a105fd34 195 int _bufferLength;
ashleymills 0:3d62a105fd34 196
ashleymills 0:3d62a105fd34 197 uint8_t *_payloadPointer;
ashleymills 0:3d62a105fd34 198 int _payloadLength;
ashleymills 0:3d62a105fd34 199
ashleymills 0:3d62a105fd34 200 int _numOptions;
ashleymills 0:3d62a105fd34 201 uint16_t _maxAddedOptionNumber;
ashleymills 0:3d62a105fd34 202
ashleymills 0:3d62a105fd34 203 // functions
ashleymills 0:3d62a105fd34 204 void shiftPDUUp(int shiftOffset, int shiftAmount);
ashleymills 0:3d62a105fd34 205 void shiftPDUDown(int startLocation, int shiftOffset, int shiftAmount);
ashleymills 0:3d62a105fd34 206 uint8_t codeToValue(CoapPDU::Code c);
ashleymills 0:3d62a105fd34 207
ashleymills 0:3d62a105fd34 208 // option stuff
ashleymills 0:3d62a105fd34 209 int findInsertionPosition(uint16_t optionNumber, uint16_t *prevOptionNumber);
ashleymills 0:3d62a105fd34 210 int computeExtraBytes(uint16_t n);
ashleymills 0:3d62a105fd34 211 int insertOption(int insertionPosition, uint16_t optionDelta, uint16_t optionValueLength, uint8_t *optionValue);
ashleymills 0:3d62a105fd34 212 uint16_t getOptionDelta(uint8_t *option);
ashleymills 0:3d62a105fd34 213 void setOptionDelta(int optionPosition, uint16_t optionDelta);
ashleymills 0:3d62a105fd34 214 uint16_t getOptionValueLength(uint8_t *option);
ashleymills 0:3d62a105fd34 215
ashleymills 0:3d62a105fd34 216 };
ashleymills 0:3d62a105fd34 217
ashleymills 0:3d62a105fd34 218 /*
ashleymills 0:3d62a105fd34 219 #define COAP_CODE_EMPTY 0x00
ashleymills 0:3d62a105fd34 220
ashleymills 0:3d62a105fd34 221 // method codes 0.01-0.31
ashleymills 0:3d62a105fd34 222 #define COAP_CODE_GET 0x01
ashleymills 0:3d62a105fd34 223 #define COAP_CODE_POST 0x02
ashleymills 0:3d62a105fd34 224 #define COAP_CODE_PUT 0x03
ashleymills 0:3d62a105fd34 225 #define COAP_CODE_DELETE 0x04
ashleymills 0:3d62a105fd34 226
ashleymills 0:3d62a105fd34 227 // Response codes 2.00 - 5.31
ashleymills 0:3d62a105fd34 228 // 2.00 - 2.05
ashleymills 0:3d62a105fd34 229 #define COAP_CODE_CREATED 0x41
ashleymills 0:3d62a105fd34 230 #define COAP_CODE_DELETED 0x42
ashleymills 0:3d62a105fd34 231 #define COAP_CODE_VALID 0x43
ashleymills 0:3d62a105fd34 232 #define COAP_CODE_CHANGED 0x44
ashleymills 0:3d62a105fd34 233 #define COAP_CODE_CONTENT 0x45
ashleymills 0:3d62a105fd34 234
ashleymills 0:3d62a105fd34 235 // 4.00 - 4.15
ashleymills 0:3d62a105fd34 236 #define COAP_CODE_BAD_REQUEST 0x80
ashleymills 0:3d62a105fd34 237 #define COAP_CODE_UNAUTHORIZED 0x81
ashleymills 0:3d62a105fd34 238 #define COAP_CODE_BAD_OPTION 0x82
ashleymills 0:3d62a105fd34 239 #define COAP_CODE_FORBIDDEN 0x83
ashleymills 0:3d62a105fd34 240 #define COAP_CODE_NOT_FOUND 0x84
ashleymills 0:3d62a105fd34 241 #define COAP_CODE_METHOD_NOT_ALLOWED 0x85
ashleymills 0:3d62a105fd34 242 #define COAP_CODE_NOT_ACCEPTABLE 0x86
ashleymills 0:3d62a105fd34 243 #define COAP_CODE_PRECONDITION_FAILED 0x8C
ashleymills 0:3d62a105fd34 244 #define COAP_CODE_REQUEST_ENTITY_TOO_LARGE 0x8D
ashleymills 0:3d62a105fd34 245 #define COAP_CODE_UNSUPPORTED_CONTENT_FORMAT 0x8F
ashleymills 0:3d62a105fd34 246
ashleymills 0:3d62a105fd34 247 // 5.00 - 5.05
ashleymills 0:3d62a105fd34 248 #define COAP_CODE_INTERNAL_SERVER_ERROR 0xA0
ashleymills 0:3d62a105fd34 249 #define COAP_CODE_NOT_IMPLEMENTED 0xA1
ashleymills 0:3d62a105fd34 250 #define COAP_CODE_BAD_GATEWAY 0xA2
ashleymills 0:3d62a105fd34 251 #define COAP_CODE_SERVICE_UNAVAILABLE 0xA3
ashleymills 0:3d62a105fd34 252 #define COAP_CODE_GATEWAY_TIMEOUT 0xA4
ashleymills 0:3d62a105fd34 253 #define COAP_CODE_PROXYING_NOT_SUPPORTED 0xA5
ashleymills 0:3d62a105fd34 254 */