Lines Matching refs:buf
46 static int pack_uint8(uint8_t val, struct buf_ctx *buf) in pack_uint8() argument
48 uint8_t *cur = buf->cur; in pack_uint8()
49 uint8_t *end = buf->end; in pack_uint8()
59 buf->cur = (cur + sizeof(uint8_t)); in pack_uint8()
74 static int pack_uint16(uint16_t val, struct buf_ctx *buf) in pack_uint16() argument
76 uint8_t *cur = buf->cur; in pack_uint16()
77 uint8_t *end = buf->end; in pack_uint16()
87 buf->cur = (cur + sizeof(uint16_t)); in pack_uint16()
102 static int pack_utf8_str(const struct mqtt_utf8 *str, struct buf_ctx *buf) in pack_utf8_str() argument
104 if ((buf->end - buf->cur) < GET_UT8STR_BUFFER_SIZE(str)) { in pack_utf8_str()
109 (uint32_t)GET_UT8STR_BUFFER_SIZE(str), (void *)buf->cur, (void *)buf->end); in pack_utf8_str()
112 (void)pack_uint16(str->size, buf); in pack_utf8_str()
114 memcpy(buf->cur, str->utf8, str->size); in pack_utf8_str()
115 buf->cur += str->size; in pack_utf8_str()
144 static int pack_variable_int(uint32_t value, struct buf_ctx *buf) in pack_variable_int() argument
149 (buf == NULL) ? 0 : (void *)buf->cur, (buf == NULL) ? 0 : (void *)buf->end); in pack_variable_int()
154 if (buf != NULL) { in pack_variable_int()
155 if (buf->cur >= buf->end) { in pack_variable_int()
159 *(buf->cur) = value & MQTT_LENGTH_VALUE_MASK; in pack_variable_int()
164 if (buf != NULL) { in pack_variable_int()
166 *(buf->cur) |= MQTT_LENGTH_CONTINUATION_BIT; in pack_variable_int()
168 buf->cur++; in pack_variable_int()
197 struct buf_ctx *buf) in mqtt_encode_fixed_header() argument
199 uint32_t length = buf->cur - start; in mqtt_encode_fixed_header()
214 buf->cur = start - fixed_header_length; in mqtt_encode_fixed_header()
216 (void)pack_uint8(message_type, buf); in mqtt_encode_fixed_header()
217 (void)pack_variable_int(length, buf); in mqtt_encode_fixed_header()
222 buf->cur = buf->cur - fixed_header_length; in mqtt_encode_fixed_header()
223 buf->end = buf->cur + length + fixed_header_length; in mqtt_encode_fixed_header()
240 static int zero_len_str_encode(struct buf_ctx *buf) in zero_len_str_encode() argument
242 return pack_uint16(0x0000, buf); in zero_len_str_encode()
256 static int pack_uint32(uint32_t val, struct buf_ctx *buf) in pack_uint32() argument
258 uint8_t *cur = buf->cur; in pack_uint32()
259 uint8_t *end = buf->end; in pack_uint32()
267 buf->cur = (cur + sizeof(uint32_t)); in pack_uint32()
282 static int pack_bin_data(const struct mqtt_binstr *bin, struct buf_ctx *buf) in pack_bin_data() argument
284 if ((buf->end - buf->cur) < GET_BINSTR_BUFFER_SIZE(bin)) { in pack_bin_data()
289 (void)pack_uint16(bin->len, buf); in pack_bin_data()
291 memcpy(buf->cur, bin->data, bin->len); in pack_bin_data()
292 buf->cur += bin->len; in pack_bin_data()
317 static int encode_uint8_property(uint8_t prop, uint8_t value, struct buf_ctx *buf) in encode_uint8_property() argument
326 err = pack_uint8(prop, buf); in encode_uint8_property()
331 return pack_uint8(value, buf); in encode_uint8_property()
344 struct buf_ctx *buf) in encode_uint16_property() argument
352 err = pack_uint8(prop, buf); in encode_uint16_property()
357 return pack_uint16(value, buf); in encode_uint16_property()
370 struct buf_ctx *buf) in encode_uint32_property() argument
378 err = pack_uint8(prop, buf); in encode_uint32_property()
383 return pack_uint32(value, buf); in encode_uint32_property()
396 struct buf_ctx *buf) in encode_var_int_property() argument
404 err = pack_uint8(prop, buf); in encode_var_int_property()
409 return pack_variable_int(value, buf); in encode_var_int_property()
422 struct buf_ctx *buf) in encode_string_property() argument
430 err = pack_uint8(prop, buf); in encode_string_property()
435 return pack_utf8_str(str, buf); in encode_string_property()
451 struct buf_ctx *buf) in encode_string_pair_property() argument
459 err = pack_uint8(prop, buf); in encode_string_pair_property()
464 err = pack_utf8_str(name, buf); in encode_string_pair_property()
469 return pack_utf8_str(value, buf); in encode_string_pair_property()
482 struct buf_ctx *buf) in encode_binary_property() argument
490 err = pack_uint8(prop, buf); in encode_binary_property()
495 return pack_bin_data(bin, buf); in encode_binary_property()
517 struct buf_ctx *buf) in encode_user_properties() argument
532 &user_props[i].value, buf); in encode_user_properties()
557 struct buf_ctx *buf) in connect_properties_encode() argument
564 err = pack_variable_int(properties_len, buf); in connect_properties_encode()
570 client->prop.session_expiry_interval, buf); in connect_properties_encode()
576 client->prop.receive_maximum, buf); in connect_properties_encode()
582 client->prop.maximum_packet_size, buf); in connect_properties_encode()
588 CONFIG_MQTT_TOPIC_ALIAS_MAX, buf); in connect_properties_encode()
595 buf); in connect_properties_encode()
602 buf); in connect_properties_encode()
607 err = encode_user_properties(client->prop.user_prop, buf); in connect_properties_encode()
613 &client->prop.auth_method, buf); in connect_properties_encode()
619 &client->prop.auth_data, buf); in connect_properties_encode()
640 struct buf_ctx *buf) in will_properties_encode() argument
647 err = pack_variable_int(properties_len, buf); in will_properties_encode()
653 client->will_prop.will_delay_interval, buf); in will_properties_encode()
660 buf); in will_properties_encode()
667 buf); in will_properties_encode()
673 &client->will_prop.content_type, buf); in will_properties_encode()
679 &client->will_prop.response_topic, buf); in will_properties_encode()
685 &client->will_prop.correlation_data, buf); in will_properties_encode()
690 err = encode_user_properties(client->will_prop.user_prop, buf); in will_properties_encode()
700 struct buf_ctx *buf) in connect_properties_encode() argument
703 ARG_UNUSED(buf); in connect_properties_encode()
709 struct buf_ctx *buf) in will_properties_encode() argument
712 ARG_UNUSED(buf); in will_properties_encode()
719 struct buf_ctx *buf) in connect_request_encode() argument
737 buf->cur += MQTT_FIXED_HEADER_MAX_SIZE; in connect_request_encode()
738 start = buf->cur; in connect_request_encode()
743 err_code = pack_utf8_str(proto_desc, buf); in connect_request_encode()
749 err_code = pack_uint8(client->protocol_version, buf); in connect_request_encode()
757 connect_flags_pos = buf->cur; in connect_request_encode()
759 err_code = pack_uint8(0, buf); in connect_request_encode()
765 err_code = pack_uint16(client->keepalive, buf); in connect_request_encode()
772 err_code = connect_properties_encode(client, buf); in connect_request_encode()
780 err_code = pack_utf8_str(&client->client_id, buf); in connect_request_encode()
794 err_code = will_properties_encode(client, buf); in connect_request_encode()
803 err_code = pack_utf8_str(&client->will_topic->topic, buf); in connect_request_encode()
812 err_code = pack_utf8_str(client->will_message, buf); in connect_request_encode()
818 err_code = zero_len_str_encode(buf); in connect_request_encode()
832 err_code = pack_utf8_str(client->user_name, buf); in connect_request_encode()
845 err_code = pack_utf8_str(client->password, buf); in connect_request_encode()
854 return mqtt_encode_fixed_header(message_type, start, buf); in connect_request_encode()
872 struct buf_ctx *buf) in publish_properties_encode() argument
879 err = pack_variable_int(properties_len, buf); in publish_properties_encode()
885 param->prop.payload_format_indicator, buf); in publish_properties_encode()
891 param->prop.message_expiry_interval, buf); in publish_properties_encode()
897 param->prop.topic_alias, buf); in publish_properties_encode()
903 ¶m->prop.response_topic, buf); in publish_properties_encode()
909 ¶m->prop.correlation_data, buf); in publish_properties_encode()
914 err = encode_user_properties(param->prop.user_prop, buf); in publish_properties_encode()
922 ¶m->prop.content_type, buf); in publish_properties_encode()
931 struct buf_ctx *buf) in publish_properties_encode() argument
934 ARG_UNUSED(buf); in publish_properties_encode()
942 struct buf_ctx *buf) in publish_encode() argument
956 buf->cur += MQTT_FIXED_HEADER_MAX_SIZE; in publish_encode()
957 start = buf->cur; in publish_encode()
959 err_code = pack_utf8_str(¶m->message.topic.topic, buf); in publish_encode()
965 err_code = pack_uint16(param->message_id, buf); in publish_encode()
972 err_code = publish_properties_encode(param, buf); in publish_encode()
981 buf->cur += param->message.payload.len; in publish_encode()
983 err_code = mqtt_encode_fixed_header(message_type, start, buf); in publish_encode()
988 buf->end -= param->message.payload.len; in publish_encode()
1003 struct buf_ctx *buf) in common_ack_properties_encode() argument
1015 err = pack_variable_int(properties_len, buf); in common_ack_properties_encode()
1020 err = encode_user_properties(prop->user_prop, buf); in common_ack_properties_encode()
1026 &prop->reason_string, buf); in common_ack_properties_encode()
1042 struct buf_ctx *buf) in common_ack_properties_encode() argument
1045 ARG_UNUSED(buf); in common_ack_properties_encode()
1054 struct buf_ctx *buf) in common_ack_encode() argument
1065 buf->cur += MQTT_FIXED_HEADER_MAX_SIZE; in common_ack_encode()
1066 start = buf->cur; in common_ack_encode()
1068 err_code = pack_uint16(message_id, buf); in common_ack_encode()
1083 err_code = pack_uint8(reason_code, buf); in common_ack_encode()
1088 err_code = common_ack_properties_encode(prop, buf); in common_ack_encode()
1095 return mqtt_encode_fixed_header(message_type, start, buf); in common_ack_encode()
1100 struct buf_ctx *buf) in publish_ack_encode() argument
1115 reason_code, prop, buf); in publish_ack_encode()
1120 struct buf_ctx *buf) in publish_receive_encode() argument
1135 reason_code, prop, buf); in publish_receive_encode()
1140 struct buf_ctx *buf) in publish_release_encode() argument
1155 reason_code, prop, buf); in publish_release_encode()
1160 struct buf_ctx *buf) in publish_complete_encode() argument
1175 reason_code, prop, buf); in publish_complete_encode()
1178 static int empty_disconnect_encode(struct buf_ctx *buf) in empty_disconnect_encode() argument
1180 uint8_t *cur = buf->cur; in empty_disconnect_encode()
1181 uint8_t *end = buf->end; in empty_disconnect_encode()
1188 buf->end = (cur + sizeof(empty_disc_packet)); in empty_disconnect_encode()
1203 struct buf_ctx *buf) in disconnect_properties_encode() argument
1215 err = pack_variable_int(properties_len, buf); in disconnect_properties_encode()
1221 param->prop.session_expiry_interval, buf); in disconnect_properties_encode()
1227 ¶m->prop.reason_string, buf); in disconnect_properties_encode()
1232 err = encode_user_properties(param->prop.user_prop, buf); in disconnect_properties_encode()
1238 ¶m->prop.server_reference, buf); in disconnect_properties_encode()
1247 struct buf_ctx *buf) in disconnect_5_0_encode() argument
1259 return empty_disconnect_encode(buf); in disconnect_5_0_encode()
1263 buf->cur += MQTT_FIXED_HEADER_MAX_SIZE; in disconnect_5_0_encode()
1264 start = buf->cur; in disconnect_5_0_encode()
1266 err = pack_uint8(param->reason_code, buf); in disconnect_5_0_encode()
1271 err = disconnect_properties_encode(param, buf); in disconnect_5_0_encode()
1276 err = mqtt_encode_fixed_header(message_type, start, buf); in disconnect_5_0_encode()
1285 struct buf_ctx *buf) in disconnect_5_0_encode() argument
1288 ARG_UNUSED(buf); in disconnect_5_0_encode()
1296 struct buf_ctx *buf) in disconnect_encode() argument
1299 return empty_disconnect_encode(buf); in disconnect_encode()
1302 return disconnect_5_0_encode(param, buf); in disconnect_encode()
1314 struct buf_ctx *buf) in subscribe_properties_encode() argument
1321 err = pack_variable_int(properties_len, buf); in subscribe_properties_encode()
1328 buf); in subscribe_properties_encode()
1333 err = encode_user_properties(param->prop.user_prop, buf); in subscribe_properties_encode()
1342 struct buf_ctx *buf) in subscribe_properties_encode() argument
1345 ARG_UNUSED(buf); in subscribe_properties_encode()
1353 struct buf_ctx *buf) in subscribe_encode() argument
1366 buf->cur += MQTT_FIXED_HEADER_MAX_SIZE; in subscribe_encode()
1367 start = buf->cur; in subscribe_encode()
1369 err_code = pack_uint16(param->message_id, buf); in subscribe_encode()
1375 err_code = subscribe_properties_encode(param, buf); in subscribe_encode()
1382 err_code = pack_utf8_str(¶m->list[i].topic, buf); in subscribe_encode()
1387 err_code = pack_uint8(param->list[i].qos, buf); in subscribe_encode()
1393 return mqtt_encode_fixed_header(message_type, start, buf); in subscribe_encode()
1404 const struct mqtt_subscription_list *param, struct buf_ctx *buf) in unsubscribe_properties_encode() argument
1411 err = pack_variable_int(properties_len, buf); in unsubscribe_properties_encode()
1416 err = encode_user_properties(param->prop.user_prop, buf); in unsubscribe_properties_encode()
1425 const struct mqtt_subscription_list *param, struct buf_ctx *buf) in unsubscribe_properties_encode() argument
1428 ARG_UNUSED(buf); in unsubscribe_properties_encode()
1436 struct buf_ctx *buf) in unsubscribe_encode() argument
1444 buf->cur += MQTT_FIXED_HEADER_MAX_SIZE; in unsubscribe_encode()
1445 start = buf->cur; in unsubscribe_encode()
1447 err_code = pack_uint16(param->message_id, buf); in unsubscribe_encode()
1453 err_code = unsubscribe_properties_encode(param, buf); in unsubscribe_encode()
1460 err_code = pack_utf8_str(¶m->list[i].topic, buf); in unsubscribe_encode()
1466 return mqtt_encode_fixed_header(message_type, start, buf); in unsubscribe_encode()
1469 int ping_request_encode(struct buf_ctx *buf) in ping_request_encode() argument
1471 uint8_t *cur = buf->cur; in ping_request_encode()
1472 uint8_t *end = buf->end; in ping_request_encode()
1479 buf->end = (cur + sizeof(ping_packet)); in ping_request_encode()
1494 struct buf_ctx *buf) in auth_properties_encode() argument
1505 err = pack_variable_int(properties_len, buf); in auth_properties_encode()
1511 ¶m->prop.auth_method, buf); in auth_properties_encode()
1517 ¶m->prop.auth_data, buf); in auth_properties_encode()
1523 ¶m->prop.reason_string, buf); in auth_properties_encode()
1528 err = encode_user_properties(param->prop.user_prop, buf); in auth_properties_encode()
1536 static int empty_auth_encode(struct buf_ctx *buf) in empty_auth_encode() argument
1542 uint8_t *cur = buf->cur; in empty_auth_encode()
1543 uint8_t *end = buf->end; in empty_auth_encode()
1550 buf->end = (cur + sizeof(empty_auth_packet)); in empty_auth_encode()
1555 int auth_encode(const struct mqtt_auth_param *param, struct buf_ctx *buf) in auth_encode() argument
1563 buf->cur += MQTT_FIXED_HEADER_MAX_SIZE; in auth_encode()
1564 start = buf->cur; in auth_encode()
1568 return empty_auth_encode(buf); in auth_encode()
1571 err = pack_uint8(param->reason_code, buf); in auth_encode()
1576 err = auth_properties_encode(param, buf); in auth_encode()
1581 err = mqtt_encode_fixed_header(message_type, start, buf); in auth_encode()