Skip to content

Commit b7c4047

Browse files
BeckmaRfabiobaltieri
authored andcommitted
net: mqtt-sn: Add comments
Add some comments to static functions and variables. Signed-off-by: Rene Beckmann <rene.bckmnn@gmail.com>
1 parent 91f99fc commit b7c4047

File tree

1 file changed

+98
-2
lines changed

1 file changed

+98
-2
lines changed

subsys/net/lib/mqtt_sn/mqtt_sn.c

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ LOG_MODULE_REGISTER(net_mqtt_sn, CONFIG_MQTT_SN_LOG_LEVEL);
2121
NET_BUF_POOL_FIXED_DEFINE(mqtt_sn_messages, MQTT_SN_NET_BUFS, CONFIG_MQTT_SN_LIB_MAX_PAYLOAD_SIZE,
2222
0, NULL);
2323

24+
/**
25+
* A struct to track attempts for actions that require acknowledgment,
26+
* i.e. topic registering, subscribing, or unsubscribing.
27+
*/
2428
struct mqtt_sn_confirmable {
2529
int64_t last_attempt;
2630
uint16_t msg_id;
@@ -403,6 +407,13 @@ static void mqtt_sn_sleep_internal(struct mqtt_sn_client *client)
403407
}
404408
}
405409

410+
/**
411+
* @brief Internal function to send a SUBSCRIBE message for a topic.
412+
*
413+
* @param client
414+
* @param topic
415+
* @param dup DUP flag - see MQTT-SN spec
416+
*/
406417
static void mqtt_sn_do_subscribe(struct mqtt_sn_client *client, struct mqtt_sn_topic *topic,
407418
bool dup)
408419
{
@@ -438,6 +449,12 @@ static void mqtt_sn_do_subscribe(struct mqtt_sn_client *client, struct mqtt_sn_t
438449
encode_and_send(client, &p, 0);
439450
}
440451

452+
/**
453+
* @brief Internal function to send an UNSUBSCRIBE message for a topic.
454+
*
455+
* @param client
456+
* @param topic
457+
*/
441458
static void mqtt_sn_do_unsubscribe(struct mqtt_sn_client *client, struct mqtt_sn_topic *topic)
442459
{
443460
struct mqtt_sn_param p = {.type = MQTT_SN_MSG_TYPE_UNSUBSCRIBE};
@@ -470,6 +487,12 @@ static void mqtt_sn_do_unsubscribe(struct mqtt_sn_client *client, struct mqtt_sn
470487
encode_and_send(client, &p, 0);
471488
}
472489

490+
/**
491+
* @brief Internal function to a register a topic with the MQTT-SN gateway.
492+
*
493+
* @param client
494+
* @param topic
495+
*/
473496
static void mqtt_sn_do_register(struct mqtt_sn_client *client, struct mqtt_sn_topic *topic)
474497
{
475498
struct mqtt_sn_param p = {.type = MQTT_SN_MSG_TYPE_REGISTER};
@@ -498,6 +521,15 @@ static void mqtt_sn_do_register(struct mqtt_sn_client *client, struct mqtt_sn_to
498521
encode_and_send(client, &p, 0);
499522
}
500523

524+
/**
525+
* @brief Internal function to send a PUBLISH message.
526+
*
527+
* Note that this function does not do sanity checks regarding the pub's topic.
528+
*
529+
* @param client
530+
* @param pub
531+
* @param dup DUP flag - see MQTT-SN spec.
532+
*/
501533
static void mqtt_sn_do_publish(struct mqtt_sn_client *client, struct mqtt_sn_publish *pub, bool dup)
502534
{
503535
struct mqtt_sn_param p = {.type = MQTT_SN_MSG_TYPE_PUBLISH};
@@ -525,6 +557,11 @@ static void mqtt_sn_do_publish(struct mqtt_sn_client *client, struct mqtt_sn_pub
525557
encode_and_send(client, &p, 0);
526558
}
527559

560+
/**
561+
* @brief Internal function to send a SEARCHGW message.
562+
*
563+
* @param client
564+
*/
528565
static void mqtt_sn_do_searchgw(struct mqtt_sn_client *client)
529566
{
530567
struct mqtt_sn_param p = {.type = MQTT_SN_MSG_TYPE_SEARCHGW};
@@ -534,6 +571,11 @@ static void mqtt_sn_do_searchgw(struct mqtt_sn_client *client)
534571
encode_and_send(client, &p, CONFIG_MQTT_SN_LIB_BROADCAST_RADIUS);
535572
}
536573

574+
/**
575+
* @brief Internal function to send a GWINFO message.
576+
*
577+
* @param client
578+
*/
537579
static void mqtt_sn_do_gwinfo(struct mqtt_sn_client *client)
538580
{
539581
struct mqtt_sn_param response = {.type = MQTT_SN_MSG_TYPE_GWINFO};
@@ -555,6 +597,11 @@ static void mqtt_sn_do_gwinfo(struct mqtt_sn_client *client)
555597
encode_and_send(client, &response, client->radius_gwinfo);
556598
}
557599

600+
/**
601+
* @brief Internal function to send a PINGREQ message.
602+
*
603+
* @param client
604+
*/
558605
static void mqtt_sn_do_ping(struct mqtt_sn_client *client)
559606
{
560607
struct mqtt_sn_param p = {.type = MQTT_SN_MSG_TYPE_PINGREQ};
@@ -579,12 +626,21 @@ static void mqtt_sn_do_ping(struct mqtt_sn_client *client)
579626
}
580627
}
581628

629+
/**
630+
* @brief Process all publish tasks in the queue.
631+
*
632+
* @param client
633+
* @param next_cycle will be set to the time when the next action is required
634+
*
635+
* @retval 0 on success
636+
* @retval -ETIMEDOUT when a publish task ran out of retries
637+
*/
582638
static int process_pubs(struct mqtt_sn_client *client, int64_t *next_cycle)
583639
{
584640
struct mqtt_sn_publish *pub, *pubs;
585641
const int64_t now = k_uptime_get();
586642
int64_t next_attempt;
587-
bool dup;
643+
bool dup; /* dup flag if message is resent */
588644

589645
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&client->publish, pub, pubs, next) {
590646
LOG_HEXDUMP_DBG(pub->topic->name, pub->topic->namelen,
@@ -599,6 +655,7 @@ static int process_pubs(struct mqtt_sn_client *client, int64_t *next_cycle)
599655
dup = true;
600656
}
601657

658+
/* Check if action is due */
602659
if (next_attempt <= now) {
603660
switch (pub->topic->state) {
604661
case MQTT_SN_TOPIC_STATE_REGISTERING:
@@ -627,6 +684,7 @@ static int process_pubs(struct mqtt_sn_client *client, int64_t *next_cycle)
627684
}
628685
}
629686

687+
/* Remember time when next action is due */
630688
if (next_attempt > now && (*next_cycle == 0 || next_attempt < *next_cycle)) {
631689
*next_cycle = next_attempt;
632690
}
@@ -637,12 +695,21 @@ static int process_pubs(struct mqtt_sn_client *client, int64_t *next_cycle)
637695
return 0;
638696
}
639697

698+
/**
699+
* @brief Process all topic tasks in the queue.
700+
*
701+
* @param client
702+
* @param next_cycle will be set to the time when the next action is required
703+
*
704+
* @retval 0 on success
705+
* @retval -ETIMEDOUT when a publish task ran out of retries
706+
*/
640707
static int process_topics(struct mqtt_sn_client *client, int64_t *next_cycle)
641708
{
642709
struct mqtt_sn_topic *topic;
643710
const int64_t now = k_uptime_get();
644711
int64_t next_attempt;
645-
bool dup;
712+
bool dup; /* dup flag if message is resent */
646713

647714
SYS_SLIST_FOR_EACH_CONTAINER(&client->topic, topic, next) {
648715
LOG_HEXDUMP_DBG(topic->name, topic->namelen, "Processing topic");
@@ -655,6 +722,7 @@ static int process_topics(struct mqtt_sn_client *client, int64_t *next_cycle)
655722
dup = true;
656723
}
657724

725+
/* Check if action is due */
658726
if (next_attempt <= now) {
659727
switch (topic->state) {
660728
case MQTT_SN_TOPIC_STATE_SUBSCRIBING:
@@ -695,6 +763,7 @@ static int process_topics(struct mqtt_sn_client *client, int64_t *next_cycle)
695763
}
696764
}
697765

766+
/* Remember time when next action is due */
698767
if (next_attempt > now && (*next_cycle == 0 || next_attempt < *next_cycle)) {
699768
*next_cycle = next_attempt;
700769
}
@@ -705,6 +774,14 @@ static int process_topics(struct mqtt_sn_client *client, int64_t *next_cycle)
705774
return 0;
706775
}
707776

777+
/**
778+
* @brief Housekeeping task for the client ping
779+
*
780+
* @param client
781+
* @param next_cycle will be set to the time when the next action is required
782+
* @retval 0 on success
783+
* @retval -ETIMEDOUT if client ran out of ping retries
784+
*/
708785
static int process_ping(struct mqtt_sn_client *client, int64_t *next_cycle)
709786
{
710787
const int64_t now = k_uptime_get();
@@ -743,6 +820,13 @@ static int process_ping(struct mqtt_sn_client *client, int64_t *next_cycle)
743820
return 0;
744821
}
745822

823+
/**
824+
* @brief Housekeeping task for the gateway search
825+
*
826+
* @param client
827+
* @param next_cycle will be set to the time when the next action is required
828+
* @retval 0 on success
829+
*/
746830
static int process_search(struct mqtt_sn_client *client, int64_t *next_cycle)
747831
{
748832
const int64_t now = k_uptime_get();
@@ -774,6 +858,13 @@ static int process_search(struct mqtt_sn_client *client, int64_t *next_cycle)
774858
return 0;
775859
}
776860

861+
/**
862+
* @brief Housekeeping task for gateway advertisements
863+
*
864+
* @param client
865+
* @param next_cycle will be set to the time when the next action is required
866+
* @return int
867+
*/
777868
static int process_advertise(struct mqtt_sn_client *client, int64_t *next_cycle)
778869
{
779870
const int64_t now = k_uptime_get();
@@ -798,6 +889,11 @@ static int process_advertise(struct mqtt_sn_client *client, int64_t *next_cycle)
798889
return 0;
799890
}
800891

892+
/**
893+
* @brief Housekeeping task that is called by workqueue item
894+
*
895+
* @param wrk The work item
896+
*/
801897
static void process_work(struct k_work *wrk)
802898
{
803899
struct mqtt_sn_client *client;

0 commit comments

Comments
 (0)