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+
283346bool 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