Lines Matching refs:pdu
29 coap_pdu_clear(coap_pdu_t *pdu, size_t size) { in coap_pdu_clear() argument
30 assert(pdu); in coap_pdu_clear()
35 pdu->hdr = pdu->pbuf->payload; in coap_pdu_clear()
37 pdu->max_delta = 0; in coap_pdu_clear()
38 pdu->data = NULL; in coap_pdu_clear()
40 memset(pdu->hdr, 0, size); in coap_pdu_clear()
41 pdu->max_size = size; in coap_pdu_clear()
42 pdu->hdr->version = COAP_DEFAULT_VERSION; in coap_pdu_clear()
45 pdu->length = sizeof(coap_hdr_t); in coap_pdu_clear()
77 coap_pdu_t *pdu; in coap_pdu_init() local
89 pdu = coap_malloc_type(COAP_PDU, sizeof(coap_pdu_t)); in coap_pdu_init()
90 if (!pdu) return NULL; in coap_pdu_init()
91 pdu->hdr = coap_malloc_type(COAP_PDU_BUF, size); in coap_pdu_init()
92 if (pdu->hdr == NULL) { in coap_pdu_init()
93 coap_free_type(COAP_PDU, pdu); in coap_pdu_init()
94 pdu = NULL; in coap_pdu_init()
98 pdu = (coap_pdu_t*)coap_malloc_type(COAP_PDU, sizeof(coap_pdu_t)); in coap_pdu_init()
99 if (!pdu) return NULL; in coap_pdu_init()
102 coap_free_type(COAP_PDU, pdu); in coap_pdu_init()
103 pdu = NULL; in coap_pdu_init()
106 if (pdu) { in coap_pdu_init()
108 pdu->pbuf = p; in coap_pdu_init()
110 coap_pdu_clear(pdu, size); in coap_pdu_init()
111 pdu->hdr->id = id; in coap_pdu_init()
112 pdu->hdr->type = type; in coap_pdu_init()
113 pdu->hdr->code = code; in coap_pdu_init()
115 return pdu; in coap_pdu_init()
120 coap_pdu_t *pdu; in coap_new_pdu() local
123 pdu = coap_pdu_init(0, 0, ntohs(COAP_INVALID_TID), COAP_MAX_PDU_SIZE); in coap_new_pdu()
125 pdu = coap_pdu_init(0, 0, uip_ntohs(COAP_INVALID_TID), COAP_MAX_PDU_SIZE); in coap_new_pdu()
129 if (!pdu) in coap_new_pdu()
132 return pdu; in coap_new_pdu()
136 coap_delete_pdu(coap_pdu_t *pdu) { in coap_delete_pdu() argument
138 if (pdu != NULL) { in coap_delete_pdu()
139 if (pdu->hdr != NULL) { in coap_delete_pdu()
140 coap_free_type(COAP_PDU_BUF, pdu->hdr); in coap_delete_pdu()
142 coap_free_type(COAP_PDU, pdu); in coap_delete_pdu()
146 if (pdu != NULL) /* accepting double free as the other implementation accept that too */ in coap_delete_pdu()
147 pbuf_free(pdu->pbuf); in coap_delete_pdu()
148 coap_free_type(COAP_PDU, pdu); in coap_delete_pdu()
153 coap_add_token(coap_pdu_t *pdu, size_t len, const unsigned char *data) { in coap_add_token() argument
156 if (!pdu || len > 8 || pdu->max_size < HEADERLENGTH) in coap_add_token()
159 pdu->hdr->token_length = len; in coap_add_token()
161 memcpy(pdu->hdr->token, data, len); in coap_add_token()
162 pdu->max_delta = 0; in coap_add_token()
163 pdu->length = HEADERLENGTH; in coap_add_token()
164 pdu->data = NULL; in coap_add_token()
171 coap_add_option(coap_pdu_t *pdu, unsigned short type, unsigned int len, const unsigned char *data) { in coap_add_option() argument
175 assert(pdu); in coap_add_option()
176 pdu->data = NULL; in coap_add_option()
178 if (type < pdu->max_delta) { in coap_add_option()
183 opt = (unsigned char *)pdu->hdr + pdu->length; in coap_add_option()
186 optsize = coap_opt_encode(opt, pdu->max_size - pdu->length, in coap_add_option()
187 type - pdu->max_delta, data, len); in coap_add_option()
194 pdu->max_delta = type; in coap_add_option()
195 pdu->length += optsize; in coap_add_option()
203 coap_add_option_later(coap_pdu_t *pdu, unsigned short type, unsigned int len) { in coap_add_option_later() argument
207 assert(pdu); in coap_add_option_later()
208 pdu->data = NULL; in coap_add_option_later()
210 if (type < pdu->max_delta) { in coap_add_option_later()
215 opt = (unsigned char *)pdu->hdr + pdu->length; in coap_add_option_later()
218 optsize = coap_opt_encode(opt, pdu->max_size - pdu->length, in coap_add_option_later()
219 type - pdu->max_delta, NULL, len); in coap_add_option_later()
226 pdu->max_delta = type; in coap_add_option_later()
227 pdu->length += optsize; in coap_add_option_later()
234 coap_add_data(coap_pdu_t *pdu, unsigned int len, const unsigned char *data) { in coap_add_data() argument
235 assert(pdu); in coap_add_data()
236 assert(pdu->data == NULL); in coap_add_data()
241 if (pdu->length + len + 1 > pdu->max_size) { in coap_add_data()
243 assert(pdu->data == NULL); in coap_add_data()
247 pdu->data = (unsigned char *)pdu->hdr + pdu->length; in coap_add_data()
248 *pdu->data = COAP_PAYLOAD_START; in coap_add_data()
249 pdu->data++; in coap_add_data()
251 memcpy(pdu->data, data, len); in coap_add_data()
252 pdu->length += len + 1; in coap_add_data()
257 coap_get_data(coap_pdu_t *pdu, size_t *len, unsigned char **data) { in coap_get_data() argument
258 assert(pdu); in coap_get_data()
262 if (pdu->data) { in coap_get_data()
263 *len = (unsigned char *)pdu->hdr + pdu->length - pdu->data; in coap_get_data()
264 *data = pdu->data; in coap_get_data()
341 coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu) { in coap_pdu_parse() argument
345 assert(pdu); in coap_pdu_parse()
347 if (pdu->max_size < length) { in coap_pdu_parse()
357 LWIP_ASSERT("coap_pdu_parse with unexpected addresses", data == pdu->hdr); in coap_pdu_parse()
358 LWIP_ASSERT("coap_pdu_parse with unexpected length", length == pdu->length); in coap_pdu_parse()
361 pdu->hdr->version = data[0] >> 6; in coap_pdu_parse()
362 pdu->hdr->type = (data[0] >> 4) & 0x03; in coap_pdu_parse()
363 pdu->hdr->token_length = data[0] & 0x0f; in coap_pdu_parse()
364 pdu->hdr->code = data[1]; in coap_pdu_parse()
366 pdu->data = NULL; in coap_pdu_parse()
369 if (pdu->hdr->code == 0) { in coap_pdu_parse()
370 if (length != sizeof(coap_hdr_t) || pdu->hdr->token_length) { in coap_pdu_parse()
376 if (length < sizeof(coap_hdr_t) + pdu->hdr->token_length in coap_pdu_parse()
377 || pdu->hdr->token_length > 8) { in coap_pdu_parse()
385 memcpy(&pdu->hdr->id, data + 2, 2); in coap_pdu_parse()
388 memcpy(pdu->hdr + 1, data + sizeof(coap_hdr_t), length - sizeof(coap_hdr_t)); in coap_pdu_parse()
389 pdu->length = length; in coap_pdu_parse()
396 length -= (pdu->hdr->token_length + sizeof(coap_hdr_t)); in coap_pdu_parse()
397 opt = (unsigned char *)(pdu->hdr + 1) + pdu->hdr->token_length; in coap_pdu_parse()
417 (unsigned char *)pdu->hdr + pdu->length); in coap_pdu_parse()
418 pdu->data = (unsigned char *)opt; in coap_pdu_parse()