mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Embed: (wiki syntax)

« Back to documentation index

sn_coap_builder.c File Reference

sn_coap_builder.c File Reference

CoAP Message builder. More...

Go to the source code of this file.

Functions

static int8_t sn_coap_builder_header_build (uint8_t **dst_packet_data_pptr, sn_coap_hdr_s *src_coap_msg_ptr)
 Builds Header part of Packet data.
static int8_t sn_coap_builder_options_build (uint8_t **dst_packet_data_pptr, sn_coap_hdr_s *src_coap_msg_ptr)
 Builds Options part of Packet data.
static uint16_t sn_coap_builder_options_calc_option_size (uint16_t query_len, uint8_t *query_ptr, sn_coap_option_numbers_e option)
 Calculates needed Packet data memory size for option.
static int16_t sn_coap_builder_options_build_add_one_option (uint8_t **dst_packet_data_pptr, uint16_t option_len, uint8_t *option_ptr, sn_coap_option_numbers_e option_number)
 Adds Options part of Packet data.
static int16_t sn_coap_builder_options_build_add_multiple_option (uint8_t **dst_packet_data_pptr, uint8_t **src_pptr, uint16_t *src_len_ptr, sn_coap_option_numbers_e option)
 Builds Option Uri-Query from given CoAP Header structure to Packet data.
static uint8_t sn_coap_builder_options_get_option_part_count (uint16_t query_len, uint8_t *query_ptr, sn_coap_option_numbers_e option)
 Gets query part count from whole option string.
static uint16_t sn_coap_builder_options_get_option_part_length_from_whole_option_string (uint16_t query_len, uint8_t *query_ptr, uint8_t query_index, sn_coap_option_numbers_e option)
 Gets one's query part length from whole query string.
static int16_t sn_coap_builder_options_get_option_part_position (uint16_t query_len, uint8_t *query_ptr, uint8_t query_index, sn_coap_option_numbers_e option)
 Gets query part position in whole query.
static void sn_coap_builder_payload_build (uint8_t **dst_packet_data_pptr, sn_coap_hdr_s *src_coap_msg_ptr)
 Builds Options part of Packet data.
static uint8_t sn_coap_builder_options_calculate_jump_need (sn_coap_hdr_s *src_coap_msg_ptr, uint8_t block_option)
 Checks if there is need for option jump.
sn_coap_hdr_ssn_coap_build_response (struct coap_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code)
 Prepares generic response packet from a request packet.
int16_t sn_coap_builder (uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr)
 Builds an outgoing message buffer from a CoAP header structure.
uint16_t sn_coap_builder_calc_needed_packet_data_size (sn_coap_hdr_s *src_coap_msg_ptr)
 Calculates needed Packet data memory size for given CoAP message.

Detailed Description

CoAP Message builder.

Functionality: Builds CoAP message

Definition in file sn_coap_builder.c.


Function Documentation

sn_coap_hdr_s* sn_coap_build_response ( struct coap_s *  handle,
sn_coap_hdr_s coap_packet_ptr,
uint8_t  msg_code 
)

Prepares generic response packet from a request packet.

This function allocates memory for the resulting sn_coap_hdr_s

Parameters:
*handlePointer to CoAP library handle
*coap_packet_ptrThe request packet pointer
msg_coderesponse messages code
Returns:
*coap_packet_ptr The allocated and pre-filled response packet pointer NULL Error in parsing the request

Definition at line 59 of file sn_coap_builder.c.

int16_t sn_coap_builder ( uint8_t *  dst_packet_data_ptr,
sn_coap_hdr_s src_coap_msg_ptr 
)

Builds an outgoing message buffer from a CoAP header structure.

Parameters:
*dst_packet_data_ptris pointer to allocated destination to built CoAP packet
*src_coap_msg_ptris pointer to source structure for building Packet data
Returns:
Return value is byte count of built Packet data. In failure cases:
-1 = Failure in given CoAP header structure
-2 = Failure in given pointer (= NULL)

Definition at line 103 of file sn_coap_builder.c.

uint16_t sn_coap_builder_calc_needed_packet_data_size ( sn_coap_hdr_s src_coap_msg_ptr )

Calculates needed Packet data memory size for given CoAP message.

Parameters:
*src_coap_msg_ptris pointer to data which needed Packet data length is calculated
Returns:
Return value is count of needed memory as bytes for build Packet data Null if failed

Definition at line 149 of file sn_coap_builder.c.

static int8_t sn_coap_builder_header_build ( uint8_t **  dst_packet_data_pptr,
sn_coap_hdr_s src_coap_msg_ptr 
) [static]

Builds Header part of Packet data.

Parameters:
**dst_packet_data_pptris destination for built Packet data
*src_coap_msg_ptris source for building Packet data
Returns:
Return value is 0 in ok case and -1 in failure case

Definition at line 527 of file sn_coap_builder.c.

static int8_t sn_coap_builder_options_build ( uint8_t **  dst_packet_data_pptr,
sn_coap_hdr_s src_coap_msg_ptr 
) [static]

Builds Options part of Packet data.

Parameters:
**dst_packet_data_pptris destination for built Packet data
*src_coap_msg_ptris source for building Packet data
Returns:
Return value is 0 in every case

Definition at line 569 of file sn_coap_builder.c.

static int16_t sn_coap_builder_options_build_add_multiple_option ( uint8_t **  dst_packet_data_pptr,
uint8_t **  src_pptr,
uint16_t *  src_len_ptr,
sn_coap_option_numbers_e  option 
) [static]

Builds Option Uri-Query from given CoAP Header structure to Packet data.

Parameters:
**dst_packet_data_pptris destination for built Packet data
uint8_t**src_pptr
uint16_t*src_len_ptr

option option to be added

Returns:
Return value is 0 always

Definition at line 811 of file sn_coap_builder.c.

static int16_t sn_coap_builder_options_build_add_one_option ( uint8_t **  dst_packet_data_pptr,
uint16_t  option_value_len,
uint8_t *  option_value_ptr,
sn_coap_option_numbers_e  option_number 
) [static]

Adds Options part of Packet data.

Parameters:
**dst_packet_data_pptris destination for built Packet data
option_value_lenis Option value length to be added
*option_value_ptris pointer to Option value data to be added
option_numberis Option number to be added
Returns:
Return value is 0 if option was not added, 1 if added

Definition at line 676 of file sn_coap_builder.c.

static uint16_t sn_coap_builder_options_calc_option_size ( uint16_t  query_len,
uint8_t *  query_ptr,
sn_coap_option_numbers_e  option 
) [static]

Calculates needed Packet data memory size for option.

Parameters:
path_lenis length of calculated strting(s)
*path_ptris pointer to calculated options
Returns:
Return value is count of needed memory as bytes for Uri-query option

Definition at line 852 of file sn_coap_builder.c.

static uint8_t sn_coap_builder_options_calculate_jump_need ( sn_coap_hdr_s src_coap_msg_ptr,
uint8_t  block_option 
) [static]

Checks if there is need for option jump.

Parameters:
*src_coap_msg_ptris source of checked CoAP message
blockoption marks if block option is to be added to message later. 0 = no block option, 1 = block1 and 2 = block2
Returns:
Returns bytes needed for jumping

Definition at line 397 of file sn_coap_builder.c.

static uint8_t sn_coap_builder_options_get_option_part_count ( uint16_t  query_len,
uint8_t *  query_ptr,
sn_coap_option_numbers_e  option 
) [static]

Gets query part count from whole option string.

Parameters:
query_lenis length of whole Path
*query_ptris pointer to the start of whole Path
Returns:
Return value is count of query parts

Definition at line 933 of file sn_coap_builder.c.

static uint16_t sn_coap_builder_options_get_option_part_length_from_whole_option_string ( uint16_t  query_len,
uint8_t *  query_ptr,
uint8_t  query_index,
sn_coap_option_numbers_e  option 
) [static]

Gets one's query part length from whole query string.

Parameters:
query_lenis length of whole string
*query_ptris pointer to the start of whole string
query_indexis query part index to be found
sn_coap_option_numbers_eoption is option number of the option
Returns:
Return value is length of query part

Definition at line 973 of file sn_coap_builder.c.

static int16_t sn_coap_builder_options_get_option_part_position ( uint16_t  query_len,
uint8_t *  query_ptr,
uint8_t  query_index,
sn_coap_option_numbers_e  option 
) [static]

Gets query part position in whole query.

Parameters:
query_lenis length of whole query
*query_ptris pointer to the start of whole query
query_indexis query part index to be found
Returns:
Return value is position (= offset) of query part in whole query. In fail cases -1 is returned.

Definition at line 1031 of file sn_coap_builder.c.

static void sn_coap_builder_payload_build ( uint8_t **  dst_packet_data_pptr,
sn_coap_hdr_s src_coap_msg_ptr 
) [static]

Builds Options part of Packet data.

Parameters:
**dst_packet_data_pptris destination for built Packet data
*src_coap_msg_ptris source for building Packet data

Definition at line 1086 of file sn_coap_builder.c.