Skip to content

Commit e8130ab

Browse files
jhirsirlubos
authored andcommitted
samples: dect_phy: dect_shell: mac: keep timing synch with target beacon
To keep timing synch up to date within associated clients, periodic background scanning towards target beacons implemented. Additionally, dect mac status -command output is updated to show association and background scanning status. Jira: MOSH-624 Signed-off-by: Jani Hirsimäki <[email protected]>
1 parent 898c58f commit e8130ab

16 files changed

+907
-86
lines changed

samples/dect/dect_phy/dect_shell/README.rst

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,11 @@ Example: starting of cluster beacon and sending RA data to it
623623
dect-phy-mac status:
624624
Cluster beacon status:
625625
Beacon running: yes
626-
Beacon channel: 1665
626+
Beacon channel: 1659
627627
Beacon tx power: 0 dBm
628628
Beacon interval: 2000 ms
629629
Beacon payload PDU byte count: 50
630+
Client status:
630631
Neighbor list status:
631632
632633
* FT/Beacon device - Check generated long and short RD IDs from settings:
@@ -736,16 +737,19 @@ Example: starting of cluster beacon and sending RA data to it
736737
desh:~$ dect mac status
737738
dect-phy-mac status:
738739
Cluster beacon status:
739-
Beacon running: no
740+
Beacon running: no
741+
Client status:
740742
Neighbor list status:
741-
Neighbor 1:
742-
network ID (24bit MSB): 1193046 (0x123456)
743-
network ID (8bit LSB): 120 (0x78)
744-
network ID (32bit): 305419896 (0x12345678)
745-
long RD ID: 1234
746-
short RD ID: 27462
747-
channel: 1659
748-
last seen time: 17016336625
743+
Neighbor 1:
744+
network ID (24bit MSB): 1193046 (0x123456)
745+
network ID (8bit LSB): 120 (0x78)
746+
network ID (32bit): 305419896 (0x12345678)
747+
long RD ID: 1234
748+
short RD ID: 27462
749+
channel: 1659
750+
Last seen: 12964 msecs ago
751+
Background scan status:
752+
Running: false
749753
750754
* PT/client side - Send association request to the scanned beacon:
751755

@@ -788,6 +792,33 @@ Example: starting of cluster beacon and sending RA data to it
788792
Received padding data, len 1, payload is not printed
789793
RX for Association Response completed.
790794
795+
* PT/client side - Check that the client is associated with the device with long RD ID 1234 and a background scan is running:
796+
797+
.. code-block:: console
798+
799+
desh:~$ dect mac status
800+
dect-phy-mac status:
801+
Cluster beacon status:
802+
Beacon running: no
803+
Client status:
804+
Association #1: long RD ID 1234
805+
Neighbor list status:
806+
Neighbor 1:
807+
network ID (24bit MSB): 1193046 (0x123456)
808+
network ID (8bit LSB): 120 (0x78)
809+
network ID (32bit): 305419896 (0x12345678)
810+
long RD ID: 1234
811+
short RD ID: 64945
812+
channel: 1671
813+
Last seen: 1428 msecs ago
814+
Last timestamp: 16878096625 mdm ticks
815+
Metrics:
816+
Scan info updated count: 1
817+
Scan started ok count: 1
818+
Scan start fail count: 0
819+
Scan info time shift updated count: 0
820+
Scan info time shift last value: 0
821+
791822
* PT/client side - Send RA data to the scanned beacon:
792823

793824
.. code-block:: console
@@ -887,6 +918,12 @@ Example: starting of cluster beacon and sending RA data to it
887918
Payload length: 1
888919
Received padding data, len 1, payload is not printed
889920
921+
* PT/client side - Check that no associations and background scans are running:
922+
923+
.. code-block:: console
924+
925+
desh:~$ dect mac status
926+
890927
* FT/Beacon device - Stop the beacon:
891928

892929
.. code-block:: console

samples/dect/dect_phy/dect_shell/src/dect/dect_phy_ctrl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,11 @@ int dect_phy_ctrl_modem_temperature_get(void)
790790

791791
/**************************************************************************************************/
792792

793+
bool dect_phy_ctrl_rx_is_on_going(void)
794+
{
795+
return ctrl_data.rx_cmd_on_going;
796+
}
797+
793798
void dect_phy_ctrl_rx_stop(void)
794799
{
795800
ctrl_data.rx_cmd_on_going = false;

samples/dect/dect_phy/dect_shell/src/dect/dect_phy_ctrl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void dect_phy_ctrl_status_get_n_print(void);
4646

4747
int dect_phy_ctrl_rx_start(struct dect_phy_rx_cmd_params *params, bool restart);
4848
void dect_phy_ctrl_rx_stop(void);
49+
bool dect_phy_ctrl_rx_is_on_going(void);
4950

5051
int dect_phy_ctrl_time_query(void);
5152

samples/dect/dect_phy/dect_shell/src/dect/dect_phy_shell.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ struct dect_phy_common_op_event_msgq_item {
190190
#define DECT_PHY_MAC_CLIENT_ASSOCIATION_TX_HANDLE 1003
191191
#define DECT_PHY_MAC_CLIENT_ASSOCIATION_RX_HANDLE 1004
192192
#define DECT_PHY_MAC_CLIENT_ASSOCIATION_REL_TX_HANDLE 1005
193-
193+
#define DECT_PHY_MAC_CLIENT_ASSOCIATED_BG_SCAN 1006
194+
/* Following handles DECT_PHY_MAC_CLIENT_ASSOCIATED_BG_SCAN + DECT_PHY_MAC_MAX_NEIGBORS
195+
* are reserved for associated bg scannings.
196+
*/
194197

195198
#define DECT_PHY_PERF_TX_HANDLE_START 10000
196199
#define DECT_PHY_PERF_TX_HANDLE_END 10049

samples/dect/dect_phy/dect_shell/src/dect/mac/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ target_sources(app PRIVATE
1212
${CMAKE_CURRENT_SOURCE_DIR}/dect_phy_mac_client.c
1313
${CMAKE_CURRENT_SOURCE_DIR}/dect_phy_mac_pdu.c
1414
${CMAKE_CURRENT_SOURCE_DIR}/dect_phy_mac_nbr.c
15+
${CMAKE_CURRENT_SOURCE_DIR}/dect_phy_mac_nbr_bg_scan.c
1516
${CMAKE_CURRENT_SOURCE_DIR}/dect_phy_mac.c
1617
)

samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac.c

Lines changed: 119 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
#include "dect_phy_common.h"
1717
#include "dect_common_utils.h"
1818
#include "dect_common_pdu.h"
19+
#include "dect_phy_ctrl.h"
1920

2021
#include "dect_phy_mac_pdu.h"
2122
#include "dect_phy_mac_nbr.h"
2223
#include "dect_phy_mac_cluster_beacon.h"
24+
#include "dect_phy_mac_client.h"
2325
#include "dect_phy_mac.h"
2426

2527
/**************************************************************************************************/
@@ -135,6 +137,10 @@ static void dect_phy_mac_message_print(dect_phy_mac_message_type_t message_type,
135137
break;
136138
}
137139
case DECT_PHY_MAC_MESSAGE_TYPE_CLUSTER_BEACON: {
140+
int beacon_interval_ms = dect_phy_mac_pdu_cluster_beacon_period_in_ms(
141+
message->cluster_beacon.cluster_beacon_period);
142+
uint64_t beacon_interval_mdm_ticks = MS_TO_MODEM_TICKS(beacon_interval_ms);
143+
138144
desh_print(" Received cluster beacon:");
139145
desh_print(" System frame number: %d",
140146
message->cluster_beacon.system_frame_number);
@@ -178,9 +184,8 @@ static void dect_phy_mac_message_print(dect_phy_mac_message_type_t message_type,
178184
desh_print(" Network Beacon period %d ms",
179185
dect_phy_mac_pdu_nw_beacon_period_in_ms(
180186
message->cluster_beacon.nw_beacon_period));
181-
desh_print(" Cluster Beacon period %d ms",
182-
dect_phy_mac_pdu_cluster_beacon_period_in_ms(
183-
message->cluster_beacon.cluster_beacon_period));
187+
desh_print(" Cluster Beacon period %d ms (%lld mdm ticks)",
188+
beacon_interval_ms, beacon_interval_mdm_ticks);
184189
desh_print(" Count to trigger: %d (coded value)",
185190
message->cluster_beacon.count_to_trigger);
186191
desh_print(" Relative quality: %d (coded value)",
@@ -280,61 +285,127 @@ static void dect_phy_mac_message_print(dect_phy_mac_message_type_t message_type,
280285
}
281286
}
282287

288+
static void dect_phy_mac_type_header_print(dect_phy_mac_type_header_t *type_header)
289+
{
290+
char tmp_str[128] = {0};
291+
292+
desh_print(" DECT NR+ MAC PDU:");
293+
desh_print(" MAC header:");
294+
desh_print(" Version: %d", type_header->version);
295+
desh_print(" Security: %s",
296+
dect_phy_mac_pdu_security_to_string(type_header->version, tmp_str));
297+
desh_print(" Type: %s",
298+
dect_phy_mac_pdu_header_type_to_string(type_header->type, tmp_str));
299+
}
300+
301+
static void dect_phy_mac_common_header_print(dect_phy_mac_type_header_t *type_header,
302+
dect_phy_mac_common_header_t *common_header)
303+
{
304+
if (type_header->type == DECT_PHY_MAC_HEADER_TYPE_BEACON) {
305+
desh_print(" Network ID (24bit MSB): %u (0x%06x)", common_header->nw_id,
306+
common_header->nw_id);
307+
desh_print(" Transmitter ID: %u (0x%08x)",
308+
common_header->transmitter_id, common_header->transmitter_id);
309+
} else {
310+
desh_print(" Reset: %s", (common_header->reset > 0) ? "yes" : "no");
311+
desh_print(" Seq Nbr: %u", common_header->seq_nbr);
312+
313+
if (type_header->type == DECT_PHY_MAC_HEADER_TYPE_UNICAST) {
314+
desh_print(" Receiver: %u (0x%08x)", common_header->receiver_id,
315+
common_header->receiver_id);
316+
desh_print(" Transmitter: %u (0x%08x)", common_header->transmitter_id,
317+
common_header->transmitter_id);
318+
} else if (type_header->type == DECT_PHY_MAC_HEADER_TYPE_BROADCAST) {
319+
desh_print(" Transmitter: %u (0x%08x)", common_header->transmitter_id,
320+
common_header->transmitter_id);
321+
}
322+
}
323+
}
324+
325+
static void dect_phy_mac_mux_header_print(dect_phy_mac_mux_header_t *mux_header)
326+
{
327+
char tmp_str[128] = {0};
328+
329+
desh_print(" MAC MUX header:");
330+
desh_print(" IE type: %s", dect_phy_mac_pdu_ie_type_to_string(
331+
mux_header->mac_ext, mux_header->payload_length,
332+
mux_header->ie_type, tmp_str));
333+
desh_print(" Payload length: %u", mux_header->payload_length);
334+
if (mux_header->ie_type == DECT_PHY_MAC_IE_TYPE_EXTENSION) {
335+
desh_print(" IE extension: 0x%02x", mux_header->ie_ext);
336+
}
337+
}
338+
339+
static void dect_phy_mac_sdu_print(dect_phy_mac_sdu_t *sdu_list_item, int sdu_nbr)
340+
{
341+
desh_print(" SDU %u:", sdu_nbr);
342+
dect_phy_mac_mux_header_print(&sdu_list_item->mux_header);
343+
dect_phy_mac_message_print(sdu_list_item->message_type, &sdu_list_item->message);
344+
}
345+
283346
bool dect_phy_mac_handle(struct dect_phy_commmon_op_pdc_rcv_params *rcv_params)
284347
{
285348
dect_phy_mac_type_header_t type_header;
286349
bool handled = false;
287350
uint8_t *data_ptr = rcv_params->data;
288351
uint32_t data_len = rcv_params->data_length;
352+
bool print = false;
289353

290354
handled = dect_phy_mac_pdu_type_header_decode(data_ptr, data_len, &type_header);
291355
if (!handled) {
292356
return false;
293357
}
294358

359+
/* Print only if:
360+
* - client is associating/associated with the target device and
361+
* the received message is not a beacon from target
362+
* - beacon scan / rx cmd is ongoing
363+
* - beacon tx ongoing and we have announced RA resources.
364+
*/
365+
if (dect_phy_mac_client_associated_by_target_short_rd_id(
366+
rcv_params->last_received_pcc_transmitter_short_rd_id) &&
367+
type_header.type != DECT_PHY_MAC_HEADER_TYPE_BEACON) {
368+
print = true;
369+
}
370+
if (dect_phy_ctrl_rx_is_on_going()) {
371+
print = true;
372+
}
373+
if (dect_phy_mac_cluster_beacon_is_running()) {
374+
print = true;
375+
}
376+
295377
const uint8_t *p_ptr = data_ptr + 1;
296378
struct nrf_modem_dect_phy_rx_pdc_status *p_rx_status = &(rcv_params->rx_status);
297379
dect_phy_mac_common_header_t common_header;
298380
int16_t rssi_level = p_rx_status->rssi_2 / 2;
299-
char tmp_str[128] = {0};
300381

301-
desh_print("PDC received (stf start time %llu): snr %d, RSSI-2 %d (RSSI %d), len %d",
302-
rcv_params->time, p_rx_status->snr, p_rx_status->rssi_2, rssi_level,
303-
rcv_params->data_length);
382+
if (print) {
383+
desh_print("PDC received (stf start time %llu): snr %d, "
384+
"RSSI-2 %d (RSSI %d), len %d",
385+
rcv_params->time, p_rx_status->snr, p_rx_status->rssi_2, rssi_level,
386+
rcv_params->data_length);
387+
388+
dect_phy_mac_type_header_print(&type_header);
389+
}
304390

305-
desh_print(" DECT NR+ MAC PDU:");
306-
desh_print(" MAC header:");
307-
desh_print(" Version: %d", type_header.version);
308-
desh_print(" Security: %s",
309-
dect_phy_mac_pdu_security_to_string(type_header.version, tmp_str));
310-
desh_print(" Type: %s",
311-
dect_phy_mac_pdu_header_type_to_string(type_header.type, tmp_str));
312391
/* Then continue on: ch. 6.3.3, MAC Common header */
313392
handled = dect_phy_mac_pdu_common_header_decode(p_ptr, data_len - 1, &type_header,
314393
&common_header);
315394
if (!handled) {
395+
/* In failure, we want to print what we got */
396+
if (!print) {
397+
desh_print("PDC received (stf start time %llu): snr %d, "
398+
"RSSI-2 %d (RSSI %d), len %d",
399+
rcv_params->time, p_rx_status->snr, p_rx_status->rssi_2, rssi_level,
400+
rcv_params->data_length);
401+
}
316402
desh_error("Failed to decode MAC Common header");
317403
return false;
318404
}
319-
if (type_header.type == DECT_PHY_MAC_HEADER_TYPE_BEACON) {
320-
desh_print(" Network ID (24bit MSB): %u (0x%06x)", common_header.nw_id,
321-
common_header.nw_id);
322-
desh_print(" Transmitter ID: %u (0x%08x)",
323-
common_header.transmitter_id, common_header.transmitter_id);
324-
} else {
325-
desh_print(" Reset: %s", (common_header.reset > 0) ? "yes" : "no");
326-
desh_print(" Seq Nbr: %u", common_header.seq_nbr);
327-
328-
if (type_header.type == DECT_PHY_MAC_HEADER_TYPE_UNICAST) {
329-
desh_print(" Receiver: %u (0x%08x)", common_header.receiver_id,
330-
common_header.receiver_id);
331-
desh_print(" Transmitter: %u (0x%08x)", common_header.transmitter_id,
332-
common_header.transmitter_id);
333-
} else if (type_header.type == DECT_PHY_MAC_HEADER_TYPE_BROADCAST) {
334-
desh_print(" Transmitter: %u (0x%08x)", common_header.transmitter_id,
335-
common_header.transmitter_id);
336-
}
405+
if (print) {
406+
dect_phy_mac_common_header_print(&type_header, &common_header);
337407
}
408+
338409
sys_dlist_t sdu_list;
339410
uint8_t header_len = dect_phy_mac_pdy_type_n_common_header_len_get(type_header.type);
340411
uint8_t *payload_ptr = rcv_params->data + header_len;
@@ -348,43 +419,40 @@ bool dect_phy_mac_handle(struct dect_phy_commmon_op_pdc_rcv_params *rcv_params)
348419
} else {
349420
dect_phy_mac_cluster_beacon_t *beacon_msg = NULL;
350421
dect_phy_mac_random_access_resource_ie_t *ra_ie = NULL;
422+
dect_phy_mac_association_resp_t *association_resp = NULL;
351423
uint32_t sdu_count = 0;
352424

353425
SYS_DLIST_FOR_EACH_CONTAINER(&sdu_list, sdu_list_item, dnode) {
354-
desh_print(" SDU %u:", ++sdu_count);
355-
desh_print(" MAC MUX header:");
356-
desh_print(" IE type: %s",
357-
dect_phy_mac_pdu_ie_type_to_string(
358-
sdu_list_item->mux_header.mac_ext,
359-
sdu_list_item->mux_header.payload_length,
360-
sdu_list_item->mux_header.ie_type, tmp_str));
361-
desh_print(" Payload length: %u",
362-
sdu_list_item->mux_header.payload_length);
363-
if (sdu_list_item->mux_header.ie_type == DECT_PHY_MAC_IE_TYPE_EXTENSION) {
364-
desh_print(" IE extension: 0x%02x",
365-
sdu_list_item->mux_header.ie_ext);
426+
if (print) {
427+
dect_phy_mac_sdu_print(sdu_list_item, ++sdu_count);
366428
}
367-
dect_phy_mac_message_print(sdu_list_item->message_type,
368-
&sdu_list_item->message);
429+
369430
if (sdu_list_item->message_type ==
370431
DECT_PHY_MAC_MESSAGE_TYPE_CLUSTER_BEACON) {
371432
beacon_msg = &sdu_list_item->message.cluster_beacon;
372433
} else if (sdu_list_item->message_type ==
373434
DECT_PHY_MAC_MESSAGE_RANDOM_ACCESS_RESOURCE_IE) {
374-
/* Note: there could be many of these, this takes only the last */
435+
/* Note: there could be many of these,
436+
* but this takes only the last
437+
*/
375438
ra_ie = &sdu_list_item->message.rach_ie;
439+
} else if (sdu_list_item->message_type ==
440+
DECT_PHY_MAC_MESSAGE_TYPE_ASSOCIATION_RESP) {
441+
association_resp = &sdu_list_item->message.association_resp;
376442
}
377443
}
378-
/* If received cluster beacon with RA IE,
379-
* store as a neighbor
380-
*/
444+
/* If received cluster beacon with RA IE, store as a neighbor */
381445
if (beacon_msg != NULL && ra_ie != NULL) {
382446
dect_phy_mac_nbr_info_store_n_update(
383447
&rcv_params->time, rcv_params->last_rx_op_channel,
384448
common_header.nw_id, rcv_params->last_received_pcc_short_nw_id,
385449
common_header.transmitter_id,
386450
rcv_params->last_received_pcc_transmitter_short_rd_id, beacon_msg,
387-
ra_ie); /* Storing only the last */
451+
ra_ie, /* Note: storing only the last RA IE */
452+
print);
453+
}
454+
if (association_resp != NULL) {
455+
dect_phy_mac_client_associate_resp_handle(&common_header, association_resp);
388456
}
389457
}
390458
/* Remove all nodes from the list and dealloc */

0 commit comments

Comments
 (0)