libschc
Functions
picocoap.c File Reference
#include <stddef.h>
#include <string.h>
#include "picocoap.h"
#include "schc.h"

Functions

uint8_t pcoap_get_coap_offset (pcoap_pdu *pdu)
 Finds the length of the CoAP header. More...
 
pcoap_error pcoap_validate_pkt (pcoap_pdu *pdu)
 Validate Packet. More...
 
uint8_t pcoap_get_token (pcoap_pdu *pdu, uint8_t *ptr)
 Get Message Token. More...
 
pcoap_option pcoap_get_option (pcoap_pdu *pdu, pcoap_option *last)
 Get Option. More...
 
pcoap_option pcoap_get_option_by_num (pcoap_pdu *pdu, pcoap_option_number num, uint8_t occ)
 Get Option by Option Number. More...
 
pcoap_error pcoap_decode_option (uint8_t *pkt_ptr, size_t pkt_len, uint16_t *option_number, size_t *option_length, uint8_t **value)
 Internal Method. More...
 
pcoap_payload pcoap_get_payload (pcoap_pdu *pdu)
 Get Option. More...
 
pcoap_error pcoap_init_pdu (pcoap_pdu *pdu)
 Initialize Packet. More...
 
pcoap_error pcoap_set_version (pcoap_pdu *pdu, pcoap_version ver)
 Set Version. More...
 
pcoap_error pcoap_set_type (pcoap_pdu *pdu, pcoap_type mtype)
 Set Message Type. More...
 
pcoap_error pcoap_set_code (pcoap_pdu *pdu, pcoap_code code)
 Set Message Code. More...
 
pcoap_error pcoap_set_mid (pcoap_pdu *pdu, uint16_t mid)
 Set Message ID. More...
 
pcoap_error pcoap_set_token (pcoap_pdu *pdu, uint8_t *token, uint8_t tkl)
 Set Message Token. More...
 
pcoap_error pcoap_add_option (pcoap_pdu *pdu, int32_t opt_num, uint8_t *value, uint16_t opt_len)
 Add Message Option. More...
 
pcoap_error pcoap_set_payload (pcoap_pdu *pdu, uint8_t *payload, size_t payload_len)
 Add Message Option. More...
 
pcoap_error pcoap_adjust_option_deltas (uint8_t *opts_start, size_t *opts_len, size_t max_len, int32_t offset)
 Internal Method. More...
 
int8_t pcoap_build_option_header (uint8_t *buf, size_t max_len, int32_t opt_delta, int32_t opt_len)
 Internal Method. More...
 
int8_t pcoap_compute_option_header_len (int32_t opt_delta, int32_t opt_len)
 Internal Method. More...
 

Function Documentation

◆ pcoap_add_option()

pcoap_error pcoap_add_option ( pcoap_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)

◆ pcoap_adjust_option_deltas()

pcoap_error pcoap_adjust_option_deltas ( uint8_t *  opts_start,
size_t *  opts_len,
size_t  max_len,
int32_t  offset 
)

Internal Method.

◆ pcoap_build_option_header()

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

Internal Method.

◆ pcoap_compute_option_header_len()

int8_t pcoap_compute_option_header_len ( int32_t  opt_delta,
int32_t  opt_len 
)

Internal Method.

◆ pcoap_decode_option()

pcoap_error pcoap_decode_option ( uint8_t *  pkt_ptr,
size_t  pkt_len,
uint16_t *  option_number,
size_t *  option_length,
uint8_t **  value 
)

Internal Method.

◆ pcoap_get_coap_offset()

uint8_t pcoap_get_coap_offset ( pcoap_pdu pdu)

Finds the length of the CoAP header.

Parameters
pduthe CoAP pdu, containing the header and payload
Returns
the length of the CoAP header

◆ pcoap_get_option()

pcoap_option pcoap_get_option ( pcoap_pdu pdu,
pcoap_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

◆ pcoap_get_option_by_num()

pcoap_option pcoap_get_option_by_num ( pcoap_pdu pdu,
pcoap_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

◆ pcoap_get_payload()

pcoap_payload pcoap_get_payload ( pcoap_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

◆ pcoap_get_token()

uint8_t pcoap_get_token ( pcoap_pdu pdu,
uint8_t *  ptr 
)

Get Message Token.

Extracts the token from the given message.

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

◆ pcoap_init_pdu()

pcoap_error pcoap_init_pdu ( pcoap_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)

◆ pcoap_set_code()

pcoap_error pcoap_set_code ( pcoap_pdu pdu,
pcoap_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

◆ pcoap_set_mid()

pcoap_error pcoap_set_mid ( pcoap_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)

◆ pcoap_set_payload()

pcoap_error pcoap_set_payload ( pcoap_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)

◆ pcoap_set_token()

pcoap_error pcoap_set_token ( pcoap_pdu pdu,
uint8_t *  token,
uint8_t  tkl 
)

Set Message Token.

Sets the message token header field.

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

◆ pcoap_set_type()

pcoap_error pcoap_set_type ( pcoap_pdu pdu,
pcoap_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

◆ pcoap_set_version()

pcoap_error pcoap_set_version ( pcoap_pdu pdu,
pcoap_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

◆ pcoap_validate_pkt()

pcoap_error pcoap_validate_pkt ( pcoap_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