Patrick Barrett / libexositecoap
Embed: (wiki syntax)

« Back to documentation index

coap.h File Reference

coap.h File Reference

CoAP Message Parsing. More...

Go to the source code of this file.

Data Structures

struct  coap_pdu
 Packet Data Unit. More...
struct  coap_option
 CoAP Option. More...
struct  coap_payload
 CoAP Payload. More...

Typedefs

typedef enum coap_error coap_error
 Status Codes.
typedef enum coap_version coap_version
 Protocol Versions.
typedef enum coap_type coap_type
 Message Types.
typedef enum coap_code coap_code
 Message Codes.
typedef enum coap_option_number coap_option_number
 Option Numbers.
typedef struct coap_pdu coap_pdu
 Packet Data Unit.
typedef struct coap_option coap_option
 CoAP Option.
typedef struct coap_payload coap_payload
 CoAP Payload.

Enumerations

enum  coap_error
 

Status Codes.

More...
enum  coap_version
 

Protocol Versions.

More...
enum  coap_type
 

Message Types.

More...
enum  coap_code
 

Message Codes.

More...
enum  coap_option_number
 

Option Numbers.

More...

Functions

coap_error coap_validate_pkt (coap_pdu *pdu)
 Validate Packet.
static coap_version coap_get_version (coap_pdu *pdu)
 Get Version.
static coap_type coap_get_type (coap_pdu *pdu)
 Get Message Type.
static uint8_t coap_get_tkl (coap_pdu *pdu)
 Get Token Length.
static coap_code coap_get_code (coap_pdu *pdu)
 Get Message Code.
static uint8_t coap_get_code_class (coap_pdu *pdu)
 Get Message Code Class.
static uint8_t coap_get_code_detail (coap_pdu *pdu)
 Get Message Code Detail.
static uint16_t coap_get_mid (coap_pdu *pdu)
 Get Message ID.
uint64_t coap_get_token (coap_pdu *pdu)
 Get Message Token.
coap_option coap_get_option (coap_pdu *pdu, coap_option *last)
 Get Option.
coap_option coap_get_option_by_num (coap_pdu *pdu, coap_option_number num, uint8_t occ)
 Get Option by Option Number.
coap_payload coap_get_payload (coap_pdu *pdu)
 Get Option.
coap_error coap_decode_option (uint8_t *pkt_ptr, size_t pkt_len, uint16_t *option_number, size_t *option_length, uint8_t **value)
 Internal Method.
coap_error coap_init_pdu (coap_pdu *pdu)
 Initialize Packet.
coap_error coap_set_version (coap_pdu *pdu, coap_version ver)
 Set Version.
coap_error coap_set_type (coap_pdu *pdu, coap_type mtype)
 Set Message Type.
coap_error coap_set_code (coap_pdu *pdu, coap_code code)
 Set Message Code.
coap_error coap_set_mid (coap_pdu *pdu, uint16_t mid)
 Set Message ID.
coap_error coap_set_token (coap_pdu *pdu, uint64_t token, uint8_t tkl)
 Set Message Token.
coap_error coap_add_option (coap_pdu *pdu, int32_t opt_num, uint8_t *value, uint16_t opt_len)
 Add Message Option.
coap_error coap_set_payload (coap_pdu *pdu, uint8_t *payload, size_t payload_len)
 Add Message Option.
static uint8_t coap_build_code (uint8_t _class, uint8_t detail)
 Build Message Code from Class and Detail.
coap_error coap_adjust_option_deltas (uint8_t *opts, size_t *opts_len, size_t max_len, int32_t offset)
 Internal Method.
int8_t coap_build_option_header (uint8_t *buf, size_t max_len, int32_t opt_delta, int32_t opt_len)
 Internal Method.
int8_t coap_compute_option_header_len (int32_t opt_delta, int32_t opt_len)
 Internal Method.

Detailed Description

CoAP Message Parsing.

Author:
Patrick Barrett <patrickbarrett@exosite.com>
Date:
2014-07-10

This file provides functions for parsing and building CoAP message packets using only the actual binary of the message, not needing additional memory for secondary data structures.

Definition in file coap.h.


Typedef Documentation

typedef enum coap_code coap_code

Message Codes.

All known message request/response codes.

typedef enum coap_error coap_error

Status Codes.

These codes represent the possible errors that functions in this library can return.

typedef struct coap_option coap_option

CoAP Option.

One option in a CoAP message.

Option Numbers.

All known option numbers.

typedef struct coap_payload coap_payload

CoAP Payload.

Payload container.

typedef struct coap_pdu coap_pdu

Packet Data Unit.

This contains all information about the message buffer.

typedef enum coap_type coap_type

Message Types.

The four types of messages possible.

typedef enum coap_version coap_version

Protocol Versions.

All known version of the protocol.


Enumeration Type Documentation

enum coap_code

Message Codes.

All known message request/response codes.

Definition at line 86 of file coap.h.

enum coap_error

Status Codes.

These codes represent the possible errors that functions in this library can return.

Definition at line 47 of file coap.h.

Option Numbers.

All known option numbers.

Definition at line 122 of file coap.h.

enum coap_type

Message Types.

The four types of messages possible.

Definition at line 74 of file coap.h.

Protocol Versions.

All known version of the protocol.

Definition at line 65 of file coap.h.


Function Documentation

coap_error coap_add_option ( coap_pdu pdu,
int32_t  opt_num,
uint8_t *  value,
uint16_t  opt_len 
)

Add Message Option.

Adds an option to the existing message. Options SHOULD be added in order of option number. In the case of multiple options of the same type, they are sorted in the order that they are added.

Parameters:
[in,out]pdupointer to the coap message struct.
[in]optoption container.
Returns:
coap_error (0 == no error)

Definition at line 358 of file coap.c.

coap_error coap_adjust_option_deltas ( uint8_t *  opts,
size_t *  opts_len,
size_t  max_len,
int32_t  offset 
)

Internal Method.

Definition at line 460 of file coap.c.

static uint8_t coap_build_code ( uint8_t  _class,
uint8_t  detail 
) [static]

Build Message Code from Class and Detail.

Gets the class portion of the message code.

Parameters:
[in]classthe code class.
[in]detailthe code detail.
See also:
coap_get_code

Definition at line 407 of file coap.h.

int8_t coap_build_option_header ( uint8_t *  buf,
size_t  max_len,
int32_t  opt_delta,
int32_t  opt_len 
)

Internal Method.

Definition at line 513 of file coap.c.

int8_t coap_compute_option_header_len ( int32_t  opt_delta,
int32_t  opt_len 
)

Internal Method.

Definition at line 564 of file coap.c.

coap_error coap_decode_option ( uint8_t *  pkt_ptr,
size_t  pkt_len,
uint16_t *  option_number,
size_t *  option_length,
uint8_t **  value 
)

Internal Method.

Definition at line 153 of file coap.c.

static coap_code coap_get_code ( coap_pdu pdu ) [static]

Get Message Code.

Extracts the message code from the given message.

Parameters:
[in]pdupointer to the coap message struct.
Returns:
code.
See also:
coap_code

Definition at line 231 of file coap.h.

static uint8_t coap_get_code_class ( coap_pdu pdu ) [static]

Get Message Code Class.

Gets the class portion of the message code.

Parameters:
[in]pdupointer to the coap message struct.
See also:
coap_get_code

Definition at line 240 of file coap.h.

static uint8_t coap_get_code_detail ( coap_pdu pdu ) [static]

Get Message Code Detail.

Gets the detail portion of the message code.

Parameters:
[in]pdupointer to the coap message struct.
See also:
coap_get_code

Definition at line 249 of file coap.h.

static uint16_t coap_get_mid ( coap_pdu pdu ) [static]

Get Message ID.

Extracts the message ID from the given message.

Parameters:
[in]pdupointer to the coap message struct.
Returns:
mid.

Definition at line 258 of file coap.h.

coap_option coap_get_option ( coap_pdu pdu,
coap_option last 
)

Get Option.

Iterates over the options in the given message.

Parameters:
[in]pdupointer to the coap message struct.
[in,out]pointerto the last/next option, pass 0 for the first option.
Returns:
coap_option

Definition at line 74 of file coap.c.

coap_option coap_get_option_by_num ( coap_pdu pdu,
coap_option_number  num,
uint8_t  occ 
)

Get Option by Option Number.

Gets a single specified by the option number and index of which occurrence of that option number you'd like.

Parameters:
[in]pdupointer to the coap message struct.
[in]numoption number to get.
[in]occoccurrence of to get (0th, 1st, 2nd, etc) 0 for the first option.
Returns:
coap_option

Definition at line 123 of file coap.c.

coap_payload coap_get_payload ( coap_pdu pdu )

Get Option.

Extracts the option with the given index in the given message.

Parameters:
[in]pdupointer to the coap message struct.
Returns:
coap_payload

Definition at line 213 of file coap.c.

static uint8_t coap_get_tkl ( coap_pdu pdu ) [static]

Get Token Length.

Extracts the token length from the given message.

Parameters:
[in]pdupointer to the coap message struct.
Returns:
length.
See also:
coap_type

Definition at line 221 of file coap.h.

uint64_t coap_get_token ( coap_pdu pdu )

Get Message Token.

Extracts the token from the given message.

Parameters:
[in]pdupointer to the coap message struct.
Returns:
token.

Definition at line 56 of file coap.c.

static coap_type coap_get_type ( coap_pdu pdu ) [static]

Get Message Type.

Extracts the message type from the given message.

Parameters:
[in]pdupointer to the coap message struct.
Returns:
type.
See also:
coap_type

Definition at line 211 of file coap.h.

static coap_version coap_get_version ( coap_pdu pdu ) [static]

Get Version.

Extracts the CoAP version from the given message.

Parameters:
[in]pdupointer to the coap message struct.
Returns:
version.
See also:
coap_version

Definition at line 201 of file coap.h.

coap_error coap_init_pdu ( coap_pdu pdu )

Initialize Packet.

Initializes on an empty buffer for creating new CoAP packets. This function (or coap_validate for parsing packets) must be called and must return CE_NONE before you can use any of the getters or setter. The packet is initialized to a CoAP Ping.

Parameters:
[in,out]pdupointer to the coap message struct.
Returns:
coap_error (0 == no error)

Definition at line 251 of file coap.c.

coap_error coap_set_code ( coap_pdu pdu,
coap_code  code 
)

Set Message Code.

Sets the message type header field.

Parameters:
[in,out]pdupointer to the coap message struct.
[in]codecode to set.
Returns:
coap_error (0 == no error)
See also:
coap_code

Definition at line 299 of file coap.c.

coap_error coap_set_mid ( coap_pdu pdu,
uint16_t  mid 
)

Set Message ID.

Sets the message ID header field.

Parameters:
[in,out]pdupointer to the coap message struct.
[in]midmessage ID to set.
Returns:
coap_error (0 == no error)

Definition at line 313 of file coap.c.

coap_error coap_set_payload ( coap_pdu pdu,
uint8_t *  payload,
size_t  payload_len 
)

Add Message Option.

Sets the payload of the given message to the value in `payload`.

Parameters:
[in,out]pdupointer to the coap message struct.
[in]plpayload container.
Returns:
coap_error (0 == no error)

Definition at line 420 of file coap.c.

coap_error coap_set_token ( coap_pdu pdu,
uint64_t  token,
uint8_t  tkl 
)

Set Message Token.

Sets the message token header field.

Parameters:
[in,out]pdupointer to the coap message struct.
[in]tokentoken value to set.
Returns:
coap_error (0 == no error)

Definition at line 328 of file coap.c.

coap_error coap_set_type ( coap_pdu pdu,
coap_type  mtype 
)

Set Message Type.

Sets the message type header field.

Parameters:
[in,out]pdupointer to the coap message struct.
[in]mtypetype to set.
Returns:
coap_error (0 == no error)
See also:
coap_type

Definition at line 285 of file coap.c.

coap_error coap_set_version ( coap_pdu pdu,
coap_version  ver 
)

Set Version.

Sets the version number header field.

Parameters:
[in,out]pdupointer to the coap message struct.
[in]verversion to set. Must be COAP_V1.
Returns:
coap_error (0 == no error)
See also:
coap_version

Definition at line 271 of file coap.c.

coap_error coap_validate_pkt ( coap_pdu pdu )

Validate Packet.

Parses the given packet to check if it is a valid CoAP message. This function (or coap_init_pdu for creating new packets) must be called and must return CE_NONE before you can use any of the getters or setter.

Parameters:
[in]pdupointer to the coap message struct.
Returns:
error code (CE_NONE == 0 == no error).
See also:
coap_error
coap_init_pdu

Definition at line 11 of file coap.c.