15 out->
version = (hdr[0] & 0xC0) >> 6;
16 out->
type = (hdr[0] & 0x30) >> 4;
20 out->
message_ID = (((uint16_t)hdr[2]) << 8) | (hdr[3]);
26 uint16_t option_delta,option_length;
30 option_delta = buf[buf_index] >> 4;
31 option_length = buf[buf_index] & 0x0F;
37 case COAP_OPTION_DELTA_EXTRA1B:
39 option_delta = buf[buf_index] + 13;
42 case COAP_OPTION_DELTA_EXTRA2B:
44 option_delta = ((((uint16_t)(buf[buf_index]))<<8) | (buf[buf_index+1])) + 269;
47 case COAP_OPTION_DELTA_DATA_MKR:
65 switch (option_length)
67 case COAP_OPTION_LENGTH_EXTRA1B:
69 option_length = buf[buf_index] + 13;
72 case COAP_OPTION_LENGTH_EXTRA2B:
74 option_length = ((((uint16_t)(buf[buf_index]))<<8) | (buf[buf_index+1])) + 269;
77 case COAP_OPTION_LENGTH_DATA_MKR:
92 out->option_id = out->option_id + option_delta;
93 out->data_length = option_length;
94 out->data_ptr = &(buf[buf_index]);
96 return (buf_index + option_length);
104 uint16_t safety_counter;
105 uint16_t total_option_length;
109 if (hdr_data.
version!=COAP_MSG_VERSION)
115 if ((hdr_data.
type!=COAP_TYPE_CONFIRMABLE) &&
116 (hdr_data.
type!=COAP_TYPE_NON_CONFIRMABLE) &&
117 (hdr_data.
type!=COAP_TYPE_ACK) &&
118 (hdr_data.
type!=COAP_TYPE_RESET))
133 if ((buf_ptr<buf_length) && (buf[buf_ptr]!=0xFF))
136 opt_data.option_id=0;
138 while ((buf[buf_ptr]!=0xFF) && (safety_counter<
MAX_PARSED_OPTIONS) && (buf_ptr<buf_length))
140 total_option_length = CoAP_parse_option(&(buf[buf_ptr]),&opt_data);
142 if (total_option_length == 0xFFFF)
147 buf_ptr += total_option_length;
158 if (data_start!=NULL)
163 (*data_start) = &(buf[buf_ptr+1]);
167 (*data_start) = NULL;
174 uint16_t
CoAP_assemble_request_extended(uint8_t request_method,uint8_t is_observe_request,uint8_t *msg_buffer,uint16_t buffer_length,uint8_t *url_string,uint8_t *data,uint16_t data_length)
176 static uint8_t message_ID_counter=0;
178 uint16_t uri_ptr_counter;
179 uint16_t uri_entry_length;
185 msg_buffer[0] = (COAP_MSG_VERSION<<6) | (COAP_TYPE_NON_CONFIRMABLE<<4) | 1;
186 msg_buffer[1] = (COAP_CLASS_REQUEST<<5) | (request_method & 0x1F);
187 msg_buffer[2] = (message_ID_counter & 0xFF00) >> 8;
188 msg_buffer[3] = (message_ID_counter & 0x00FF);
191 msg_buffer[4] = message_ID_counter & 0x00FF;
193 message_ID_counter++;
195 if (url_string[0]!=
'/')
201 buffer_ptr = COAP_MSG_HDR_LENGTH + 1;
203 if ((is_observe_request != 0) && (request_method == COAP_METHOD_GET))
206 option_id = COAP_OPTION_OBSERVE;
207 msg_buffer[buffer_ptr] = (option_id << 4) | 1;
209 msg_buffer[buffer_ptr] = 0;
220 if (URI_copy[k]==
'/')
227 URI_ptrs[uri_ptr_counter] = &(URI_copy[k+1]);
234 for (k=0; k<uri_ptr_counter; k++)
236 if (buffer_ptr>=buffer_length)
248 option_id = COAP_OPTION_URI_PATH - option_id;
255 uri_entry_length = strlen(URI_ptrs[k]);
263 if (uri_entry_length<13)
265 msg_buffer[buffer_ptr] = (option_id << 4) | uri_entry_length;
270 msg_buffer[buffer_ptr] = (option_id << 4) | 13;
272 msg_buffer[buffer_ptr] = uri_entry_length - 13;
279 for (j=0; j<uri_entry_length; j++)
281 msg_buffer[buffer_ptr] = URI_ptrs[k][j];
284 if (buffer_ptr>=buffer_length)
294 if ((data!=NULL) && (data_length!=0))
301 msg_buffer[buffer_ptr] = 0xFF;
307 for (j=0; j<data_length; j++)
309 msg_buffer[buffer_ptr] = data[j];
312 if (buffer_ptr>=buffer_length)