Lines Matching refs:client
87 static void mqtt_sn_set_state(struct mqtt_sn_client *client, enum mqtt_sn_client_state state) in mqtt_sn_set_state() argument
89 int prev_state = client->state; in mqtt_sn_set_state()
91 client->state = state; in mqtt_sn_set_state()
92 LOG_DBG("Client %p state (%d) -> (%d)", client, prev_state, state); in mqtt_sn_set_state()
108 static int encode_and_send(struct mqtt_sn_client *client, struct mqtt_sn_param *p, in encode_and_send() argument
113 err = mqtt_sn_encode_msg(&client->tx, p); in encode_and_send()
118 LOG_HEXDUMP_DBG(client->tx.data, client->tx.len, "Send message"); in encode_and_send()
120 if (!client->transport->sendto) { in encode_and_send()
126 if (!client->tx.len) { in encode_and_send()
133 err = client->transport->sendto(client, client->tx.data, client->tx.len, NULL, in encode_and_send()
138 gw = SYS_SLIST_PEEK_HEAD_CONTAINER(&client->gateway, gw, next); in encode_and_send()
144 err = client->transport->sendto(client, client->tx.data, client->tx.len, gw->addr, in encode_and_send()
152 net_buf_simple_reset(&client->tx); in encode_and_send()
164 static void mqtt_sn_publish_destroy(struct mqtt_sn_client *client, struct mqtt_sn_publish *pub) in mqtt_sn_publish_destroy() argument
166 sys_slist_find_and_remove(&client->publish, &pub->next); in mqtt_sn_publish_destroy()
170 static void mqtt_sn_publish_destroy_all(struct mqtt_sn_client *client) in mqtt_sn_publish_destroy_all() argument
175 while ((next = sys_slist_get(&client->publish)) != NULL) { in mqtt_sn_publish_destroy_all()
207 static struct mqtt_sn_publish *mqtt_sn_publish_find_by_msg_id(struct mqtt_sn_client *client, in mqtt_sn_publish_find_by_msg_id() argument
212 SYS_SLIST_FOR_EACH_CONTAINER(&client->publish, pub, next) { in mqtt_sn_publish_find_by_msg_id()
221 static struct mqtt_sn_publish *mqtt_sn_publish_find_by_topic(struct mqtt_sn_client *client, in mqtt_sn_publish_find_by_topic() argument
226 SYS_SLIST_FOR_EACH_CONTAINER(&client->publish, pub, next) { in mqtt_sn_publish_find_by_topic()
264 static struct mqtt_sn_topic *mqtt_sn_topic_find_by_name(struct mqtt_sn_client *client, in mqtt_sn_topic_find_by_name() argument
269 SYS_SLIST_FOR_EACH_CONTAINER(&client->topic, topic, next) { in mqtt_sn_topic_find_by_name()
279 static struct mqtt_sn_topic *mqtt_sn_topic_find_by_msg_id(struct mqtt_sn_client *client, in mqtt_sn_topic_find_by_msg_id() argument
284 SYS_SLIST_FOR_EACH_CONTAINER(&client->topic, topic, next) { in mqtt_sn_topic_find_by_msg_id()
293 static void mqtt_sn_topic_destroy(struct mqtt_sn_client *client, struct mqtt_sn_topic *topic) in mqtt_sn_topic_destroy() argument
298 while ((pub = mqtt_sn_publish_find_by_topic(client, topic)) != NULL) { in mqtt_sn_topic_destroy()
300 mqtt_sn_publish_destroy(client, pub); in mqtt_sn_topic_destroy()
303 sys_slist_find_and_remove(&client->topic, &topic->next); in mqtt_sn_topic_destroy()
306 static void mqtt_sn_topic_destroy_all(struct mqtt_sn_client *client) in mqtt_sn_topic_destroy_all() argument
312 while ((next = sys_slist_get(&client->topic)) != NULL) { in mqtt_sn_topic_destroy_all()
315 while ((pub = mqtt_sn_publish_find_by_topic(client, topic)) != NULL) { in mqtt_sn_topic_destroy_all()
317 mqtt_sn_publish_destroy(client, pub); in mqtt_sn_topic_destroy_all()
324 static void mqtt_sn_gw_destroy(struct mqtt_sn_client *client, struct mqtt_sn_gateway *gw) in mqtt_sn_gw_destroy() argument
327 sys_slist_find_and_remove(&client->gateway, &gw->next); in mqtt_sn_gw_destroy()
331 static void mqtt_sn_gw_destroy_all(struct mqtt_sn_client *client) in mqtt_sn_gw_destroy_all() argument
336 while ((next = sys_slist_get(&client->gateway)) != NULL) { in mqtt_sn_gw_destroy_all()
338 sys_slist_find_and_remove(&client->gateway, next); in mqtt_sn_gw_destroy_all()
371 static struct mqtt_sn_gateway *mqtt_sn_gw_find_by_id(struct mqtt_sn_client *client, uint16_t gw_id) in mqtt_sn_gw_find_by_id() argument
375 SYS_SLIST_FOR_EACH_CONTAINER(&client->gateway, gw, next) { in mqtt_sn_gw_find_by_id()
384 static void mqtt_sn_disconnect_internal(struct mqtt_sn_client *client) in mqtt_sn_disconnect_internal() argument
388 mqtt_sn_set_state(client, MQTT_SN_CLIENT_DISCONNECTED); in mqtt_sn_disconnect_internal()
389 if (client->evt_cb) { in mqtt_sn_disconnect_internal()
390 client->evt_cb(client, &evt); in mqtt_sn_disconnect_internal()
398 mqtt_sn_publish_destroy_all(client); in mqtt_sn_disconnect_internal()
400 k_work_cancel_delayable(&client->process_work); in mqtt_sn_disconnect_internal()
403 static void mqtt_sn_sleep_internal(struct mqtt_sn_client *client) in mqtt_sn_sleep_internal() argument
407 mqtt_sn_set_state(client, MQTT_SN_CLIENT_ASLEEP); in mqtt_sn_sleep_internal()
408 if (client->evt_cb) { in mqtt_sn_sleep_internal()
409 client->evt_cb(client, &evt); in mqtt_sn_sleep_internal()
420 static void mqtt_sn_do_subscribe(struct mqtt_sn_client *client, struct mqtt_sn_topic *topic, in mqtt_sn_do_subscribe() argument
425 if (!client || !topic) { in mqtt_sn_do_subscribe()
429 if (client->state != MQTT_SN_CLIENT_ACTIVE) { in mqtt_sn_do_subscribe()
452 encode_and_send(client, &p, 0); in mqtt_sn_do_subscribe()
461 static void mqtt_sn_do_unsubscribe(struct mqtt_sn_client *client, struct mqtt_sn_topic *topic) in mqtt_sn_do_unsubscribe() argument
465 if (!client || !topic) { in mqtt_sn_do_unsubscribe()
469 if (client->state != MQTT_SN_CLIENT_ACTIVE) { in mqtt_sn_do_unsubscribe()
490 encode_and_send(client, &p, 0); in mqtt_sn_do_unsubscribe()
499 static void mqtt_sn_do_register(struct mqtt_sn_client *client, struct mqtt_sn_topic *topic) in mqtt_sn_do_register() argument
503 if (!client || !topic) { in mqtt_sn_do_register()
507 if (client->state != MQTT_SN_CLIENT_ACTIVE) { in mqtt_sn_do_register()
524 encode_and_send(client, &p, 0); in mqtt_sn_do_register()
536 static void mqtt_sn_do_publish(struct mqtt_sn_client *client, struct mqtt_sn_publish *pub, bool dup) in mqtt_sn_do_publish() argument
540 if (!client || !pub) { in mqtt_sn_do_publish()
544 if (client->state != MQTT_SN_CLIENT_ACTIVE) { in mqtt_sn_do_publish()
560 encode_and_send(client, &p, 0); in mqtt_sn_do_publish()
568 static void mqtt_sn_do_searchgw(struct mqtt_sn_client *client) in mqtt_sn_do_searchgw() argument
574 encode_and_send(client, &p, CONFIG_MQTT_SN_LIB_BROADCAST_RADIUS); in mqtt_sn_do_searchgw()
582 static void mqtt_sn_do_gwinfo(struct mqtt_sn_client *client) in mqtt_sn_do_gwinfo() argument
588 gw = SYS_SLIST_PEEK_HEAD_CONTAINER(&client->gateway, gw, next); in mqtt_sn_do_gwinfo()
600 encode_and_send(client, &response, client->radius_gwinfo); in mqtt_sn_do_gwinfo()
608 static void mqtt_sn_do_ping(struct mqtt_sn_client *client) in mqtt_sn_do_ping() argument
612 switch (client->state) { in mqtt_sn_do_ping()
621 p.params.pingreq.client_id.data = client->client_id.data; in mqtt_sn_do_ping()
622 p.params.pingreq.client_id.size = client->client_id.size; in mqtt_sn_do_ping()
624 encode_and_send(client, &p, 0); in mqtt_sn_do_ping()
627 LOG_WRN("Can't ping in state %d", client->state); in mqtt_sn_do_ping()
641 static int process_pubs(struct mqtt_sn_client *client, int64_t *next_cycle) in process_pubs() argument
648 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&client->publish, pub, pubs, next) { in process_pubs()
668 mqtt_sn_disconnect_internal(client); in process_pubs()
671 mqtt_sn_do_publish(client, pub, dup); in process_pubs()
674 mqtt_sn_publish_destroy(client, pub); in process_pubs()
708 static int process_topics(struct mqtt_sn_client *client, int64_t *next_cycle) in process_topics() argument
720 SYS_SLIST_FOR_EACH_CONTAINER(&client->topic, topic, next) { in process_topics()
735 SYS_SLIST_FOR_EACH_CONTAINER(&client->topic, topic, next) { in process_topics()
764 mqtt_sn_disconnect_internal(client); in process_topics()
768 mqtt_sn_do_subscribe(client, topic, dup); in process_topics()
784 mqtt_sn_disconnect_internal(client); in process_topics()
788 mqtt_sn_do_register(client, topic); in process_topics()
807 mqtt_sn_disconnect_internal(client); in process_topics()
810 mqtt_sn_do_unsubscribe(client, topic); in process_topics()
839 static int process_ping(struct mqtt_sn_client *client, int64_t *next_cycle) in process_ping() argument
850 if (client->ping_retries == N_RETRY) { in process_ping()
852 next_ping = client->last_ping + T_KEEPALIVE_MSEC; in process_ping()
854 next_ping = client->last_ping + T_RETRY_MSEC; in process_ping()
858 if (!client->ping_retries--) { in process_ping()
860 mqtt_sn_disconnect_internal(client); in process_ping()
861 SYS_SLIST_PEEK_HEAD_CONTAINER(&client->gateway, gw, next); in process_ping()
863 mqtt_sn_gw_destroy(client, gw); in process_ping()
868 mqtt_sn_do_ping(client); in process_ping()
869 client->last_ping = now; in process_ping()
889 static int process_search(struct mqtt_sn_client *client, int64_t *next_cycle) in process_search() argument
893 LOG_DBG("ts_searchgw: %lld", client->ts_searchgw); in process_search()
894 LOG_DBG("ts_gwinfo: %lld", client->ts_gwinfo); in process_search()
896 if (client->ts_searchgw != 0 && client->ts_searchgw <= now) { in process_search()
898 mqtt_sn_do_searchgw(client); in process_search()
899 client->ts_searchgw = 0; in process_search()
902 if (client->ts_gwinfo != 0 && client->ts_gwinfo <= now) { in process_search()
904 mqtt_sn_do_gwinfo(client); in process_search()
905 client->ts_gwinfo = 0; in process_search()
908 if (*next_cycle == 0 || (client->ts_searchgw != 0 && client->ts_searchgw < *next_cycle)) { in process_search()
909 *next_cycle = client->ts_searchgw; in process_search()
911 if (*next_cycle == 0 || (client->ts_gwinfo != 0 && client->ts_gwinfo < *next_cycle)) { in process_search()
912 *next_cycle = client->ts_gwinfo; in process_search()
927 static int process_advertise(struct mqtt_sn_client *client, int64_t *next_cycle) in process_advertise() argument
933 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&client->gateway, gw, gw_next, next) { in process_advertise()
937 if (client->gateway.head == &gw->next) { in process_advertise()
938 mqtt_sn_disconnect(client); in process_advertise()
940 mqtt_sn_gw_destroy(client, gw); in process_advertise()
958 struct mqtt_sn_client *client; in process_work() local
964 client = CONTAINER_OF(dwork, struct mqtt_sn_client, process_work); in process_work()
966 LOG_DBG("Executing work of client %p in state %d at time %lld", client, client->state, in process_work()
970 err = process_advertise(client, &next_cycle); in process_work()
976 err = process_search(client, &next_cycle); in process_work()
981 if (client->state == MQTT_SN_CLIENT_ACTIVE) { in process_work()
982 err = process_topics(client, &next_cycle); in process_work()
987 err = process_pubs(client, &next_cycle); in process_work()
992 err = process_ping(client, &next_cycle); in process_work()
1004 int mqtt_sn_client_init(struct mqtt_sn_client *client, const struct mqtt_sn_data *client_id, in mqtt_sn_client_init() argument
1010 if (!client || !client_id || !transport || !evt_cb || !tx || !rx) { in mqtt_sn_client_init()
1014 memset(client, 0, sizeof(*client)); in mqtt_sn_client_init()
1016 client->client_id.data = client_id->data; in mqtt_sn_client_init()
1017 client->client_id.size = client_id->size; in mqtt_sn_client_init()
1018 client->transport = transport; in mqtt_sn_client_init()
1019 client->evt_cb = evt_cb; in mqtt_sn_client_init()
1021 net_buf_simple_init_with_data(&client->tx, tx, txsz); in mqtt_sn_client_init()
1022 net_buf_simple_reset(&client->tx); in mqtt_sn_client_init()
1024 net_buf_simple_init_with_data(&client->rx, rx, rxsz); in mqtt_sn_client_init()
1025 net_buf_simple_reset(&client->rx); in mqtt_sn_client_init()
1027 k_work_init_delayable(&client->process_work, process_work); in mqtt_sn_client_init()
1036 void mqtt_sn_client_deinit(struct mqtt_sn_client *client) in mqtt_sn_client_deinit() argument
1038 if (!client) { in mqtt_sn_client_deinit()
1042 mqtt_sn_publish_destroy_all(client); in mqtt_sn_client_deinit()
1043 mqtt_sn_topic_destroy_all(client); in mqtt_sn_client_deinit()
1044 mqtt_sn_gw_destroy_all(client); in mqtt_sn_client_deinit()
1046 if (client->transport && client->transport->deinit) { in mqtt_sn_client_deinit()
1047 client->transport->deinit(client->transport); in mqtt_sn_client_deinit()
1050 k_work_cancel_delayable(&client->process_work); in mqtt_sn_client_deinit()
1053 int mqtt_sn_add_gw(struct mqtt_sn_client *client, uint8_t gw_id, struct mqtt_sn_data gw_addr) in mqtt_sn_add_gw() argument
1057 gw = mqtt_sn_gw_find_by_id(client, gw_id); in mqtt_sn_add_gw()
1060 mqtt_sn_gw_destroy(client, gw); in mqtt_sn_add_gw()
1068 sys_slist_append(&client->gateway, &gw->next); in mqtt_sn_add_gw()
1073 int mqtt_sn_search(struct mqtt_sn_client *client, uint8_t radius) in mqtt_sn_search() argument
1075 if (!client) { in mqtt_sn_search()
1079 client->ts_searchgw = k_uptime_get() + (T_SEARCHGW_MSEC * sys_rand8_get() / 255); in mqtt_sn_search()
1080 k_work_schedule(&client->process_work, K_NO_WAIT); in mqtt_sn_search()
1081 LOG_DBG("Requested SEARCHGW for time %lld at time %lld", client->ts_searchgw, in mqtt_sn_search()
1087 int mqtt_sn_connect(struct mqtt_sn_client *client, bool will, bool clean_session) in mqtt_sn_connect() argument
1091 if (!client) { in mqtt_sn_connect()
1095 if (will && (!client->will_msg.data || !client->will_topic.data)) { in mqtt_sn_connect()
1101 mqtt_sn_topic_destroy_all(client); in mqtt_sn_connect()
1107 p.params.connect.client_id.data = client->client_id.data; in mqtt_sn_connect()
1108 p.params.connect.client_id.size = client->client_id.size; in mqtt_sn_connect()
1110 client->last_ping = k_uptime_get(); in mqtt_sn_connect()
1112 return encode_and_send(client, &p, 0); in mqtt_sn_connect()
1115 int mqtt_sn_disconnect(struct mqtt_sn_client *client) in mqtt_sn_disconnect() argument
1120 if (!client) { in mqtt_sn_disconnect()
1126 err = encode_and_send(client, &p, 0); in mqtt_sn_disconnect()
1127 mqtt_sn_disconnect_internal(client); in mqtt_sn_disconnect()
1132 int mqtt_sn_sleep(struct mqtt_sn_client *client, uint16_t duration) in mqtt_sn_sleep() argument
1137 if (!client || !duration) { in mqtt_sn_sleep()
1143 err = encode_and_send(client, &p, 0); in mqtt_sn_sleep()
1144 mqtt_sn_sleep_internal(client); in mqtt_sn_sleep()
1149 int mqtt_sn_subscribe(struct mqtt_sn_client *client, enum mqtt_sn_qos qos, in mqtt_sn_subscribe() argument
1155 if (!client || !topic_name || !topic_name->data || !topic_name->size) { in mqtt_sn_subscribe()
1159 if (client->state != MQTT_SN_CLIENT_ACTIVE) { in mqtt_sn_subscribe()
1164 topic = mqtt_sn_topic_find_by_name(client, topic_name); in mqtt_sn_subscribe()
1173 sys_slist_append(&client->topic, &topic->next); in mqtt_sn_subscribe()
1176 err = k_work_reschedule(&client->process_work, K_NO_WAIT); in mqtt_sn_subscribe()
1184 int mqtt_sn_unsubscribe(struct mqtt_sn_client *client, enum mqtt_sn_qos qos, in mqtt_sn_unsubscribe() argument
1190 if (!client || !topic_name) { in mqtt_sn_unsubscribe()
1194 if (client->state != MQTT_SN_CLIENT_ACTIVE) { in mqtt_sn_unsubscribe()
1199 topic = mqtt_sn_topic_find_by_name(client, topic_name); in mqtt_sn_unsubscribe()
1213 err = k_work_reschedule(&client->process_work, K_NO_WAIT); in mqtt_sn_unsubscribe()
1221 int mqtt_sn_publish(struct mqtt_sn_client *client, enum mqtt_sn_qos qos, in mqtt_sn_publish() argument
1228 if (!client || !topic_name) { in mqtt_sn_publish()
1237 if (client->state != MQTT_SN_CLIENT_ACTIVE) { in mqtt_sn_publish()
1242 topic = mqtt_sn_topic_find_by_name(client, topic_name); in mqtt_sn_publish()
1251 sys_slist_append(&client->topic, &topic->next); in mqtt_sn_publish()
1256 k_work_reschedule(&client->process_work, K_NO_WAIT); in mqtt_sn_publish()
1264 sys_slist_append(&client->publish, &pub->next); in mqtt_sn_publish()
1266 err = k_work_reschedule(&client->process_work, K_NO_WAIT); in mqtt_sn_publish()
1274 static void handle_advertise(struct mqtt_sn_client *client, struct mqtt_sn_param_advertise *p, in handle_advertise() argument
1280 gw = mqtt_sn_gw_find_by_id(client, p->gw_id); in handle_advertise()
1288 sys_slist_append(&client->gateway, &gw->next); in handle_advertise()
1295 k_work_schedule(&client->process_work, K_NO_WAIT); in handle_advertise()
1296 if (client->evt_cb) { in handle_advertise()
1297 client->evt_cb(client, &evt); in handle_advertise()
1301 static void handle_searchgw(struct mqtt_sn_client *client, struct mqtt_sn_param_searchgw *p) in handle_searchgw() argument
1306 if (client->ts_searchgw != 0) { in handle_searchgw()
1307 client->ts_searchgw = k_uptime_get() + (T_SEARCHGW_MSEC * sys_rand8_get() / 255); in handle_searchgw()
1311 if (sys_slist_len(&client->gateway) > 0) { in handle_searchgw()
1312 client->ts_gwinfo = k_uptime_get() + (T_GWINFO_MSEC * sys_rand8_get() / 255); in handle_searchgw()
1314 client->radius_gwinfo = p->radius; in handle_searchgw()
1315 k_work_schedule(&client->process_work, K_NO_WAIT); in handle_searchgw()
1317 if (client->evt_cb) { in handle_searchgw()
1318 client->evt_cb(client, &evt); in handle_searchgw()
1322 static void handle_gwinfo(struct mqtt_sn_client *client, struct mqtt_sn_param_gwinfo *p, in handle_gwinfo() argument
1329 client->ts_searchgw = 0; in handle_gwinfo()
1330 client->ts_gwinfo = 0; in handle_gwinfo()
1331 k_work_schedule(&client->process_work, K_NO_WAIT); in handle_gwinfo()
1345 sys_slist_append(&client->gateway, &gw->next); in handle_gwinfo()
1347 if (client->evt_cb) { in handle_gwinfo()
1348 client->evt_cb(client, &evt); in handle_gwinfo()
1352 static void handle_connack(struct mqtt_sn_client *client, struct mqtt_sn_param_connack *p) in handle_connack() argument
1358 switch (client->state) { in handle_connack()
1362 mqtt_sn_set_state(client, MQTT_SN_CLIENT_ACTIVE); in handle_connack()
1363 if (client->evt_cb) { in handle_connack()
1364 client->evt_cb(client, &evt); in handle_connack()
1366 client->ping_retries = N_RETRY; in handle_connack()
1369 LOG_ERR("Client received CONNACK but was in state %d", client->state); in handle_connack()
1374 mqtt_sn_disconnect_internal(client); in handle_connack()
1377 k_work_schedule(&client->process_work, K_NO_WAIT); in handle_connack()
1380 static void handle_willtopicreq(struct mqtt_sn_client *client) in handle_willtopicreq() argument
1384 response.params.willtopic.qos = client->will_qos; in handle_willtopicreq()
1385 response.params.willtopic.retain = client->will_retain; in handle_willtopicreq()
1386 response.params.willtopic.topic.data = client->will_topic.data; in handle_willtopicreq()
1387 response.params.willtopic.topic.size = client->will_topic.size; in handle_willtopicreq()
1389 encode_and_send(client, &response, 0); in handle_willtopicreq()
1392 static void handle_willmsgreq(struct mqtt_sn_client *client) in handle_willmsgreq() argument
1396 response.params.willmsg.msg.data = client->will_msg.data; in handle_willmsgreq()
1397 response.params.willmsg.msg.size = client->will_msg.size; in handle_willmsgreq()
1399 encode_and_send(client, &response, 0); in handle_willmsgreq()
1402 static void handle_register(struct mqtt_sn_client *client, struct mqtt_sn_param_register *p) in handle_register() argument
1416 sys_slist_append(&client->topic, &topic->next); in handle_register()
1422 encode_and_send(client, &response, 0); in handle_register()
1425 static void handle_regack(struct mqtt_sn_client *client, struct mqtt_sn_param_regack *p) in handle_regack() argument
1427 struct mqtt_sn_topic *topic = mqtt_sn_topic_find_by_msg_id(client, p->msg_id); in handle_regack()
1443 static void handle_publish(struct mqtt_sn_client *client, struct mqtt_sn_param_publish *p) in handle_publish() argument
1457 encode_and_send(client, &response, 0); in handle_publish()
1462 encode_and_send(client, &response, 0); in handle_publish()
1465 if (client->evt_cb) { in handle_publish()
1466 client->evt_cb(client, &evt); in handle_publish()
1470 static void handle_puback(struct mqtt_sn_client *client, struct mqtt_sn_param_puback *p) in handle_puback() argument
1472 struct mqtt_sn_publish *pub = mqtt_sn_publish_find_by_msg_id(client, p->msg_id); in handle_puback()
1479 mqtt_sn_publish_destroy(client, pub); in handle_puback()
1482 static void handle_pubrec(struct mqtt_sn_client *client, struct mqtt_sn_param_pubrec *p) in handle_pubrec() argument
1485 struct mqtt_sn_publish *pub = mqtt_sn_publish_find_by_msg_id(client, p->msg_id); in handle_pubrec()
1497 encode_and_send(client, &response, 0); in handle_pubrec()
1500 static void handle_pubrel(struct mqtt_sn_client *client, struct mqtt_sn_param_pubrel *p) in handle_pubrel() argument
1506 encode_and_send(client, &response, 0); in handle_pubrel()
1509 static void handle_pubcomp(struct mqtt_sn_client *client, struct mqtt_sn_param_pubcomp *p) in handle_pubcomp() argument
1511 struct mqtt_sn_publish *pub = mqtt_sn_publish_find_by_msg_id(client, p->msg_id); in handle_pubcomp()
1518 mqtt_sn_publish_destroy(client, pub); in handle_pubcomp()
1521 static void handle_suback(struct mqtt_sn_client *client, struct mqtt_sn_param_suback *p) in handle_suback() argument
1523 struct mqtt_sn_topic *topic = mqtt_sn_topic_find_by_msg_id(client, p->msg_id); in handle_suback()
1539 static void handle_unsuback(struct mqtt_sn_client *client, struct mqtt_sn_param_unsuback *p) in handle_unsuback() argument
1541 struct mqtt_sn_topic *topic = mqtt_sn_topic_find_by_msg_id(client, p->msg_id); in handle_unsuback()
1548 mqtt_sn_topic_destroy(client, topic); in handle_unsuback()
1551 static void handle_pingreq(struct mqtt_sn_client *client) in handle_pingreq() argument
1555 encode_and_send(client, &response, 0); in handle_pingreq()
1558 static void handle_pingresp(struct mqtt_sn_client *client) in handle_pingresp() argument
1562 if (client->evt_cb) { in handle_pingresp()
1563 client->evt_cb(client, &evt); in handle_pingresp()
1566 if (client->state == MQTT_SN_CLIENT_AWAKE) { in handle_pingresp()
1567 mqtt_sn_set_state(client, MQTT_SN_CLIENT_ASLEEP); in handle_pingresp()
1570 client->ping_retries = N_RETRY; in handle_pingresp()
1573 static void handle_disconnect(struct mqtt_sn_client *client, struct mqtt_sn_param_disconnect *p) in handle_disconnect() argument
1576 mqtt_sn_disconnect_internal(client); in handle_disconnect()
1579 static int handle_msg(struct mqtt_sn_client *client, struct mqtt_sn_data rx_addr) in handle_msg() argument
1584 err = mqtt_sn_decode_msg(&client->rx, &p); in handle_msg()
1593 handle_advertise(client, &p.params.advertise, rx_addr); in handle_msg()
1596 handle_searchgw(client, &p.params.searchgw); in handle_msg()
1599 handle_gwinfo(client, &p.params.gwinfo, rx_addr); in handle_msg()
1602 handle_connack(client, &p.params.connack); in handle_msg()
1605 handle_willtopicreq(client); in handle_msg()
1608 handle_willmsgreq(client); in handle_msg()
1611 handle_register(client, &p.params.reg); in handle_msg()
1614 handle_regack(client, &p.params.regack); in handle_msg()
1617 handle_publish(client, &p.params.publish); in handle_msg()
1620 handle_puback(client, &p.params.puback); in handle_msg()
1623 handle_pubrec(client, &p.params.pubrec); in handle_msg()
1626 handle_pubrel(client, &p.params.pubrel); in handle_msg()
1629 handle_pubcomp(client, &p.params.pubcomp); in handle_msg()
1632 handle_suback(client, &p.params.suback); in handle_msg()
1635 handle_unsuback(client, &p.params.unsuback); in handle_msg()
1638 handle_pingreq(client); in handle_msg()
1641 handle_pingresp(client); in handle_msg()
1644 handle_disconnect(client, &p.params.disconnect); in handle_msg()
1655 k_work_reschedule(&client->process_work, K_NO_WAIT); in handle_msg()
1660 int mqtt_sn_input(struct mqtt_sn_client *client) in mqtt_sn_input() argument
1667 if (!client || !client->transport || !client->transport->recvfrom) { in mqtt_sn_input()
1671 if (client->transport->poll) { in mqtt_sn_input()
1672 next_frame_size = client->transport->poll(client); in mqtt_sn_input()
1678 net_buf_simple_reset(&client->rx); in mqtt_sn_input()
1680 next_frame_size = client->transport->recvfrom(client, client->rx.data, client->rx.size, in mqtt_sn_input()
1686 if (next_frame_size > client->rx.size) { in mqtt_sn_input()
1690 client->rx.len = next_frame_size; in mqtt_sn_input()
1692 LOG_HEXDUMP_DBG(client->rx.data, client->rx.len, "Received data"); in mqtt_sn_input()
1694 err = handle_msg(client, rx_addr); in mqtt_sn_input()
1701 return -client->rx.len; in mqtt_sn_input()
1704 int mqtt_sn_get_topic_name(struct mqtt_sn_client *client, uint16_t id, in mqtt_sn_get_topic_name() argument
1709 if (!client || !topic_name) { in mqtt_sn_get_topic_name()
1713 SYS_SLIST_FOR_EACH_CONTAINER(&client->topic, topic, next) { in mqtt_sn_get_topic_name()