@@ -75,10 +75,9 @@ static void discard_buffer(void)
75
75
}
76
76
}
77
77
78
- BT_WARN ("Discarding buffer for LPN 0x%04x" , frnd -> lpn );
79
-
80
78
buf = net_buf_slist_get (& frnd -> queue );
81
79
__ASSERT_NO_MSG (buf != NULL );
80
+ BT_WARN ("Discarding buffer %p for LPN 0x%04x" , buf , frnd -> lpn );
82
81
net_buf_unref (buf );
83
82
}
84
83
@@ -163,6 +162,11 @@ static void friend_clear(struct bt_mesh_friend *frnd)
163
162
friend_cred_del (frnd -> net_idx , frnd -> lpn );
164
163
165
164
if (frnd -> last ) {
165
+ /* Cancel the sending if necessary */
166
+ if (frnd -> pending_buf ) {
167
+ BT_MESH_ADV (frnd -> last )-> busy = 0 ;
168
+ }
169
+
166
170
net_buf_unref (frnd -> last );
167
171
frnd -> last = NULL ;
168
172
}
@@ -184,6 +188,7 @@ static void friend_clear(struct bt_mesh_friend *frnd)
184
188
frnd -> pending_buf = 0 ;
185
189
frnd -> fsn = 0 ;
186
190
frnd -> queue_size = 0 ;
191
+ frnd -> pending_req = 0 ;
187
192
memset (frnd -> sub_list , 0 , sizeof (frnd -> sub_list ));
188
193
}
189
194
@@ -440,6 +445,13 @@ static void enqueue_sub_cfm(struct bt_mesh_friend *frnd, u8_t xact)
440
445
frnd -> send_last = 1 ;
441
446
}
442
447
448
+ static void friend_recv_delay (struct bt_mesh_friend * frnd )
449
+ {
450
+ frnd -> pending_req = 1 ;
451
+ k_delayed_work_submit (& frnd -> timer , recv_delay (frnd ));
452
+ BT_DBG ("Waiting RecvDelay of %d ms" , recv_delay (frnd ));
453
+ }
454
+
443
455
int bt_mesh_friend_sub_add (struct bt_mesh_net_rx * rx ,
444
456
struct net_buf_simple * buf )
445
457
{
@@ -462,7 +474,7 @@ int bt_mesh_friend_sub_add(struct bt_mesh_net_rx *rx,
462
474
return 0 ;
463
475
}
464
476
465
- k_delayed_work_submit ( & frnd -> timer , recv_delay ( frnd ) );
477
+ friend_recv_delay ( frnd );
466
478
467
479
xact = net_buf_simple_pull_u8 (buf );
468
480
@@ -472,8 +484,6 @@ int bt_mesh_friend_sub_add(struct bt_mesh_net_rx *rx,
472
484
473
485
enqueue_sub_cfm (frnd , xact );
474
486
475
- BT_DBG ("Waiting RecvDelay of %d ms" , recv_delay (frnd ));
476
-
477
487
return 0 ;
478
488
}
479
489
@@ -499,7 +509,7 @@ int bt_mesh_friend_sub_rem(struct bt_mesh_net_rx *rx,
499
509
return 0 ;
500
510
}
501
511
502
- k_delayed_work_submit ( & frnd -> timer , recv_delay ( frnd ) );
512
+ friend_recv_delay ( frnd );
503
513
504
514
xact = net_buf_simple_pull_u8 (buf );
505
515
@@ -509,8 +519,6 @@ int bt_mesh_friend_sub_rem(struct bt_mesh_net_rx *rx,
509
519
510
520
enqueue_sub_cfm (frnd , xact );
511
521
512
- BT_DBG ("Waiting RecvDelay of %d ms" , recv_delay (frnd ));
513
-
514
522
return 0 ;
515
523
}
516
524
@@ -560,19 +568,24 @@ int bt_mesh_friend_poll(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
560
568
return 0 ;
561
569
}
562
570
563
- k_delayed_work_submit (& frnd -> timer , recv_delay (frnd ));
571
+ BT_DBG ("msg->fsn %u frnd->fsn %u" , (msg -> fsn & 1 ), frnd -> fsn );
572
+
573
+ friend_recv_delay (frnd );
564
574
565
575
if (!frnd -> established ) {
566
576
BT_DBG ("Friendship established with 0x%04x" , frnd -> lpn );
567
577
frnd -> established = 1 ;
568
578
}
569
579
570
- BT_DBG ("msg->fsn %u frnd->fsn %u" , (msg -> fsn & 1 ), frnd -> fsn );
571
-
572
580
if (msg -> fsn == frnd -> fsn && frnd -> last ) {
573
581
BT_DBG ("Re-sending last PDU" );
574
582
frnd -> send_last = 1 ;
575
583
} else {
584
+ if (frnd -> last ) {
585
+ net_buf_unref (frnd -> last );
586
+ frnd -> last = NULL ;
587
+ }
588
+
576
589
frnd -> fsn = msg -> fsn ;
577
590
578
591
if (sys_slist_is_empty (& frnd -> queue )) {
@@ -581,8 +594,6 @@ int bt_mesh_friend_poll(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
581
594
}
582
595
}
583
596
584
- BT_DBG ("Waiting RecvDelay of %d ms" , recv_delay (frnd ));
585
-
586
597
return 0 ;
587
598
}
588
599
@@ -733,7 +744,12 @@ static void enqueue_offer(struct bt_mesh_friend *frnd, s8_t rssi)
733
744
734
745
frnd -> counter ++ ;
735
746
736
- enqueue_buf (frnd , buf );
747
+ if (frnd -> last ) {
748
+ net_buf_unref (frnd -> last );
749
+ }
750
+
751
+ frnd -> last = buf ;
752
+ frnd -> send_last = 1 ;
737
753
}
738
754
739
755
#define RECV_WIN CONFIG_BT_MESH_FRIEND_RECV_WIN
@@ -944,6 +960,12 @@ static void buf_send_start(u16_t duration, int err, void *user_data)
944
960
BT_DBG ("err %d" , err );
945
961
946
962
frnd -> pending_buf = 0 ;
963
+
964
+ /* Friend Offer doesn't follow the re-sending semantics */
965
+ if (!frnd -> established ) {
966
+ net_buf_unref (frnd -> last );
967
+ frnd -> last = NULL ;
968
+ }
947
969
}
948
970
949
971
static void buf_send_end (int err , void * user_data )
@@ -952,17 +974,18 @@ static void buf_send_end(int err, void *user_data)
952
974
953
975
BT_DBG ("err %d" , err );
954
976
977
+ if (frnd -> pending_req ) {
978
+ BT_WARN ("Another request before previous completed sending" );
979
+ return ;
980
+ }
981
+
955
982
if (frnd -> established ) {
956
983
k_delayed_work_submit (& frnd -> timer , frnd -> poll_to );
957
984
BT_DBG ("Waiting %u ms for next poll" , frnd -> poll_to );
958
985
} else {
959
986
/* Friend offer timeout is 1 second */
960
987
k_delayed_work_submit (& frnd -> timer , K_SECONDS (1 ));
961
988
BT_DBG ("Waiting for first poll" );
962
-
963
- /* Friend Offer doesn't follow the re-sending semantics */
964
- net_buf_unref (frnd -> last );
965
- frnd -> last = NULL ;
966
989
}
967
990
}
968
991
@@ -981,31 +1004,30 @@ static void friend_timeout(struct k_work *work)
981
1004
frnd -> send_last , frnd -> last );
982
1005
983
1006
if (frnd -> send_last && frnd -> last ) {
984
- BT_DBG ("Sending frnd->last" );
1007
+ BT_DBG ("Sending frnd->last %p" , frnd -> last );
985
1008
frnd -> send_last = 0 ;
986
1009
goto send_last ;
987
1010
}
988
1011
989
- if (frnd -> last ) {
990
- net_buf_unref (frnd -> last );
1012
+ if (frnd -> established && !frnd -> pending_req ) {
1013
+ BT_WARN ("Friendship lost with 0x%04x" , frnd -> lpn );
1014
+ friend_clear (frnd );
1015
+ return ;
991
1016
}
992
1017
993
- /* If the timeout is triggered without anything in the queue, it
994
- * means that there was no poll/req from the LPN and the timeout
995
- * occured because we hit the poll timeout.
996
- */
997
1018
frnd -> last = net_buf_slist_get (& frnd -> queue );
998
1019
if (!frnd -> last ) {
999
- BT_WARN ("Friendship %s" ,
1000
- frnd -> established ? "lost" : "not established" );
1020
+ BT_WARN ("Friendship not established with 0x%04x" , frnd -> lpn );
1001
1021
friend_clear (frnd );
1002
1022
return ;
1003
1023
}
1004
1024
1005
1025
BT_DBG ("Sending buf %p from Friend Queue of LPN 0x%04x" ,
1006
1026
frnd -> last , frnd -> lpn );
1027
+ frnd -> queue_size -- ;
1007
1028
1008
1029
send_last :
1030
+ frnd -> pending_req = 0 ;
1009
1031
frnd -> pending_buf = 1 ;
1010
1032
bt_mesh_adv_send (frnd -> last , & buf_sent_cb , frnd );
1011
1033
}
@@ -1049,6 +1071,7 @@ static void friend_purge_old_ack(struct bt_mesh_friend *frnd, u64_t *seq_auth,
1049
1071
BT_DBG ("Removing old ack from Friend Queue" );
1050
1072
1051
1073
sys_slist_remove (& frnd -> queue , prev , cur );
1074
+ frnd -> queue_size -- ;
1052
1075
/* Make sure old slist entry state doesn't remain */
1053
1076
buf -> frags = NULL ;
1054
1077
@@ -1066,7 +1089,7 @@ static void friend_lpn_enqueue_rx(struct bt_mesh_friend *frnd,
1066
1089
struct friend_pdu_info info ;
1067
1090
struct net_buf * buf ;
1068
1091
1069
- BT_DBG ("LPN 0x%04x" , frnd -> lpn );
1092
+ BT_DBG ("LPN 0x%04x queue_size %u " , frnd -> lpn , frnd -> queue_size );
1070
1093
1071
1094
if (type == BT_MESH_FRIEND_PDU_SINGLE && seq_auth ) {
1072
1095
friend_purge_old_ack (frnd , seq_auth , rx -> ctx .addr );
@@ -1101,7 +1124,8 @@ static void friend_lpn_enqueue_rx(struct bt_mesh_friend *frnd,
1101
1124
1102
1125
enqueue_friend_pdu (frnd , type , buf );
1103
1126
1104
- BT_DBG ("Queued message for LPN 0x%04x" , frnd -> lpn );
1127
+ BT_DBG ("Queued message for LPN 0x%04x, queue_size %u" ,
1128
+ frnd -> lpn , frnd -> queue_size );
1105
1129
}
1106
1130
1107
1131
static void friend_lpn_enqueue_tx (struct bt_mesh_friend * frnd ,
0 commit comments