hello

Dependents:   nespresso_demo nespresso_endpoint EnvoyNespressoEndpointColorDetectorV2

Fork of nsdl by Robert Taylor

Committer:
bjblazkowicz
Date:
Mon Jul 14 12:33:59 2014 +0000
Revision:
2:05e4cd1a1542
Parent:
0:f6e4e1bbb3fe
WIP - registration is broken in this commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GeofferyOmlette 0:f6e4e1bbb3fe 1 /**
GeofferyOmlette 0:f6e4e1bbb3fe 2 *\file sn_coap_parser.c
GeofferyOmlette 0:f6e4e1bbb3fe 3 *
GeofferyOmlette 0:f6e4e1bbb3fe 4 * \brief CoAP Header parser
GeofferyOmlette 0:f6e4e1bbb3fe 5 *
GeofferyOmlette 0:f6e4e1bbb3fe 6 * Functionality: Parses CoAP Header
GeofferyOmlette 0:f6e4e1bbb3fe 7 *
GeofferyOmlette 0:f6e4e1bbb3fe 8 * Created on: Jun 30, 2011
GeofferyOmlette 0:f6e4e1bbb3fe 9 * Author: tero
GeofferyOmlette 0:f6e4e1bbb3fe 10 *
GeofferyOmlette 0:f6e4e1bbb3fe 11 * \note Supports draft-ietf-core-coap-12
GeofferyOmlette 0:f6e4e1bbb3fe 12 */
GeofferyOmlette 0:f6e4e1bbb3fe 13
GeofferyOmlette 0:f6e4e1bbb3fe 14 /* * * * * * * * * * * * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 15 /* * * * INCLUDE FILES * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 16 /* * * * * * * * * * * * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 17
GeofferyOmlette 0:f6e4e1bbb3fe 18 #include <stdio.h>
GeofferyOmlette 0:f6e4e1bbb3fe 19 #include <string.h> /* For memset() and memcpy() */
GeofferyOmlette 0:f6e4e1bbb3fe 20
GeofferyOmlette 0:f6e4e1bbb3fe 21 #include "nsdl_types.h"
GeofferyOmlette 0:f6e4e1bbb3fe 22 #include "sn_nsdl.h"
GeofferyOmlette 0:f6e4e1bbb3fe 23 #include "sn_coap_header.h"
GeofferyOmlette 0:f6e4e1bbb3fe 24 #include "sn_coap_protocol.h"
GeofferyOmlette 0:f6e4e1bbb3fe 25 #include "sn_coap_header_internal.h"
GeofferyOmlette 0:f6e4e1bbb3fe 26 #include "sn_coap_protocol_internal.h"
GeofferyOmlette 0:f6e4e1bbb3fe 27
GeofferyOmlette 0:f6e4e1bbb3fe 28 /* * * * * * * * * * * * * * * * * * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 29 /* * * * LOCAL FUNCTION PROTOTYPES * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 30 /* * * * * * * * * * * * * * * * * * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 31
GeofferyOmlette 0:f6e4e1bbb3fe 32 static void sn_coap_parser_header_parse(uint8_t **packet_data_pptr, sn_coap_hdr_s *dst_coap_msg_ptr, coap_version_e *coap_version_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 33 static int8_t sn_coap_parser_options_parse(uint8_t **packet_data_pptr, sn_coap_hdr_s *dst_coap_msg_ptr, uint8_t *packet_data_start_ptr, uint16_t packet_len);
GeofferyOmlette 0:f6e4e1bbb3fe 34 static int8_t sn_coap_parser_options_parse_multiple_options(uint8_t **packet_data_pptr, uint16_t packet_left_len, uint8_t **dst_pptr, uint16_t *dst_len_ptr, sn_coap_option_numbers_e option, uint16_t option_number_len);
GeofferyOmlette 0:f6e4e1bbb3fe 35 static int16_t sn_coap_parser_options_count_needed_memory_multiple_option(uint8_t *packet_data_ptr, uint16_t packet_left_len, sn_coap_option_numbers_e option, uint16_t option_number_len);
GeofferyOmlette 0:f6e4e1bbb3fe 36 static int8_t sn_coap_parser_payload_parse(uint16_t packet_data_len, uint8_t *packet_data_start_ptr, uint8_t **packet_data_pptr, sn_coap_hdr_s *dst_coap_msg_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 37
GeofferyOmlette 0:f6e4e1bbb3fe 38 /* * * * * * * * * * * * * * * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 39 /* * * * GLOBAL DECLARATIONS * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 40 /* * * * * * * * * * * * * * * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 41
GeofferyOmlette 0:f6e4e1bbb3fe 42
GeofferyOmlette 0:f6e4e1bbb3fe 43 SN_MEM_ATTR_COAP_PARSER_FUNC
GeofferyOmlette 0:f6e4e1bbb3fe 44 sn_coap_hdr_s *sn_coap_parser(uint16_t packet_data_len, uint8_t *packet_data_ptr, coap_version_e *coap_version_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 45 {
GeofferyOmlette 0:f6e4e1bbb3fe 46 uint8_t *data_temp_ptr = packet_data_ptr;
GeofferyOmlette 0:f6e4e1bbb3fe 47 sn_coap_hdr_s *parsed_and_returned_coap_msg_ptr = NULL;
GeofferyOmlette 0:f6e4e1bbb3fe 48
GeofferyOmlette 0:f6e4e1bbb3fe 49 /* * * * Check given pointer * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 50 if (packet_data_ptr == NULL || packet_data_len < 4)
GeofferyOmlette 0:f6e4e1bbb3fe 51 return NULL;
GeofferyOmlette 0:f6e4e1bbb3fe 52
GeofferyOmlette 0:f6e4e1bbb3fe 53 /* * * * Allocate memory for parsed and returned CoAP message and initialize allocated memory with with zero values * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 54 parsed_and_returned_coap_msg_ptr = sn_coap_malloc(sizeof(sn_coap_hdr_s));
GeofferyOmlette 0:f6e4e1bbb3fe 55
GeofferyOmlette 0:f6e4e1bbb3fe 56 if (parsed_and_returned_coap_msg_ptr == NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 57 return NULL;
GeofferyOmlette 0:f6e4e1bbb3fe 58
GeofferyOmlette 0:f6e4e1bbb3fe 59 memset(parsed_and_returned_coap_msg_ptr, 0x00, sizeof(sn_coap_hdr_s));
GeofferyOmlette 0:f6e4e1bbb3fe 60
GeofferyOmlette 0:f6e4e1bbb3fe 61
GeofferyOmlette 0:f6e4e1bbb3fe 62 /* * * * Header parsing, move pointer over the header... * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 63 sn_coap_parser_header_parse(&data_temp_ptr, parsed_and_returned_coap_msg_ptr, coap_version_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 64
GeofferyOmlette 0:f6e4e1bbb3fe 65
GeofferyOmlette 0:f6e4e1bbb3fe 66 /* * * * Options parsing, move pointer over the options... * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 67 if (sn_coap_parser_options_parse(&data_temp_ptr, parsed_and_returned_coap_msg_ptr, packet_data_ptr, packet_data_len) != 0)
GeofferyOmlette 0:f6e4e1bbb3fe 68 {
GeofferyOmlette 0:f6e4e1bbb3fe 69 /* Release memory of CoAP message */
GeofferyOmlette 0:f6e4e1bbb3fe 70 sn_coap_parser_release_allocated_coap_msg_mem(parsed_and_returned_coap_msg_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 71 return NULL;
GeofferyOmlette 0:f6e4e1bbb3fe 72 }
GeofferyOmlette 0:f6e4e1bbb3fe 73
GeofferyOmlette 0:f6e4e1bbb3fe 74 /* * * * Payload parsing * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 75 if(sn_coap_parser_payload_parse(packet_data_len, packet_data_ptr, &data_temp_ptr, parsed_and_returned_coap_msg_ptr) == -1)
GeofferyOmlette 0:f6e4e1bbb3fe 76 {
GeofferyOmlette 0:f6e4e1bbb3fe 77 /* Release memory of CoAP message */
GeofferyOmlette 0:f6e4e1bbb3fe 78 sn_coap_parser_release_allocated_coap_msg_mem(parsed_and_returned_coap_msg_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 79 return NULL;
GeofferyOmlette 0:f6e4e1bbb3fe 80 }
GeofferyOmlette 0:f6e4e1bbb3fe 81 /* * * * Return parsed CoAP message * * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 82 return parsed_and_returned_coap_msg_ptr;
GeofferyOmlette 0:f6e4e1bbb3fe 83 }
GeofferyOmlette 0:f6e4e1bbb3fe 84
GeofferyOmlette 0:f6e4e1bbb3fe 85
GeofferyOmlette 0:f6e4e1bbb3fe 86 SN_MEM_ATTR_COAP_PARSER_FUNC
GeofferyOmlette 0:f6e4e1bbb3fe 87 void sn_coap_parser_release_allocated_coap_msg_mem(sn_coap_hdr_s *freed_coap_msg_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 88 {
GeofferyOmlette 0:f6e4e1bbb3fe 89 if (freed_coap_msg_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 90 {
GeofferyOmlette 0:f6e4e1bbb3fe 91 if (freed_coap_msg_ptr->uri_path_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 92 {
GeofferyOmlette 0:f6e4e1bbb3fe 93 sn_coap_free(freed_coap_msg_ptr->uri_path_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 94 }
GeofferyOmlette 0:f6e4e1bbb3fe 95
GeofferyOmlette 0:f6e4e1bbb3fe 96 if (freed_coap_msg_ptr->token_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 97 {
GeofferyOmlette 0:f6e4e1bbb3fe 98 sn_coap_free(freed_coap_msg_ptr->token_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 99 }
GeofferyOmlette 0:f6e4e1bbb3fe 100
GeofferyOmlette 0:f6e4e1bbb3fe 101 if (freed_coap_msg_ptr->content_type_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 102 {
GeofferyOmlette 0:f6e4e1bbb3fe 103 sn_coap_free(freed_coap_msg_ptr->content_type_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 104 }
GeofferyOmlette 0:f6e4e1bbb3fe 105
GeofferyOmlette 0:f6e4e1bbb3fe 106 if (freed_coap_msg_ptr->options_list_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 107 {
GeofferyOmlette 0:f6e4e1bbb3fe 108 if (freed_coap_msg_ptr->options_list_ptr->max_age_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 109 {
GeofferyOmlette 0:f6e4e1bbb3fe 110 sn_coap_free(freed_coap_msg_ptr->options_list_ptr->max_age_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 111 }
GeofferyOmlette 0:f6e4e1bbb3fe 112
GeofferyOmlette 0:f6e4e1bbb3fe 113 if (freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 114 {
GeofferyOmlette 0:f6e4e1bbb3fe 115 sn_coap_free(freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 116 }
GeofferyOmlette 0:f6e4e1bbb3fe 117
GeofferyOmlette 0:f6e4e1bbb3fe 118 if (freed_coap_msg_ptr->options_list_ptr->etag_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 119 {
GeofferyOmlette 0:f6e4e1bbb3fe 120 sn_coap_free(freed_coap_msg_ptr->options_list_ptr->etag_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 121 }
GeofferyOmlette 0:f6e4e1bbb3fe 122
GeofferyOmlette 0:f6e4e1bbb3fe 123 if (freed_coap_msg_ptr->options_list_ptr->uri_host_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 124 {
GeofferyOmlette 0:f6e4e1bbb3fe 125 sn_coap_free(freed_coap_msg_ptr->options_list_ptr->uri_host_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 126 }
GeofferyOmlette 0:f6e4e1bbb3fe 127
GeofferyOmlette 0:f6e4e1bbb3fe 128 if (freed_coap_msg_ptr->options_list_ptr->location_path_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 129 {
GeofferyOmlette 0:f6e4e1bbb3fe 130 sn_coap_free(freed_coap_msg_ptr->options_list_ptr->location_path_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 131 }
GeofferyOmlette 0:f6e4e1bbb3fe 132
GeofferyOmlette 0:f6e4e1bbb3fe 133 if (freed_coap_msg_ptr->options_list_ptr->uri_port_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 134 {
GeofferyOmlette 0:f6e4e1bbb3fe 135 sn_coap_free(freed_coap_msg_ptr->options_list_ptr->uri_port_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 136 }
GeofferyOmlette 0:f6e4e1bbb3fe 137
GeofferyOmlette 0:f6e4e1bbb3fe 138 if (freed_coap_msg_ptr->options_list_ptr->location_query_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 139 {
GeofferyOmlette 0:f6e4e1bbb3fe 140 sn_coap_free(freed_coap_msg_ptr->options_list_ptr->location_query_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 141 }
GeofferyOmlette 0:f6e4e1bbb3fe 142
GeofferyOmlette 0:f6e4e1bbb3fe 143 if (freed_coap_msg_ptr->options_list_ptr->observe_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 144 {
GeofferyOmlette 0:f6e4e1bbb3fe 145 sn_coap_free(freed_coap_msg_ptr->options_list_ptr->observe_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 146 }
GeofferyOmlette 0:f6e4e1bbb3fe 147
GeofferyOmlette 0:f6e4e1bbb3fe 148 if (freed_coap_msg_ptr->options_list_ptr->uri_query_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 149 {
GeofferyOmlette 0:f6e4e1bbb3fe 150 sn_coap_free(freed_coap_msg_ptr->options_list_ptr->uri_query_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 151 }
GeofferyOmlette 0:f6e4e1bbb3fe 152
GeofferyOmlette 0:f6e4e1bbb3fe 153 if (freed_coap_msg_ptr->options_list_ptr->block2_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 154 {
GeofferyOmlette 0:f6e4e1bbb3fe 155 sn_coap_free(freed_coap_msg_ptr->options_list_ptr->block2_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 156 }
GeofferyOmlette 0:f6e4e1bbb3fe 157
GeofferyOmlette 0:f6e4e1bbb3fe 158 if (freed_coap_msg_ptr->options_list_ptr->block1_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 159 {
GeofferyOmlette 0:f6e4e1bbb3fe 160 sn_coap_free(freed_coap_msg_ptr->options_list_ptr->block1_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 161 }
GeofferyOmlette 0:f6e4e1bbb3fe 162 if (freed_coap_msg_ptr->options_list_ptr->accept_ptr != NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 163 {
GeofferyOmlette 0:f6e4e1bbb3fe 164 sn_coap_free(freed_coap_msg_ptr->options_list_ptr->accept_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 165 }
GeofferyOmlette 0:f6e4e1bbb3fe 166
GeofferyOmlette 0:f6e4e1bbb3fe 167 sn_coap_free(freed_coap_msg_ptr->options_list_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 168 }
GeofferyOmlette 0:f6e4e1bbb3fe 169
GeofferyOmlette 0:f6e4e1bbb3fe 170 sn_coap_free(freed_coap_msg_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 171 }
GeofferyOmlette 0:f6e4e1bbb3fe 172 }
GeofferyOmlette 0:f6e4e1bbb3fe 173
GeofferyOmlette 0:f6e4e1bbb3fe 174 /**
GeofferyOmlette 0:f6e4e1bbb3fe 175 * \fn static void sn_coap_parser_header_parse(uint8_t **packet_data_pptr, sn_coap_hdr_s *dst_coap_msg_ptr, coap_version_e *coap_version_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 176 *
GeofferyOmlette 0:f6e4e1bbb3fe 177 * \brief Parses CoAP message's Header part from given Packet data
GeofferyOmlette 0:f6e4e1bbb3fe 178 *
GeofferyOmlette 0:f6e4e1bbb3fe 179 * \param **packet_data_ptr is source for Packet data to be parsed to CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 180 *
GeofferyOmlette 0:f6e4e1bbb3fe 181 * \param *dst_coap_msg_ptr is destination for parsed CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 182 *
GeofferyOmlette 0:f6e4e1bbb3fe 183 * \param *coap_version_ptr is destination for parsed CoAP specification version
GeofferyOmlette 0:f6e4e1bbb3fe 184 */
GeofferyOmlette 0:f6e4e1bbb3fe 185 SN_MEM_ATTR_COAP_PARSER_FUNC
GeofferyOmlette 0:f6e4e1bbb3fe 186 static void sn_coap_parser_header_parse(uint8_t **packet_data_pptr, sn_coap_hdr_s *dst_coap_msg_ptr, coap_version_e *coap_version_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 187 {
GeofferyOmlette 0:f6e4e1bbb3fe 188 /* Parse CoAP Version and message type*/
GeofferyOmlette 0:f6e4e1bbb3fe 189 *coap_version_ptr = (coap_version_e)(**packet_data_pptr & COAP_HEADER_VERSION_MASK);
GeofferyOmlette 0:f6e4e1bbb3fe 190 dst_coap_msg_ptr->msg_type = (sn_coap_msg_type_e)(**packet_data_pptr & COAP_HEADER_MSG_TYPE_MASK);
GeofferyOmlette 0:f6e4e1bbb3fe 191 (*packet_data_pptr) += 1;
GeofferyOmlette 0:f6e4e1bbb3fe 192
GeofferyOmlette 0:f6e4e1bbb3fe 193 /* Parse Message code */
GeofferyOmlette 0:f6e4e1bbb3fe 194 dst_coap_msg_ptr->msg_code = (sn_coap_msg_code_e)**packet_data_pptr;
GeofferyOmlette 0:f6e4e1bbb3fe 195 (*packet_data_pptr) += 1;
GeofferyOmlette 0:f6e4e1bbb3fe 196
GeofferyOmlette 0:f6e4e1bbb3fe 197 /* Parse Message ID */
GeofferyOmlette 0:f6e4e1bbb3fe 198 dst_coap_msg_ptr->msg_id = *(*packet_data_pptr+1);
GeofferyOmlette 0:f6e4e1bbb3fe 199 dst_coap_msg_ptr->msg_id += **packet_data_pptr << COAP_HEADER_MSG_ID_MSB_SHIFT;
GeofferyOmlette 0:f6e4e1bbb3fe 200 (*packet_data_pptr) += 2;
GeofferyOmlette 0:f6e4e1bbb3fe 201
GeofferyOmlette 0:f6e4e1bbb3fe 202 }
GeofferyOmlette 0:f6e4e1bbb3fe 203
GeofferyOmlette 0:f6e4e1bbb3fe 204 /**
GeofferyOmlette 0:f6e4e1bbb3fe 205 * \fn static uint8_t sn_coap_parser_options_parse(uint8_t **packet_data_pptr, sn_coap_hdr_s *dst_coap_msg_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 206 *
GeofferyOmlette 0:f6e4e1bbb3fe 207 * \brief Parses CoAP message's Options part from given Packet data
GeofferyOmlette 0:f6e4e1bbb3fe 208 *
GeofferyOmlette 0:f6e4e1bbb3fe 209 * \param **packet_data_pptr is source of Packet data to be parsed to CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 210 * \param *dst_coap_msg_ptr is destination for parsed CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 211 *
GeofferyOmlette 0:f6e4e1bbb3fe 212 * \return Return value is 0 in ok case and -1 in failure case
GeofferyOmlette 0:f6e4e1bbb3fe 213 */
GeofferyOmlette 0:f6e4e1bbb3fe 214 SN_MEM_ATTR_COAP_PARSER_FUNC
GeofferyOmlette 0:f6e4e1bbb3fe 215 static int8_t sn_coap_parser_options_parse(uint8_t **packet_data_pptr, sn_coap_hdr_s *dst_coap_msg_ptr, uint8_t *packet_data_start_ptr, uint16_t packet_len)
GeofferyOmlette 0:f6e4e1bbb3fe 216 {
GeofferyOmlette 0:f6e4e1bbb3fe 217 uint8_t previous_option_number = 0;
GeofferyOmlette 0:f6e4e1bbb3fe 218 uint8_t i = 0;
GeofferyOmlette 0:f6e4e1bbb3fe 219 int8_t ret_status = 0;
GeofferyOmlette 0:f6e4e1bbb3fe 220 uint16_t message_left = 0;
GeofferyOmlette 0:f6e4e1bbb3fe 221
GeofferyOmlette 0:f6e4e1bbb3fe 222
GeofferyOmlette 0:f6e4e1bbb3fe 223 /* Parse token, if exists */
GeofferyOmlette 0:f6e4e1bbb3fe 224 dst_coap_msg_ptr->token_len = *packet_data_start_ptr & COAP_HEADER_TOKEN_LENGTH_MASK;
GeofferyOmlette 0:f6e4e1bbb3fe 225
GeofferyOmlette 0:f6e4e1bbb3fe 226 if(dst_coap_msg_ptr->token_len)
GeofferyOmlette 0:f6e4e1bbb3fe 227 {
GeofferyOmlette 0:f6e4e1bbb3fe 228 if((dst_coap_msg_ptr->token_len > 8) || dst_coap_msg_ptr->token_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 229 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 230
GeofferyOmlette 0:f6e4e1bbb3fe 231 dst_coap_msg_ptr->token_ptr = sn_coap_malloc(dst_coap_msg_ptr->token_len);
GeofferyOmlette 0:f6e4e1bbb3fe 232
GeofferyOmlette 0:f6e4e1bbb3fe 233 if (dst_coap_msg_ptr->token_ptr == NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 234 {
GeofferyOmlette 0:f6e4e1bbb3fe 235 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 236 }
GeofferyOmlette 0:f6e4e1bbb3fe 237
GeofferyOmlette 0:f6e4e1bbb3fe 238 memcpy(dst_coap_msg_ptr->token_ptr, *packet_data_pptr, dst_coap_msg_ptr->token_len);
GeofferyOmlette 0:f6e4e1bbb3fe 239 (*packet_data_pptr) += dst_coap_msg_ptr->token_len;
GeofferyOmlette 0:f6e4e1bbb3fe 240 }
GeofferyOmlette 0:f6e4e1bbb3fe 241
GeofferyOmlette 0:f6e4e1bbb3fe 242 message_left = packet_len - ((*packet_data_pptr) - packet_data_start_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 243
GeofferyOmlette 0:f6e4e1bbb3fe 244 /* Loop all Options */
GeofferyOmlette 0:f6e4e1bbb3fe 245 while((**packet_data_pptr != 0xff) && message_left)
GeofferyOmlette 0:f6e4e1bbb3fe 246 {
GeofferyOmlette 0:f6e4e1bbb3fe 247
GeofferyOmlette 0:f6e4e1bbb3fe 248 /* Get option length WITHOUT extensions */
GeofferyOmlette 0:f6e4e1bbb3fe 249 uint16_t option_len = (**packet_data_pptr & 0x0F);
GeofferyOmlette 0:f6e4e1bbb3fe 250
GeofferyOmlette 0:f6e4e1bbb3fe 251 /* Option number length 15 is reserved for the future use - ERROR */
GeofferyOmlette 0:f6e4e1bbb3fe 252 if(option_len == 15)
GeofferyOmlette 0:f6e4e1bbb3fe 253 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 254
GeofferyOmlette 0:f6e4e1bbb3fe 255 /* Resolve option delta */
GeofferyOmlette 0:f6e4e1bbb3fe 256 uint16_t option_number = (**packet_data_pptr >> COAP_OPTIONS_OPTION_NUMBER_SHIFT);
GeofferyOmlette 0:f6e4e1bbb3fe 257
GeofferyOmlette 0:f6e4e1bbb3fe 258 if(option_number == 13)
GeofferyOmlette 0:f6e4e1bbb3fe 259 {
GeofferyOmlette 0:f6e4e1bbb3fe 260 option_number = *(*packet_data_pptr+1) + 13;
GeofferyOmlette 0:f6e4e1bbb3fe 261 (*packet_data_pptr)++;
GeofferyOmlette 0:f6e4e1bbb3fe 262 }
GeofferyOmlette 0:f6e4e1bbb3fe 263 else if(option_number == 14)
GeofferyOmlette 0:f6e4e1bbb3fe 264 {
GeofferyOmlette 0:f6e4e1bbb3fe 265 option_number = *(*packet_data_pptr+2);
GeofferyOmlette 0:f6e4e1bbb3fe 266 option_number += (*(*packet_data_pptr+1) << 8) + 269;
GeofferyOmlette 0:f6e4e1bbb3fe 267 (*packet_data_pptr) += 2;
GeofferyOmlette 0:f6e4e1bbb3fe 268 }
GeofferyOmlette 0:f6e4e1bbb3fe 269 /* Option number 15 reserved for payload marker. This is handled as a error! */
GeofferyOmlette 0:f6e4e1bbb3fe 270 else if(option_number == 15)
GeofferyOmlette 0:f6e4e1bbb3fe 271 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 272
GeofferyOmlette 0:f6e4e1bbb3fe 273 /* Add previous option to option delta and get option number */
GeofferyOmlette 0:f6e4e1bbb3fe 274 option_number += previous_option_number;
GeofferyOmlette 0:f6e4e1bbb3fe 275
GeofferyOmlette 0:f6e4e1bbb3fe 276 /* Add possible option length extension to resolve full length of the option */
GeofferyOmlette 0:f6e4e1bbb3fe 277 if(option_len == 13)
GeofferyOmlette 0:f6e4e1bbb3fe 278 {
GeofferyOmlette 0:f6e4e1bbb3fe 279 option_len = *(*packet_data_pptr+1) + 13;
GeofferyOmlette 0:f6e4e1bbb3fe 280 (*packet_data_pptr)++;
GeofferyOmlette 0:f6e4e1bbb3fe 281 }
GeofferyOmlette 0:f6e4e1bbb3fe 282 else if(option_len == 14)
GeofferyOmlette 0:f6e4e1bbb3fe 283 {
GeofferyOmlette 0:f6e4e1bbb3fe 284 option_len = *(*packet_data_pptr+2);
GeofferyOmlette 0:f6e4e1bbb3fe 285 option_len += (*(*packet_data_pptr+1) << 8) + 269;
GeofferyOmlette 0:f6e4e1bbb3fe 286 (*packet_data_pptr) += 2;
GeofferyOmlette 0:f6e4e1bbb3fe 287 }
GeofferyOmlette 0:f6e4e1bbb3fe 288
GeofferyOmlette 0:f6e4e1bbb3fe 289
GeofferyOmlette 0:f6e4e1bbb3fe 290 /* * * Parse option itself * * */
GeofferyOmlette 0:f6e4e1bbb3fe 291 /* Some options are handled independently in own functions */
GeofferyOmlette 0:f6e4e1bbb3fe 292 previous_option_number = option_number;
GeofferyOmlette 0:f6e4e1bbb3fe 293
GeofferyOmlette 0:f6e4e1bbb3fe 294 /* Allocate options_list_ptr if needed */
GeofferyOmlette 0:f6e4e1bbb3fe 295 switch (option_number)
GeofferyOmlette 0:f6e4e1bbb3fe 296 {
GeofferyOmlette 0:f6e4e1bbb3fe 297 case COAP_OPTION_MAX_AGE:
GeofferyOmlette 0:f6e4e1bbb3fe 298 case COAP_OPTION_PROXY_URI:
GeofferyOmlette 0:f6e4e1bbb3fe 299 case COAP_OPTION_ETAG:
GeofferyOmlette 0:f6e4e1bbb3fe 300 case COAP_OPTION_URI_HOST:
GeofferyOmlette 0:f6e4e1bbb3fe 301 case COAP_OPTION_LOCATION_PATH:
GeofferyOmlette 0:f6e4e1bbb3fe 302 case COAP_OPTION_URI_PORT:
GeofferyOmlette 0:f6e4e1bbb3fe 303 case COAP_OPTION_LOCATION_QUERY:
GeofferyOmlette 0:f6e4e1bbb3fe 304 case COAP_OPTION_OBSERVE:
GeofferyOmlette 0:f6e4e1bbb3fe 305 case COAP_OPTION_URI_QUERY:
GeofferyOmlette 0:f6e4e1bbb3fe 306 case COAP_OPTION_BLOCK2:
GeofferyOmlette 0:f6e4e1bbb3fe 307 case COAP_OPTION_BLOCK1:
GeofferyOmlette 0:f6e4e1bbb3fe 308 case COAP_OPTION_ACCEPT:
GeofferyOmlette 0:f6e4e1bbb3fe 309 if (dst_coap_msg_ptr->options_list_ptr == NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 310 {
GeofferyOmlette 0:f6e4e1bbb3fe 311 dst_coap_msg_ptr->options_list_ptr = sn_coap_malloc(sizeof(sn_coap_options_list_s));
GeofferyOmlette 0:f6e4e1bbb3fe 312 if(NULL == dst_coap_msg_ptr->options_list_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 313 {
GeofferyOmlette 0:f6e4e1bbb3fe 314 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 315 }
GeofferyOmlette 0:f6e4e1bbb3fe 316 memset(dst_coap_msg_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s));
GeofferyOmlette 0:f6e4e1bbb3fe 317 }
GeofferyOmlette 0:f6e4e1bbb3fe 318 break;
GeofferyOmlette 0:f6e4e1bbb3fe 319 }
GeofferyOmlette 0:f6e4e1bbb3fe 320
GeofferyOmlette 0:f6e4e1bbb3fe 321 /* Parse option */
GeofferyOmlette 0:f6e4e1bbb3fe 322 switch (option_number)
GeofferyOmlette 0:f6e4e1bbb3fe 323 {
GeofferyOmlette 0:f6e4e1bbb3fe 324 case COAP_OPTION_CONTENT_FORMAT:
GeofferyOmlette 0:f6e4e1bbb3fe 325 if((option_len > 2) || (dst_coap_msg_ptr->content_type_ptr))
GeofferyOmlette 0:f6e4e1bbb3fe 326 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 327 dst_coap_msg_ptr->content_type_len = option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 328 (*packet_data_pptr)++;
GeofferyOmlette 0:f6e4e1bbb3fe 329
GeofferyOmlette 0:f6e4e1bbb3fe 330 if(option_len)
GeofferyOmlette 0:f6e4e1bbb3fe 331 {
GeofferyOmlette 0:f6e4e1bbb3fe 332 dst_coap_msg_ptr->content_type_ptr = sn_coap_malloc(option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 333
GeofferyOmlette 0:f6e4e1bbb3fe 334 if (dst_coap_msg_ptr->content_type_ptr == NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 335 {
GeofferyOmlette 0:f6e4e1bbb3fe 336 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 337 }
GeofferyOmlette 0:f6e4e1bbb3fe 338
GeofferyOmlette 0:f6e4e1bbb3fe 339 memcpy(dst_coap_msg_ptr->content_type_ptr, *packet_data_pptr, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 340 (*packet_data_pptr) += option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 341 }
GeofferyOmlette 0:f6e4e1bbb3fe 342 break;
GeofferyOmlette 0:f6e4e1bbb3fe 343
GeofferyOmlette 0:f6e4e1bbb3fe 344 case COAP_OPTION_MAX_AGE:
GeofferyOmlette 0:f6e4e1bbb3fe 345 if((option_len > 4) || dst_coap_msg_ptr->options_list_ptr->max_age_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 346 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 347 dst_coap_msg_ptr->options_list_ptr->max_age_len = option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 348 (*packet_data_pptr)++;
GeofferyOmlette 0:f6e4e1bbb3fe 349
GeofferyOmlette 0:f6e4e1bbb3fe 350 if(option_len)
GeofferyOmlette 0:f6e4e1bbb3fe 351 {
GeofferyOmlette 0:f6e4e1bbb3fe 352 dst_coap_msg_ptr->options_list_ptr->max_age_ptr = sn_coap_malloc(option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 353
GeofferyOmlette 0:f6e4e1bbb3fe 354 if (dst_coap_msg_ptr->options_list_ptr->max_age_ptr == NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 355 {
GeofferyOmlette 0:f6e4e1bbb3fe 356 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 357 }
GeofferyOmlette 0:f6e4e1bbb3fe 358
GeofferyOmlette 0:f6e4e1bbb3fe 359 memcpy(dst_coap_msg_ptr->options_list_ptr->max_age_ptr, *packet_data_pptr, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 360 (*packet_data_pptr) += option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 361 }
GeofferyOmlette 0:f6e4e1bbb3fe 362 break;
GeofferyOmlette 0:f6e4e1bbb3fe 363
GeofferyOmlette 0:f6e4e1bbb3fe 364 case COAP_OPTION_PROXY_URI:
GeofferyOmlette 0:f6e4e1bbb3fe 365 if ((option_len > 1034) || (option_len < 1) || dst_coap_msg_ptr->options_list_ptr->proxy_uri_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 366 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 367 dst_coap_msg_ptr->options_list_ptr->proxy_uri_len = option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 368 (*packet_data_pptr)++;
GeofferyOmlette 0:f6e4e1bbb3fe 369
GeofferyOmlette 0:f6e4e1bbb3fe 370 dst_coap_msg_ptr->options_list_ptr->proxy_uri_ptr = sn_coap_malloc(option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 371
GeofferyOmlette 0:f6e4e1bbb3fe 372 if (dst_coap_msg_ptr->options_list_ptr->proxy_uri_ptr == NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 373 {
GeofferyOmlette 0:f6e4e1bbb3fe 374 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 375 }
GeofferyOmlette 0:f6e4e1bbb3fe 376 memcpy(dst_coap_msg_ptr->options_list_ptr->proxy_uri_ptr, *packet_data_pptr, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 377 (*packet_data_pptr) += option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 378
GeofferyOmlette 0:f6e4e1bbb3fe 379 break;
GeofferyOmlette 0:f6e4e1bbb3fe 380
GeofferyOmlette 0:f6e4e1bbb3fe 381 case COAP_OPTION_ETAG:
GeofferyOmlette 0:f6e4e1bbb3fe 382 if(dst_coap_msg_ptr->options_list_ptr->etag_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 383 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 384 /* This is managed independently because User gives this option in one character table */
GeofferyOmlette 0:f6e4e1bbb3fe 385
GeofferyOmlette 0:f6e4e1bbb3fe 386 ret_status = sn_coap_parser_options_parse_multiple_options (packet_data_pptr,
GeofferyOmlette 0:f6e4e1bbb3fe 387 message_left,
GeofferyOmlette 0:f6e4e1bbb3fe 388 &dst_coap_msg_ptr->options_list_ptr->etag_ptr,
GeofferyOmlette 0:f6e4e1bbb3fe 389 (uint16_t*)&dst_coap_msg_ptr->options_list_ptr->etag_len,
GeofferyOmlette 0:f6e4e1bbb3fe 390 COAP_OPTION_LOCATION_PATH, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 391 if (ret_status >= 0)
GeofferyOmlette 0:f6e4e1bbb3fe 392 {
GeofferyOmlette 0:f6e4e1bbb3fe 393 i += (ret_status - 1); /* i += is because possible several Options are handled by sn_coap_parser_options_parse_multiple_options() */
GeofferyOmlette 0:f6e4e1bbb3fe 394 }
GeofferyOmlette 0:f6e4e1bbb3fe 395 else
GeofferyOmlette 0:f6e4e1bbb3fe 396 {
GeofferyOmlette 0:f6e4e1bbb3fe 397 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 398 }
GeofferyOmlette 0:f6e4e1bbb3fe 399 break;
GeofferyOmlette 0:f6e4e1bbb3fe 400
GeofferyOmlette 0:f6e4e1bbb3fe 401 case COAP_OPTION_URI_HOST:
GeofferyOmlette 0:f6e4e1bbb3fe 402 if((option_len > 255) || (option_len < 1) || dst_coap_msg_ptr->options_list_ptr->uri_host_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 403 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 404 dst_coap_msg_ptr->options_list_ptr->uri_host_len = option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 405 (*packet_data_pptr)++;
GeofferyOmlette 0:f6e4e1bbb3fe 406
GeofferyOmlette 0:f6e4e1bbb3fe 407 dst_coap_msg_ptr->options_list_ptr->uri_host_ptr = sn_coap_malloc(option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 408
GeofferyOmlette 0:f6e4e1bbb3fe 409 if (dst_coap_msg_ptr->options_list_ptr->uri_host_ptr == NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 410 {
GeofferyOmlette 0:f6e4e1bbb3fe 411 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 412 }
GeofferyOmlette 0:f6e4e1bbb3fe 413 memcpy(dst_coap_msg_ptr->options_list_ptr->uri_host_ptr, *packet_data_pptr, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 414 (*packet_data_pptr) += option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 415
GeofferyOmlette 0:f6e4e1bbb3fe 416 break;
GeofferyOmlette 0:f6e4e1bbb3fe 417
GeofferyOmlette 0:f6e4e1bbb3fe 418 case COAP_OPTION_LOCATION_PATH:
GeofferyOmlette 0:f6e4e1bbb3fe 419 if(dst_coap_msg_ptr->options_list_ptr->location_path_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 420 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 421 /* This is managed independently because User gives this option in one character table */
GeofferyOmlette 0:f6e4e1bbb3fe 422 ret_status = sn_coap_parser_options_parse_multiple_options(packet_data_pptr, message_left,
GeofferyOmlette 0:f6e4e1bbb3fe 423 &dst_coap_msg_ptr->options_list_ptr->location_path_ptr, &dst_coap_msg_ptr->options_list_ptr->location_path_len,
GeofferyOmlette 0:f6e4e1bbb3fe 424 COAP_OPTION_LOCATION_PATH, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 425 if (ret_status >= 0)
GeofferyOmlette 0:f6e4e1bbb3fe 426 {
GeofferyOmlette 0:f6e4e1bbb3fe 427 i += (ret_status - 1); /* i += is because possible several Options are handled by sn_coap_parser_options_parse_multiple_options() */
GeofferyOmlette 0:f6e4e1bbb3fe 428 }
GeofferyOmlette 0:f6e4e1bbb3fe 429 else
GeofferyOmlette 0:f6e4e1bbb3fe 430 {
GeofferyOmlette 0:f6e4e1bbb3fe 431 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 432 }
GeofferyOmlette 0:f6e4e1bbb3fe 433
GeofferyOmlette 0:f6e4e1bbb3fe 434 break;
GeofferyOmlette 0:f6e4e1bbb3fe 435
GeofferyOmlette 0:f6e4e1bbb3fe 436
GeofferyOmlette 0:f6e4e1bbb3fe 437 case COAP_OPTION_URI_PORT:
GeofferyOmlette 0:f6e4e1bbb3fe 438 if((option_len > 2) || dst_coap_msg_ptr->options_list_ptr->uri_port_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 439 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 440 dst_coap_msg_ptr->options_list_ptr->uri_port_len = option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 441 (*packet_data_pptr)++;
GeofferyOmlette 0:f6e4e1bbb3fe 442
GeofferyOmlette 0:f6e4e1bbb3fe 443 if(option_len)
GeofferyOmlette 0:f6e4e1bbb3fe 444 {
GeofferyOmlette 0:f6e4e1bbb3fe 445 dst_coap_msg_ptr->options_list_ptr->uri_port_ptr = sn_coap_malloc(option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 446
GeofferyOmlette 0:f6e4e1bbb3fe 447 if (dst_coap_msg_ptr->options_list_ptr->uri_port_ptr == NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 448 {
GeofferyOmlette 0:f6e4e1bbb3fe 449 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 450 }
GeofferyOmlette 0:f6e4e1bbb3fe 451 memcpy(dst_coap_msg_ptr->options_list_ptr->uri_port_ptr, *packet_data_pptr, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 452 (*packet_data_pptr) += option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 453 }
GeofferyOmlette 0:f6e4e1bbb3fe 454 break;
GeofferyOmlette 0:f6e4e1bbb3fe 455
GeofferyOmlette 0:f6e4e1bbb3fe 456 case COAP_OPTION_LOCATION_QUERY:
GeofferyOmlette 0:f6e4e1bbb3fe 457 if(dst_coap_msg_ptr->options_list_ptr->location_query_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 458 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 459 ret_status = sn_coap_parser_options_parse_multiple_options(packet_data_pptr, message_left,
GeofferyOmlette 0:f6e4e1bbb3fe 460 &dst_coap_msg_ptr->options_list_ptr->location_query_ptr, &dst_coap_msg_ptr->options_list_ptr->location_query_len,
GeofferyOmlette 0:f6e4e1bbb3fe 461 COAP_OPTION_LOCATION_QUERY, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 462 if (ret_status >= 0)
GeofferyOmlette 0:f6e4e1bbb3fe 463 {
GeofferyOmlette 0:f6e4e1bbb3fe 464 i += (ret_status - 1); /* i += is because possible several Options are handled by sn_coap_parser_options_parse_multiple_options() */
GeofferyOmlette 0:f6e4e1bbb3fe 465 }
GeofferyOmlette 0:f6e4e1bbb3fe 466 else
GeofferyOmlette 0:f6e4e1bbb3fe 467 {
GeofferyOmlette 0:f6e4e1bbb3fe 468 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 469 }
GeofferyOmlette 0:f6e4e1bbb3fe 470
GeofferyOmlette 0:f6e4e1bbb3fe 471 break;
GeofferyOmlette 0:f6e4e1bbb3fe 472
GeofferyOmlette 0:f6e4e1bbb3fe 473 case COAP_OPTION_URI_PATH:
GeofferyOmlette 0:f6e4e1bbb3fe 474 if(dst_coap_msg_ptr->uri_path_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 475 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 476 ret_status = sn_coap_parser_options_parse_multiple_options(packet_data_pptr, message_left,
GeofferyOmlette 0:f6e4e1bbb3fe 477 &dst_coap_msg_ptr->uri_path_ptr, &dst_coap_msg_ptr->uri_path_len,
GeofferyOmlette 0:f6e4e1bbb3fe 478 COAP_OPTION_URI_PATH, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 479 if (ret_status >= 0)
GeofferyOmlette 0:f6e4e1bbb3fe 480 {
GeofferyOmlette 0:f6e4e1bbb3fe 481 i += (ret_status - 1); /* i += is because possible several Options are handled by sn_coap_parser_options_parse_multiple_options() */
GeofferyOmlette 0:f6e4e1bbb3fe 482 }
GeofferyOmlette 0:f6e4e1bbb3fe 483 else
GeofferyOmlette 0:f6e4e1bbb3fe 484 {
GeofferyOmlette 0:f6e4e1bbb3fe 485 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 486 }
GeofferyOmlette 0:f6e4e1bbb3fe 487
GeofferyOmlette 0:f6e4e1bbb3fe 488 break;
GeofferyOmlette 0:f6e4e1bbb3fe 489
GeofferyOmlette 0:f6e4e1bbb3fe 490 case COAP_OPTION_OBSERVE:
GeofferyOmlette 0:f6e4e1bbb3fe 491 if((option_len > 2) || dst_coap_msg_ptr->options_list_ptr->observe_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 492 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 493
GeofferyOmlette 0:f6e4e1bbb3fe 494 dst_coap_msg_ptr->options_list_ptr->observe = 1;
GeofferyOmlette 0:f6e4e1bbb3fe 495 (*packet_data_pptr)++;
GeofferyOmlette 0:f6e4e1bbb3fe 496
GeofferyOmlette 0:f6e4e1bbb3fe 497 if(option_len)
GeofferyOmlette 0:f6e4e1bbb3fe 498 {
GeofferyOmlette 0:f6e4e1bbb3fe 499
GeofferyOmlette 0:f6e4e1bbb3fe 500 dst_coap_msg_ptr->options_list_ptr->observe_len = option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 501
GeofferyOmlette 0:f6e4e1bbb3fe 502 dst_coap_msg_ptr->options_list_ptr->observe_ptr = sn_coap_malloc(option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 503
GeofferyOmlette 0:f6e4e1bbb3fe 504 if (dst_coap_msg_ptr->options_list_ptr->observe_ptr == NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 505 {
GeofferyOmlette 0:f6e4e1bbb3fe 506 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 507 }
GeofferyOmlette 0:f6e4e1bbb3fe 508
GeofferyOmlette 0:f6e4e1bbb3fe 509 memcpy(dst_coap_msg_ptr->options_list_ptr->observe_ptr, *packet_data_pptr, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 510 (*packet_data_pptr) += option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 511 }
GeofferyOmlette 0:f6e4e1bbb3fe 512
GeofferyOmlette 0:f6e4e1bbb3fe 513 break;
GeofferyOmlette 0:f6e4e1bbb3fe 514
GeofferyOmlette 0:f6e4e1bbb3fe 515 case COAP_OPTION_URI_QUERY:
GeofferyOmlette 0:f6e4e1bbb3fe 516 if(dst_coap_msg_ptr->options_list_ptr->uri_query_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 517 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 518 ret_status = sn_coap_parser_options_parse_multiple_options(packet_data_pptr, message_left,
GeofferyOmlette 0:f6e4e1bbb3fe 519 &dst_coap_msg_ptr->options_list_ptr->uri_query_ptr, &dst_coap_msg_ptr->options_list_ptr->uri_query_len,
GeofferyOmlette 0:f6e4e1bbb3fe 520 COAP_OPTION_URI_QUERY, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 521 if (ret_status >= 0)
GeofferyOmlette 0:f6e4e1bbb3fe 522 {
GeofferyOmlette 0:f6e4e1bbb3fe 523 i += (ret_status - 1); /* i += is because possible several Options are handled by sn_coap_parser_options_parse_multiple_options() */
GeofferyOmlette 0:f6e4e1bbb3fe 524 }
GeofferyOmlette 0:f6e4e1bbb3fe 525 else
GeofferyOmlette 0:f6e4e1bbb3fe 526 {
GeofferyOmlette 0:f6e4e1bbb3fe 527 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 528 }
GeofferyOmlette 0:f6e4e1bbb3fe 529
GeofferyOmlette 0:f6e4e1bbb3fe 530 break;
GeofferyOmlette 0:f6e4e1bbb3fe 531
GeofferyOmlette 0:f6e4e1bbb3fe 532 case COAP_OPTION_BLOCK2:
GeofferyOmlette 0:f6e4e1bbb3fe 533 if((option_len > 4) || dst_coap_msg_ptr->options_list_ptr->block2_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 534 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 535 dst_coap_msg_ptr->options_list_ptr->block2_len = option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 536 (*packet_data_pptr)++;
GeofferyOmlette 0:f6e4e1bbb3fe 537
GeofferyOmlette 0:f6e4e1bbb3fe 538 dst_coap_msg_ptr->options_list_ptr->block2_ptr = sn_coap_malloc(option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 539
GeofferyOmlette 0:f6e4e1bbb3fe 540 if (dst_coap_msg_ptr->options_list_ptr->block2_ptr == NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 541 {
GeofferyOmlette 0:f6e4e1bbb3fe 542 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 543 }
GeofferyOmlette 0:f6e4e1bbb3fe 544
GeofferyOmlette 0:f6e4e1bbb3fe 545 memcpy(dst_coap_msg_ptr->options_list_ptr->block2_ptr, *packet_data_pptr, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 546 (*packet_data_pptr) += option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 547
GeofferyOmlette 0:f6e4e1bbb3fe 548 break;
GeofferyOmlette 0:f6e4e1bbb3fe 549
GeofferyOmlette 0:f6e4e1bbb3fe 550 case COAP_OPTION_BLOCK1:
GeofferyOmlette 0:f6e4e1bbb3fe 551 if((option_len > 4) || dst_coap_msg_ptr->options_list_ptr->block1_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 552 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 553 dst_coap_msg_ptr->options_list_ptr->block1_len = option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 554 (*packet_data_pptr)++;
GeofferyOmlette 0:f6e4e1bbb3fe 555
GeofferyOmlette 0:f6e4e1bbb3fe 556 dst_coap_msg_ptr->options_list_ptr->block1_ptr = sn_coap_malloc(option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 557
GeofferyOmlette 0:f6e4e1bbb3fe 558 if (dst_coap_msg_ptr->options_list_ptr->block1_ptr == NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 559 {
GeofferyOmlette 0:f6e4e1bbb3fe 560 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 561 }
GeofferyOmlette 0:f6e4e1bbb3fe 562
GeofferyOmlette 0:f6e4e1bbb3fe 563 memcpy(dst_coap_msg_ptr->options_list_ptr->block1_ptr, *packet_data_pptr, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 564 (*packet_data_pptr) += option_len;
GeofferyOmlette 0:f6e4e1bbb3fe 565
GeofferyOmlette 0:f6e4e1bbb3fe 566 break;
GeofferyOmlette 0:f6e4e1bbb3fe 567
GeofferyOmlette 0:f6e4e1bbb3fe 568 case COAP_OPTION_ACCEPT:
GeofferyOmlette 0:f6e4e1bbb3fe 569 if(dst_coap_msg_ptr->options_list_ptr->accept_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 570 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 571 ret_status = sn_coap_parser_options_parse_multiple_options(packet_data_pptr, message_left,
GeofferyOmlette 0:f6e4e1bbb3fe 572 &dst_coap_msg_ptr->options_list_ptr->accept_ptr, (uint16_t *)&dst_coap_msg_ptr->options_list_ptr->accept_len,
GeofferyOmlette 0:f6e4e1bbb3fe 573 COAP_OPTION_ACCEPT, option_len);
GeofferyOmlette 0:f6e4e1bbb3fe 574 if (ret_status >= 0)
GeofferyOmlette 0:f6e4e1bbb3fe 575 {
GeofferyOmlette 0:f6e4e1bbb3fe 576 i += (ret_status - 1); /* i += is because possible several Options are handled by sn_coap_parser_options_parse_multiple_options() */
GeofferyOmlette 0:f6e4e1bbb3fe 577 }
GeofferyOmlette 0:f6e4e1bbb3fe 578 else
GeofferyOmlette 0:f6e4e1bbb3fe 579 {
GeofferyOmlette 0:f6e4e1bbb3fe 580 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 581 }
GeofferyOmlette 0:f6e4e1bbb3fe 582
GeofferyOmlette 0:f6e4e1bbb3fe 583 break;
GeofferyOmlette 0:f6e4e1bbb3fe 584
GeofferyOmlette 0:f6e4e1bbb3fe 585 default:
GeofferyOmlette 0:f6e4e1bbb3fe 586 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 587 }
GeofferyOmlette 0:f6e4e1bbb3fe 588
GeofferyOmlette 0:f6e4e1bbb3fe 589 /* Check for overflow */
GeofferyOmlette 0:f6e4e1bbb3fe 590 if((*packet_data_pptr - packet_data_start_ptr) > packet_len)
GeofferyOmlette 0:f6e4e1bbb3fe 591 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 592
GeofferyOmlette 0:f6e4e1bbb3fe 593 message_left = packet_len - (*packet_data_pptr - packet_data_start_ptr); //todo: if(*packet_data_pptr < packet_data_start_ptr) message_left = 0; else
GeofferyOmlette 0:f6e4e1bbb3fe 594
GeofferyOmlette 0:f6e4e1bbb3fe 595
GeofferyOmlette 0:f6e4e1bbb3fe 596 }
GeofferyOmlette 0:f6e4e1bbb3fe 597
GeofferyOmlette 0:f6e4e1bbb3fe 598 return 0;
GeofferyOmlette 0:f6e4e1bbb3fe 599 }
GeofferyOmlette 0:f6e4e1bbb3fe 600
GeofferyOmlette 0:f6e4e1bbb3fe 601
GeofferyOmlette 0:f6e4e1bbb3fe 602 /**
GeofferyOmlette 0:f6e4e1bbb3fe 603 * \fn static int8_t sn_coap_parser_options_parse_multiple_options(uint8_t **packet_data_pptr, uint8_t options_count_left, uint8_t *previous_option_number_ptr, uint8_t **dst_pptr,
GeofferyOmlette 0:f6e4e1bbb3fe 604 * uint16_t *dst_len_ptr, sn_coap_option_numbers_e option, uint16_t option_number_len)
GeofferyOmlette 0:f6e4e1bbb3fe 605 *
GeofferyOmlette 0:f6e4e1bbb3fe 606 * \brief Parses CoAP message's Uri-query options
GeofferyOmlette 0:f6e4e1bbb3fe 607 *
GeofferyOmlette 0:f6e4e1bbb3fe 608 * \param **packet_data_pptr is source for Packet data to be parsed to CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 609 *
GeofferyOmlette 0:f6e4e1bbb3fe 610 * \param *dst_coap_msg_ptr is destination for parsed CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 611 *
GeofferyOmlette 0:f6e4e1bbb3fe 612 * \param options_count_left tells how many options are unhandled in Packet data
GeofferyOmlette 0:f6e4e1bbb3fe 613 *
GeofferyOmlette 0:f6e4e1bbb3fe 614 * \param *previous_option_number_ptr is pointer to used and returned previous Option number
GeofferyOmlette 0:f6e4e1bbb3fe 615 *
GeofferyOmlette 0:f6e4e1bbb3fe 616 * \return Return value is count of Uri-query optios parsed. In failure case -1 is returned.
GeofferyOmlette 0:f6e4e1bbb3fe 617 */
GeofferyOmlette 0:f6e4e1bbb3fe 618 SN_MEM_ATTR_COAP_PARSER_FUNC
GeofferyOmlette 0:f6e4e1bbb3fe 619 static int8_t sn_coap_parser_options_parse_multiple_options(uint8_t **packet_data_pptr, uint16_t packet_left_len, uint8_t **dst_pptr, uint16_t *dst_len_ptr, sn_coap_option_numbers_e option, uint16_t option_number_len)
GeofferyOmlette 0:f6e4e1bbb3fe 620 {
GeofferyOmlette 0:f6e4e1bbb3fe 621 int16_t uri_query_needed_heap = sn_coap_parser_options_count_needed_memory_multiple_option(*packet_data_pptr, packet_left_len, option, option_number_len);
GeofferyOmlette 0:f6e4e1bbb3fe 622 uint8_t *temp_parsed_uri_query_ptr = NULL;
GeofferyOmlette 0:f6e4e1bbb3fe 623 uint8_t returned_option_counter = 0;
GeofferyOmlette 0:f6e4e1bbb3fe 624
GeofferyOmlette 0:f6e4e1bbb3fe 625 if(uri_query_needed_heap == -1)
GeofferyOmlette 0:f6e4e1bbb3fe 626 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 627
GeofferyOmlette 0:f6e4e1bbb3fe 628 if(uri_query_needed_heap)
GeofferyOmlette 0:f6e4e1bbb3fe 629 {
GeofferyOmlette 0:f6e4e1bbb3fe 630 *dst_pptr = (uint8_t*) sn_coap_malloc(uri_query_needed_heap);
GeofferyOmlette 0:f6e4e1bbb3fe 631
GeofferyOmlette 0:f6e4e1bbb3fe 632 if (*dst_pptr == NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 633 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 634 }
GeofferyOmlette 0:f6e4e1bbb3fe 635
GeofferyOmlette 0:f6e4e1bbb3fe 636 *dst_len_ptr = uri_query_needed_heap;
GeofferyOmlette 0:f6e4e1bbb3fe 637
GeofferyOmlette 0:f6e4e1bbb3fe 638 temp_parsed_uri_query_ptr = *dst_pptr;
GeofferyOmlette 0:f6e4e1bbb3fe 639
GeofferyOmlette 0:f6e4e1bbb3fe 640 /* Loop all Uri-Query options */
GeofferyOmlette 0:f6e4e1bbb3fe 641 while ((temp_parsed_uri_query_ptr - *dst_pptr) < uri_query_needed_heap)
GeofferyOmlette 0:f6e4e1bbb3fe 642 {
GeofferyOmlette 0:f6e4e1bbb3fe 643 /* Check if this is first Uri-Query option */
GeofferyOmlette 0:f6e4e1bbb3fe 644 if (returned_option_counter > 0)
GeofferyOmlette 0:f6e4e1bbb3fe 645 {
GeofferyOmlette 0:f6e4e1bbb3fe 646 /* Uri-Query is modified to following format: temp1'\0'temp2'\0'temp3 i.e. */
GeofferyOmlette 0:f6e4e1bbb3fe 647 /* Uri-Path is modified to following format: temp1\temp2\temp3 i.e. */
GeofferyOmlette 0:f6e4e1bbb3fe 648 if(option == COAP_OPTION_URI_QUERY || option == COAP_OPTION_LOCATION_QUERY || option == COAP_OPTION_ETAG || option == COAP_OPTION_ACCEPT)
GeofferyOmlette 0:f6e4e1bbb3fe 649 memset(temp_parsed_uri_query_ptr, '&', 1);
GeofferyOmlette 0:f6e4e1bbb3fe 650 else if(option == COAP_OPTION_URI_PATH || option == COAP_OPTION_LOCATION_PATH)
GeofferyOmlette 0:f6e4e1bbb3fe 651 memset(temp_parsed_uri_query_ptr, '/', 1);
GeofferyOmlette 0:f6e4e1bbb3fe 652
GeofferyOmlette 0:f6e4e1bbb3fe 653 temp_parsed_uri_query_ptr++;
GeofferyOmlette 0:f6e4e1bbb3fe 654 }
GeofferyOmlette 0:f6e4e1bbb3fe 655
GeofferyOmlette 0:f6e4e1bbb3fe 656 returned_option_counter++;
GeofferyOmlette 0:f6e4e1bbb3fe 657
GeofferyOmlette 0:f6e4e1bbb3fe 658 (*packet_data_pptr)++;
GeofferyOmlette 0:f6e4e1bbb3fe 659
GeofferyOmlette 0:f6e4e1bbb3fe 660 if(((temp_parsed_uri_query_ptr - *dst_pptr) + option_number_len) > uri_query_needed_heap)
GeofferyOmlette 0:f6e4e1bbb3fe 661 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 662
GeofferyOmlette 0:f6e4e1bbb3fe 663 memcpy(temp_parsed_uri_query_ptr, *packet_data_pptr, option_number_len);
GeofferyOmlette 0:f6e4e1bbb3fe 664
GeofferyOmlette 0:f6e4e1bbb3fe 665 (*packet_data_pptr) += option_number_len;
GeofferyOmlette 0:f6e4e1bbb3fe 666 temp_parsed_uri_query_ptr += option_number_len;
GeofferyOmlette 0:f6e4e1bbb3fe 667
GeofferyOmlette 0:f6e4e1bbb3fe 668 if(((**packet_data_pptr >> COAP_OPTIONS_OPTION_NUMBER_SHIFT) != 0) || (temp_parsed_uri_query_ptr - *dst_pptr) >= uri_query_needed_heap)
GeofferyOmlette 0:f6e4e1bbb3fe 669 {
GeofferyOmlette 0:f6e4e1bbb3fe 670 return returned_option_counter;
GeofferyOmlette 0:f6e4e1bbb3fe 671 }
GeofferyOmlette 0:f6e4e1bbb3fe 672
GeofferyOmlette 0:f6e4e1bbb3fe 673 option_number_len = (**packet_data_pptr & 0x0F);
GeofferyOmlette 0:f6e4e1bbb3fe 674 if(option_number_len == 13)
GeofferyOmlette 0:f6e4e1bbb3fe 675 {
GeofferyOmlette 0:f6e4e1bbb3fe 676 option_number_len = *(*packet_data_pptr+1) + 13;
GeofferyOmlette 0:f6e4e1bbb3fe 677 (*packet_data_pptr)++;
GeofferyOmlette 0:f6e4e1bbb3fe 678 }
GeofferyOmlette 0:f6e4e1bbb3fe 679 else if(option_number_len == 14)
GeofferyOmlette 0:f6e4e1bbb3fe 680 {
GeofferyOmlette 0:f6e4e1bbb3fe 681 option_number_len = *(*packet_data_pptr+2);
GeofferyOmlette 0:f6e4e1bbb3fe 682 option_number_len += (*(*packet_data_pptr+1) << 8) + 269;
GeofferyOmlette 0:f6e4e1bbb3fe 683 (*packet_data_pptr) += 2;
GeofferyOmlette 0:f6e4e1bbb3fe 684 }
GeofferyOmlette 0:f6e4e1bbb3fe 685 }
GeofferyOmlette 0:f6e4e1bbb3fe 686
GeofferyOmlette 0:f6e4e1bbb3fe 687 return returned_option_counter;
GeofferyOmlette 0:f6e4e1bbb3fe 688 }
GeofferyOmlette 0:f6e4e1bbb3fe 689
GeofferyOmlette 0:f6e4e1bbb3fe 690
GeofferyOmlette 0:f6e4e1bbb3fe 691
GeofferyOmlette 0:f6e4e1bbb3fe 692
GeofferyOmlette 0:f6e4e1bbb3fe 693 /**
GeofferyOmlette 0:f6e4e1bbb3fe 694 * \fn static uint16_t sn_coap_parser_options_count_needed_memory_multiple_option(uint8_t *packet_data_ptr, uint8_t options_count_left, uint8_t previous_option_number, sn_coap_option_numbers_e option, uint16_t option_number_len)
GeofferyOmlette 0:f6e4e1bbb3fe 695 *
GeofferyOmlette 0:f6e4e1bbb3fe 696 * \brief Counts needed memory for uri query option
GeofferyOmlette 0:f6e4e1bbb3fe 697 *
GeofferyOmlette 0:f6e4e1bbb3fe 698 * \param *packet_data_ptr is start of source for Packet data to be parsed to CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 699 *
GeofferyOmlette 0:f6e4e1bbb3fe 700 * \param options_count_left tells how many options are unhandled in Packet data
GeofferyOmlette 0:f6e4e1bbb3fe 701 *
GeofferyOmlette 0:f6e4e1bbb3fe 702 * \param previous_option_number is previous Option number
GeofferyOmlette 0:f6e4e1bbb3fe 703 *
GeofferyOmlette 0:f6e4e1bbb3fe 704 * \param sn_coap_option_numbers_e option option number to be calculated
GeofferyOmlette 0:f6e4e1bbb3fe 705 *
GeofferyOmlette 0:f6e4e1bbb3fe 706 * \param uint16_t option_number_len length of the first option part
GeofferyOmlette 0:f6e4e1bbb3fe 707 */
GeofferyOmlette 0:f6e4e1bbb3fe 708 SN_MEM_ATTR_COAP_PARSER_FUNC
GeofferyOmlette 0:f6e4e1bbb3fe 709 static int16_t sn_coap_parser_options_count_needed_memory_multiple_option(uint8_t *packet_data_ptr, uint16_t packet_left_len, sn_coap_option_numbers_e option, uint16_t option_number_len)
GeofferyOmlette 0:f6e4e1bbb3fe 710 {
GeofferyOmlette 0:f6e4e1bbb3fe 711 uint16_t ret_value = 0;
GeofferyOmlette 0:f6e4e1bbb3fe 712 uint16_t i = 1;
GeofferyOmlette 0:f6e4e1bbb3fe 713
GeofferyOmlette 0:f6e4e1bbb3fe 714 /* Loop all Uri-Query options */
GeofferyOmlette 0:f6e4e1bbb3fe 715 while (i < packet_left_len)
GeofferyOmlette 0:f6e4e1bbb3fe 716 {
GeofferyOmlette 0:f6e4e1bbb3fe 717 if(option == COAP_OPTION_LOCATION_PATH && option_number_len > 255)
GeofferyOmlette 0:f6e4e1bbb3fe 718 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 719 if(option == COAP_OPTION_URI_PATH && option_number_len > 255)
GeofferyOmlette 0:f6e4e1bbb3fe 720 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 721 if(option == COAP_OPTION_URI_QUERY && option_number_len > 255)
GeofferyOmlette 0:f6e4e1bbb3fe 722 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 723 if(option == COAP_OPTION_LOCATION_QUERY && option_number_len > 255)
GeofferyOmlette 0:f6e4e1bbb3fe 724 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 725 if(option == COAP_OPTION_ACCEPT && option_number_len > 2)
GeofferyOmlette 0:f6e4e1bbb3fe 726 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 727 if(option == COAP_OPTION_ETAG && option_number_len > 8)
GeofferyOmlette 0:f6e4e1bbb3fe 728 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 729
GeofferyOmlette 0:f6e4e1bbb3fe 730 i += option_number_len;
GeofferyOmlette 0:f6e4e1bbb3fe 731 ret_value += option_number_len + 1; /* + 1 is for separator */
GeofferyOmlette 0:f6e4e1bbb3fe 732
GeofferyOmlette 0:f6e4e1bbb3fe 733 if((*(packet_data_ptr + i) >> COAP_OPTIONS_OPTION_NUMBER_SHIFT) != 0)
GeofferyOmlette 0:f6e4e1bbb3fe 734 {
GeofferyOmlette 0:f6e4e1bbb3fe 735 if(ret_value != 0)
GeofferyOmlette 0:f6e4e1bbb3fe 736 return (ret_value - 1); /* -1 because last Part path does not include separator */
GeofferyOmlette 0:f6e4e1bbb3fe 737 else
GeofferyOmlette 0:f6e4e1bbb3fe 738 return 0;
GeofferyOmlette 0:f6e4e1bbb3fe 739 }
GeofferyOmlette 0:f6e4e1bbb3fe 740
GeofferyOmlette 0:f6e4e1bbb3fe 741 option_number_len = (*(packet_data_ptr + i) & 0x0F);
GeofferyOmlette 0:f6e4e1bbb3fe 742
GeofferyOmlette 0:f6e4e1bbb3fe 743 if (option_number_len == 13)
GeofferyOmlette 0:f6e4e1bbb3fe 744 {
GeofferyOmlette 0:f6e4e1bbb3fe 745 i++;
GeofferyOmlette 0:f6e4e1bbb3fe 746 option_number_len = *(packet_data_ptr + i) + 13;
GeofferyOmlette 0:f6e4e1bbb3fe 747 }
GeofferyOmlette 0:f6e4e1bbb3fe 748 else if (option_number_len == 14)
GeofferyOmlette 0:f6e4e1bbb3fe 749 {
GeofferyOmlette 0:f6e4e1bbb3fe 750 option_number_len = *(packet_data_ptr + 2);
GeofferyOmlette 0:f6e4e1bbb3fe 751 option_number_len += (*(packet_data_ptr + 1) << 8) + 269;
GeofferyOmlette 0:f6e4e1bbb3fe 752 i += 2;
GeofferyOmlette 0:f6e4e1bbb3fe 753 }
GeofferyOmlette 0:f6e4e1bbb3fe 754 else if (option_number_len == 15)
GeofferyOmlette 0:f6e4e1bbb3fe 755 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 756 i++;
GeofferyOmlette 0:f6e4e1bbb3fe 757
GeofferyOmlette 0:f6e4e1bbb3fe 758 }
GeofferyOmlette 0:f6e4e1bbb3fe 759
GeofferyOmlette 0:f6e4e1bbb3fe 760 if(ret_value != 0)
GeofferyOmlette 0:f6e4e1bbb3fe 761 return (ret_value - 1); /* -1 because last Part path does not include separator */
GeofferyOmlette 0:f6e4e1bbb3fe 762 else
GeofferyOmlette 0:f6e4e1bbb3fe 763 return 0;
GeofferyOmlette 0:f6e4e1bbb3fe 764 }
GeofferyOmlette 0:f6e4e1bbb3fe 765
GeofferyOmlette 0:f6e4e1bbb3fe 766 /**
GeofferyOmlette 0:f6e4e1bbb3fe 767 * \fn static void sn_coap_parser_payload_parse(uint16_t packet_data_len, uint8_t *packet_data_ptr, uint8_t **packet_data_pptr, sn_coap_hdr_s *dst_coap_msg_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 768 *
GeofferyOmlette 0:f6e4e1bbb3fe 769 * \brief Parses CoAP message's Payload part from given Packet data
GeofferyOmlette 0:f6e4e1bbb3fe 770 *
GeofferyOmlette 0:f6e4e1bbb3fe 771 * \param packet_data_len is length of given Packet data to be parsed to CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 772 *
GeofferyOmlette 0:f6e4e1bbb3fe 773 * \param *packet_data_ptr is start of source for Packet data to be parsed to CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 774 *
GeofferyOmlette 0:f6e4e1bbb3fe 775 * \param **packet_data_pptr is source for Packet data to be parsed to CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 776 *
GeofferyOmlette 0:f6e4e1bbb3fe 777 * \param *dst_coap_msg_ptr is destination for parsed CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 778 *****************************************************************************/
GeofferyOmlette 0:f6e4e1bbb3fe 779 SN_MEM_ATTR_COAP_PARSER_FUNC
GeofferyOmlette 0:f6e4e1bbb3fe 780 static int8_t sn_coap_parser_payload_parse(uint16_t packet_data_len, uint8_t *packet_data_start_ptr, uint8_t **packet_data_pptr, sn_coap_hdr_s *dst_coap_msg_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 781 {
GeofferyOmlette 0:f6e4e1bbb3fe 782 /* If there is payload */
GeofferyOmlette 0:f6e4e1bbb3fe 783 if((*packet_data_pptr - packet_data_start_ptr) < packet_data_len)
GeofferyOmlette 0:f6e4e1bbb3fe 784 {
GeofferyOmlette 0:f6e4e1bbb3fe 785 if(**packet_data_pptr == 0xff)
GeofferyOmlette 0:f6e4e1bbb3fe 786 {
GeofferyOmlette 0:f6e4e1bbb3fe 787 (*packet_data_pptr)++;
GeofferyOmlette 0:f6e4e1bbb3fe 788 /* Parse Payload length */
GeofferyOmlette 0:f6e4e1bbb3fe 789 dst_coap_msg_ptr->payload_len = packet_data_len - (*packet_data_pptr - packet_data_start_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 790
GeofferyOmlette 0:f6e4e1bbb3fe 791 /* The presence of a marker followed by a zero-length payload MUST be processed as a message format error */
GeofferyOmlette 0:f6e4e1bbb3fe 792 if(dst_coap_msg_ptr->payload_len == 0)
GeofferyOmlette 0:f6e4e1bbb3fe 793 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 794
GeofferyOmlette 0:f6e4e1bbb3fe 795 /* Parse Payload by setting CoAP message's payload_ptr to point Payload in Packet data */
GeofferyOmlette 0:f6e4e1bbb3fe 796 dst_coap_msg_ptr->payload_ptr = *packet_data_pptr;
GeofferyOmlette 0:f6e4e1bbb3fe 797 }
GeofferyOmlette 0:f6e4e1bbb3fe 798 /* No payload marker.. */
GeofferyOmlette 0:f6e4e1bbb3fe 799 else
GeofferyOmlette 0:f6e4e1bbb3fe 800 return -1;
GeofferyOmlette 0:f6e4e1bbb3fe 801 }
GeofferyOmlette 0:f6e4e1bbb3fe 802 return 0;
GeofferyOmlette 0:f6e4e1bbb3fe 803 }
GeofferyOmlette 0:f6e4e1bbb3fe 804
GeofferyOmlette 0:f6e4e1bbb3fe 805
GeofferyOmlette 0:f6e4e1bbb3fe 806 /**
GeofferyOmlette 0:f6e4e1bbb3fe 807 * \fn void sn_coap_packet_debug(sn_coap_hdr_s *coap_packet_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 808 *
GeofferyOmlette 0:f6e4e1bbb3fe 809 * \brief Parses CoAP message and prints parts for debugging
GeofferyOmlette 0:f6e4e1bbb3fe 810 *
GeofferyOmlette 0:f6e4e1bbb3fe 811 * \param *coap_packet_ptr Pointer to the CoAP message to debug
GeofferyOmlette 0:f6e4e1bbb3fe 812 *
GeofferyOmlette 0:f6e4e1bbb3fe 813 *****************************************************************************/
GeofferyOmlette 0:f6e4e1bbb3fe 814 SN_MEM_ATTR_COAP_PARSER_FUNC
GeofferyOmlette 0:f6e4e1bbb3fe 815 void sn_coap_packet_debug(sn_coap_hdr_s *coap_packet_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 816 {
GeofferyOmlette 0:f6e4e1bbb3fe 817 #ifdef HAVE_DEBUG
GeofferyOmlette 0:f6e4e1bbb3fe 818 switch (coap_packet_ptr->msg_type)
GeofferyOmlette 0:f6e4e1bbb3fe 819 {
GeofferyOmlette 0:f6e4e1bbb3fe 820 case COAP_MSG_TYPE_CONFIRMABLE:
GeofferyOmlette 0:f6e4e1bbb3fe 821 printf("con ");
GeofferyOmlette 0:f6e4e1bbb3fe 822 break;
GeofferyOmlette 0:f6e4e1bbb3fe 823
GeofferyOmlette 0:f6e4e1bbb3fe 824 case COAP_MSG_TYPE_NON_CONFIRMABLE:
GeofferyOmlette 0:f6e4e1bbb3fe 825 printf("non ");
GeofferyOmlette 0:f6e4e1bbb3fe 826 break;
GeofferyOmlette 0:f6e4e1bbb3fe 827
GeofferyOmlette 0:f6e4e1bbb3fe 828 case COAP_MSG_TYPE_ACKNOWLEDGEMENT:
GeofferyOmlette 0:f6e4e1bbb3fe 829 printf("ack ");
GeofferyOmlette 0:f6e4e1bbb3fe 830 break;
GeofferyOmlette 0:f6e4e1bbb3fe 831
GeofferyOmlette 0:f6e4e1bbb3fe 832 case COAP_MSG_TYPE_RESET:
GeofferyOmlette 0:f6e4e1bbb3fe 833 printf("rst ");
GeofferyOmlette 0:f6e4e1bbb3fe 834 break;
GeofferyOmlette 0:f6e4e1bbb3fe 835 }
GeofferyOmlette 0:f6e4e1bbb3fe 836
GeofferyOmlette 0:f6e4e1bbb3fe 837 switch (coap_packet_ptr->msg_code)
GeofferyOmlette 0:f6e4e1bbb3fe 838 {
GeofferyOmlette 0:f6e4e1bbb3fe 839 case COAP_MSG_CODE_EMPTY:
GeofferyOmlette 0:f6e4e1bbb3fe 840 printf("NO CODE ");
GeofferyOmlette 0:f6e4e1bbb3fe 841 break;
GeofferyOmlette 0:f6e4e1bbb3fe 842
GeofferyOmlette 0:f6e4e1bbb3fe 843 case COAP_MSG_CODE_REQUEST_GET:
GeofferyOmlette 0:f6e4e1bbb3fe 844 printf("GET ");
GeofferyOmlette 0:f6e4e1bbb3fe 845 break;
GeofferyOmlette 0:f6e4e1bbb3fe 846
GeofferyOmlette 0:f6e4e1bbb3fe 847 case COAP_MSG_CODE_REQUEST_POST:
GeofferyOmlette 0:f6e4e1bbb3fe 848 printf("POST ");
GeofferyOmlette 0:f6e4e1bbb3fe 849 break;
GeofferyOmlette 0:f6e4e1bbb3fe 850
GeofferyOmlette 0:f6e4e1bbb3fe 851 case COAP_MSG_CODE_REQUEST_PUT:
GeofferyOmlette 0:f6e4e1bbb3fe 852 printf("PUT ");
GeofferyOmlette 0:f6e4e1bbb3fe 853 break;
GeofferyOmlette 0:f6e4e1bbb3fe 854
GeofferyOmlette 0:f6e4e1bbb3fe 855 case COAP_MSG_CODE_REQUEST_DELETE:
GeofferyOmlette 0:f6e4e1bbb3fe 856 printf("DELETE ");
GeofferyOmlette 0:f6e4e1bbb3fe 857 break;
GeofferyOmlette 0:f6e4e1bbb3fe 858
GeofferyOmlette 0:f6e4e1bbb3fe 859 case COAP_MSG_CODE_RESPONSE_CREATED:
GeofferyOmlette 0:f6e4e1bbb3fe 860 printf("2.01 Created ");
GeofferyOmlette 0:f6e4e1bbb3fe 861 break;
GeofferyOmlette 0:f6e4e1bbb3fe 862
GeofferyOmlette 0:f6e4e1bbb3fe 863 case COAP_MSG_CODE_RESPONSE_DELETED:
GeofferyOmlette 0:f6e4e1bbb3fe 864 printf("2.02 Deleted ");
GeofferyOmlette 0:f6e4e1bbb3fe 865 break;
GeofferyOmlette 0:f6e4e1bbb3fe 866
GeofferyOmlette 0:f6e4e1bbb3fe 867 case COAP_MSG_CODE_RESPONSE_VALID:
GeofferyOmlette 0:f6e4e1bbb3fe 868 printf("2.03 Valid ");
GeofferyOmlette 0:f6e4e1bbb3fe 869 break;
GeofferyOmlette 0:f6e4e1bbb3fe 870
GeofferyOmlette 0:f6e4e1bbb3fe 871 case COAP_MSG_CODE_RESPONSE_CHANGED:
GeofferyOmlette 0:f6e4e1bbb3fe 872 printf("2.04 Changed ");
GeofferyOmlette 0:f6e4e1bbb3fe 873 break;
GeofferyOmlette 0:f6e4e1bbb3fe 874
GeofferyOmlette 0:f6e4e1bbb3fe 875 case COAP_MSG_CODE_RESPONSE_CONTENT:
GeofferyOmlette 0:f6e4e1bbb3fe 876 printf("2.05 Content ");
GeofferyOmlette 0:f6e4e1bbb3fe 877 break;
GeofferyOmlette 0:f6e4e1bbb3fe 878
GeofferyOmlette 0:f6e4e1bbb3fe 879 case COAP_MSG_CODE_RESPONSE_BAD_REQUEST:
GeofferyOmlette 0:f6e4e1bbb3fe 880 printf("4.00 Bad Request ");
GeofferyOmlette 0:f6e4e1bbb3fe 881 break;
GeofferyOmlette 0:f6e4e1bbb3fe 882
GeofferyOmlette 0:f6e4e1bbb3fe 883 case COAP_MSG_CODE_RESPONSE_UNAUTHORIZED:
GeofferyOmlette 0:f6e4e1bbb3fe 884 printf("4.01 Unauthorized ");
GeofferyOmlette 0:f6e4e1bbb3fe 885 break;
GeofferyOmlette 0:f6e4e1bbb3fe 886
GeofferyOmlette 0:f6e4e1bbb3fe 887 case COAP_MSG_CODE_RESPONSE_BAD_OPTION:
GeofferyOmlette 0:f6e4e1bbb3fe 888 printf("4.02 Bad Option ");
GeofferyOmlette 0:f6e4e1bbb3fe 889 break;
GeofferyOmlette 0:f6e4e1bbb3fe 890
GeofferyOmlette 0:f6e4e1bbb3fe 891 case COAP_MSG_CODE_RESPONSE_FORBIDDEN:
GeofferyOmlette 0:f6e4e1bbb3fe 892 printf("4.03 Forbidden ");
GeofferyOmlette 0:f6e4e1bbb3fe 893 break;
GeofferyOmlette 0:f6e4e1bbb3fe 894
GeofferyOmlette 0:f6e4e1bbb3fe 895 case COAP_MSG_CODE_RESPONSE_NOT_FOUND:
GeofferyOmlette 0:f6e4e1bbb3fe 896 printf("4.04 Not Found ");
GeofferyOmlette 0:f6e4e1bbb3fe 897 break;
GeofferyOmlette 0:f6e4e1bbb3fe 898
GeofferyOmlette 0:f6e4e1bbb3fe 899 case COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED:
GeofferyOmlette 0:f6e4e1bbb3fe 900 printf("4.05 Method Not Allowed ");
GeofferyOmlette 0:f6e4e1bbb3fe 901 break;
GeofferyOmlette 0:f6e4e1bbb3fe 902
GeofferyOmlette 0:f6e4e1bbb3fe 903 case COAP_MSG_CODE_RESPONSE_NOT_ACCEPTABLE:
GeofferyOmlette 0:f6e4e1bbb3fe 904 printf("4.06 Response Not Acceptable");
GeofferyOmlette 0:f6e4e1bbb3fe 905 break;
GeofferyOmlette 0:f6e4e1bbb3fe 906
GeofferyOmlette 0:f6e4e1bbb3fe 907 case COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_INCOMPLETE:
GeofferyOmlette 0:f6e4e1bbb3fe 908 printf("4.08 Request Entity Incomplete ");
GeofferyOmlette 0:f6e4e1bbb3fe 909 break;
GeofferyOmlette 0:f6e4e1bbb3fe 910
GeofferyOmlette 0:f6e4e1bbb3fe 911 case COAP_MSG_CODE_RESPONSE_PRECONDITION_FAILED:
GeofferyOmlette 0:f6e4e1bbb3fe 912 printf("4.12 Response Precondition Failed");
GeofferyOmlette 0:f6e4e1bbb3fe 913 break;
GeofferyOmlette 0:f6e4e1bbb3fe 914
GeofferyOmlette 0:f6e4e1bbb3fe 915 case COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_TOO_LARGE:
GeofferyOmlette 0:f6e4e1bbb3fe 916 printf("4.13 Request Entity Too Large ");
GeofferyOmlette 0:f6e4e1bbb3fe 917 break;
GeofferyOmlette 0:f6e4e1bbb3fe 918
GeofferyOmlette 0:f6e4e1bbb3fe 919 case COAP_MSG_CODE_RESPONSE_UNSUPPORTED_CONTENT_FORMAT:
GeofferyOmlette 0:f6e4e1bbb3fe 920 printf("4.15 Unsupported Media Type ");
GeofferyOmlette 0:f6e4e1bbb3fe 921 break;
GeofferyOmlette 0:f6e4e1bbb3fe 922
GeofferyOmlette 0:f6e4e1bbb3fe 923 case COAP_MSG_CODE_RESPONSE_INTERNAL_SERVER_ERROR:
GeofferyOmlette 0:f6e4e1bbb3fe 924 printf("5.00 Internal Server Error ");
GeofferyOmlette 0:f6e4e1bbb3fe 925 break;
GeofferyOmlette 0:f6e4e1bbb3fe 926
GeofferyOmlette 0:f6e4e1bbb3fe 927 case COAP_MSG_CODE_RESPONSE_NOT_IMPLEMENTED:
GeofferyOmlette 0:f6e4e1bbb3fe 928 printf("5.01 Not Implemented ");
GeofferyOmlette 0:f6e4e1bbb3fe 929 break;
GeofferyOmlette 0:f6e4e1bbb3fe 930
GeofferyOmlette 0:f6e4e1bbb3fe 931 case COAP_MSG_CODE_RESPONSE_BAD_GATEWAY:
GeofferyOmlette 0:f6e4e1bbb3fe 932 printf("5.02 Bad Gateway ");
GeofferyOmlette 0:f6e4e1bbb3fe 933 break;
GeofferyOmlette 0:f6e4e1bbb3fe 934
GeofferyOmlette 0:f6e4e1bbb3fe 935 case COAP_MSG_CODE_RESPONSE_SERVICE_UNAVAILABLE:
GeofferyOmlette 0:f6e4e1bbb3fe 936 printf("5.03 Service Unavailable ");
GeofferyOmlette 0:f6e4e1bbb3fe 937 break;
GeofferyOmlette 0:f6e4e1bbb3fe 938
GeofferyOmlette 0:f6e4e1bbb3fe 939 case COAP_MSG_CODE_RESPONSE_GATEWAY_TIMEOUT:
GeofferyOmlette 0:f6e4e1bbb3fe 940 printf("5.04 Gateway Timeout ");
GeofferyOmlette 0:f6e4e1bbb3fe 941 break;
GeofferyOmlette 0:f6e4e1bbb3fe 942
GeofferyOmlette 0:f6e4e1bbb3fe 943 case COAP_MSG_CODE_RESPONSE_PROXYING_NOT_SUPPORTED:
GeofferyOmlette 0:f6e4e1bbb3fe 944 printf("5.05 Proxying Not Supported ");
GeofferyOmlette 0:f6e4e1bbb3fe 945 break;
GeofferyOmlette 0:f6e4e1bbb3fe 946
GeofferyOmlette 0:f6e4e1bbb3fe 947 default:
GeofferyOmlette 0:f6e4e1bbb3fe 948 printf("UNKNOWN CODE ");
GeofferyOmlette 0:f6e4e1bbb3fe 949 break;
GeofferyOmlette 0:f6e4e1bbb3fe 950 }
GeofferyOmlette 0:f6e4e1bbb3fe 951
GeofferyOmlette 0:f6e4e1bbb3fe 952 printf("mid=%i ", (int)(coap_packet_ptr->msg_id));
GeofferyOmlette 0:f6e4e1bbb3fe 953
GeofferyOmlette 0:f6e4e1bbb3fe 954 if (coap_packet_ptr->uri_path_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 955 {
GeofferyOmlette 0:f6e4e1bbb3fe 956 int i;
GeofferyOmlette 0:f6e4e1bbb3fe 957 printf("/");
GeofferyOmlette 0:f6e4e1bbb3fe 958 for (i=0; i < coap_packet_ptr->uri_path_len; i++) printf("%c", (char)(coap_packet_ptr->uri_path_ptr[i]));
GeofferyOmlette 0:f6e4e1bbb3fe 959 if (coap_packet_ptr->options_list_ptr && coap_packet_ptr->options_list_ptr->uri_query_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 960 {
GeofferyOmlette 0:f6e4e1bbb3fe 961 printf("?");
GeofferyOmlette 0:f6e4e1bbb3fe 962 for (i=0; i < coap_packet_ptr->options_list_ptr->uri_query_len; i++) printf("%c", (char)(coap_packet_ptr->options_list_ptr->uri_query_ptr[i]));
GeofferyOmlette 0:f6e4e1bbb3fe 963 }
GeofferyOmlette 0:f6e4e1bbb3fe 964 printf(" ");
GeofferyOmlette 0:f6e4e1bbb3fe 965 }
GeofferyOmlette 0:f6e4e1bbb3fe 966
GeofferyOmlette 0:f6e4e1bbb3fe 967 if (coap_packet_ptr->token_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 968 {
GeofferyOmlette 0:f6e4e1bbb3fe 969 int i;
GeofferyOmlette 0:f6e4e1bbb3fe 970 printf("token=0x");
GeofferyOmlette 0:f6e4e1bbb3fe 971 for (i=0; i < coap_packet_ptr->token_len; i++) printf("%02x", (unsigned char)(coap_packet_ptr->token_ptr[i]));
GeofferyOmlette 0:f6e4e1bbb3fe 972 printf(" ");
GeofferyOmlette 0:f6e4e1bbb3fe 973 }
GeofferyOmlette 0:f6e4e1bbb3fe 974
GeofferyOmlette 0:f6e4e1bbb3fe 975 if (coap_packet_ptr->content_type_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 976 {
GeofferyOmlette 0:f6e4e1bbb3fe 977 switch (coap_packet_ptr->content_type_ptr[0])
GeofferyOmlette 0:f6e4e1bbb3fe 978 {
GeofferyOmlette 0:f6e4e1bbb3fe 979 case COAP_CT_TEXT_PLAIN:
GeofferyOmlette 0:f6e4e1bbb3fe 980 printf("text/plain ");
GeofferyOmlette 0:f6e4e1bbb3fe 981 break;
GeofferyOmlette 0:f6e4e1bbb3fe 982
GeofferyOmlette 0:f6e4e1bbb3fe 983 case COAP_CT_LINK_FORMAT:
GeofferyOmlette 0:f6e4e1bbb3fe 984 printf("application/link-format ");
GeofferyOmlette 0:f6e4e1bbb3fe 985 break;
GeofferyOmlette 0:f6e4e1bbb3fe 986
GeofferyOmlette 0:f6e4e1bbb3fe 987 case COAP_CT_XML:
GeofferyOmlette 0:f6e4e1bbb3fe 988 printf("application/xml ");
GeofferyOmlette 0:f6e4e1bbb3fe 989 break;
GeofferyOmlette 0:f6e4e1bbb3fe 990
GeofferyOmlette 0:f6e4e1bbb3fe 991 case COAP_CT_OCTET_STREAM:
GeofferyOmlette 0:f6e4e1bbb3fe 992 printf("application/octet-stream ");
GeofferyOmlette 0:f6e4e1bbb3fe 993 break;
GeofferyOmlette 0:f6e4e1bbb3fe 994
GeofferyOmlette 0:f6e4e1bbb3fe 995 case COAP_CT_EXI:
GeofferyOmlette 0:f6e4e1bbb3fe 996 printf("application/exi ");
GeofferyOmlette 0:f6e4e1bbb3fe 997 break;
GeofferyOmlette 0:f6e4e1bbb3fe 998
GeofferyOmlette 0:f6e4e1bbb3fe 999 case COAP_CT_JSON:
GeofferyOmlette 0:f6e4e1bbb3fe 1000 printf("application/json ");
GeofferyOmlette 0:f6e4e1bbb3fe 1001 break;
GeofferyOmlette 0:f6e4e1bbb3fe 1002 default:
GeofferyOmlette 0:f6e4e1bbb3fe 1003 printf("uknown type (%i) ", (int)(coap_packet_ptr->content_type_ptr[0]));
GeofferyOmlette 0:f6e4e1bbb3fe 1004 break;
GeofferyOmlette 0:f6e4e1bbb3fe 1005
GeofferyOmlette 0:f6e4e1bbb3fe 1006 }
GeofferyOmlette 0:f6e4e1bbb3fe 1007 }
GeofferyOmlette 0:f6e4e1bbb3fe 1008
GeofferyOmlette 0:f6e4e1bbb3fe 1009 if (coap_packet_ptr->options_list_ptr && coap_packet_ptr->options_list_ptr->location_path_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 1010 {
GeofferyOmlette 0:f6e4e1bbb3fe 1011 printf("Location: /");
GeofferyOmlette 0:f6e4e1bbb3fe 1012 int i;
GeofferyOmlette 0:f6e4e1bbb3fe 1013 for (i=0; i < coap_packet_ptr->options_list_ptr->location_path_len; i++) printf("%c", (char)(coap_packet_ptr->options_list_ptr->location_path_ptr[i]));
GeofferyOmlette 0:f6e4e1bbb3fe 1014 printf(" ");
GeofferyOmlette 0:f6e4e1bbb3fe 1015 }
GeofferyOmlette 0:f6e4e1bbb3fe 1016
GeofferyOmlette 0:f6e4e1bbb3fe 1017 if (coap_packet_ptr->payload_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 1018 {
GeofferyOmlette 0:f6e4e1bbb3fe 1019 int i;
GeofferyOmlette 0:f6e4e1bbb3fe 1020 printf("'");
GeofferyOmlette 0:f6e4e1bbb3fe 1021 for (i=0; i < coap_packet_ptr->payload_len; i++)
GeofferyOmlette 0:f6e4e1bbb3fe 1022 printf("%c", *(coap_packet_ptr->payload_ptr + i));
GeofferyOmlette 0:f6e4e1bbb3fe 1023 printf("' ");
GeofferyOmlette 0:f6e4e1bbb3fe 1024 }
GeofferyOmlette 0:f6e4e1bbb3fe 1025
GeofferyOmlette 0:f6e4e1bbb3fe 1026 printf("\n");
GeofferyOmlette 0:f6e4e1bbb3fe 1027 #endif
GeofferyOmlette 0:f6e4e1bbb3fe 1028 }