Lines Matching full:buf

22  * @param buf Message struct to use
27 static int prepare_message(struct net_buf_simple *buf, size_t sz, enum mqtt_sn_msg_type type) in prepare_message() argument
34 size_t maxlen = net_buf_simple_max_len(buf); in prepare_message()
50 net_buf_simple_add_u8(buf, (uint8_t)sz); in prepare_message()
52 net_buf_simple_add_u8(buf, MQTT_SN_LENGTH_FIELD_EXTENDED_PREFIX); in prepare_message()
53 net_buf_simple_add_be16(buf, (uint16_t)sz); in prepare_message()
56 net_buf_simple_add_u8(buf, (uint8_t)type); in prepare_message()
61 static void encode_flags(struct net_buf_simple *buf, struct mqtt_sn_flags *flags) in encode_flags() argument
77 net_buf_simple_add_u8(buf, b); in encode_flags()
80 static int mqtt_sn_encode_msg_searchgw(struct net_buf_simple *buf, in mqtt_sn_encode_msg_searchgw() argument
86 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_SEARCHGW); in mqtt_sn_encode_msg_searchgw()
91 net_buf_simple_add_u8(buf, params->radius); in mqtt_sn_encode_msg_searchgw()
96 static int mqtt_sn_encode_msg_gwinfo(struct net_buf_simple *buf, in mqtt_sn_encode_msg_gwinfo() argument
102 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_GWINFO); in mqtt_sn_encode_msg_gwinfo()
107 net_buf_simple_add_u8(buf, params->gw_id); in mqtt_sn_encode_msg_gwinfo()
108 net_buf_simple_add_data(buf, &params->gw_add); in mqtt_sn_encode_msg_gwinfo()
113 static int mqtt_sn_encode_msg_connect(struct net_buf_simple *buf, in mqtt_sn_encode_msg_connect() argument
120 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_CONNECT); in mqtt_sn_encode_msg_connect()
125 encode_flags(buf, &flags); in mqtt_sn_encode_msg_connect()
127 net_buf_simple_add_u8(buf, MQTT_SN_PROTOCOL_ID); in mqtt_sn_encode_msg_connect()
129 net_buf_simple_add_be16(buf, params->duration); in mqtt_sn_encode_msg_connect()
131 net_buf_simple_add_data(buf, &params->client_id); in mqtt_sn_encode_msg_connect()
136 static int mqtt_sn_encode_msg_willtopic(struct net_buf_simple *buf, in mqtt_sn_encode_msg_willtopic() argument
143 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_WILLTOPIC); in mqtt_sn_encode_msg_willtopic()
148 encode_flags(buf, &flags); in mqtt_sn_encode_msg_willtopic()
150 net_buf_simple_add_data(buf, &params->topic); in mqtt_sn_encode_msg_willtopic()
155 static int mqtt_sn_encode_msg_willmsg(struct net_buf_simple *buf, in mqtt_sn_encode_msg_willmsg() argument
161 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_WILLMSG); in mqtt_sn_encode_msg_willmsg()
166 net_buf_simple_add_data(buf, &params->msg); in mqtt_sn_encode_msg_willmsg()
171 static int mqtt_sn_encode_msg_register(struct net_buf_simple *buf, in mqtt_sn_encode_msg_register() argument
177 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_REGISTER); in mqtt_sn_encode_msg_register()
183 net_buf_simple_add_be16(buf, 0x00); in mqtt_sn_encode_msg_register()
184 net_buf_simple_add_be16(buf, params->msg_id); in mqtt_sn_encode_msg_register()
185 net_buf_simple_add_data(buf, &params->topic); in mqtt_sn_encode_msg_register()
190 static int mqtt_sn_encode_msg_regack(struct net_buf_simple *buf, in mqtt_sn_encode_msg_regack() argument
196 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_REGACK); in mqtt_sn_encode_msg_regack()
201 net_buf_simple_add_be16(buf, params->topic_id); in mqtt_sn_encode_msg_regack()
202 net_buf_simple_add_be16(buf, params->msg_id); in mqtt_sn_encode_msg_regack()
203 net_buf_simple_add_u8(buf, params->ret_code); in mqtt_sn_encode_msg_regack()
208 static int mqtt_sn_encode_msg_publish(struct net_buf_simple *buf, in mqtt_sn_encode_msg_publish() argument
218 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_PUBLISH); in mqtt_sn_encode_msg_publish()
222 encode_flags(buf, &flags); in mqtt_sn_encode_msg_publish()
224 net_buf_simple_add_be16(buf, params->topic_id); in mqtt_sn_encode_msg_publish()
227 net_buf_simple_add_be16(buf, params->msg_id); in mqtt_sn_encode_msg_publish()
230 net_buf_simple_add_be16(buf, 0x0000); in mqtt_sn_encode_msg_publish()
233 net_buf_simple_add_data(buf, &params->data); in mqtt_sn_encode_msg_publish()
238 static int mqtt_sn_encode_msg_puback(struct net_buf_simple *buf, in mqtt_sn_encode_msg_puback() argument
244 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_PUBACK); in mqtt_sn_encode_msg_puback()
249 net_buf_simple_add_be16(buf, params->topic_id); in mqtt_sn_encode_msg_puback()
250 net_buf_simple_add_be16(buf, params->msg_id); in mqtt_sn_encode_msg_puback()
251 net_buf_simple_add_u8(buf, params->ret_code); in mqtt_sn_encode_msg_puback()
256 static int mqtt_sn_encode_msg_pubrec(struct net_buf_simple *buf, in mqtt_sn_encode_msg_pubrec() argument
262 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_PUBREC); in mqtt_sn_encode_msg_pubrec()
267 net_buf_simple_add_be16(buf, params->msg_id); in mqtt_sn_encode_msg_pubrec()
272 static int mqtt_sn_encode_msg_pubrel(struct net_buf_simple *buf, in mqtt_sn_encode_msg_pubrel() argument
278 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_PUBREL); in mqtt_sn_encode_msg_pubrel()
283 net_buf_simple_add_be16(buf, params->msg_id); in mqtt_sn_encode_msg_pubrel()
288 static int mqtt_sn_encode_msg_pubcomp(struct net_buf_simple *buf, in mqtt_sn_encode_msg_pubcomp() argument
294 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_PUBCOMP); in mqtt_sn_encode_msg_pubcomp()
299 net_buf_simple_add_be16(buf, params->msg_id); in mqtt_sn_encode_msg_pubcomp()
304 static int mqtt_sn_encode_msg_subscribe(struct net_buf_simple *buf, in mqtt_sn_encode_msg_subscribe() argument
319 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_SUBSCRIBE); in mqtt_sn_encode_msg_subscribe()
323 encode_flags(buf, &flags); in mqtt_sn_encode_msg_subscribe()
325 net_buf_simple_add_be16(buf, params->msg_id); in mqtt_sn_encode_msg_subscribe()
328 net_buf_simple_add_data(buf, &params->topic.topic_name); in mqtt_sn_encode_msg_subscribe()
330 net_buf_simple_add_be16(buf, params->topic.topic_id); in mqtt_sn_encode_msg_subscribe()
336 static int mqtt_sn_encode_msg_unsubscribe(struct net_buf_simple *buf, in mqtt_sn_encode_msg_unsubscribe() argument
350 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_UNSUBSCRIBE); in mqtt_sn_encode_msg_unsubscribe()
354 encode_flags(buf, &flags); in mqtt_sn_encode_msg_unsubscribe()
356 net_buf_simple_add_be16(buf, params->msg_id); in mqtt_sn_encode_msg_unsubscribe()
359 net_buf_simple_add_data(buf, &params->topic.topic_name); in mqtt_sn_encode_msg_unsubscribe()
361 net_buf_simple_add_be16(buf, params->topic.topic_id); in mqtt_sn_encode_msg_unsubscribe()
367 static int mqtt_sn_encode_msg_pingreq(struct net_buf_simple *buf, in mqtt_sn_encode_msg_pingreq() argument
373 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_PINGREQ); in mqtt_sn_encode_msg_pingreq()
379 net_buf_simple_add_data(buf, &params->client_id); in mqtt_sn_encode_msg_pingreq()
385 static int mqtt_sn_encode_msg_pingresp(struct net_buf_simple *buf) in mqtt_sn_encode_msg_pingresp() argument
387 return prepare_message(buf, 0, MQTT_SN_MSG_TYPE_PINGRESP); in mqtt_sn_encode_msg_pingresp()
390 static int mqtt_sn_encode_msg_disconnect(struct net_buf_simple *buf, in mqtt_sn_encode_msg_disconnect() argument
396 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_DISCONNECT); in mqtt_sn_encode_msg_disconnect()
402 net_buf_simple_add_be16(buf, params->duration); in mqtt_sn_encode_msg_disconnect()
408 static int mqtt_sn_encode_msg_willtopicupd(struct net_buf_simple *buf, in mqtt_sn_encode_msg_willtopicupd() argument
419 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_WILLTOPICUPD); in mqtt_sn_encode_msg_willtopicupd()
426 encode_flags(buf, &flags); in mqtt_sn_encode_msg_willtopicupd()
428 net_buf_simple_add_data(buf, &params->topic); in mqtt_sn_encode_msg_willtopicupd()
434 static int mqtt_sn_encode_msg_willmsgupd(struct net_buf_simple *buf, in mqtt_sn_encode_msg_willmsgupd() argument
440 err = prepare_message(buf, msgsz, MQTT_SN_MSG_TYPE_WILLMSGUPD); in mqtt_sn_encode_msg_willmsgupd()
445 net_buf_simple_add_data(buf, &params->msg); in mqtt_sn_encode_msg_willmsgupd()
450 int mqtt_sn_encode_msg(struct net_buf_simple *buf, struct mqtt_sn_param *param) in mqtt_sn_encode_msg() argument
454 if (buf->len) { in mqtt_sn_encode_msg()
463 result = mqtt_sn_encode_msg_searchgw(buf, &param->params.searchgw); in mqtt_sn_encode_msg()
466 result = mqtt_sn_encode_msg_gwinfo(buf, &param->params.gwinfo); in mqtt_sn_encode_msg()
469 result = mqtt_sn_encode_msg_connect(buf, &param->params.connect); in mqtt_sn_encode_msg()
472 result = mqtt_sn_encode_msg_willtopic(buf, &param->params.willtopic); in mqtt_sn_encode_msg()
475 result = mqtt_sn_encode_msg_willmsg(buf, &param->params.willmsg); in mqtt_sn_encode_msg()
478 result = mqtt_sn_encode_msg_register(buf, &param->params.reg); in mqtt_sn_encode_msg()
481 result = mqtt_sn_encode_msg_regack(buf, &param->params.regack); in mqtt_sn_encode_msg()
484 result = mqtt_sn_encode_msg_publish(buf, &param->params.publish); in mqtt_sn_encode_msg()
487 result = mqtt_sn_encode_msg_puback(buf, &param->params.puback); in mqtt_sn_encode_msg()
490 result = mqtt_sn_encode_msg_pubrec(buf, &param->params.pubrec); in mqtt_sn_encode_msg()
493 result = mqtt_sn_encode_msg_pubrel(buf, &param->params.pubrel); in mqtt_sn_encode_msg()
496 result = mqtt_sn_encode_msg_pubcomp(buf, &param->params.pubcomp); in mqtt_sn_encode_msg()
499 result = mqtt_sn_encode_msg_subscribe(buf, &param->params.subscribe); in mqtt_sn_encode_msg()
502 result = mqtt_sn_encode_msg_unsubscribe(buf, &param->params.unsubscribe); in mqtt_sn_encode_msg()
505 result = mqtt_sn_encode_msg_pingreq(buf, &param->params.pingreq); in mqtt_sn_encode_msg()
508 result = mqtt_sn_encode_msg_pingresp(buf); in mqtt_sn_encode_msg()
511 result = mqtt_sn_encode_msg_disconnect(buf, &param->params.disconnect); in mqtt_sn_encode_msg()
514 result = mqtt_sn_encode_msg_willtopicupd(buf, &param->params.willtopicupd); in mqtt_sn_encode_msg()
517 result = mqtt_sn_encode_msg_willmsgupd(buf, &param->params.willmsgupd); in mqtt_sn_encode_msg()