@@ -490,6 +490,101 @@ static bool deliver_model_data(struct mesh_element* element, uint16_t src,
490
490
return false;
491
491
}
492
492
493
+ static struct mesh_model * find_model_by_pub_addr (uint32_t addr )
494
+ {
495
+ GList * n ;
496
+ GList * e ;
497
+ GList * m ;
498
+ struct mesh_node * node ;
499
+ struct mesh_element * element ;
500
+ struct mesh_model * model ;
501
+ struct mesh_publication * pub ;
502
+
503
+ for (n = nodes ; n ; n = n -> next ) {
504
+ node = n -> data ;
505
+ for (e = node -> elements ; e ; e = e -> next ) {
506
+ element = e -> data ;
507
+ for (m = element -> models ; m ; m = m -> next ) {
508
+ model = m -> data ;
509
+ if (model ) {
510
+ pub = model -> pub ;
511
+ if (pub ) {
512
+ if (addr == pub -> u .addr16 )
513
+ return model ;
514
+ }
515
+ }
516
+ }
517
+ }
518
+ }
519
+
520
+ return NULL ;
521
+ }
522
+
523
+ static char * group_addr_type_data_to_json (uint32_t id , uint16_t src , uint32_t dst ,
524
+ uint32_t opcode , uint8_t * data , uint16_t len )
525
+ {
526
+ char * json_data ;
527
+ int json_len ;
528
+ int json_i ;
529
+ int data_i ;
530
+
531
+ json_len = 80 + (4 * len - 1 );
532
+ json_data = (char * ) g_malloc0 (json_len );
533
+ memset (json_data , 0 , json_len );
534
+
535
+ json_i = snprintf (& json_data [0 ], json_len ,
536
+ "{"
537
+ "\"id\":\"%4.4x\","
538
+ "\"source\":\"%4.4x\","
539
+ "\"dest\":\"%4.4x\","
540
+ "\"opcode\":\"%4.4x\","
541
+ "\"data\":[" ,
542
+ id , src , dst , opcode );
543
+
544
+ for (data_i = 0 ; data_i < len ; data_i ++ )
545
+ json_i += snprintf (& json_data [json_i ], json_len - json_i , "\"%2.2x\"," , data [data_i ]);
546
+
547
+ // Remove the last ','
548
+ if (len > 0 )
549
+ json_i -- ;
550
+
551
+ json_data [json_i ++ ] = ']' ;
552
+ json_data [json_i ++ ] = '}' ;
553
+ json_data [json_i ] = 0 ;
554
+
555
+ return json_data ;
556
+ }
557
+ static bool deliver_group_addr_type_data (uint16_t src , uint32_t dst ,
558
+ uint16_t app_idx , uint8_t * data , uint16_t len )
559
+ {
560
+ struct mesh_model * model ;
561
+ char * json_data ;
562
+ uint32_t id ;
563
+ uint32_t opcode ;
564
+ int n ;
565
+
566
+ bt_shell_printf ("Group Addr Msg:"
567
+ "src = %4.4x, dst = %4.4x \n" , src , dst );
568
+
569
+ model = find_model_by_pub_addr (dst );
570
+ if (!model )
571
+ return false;
572
+
573
+ id = model -> id & 0xFFFF ;
574
+
575
+ if (mesh_opcode_get (data , len , & opcode , & n )) {
576
+ len -= n ;
577
+ data += n ;
578
+ } else
579
+ return false;
580
+
581
+ json_data = group_addr_type_data_to_json (id , src , dst , opcode , data , len );
582
+ bt_shell_printf ("[PubCaptured]:%s\n" , json_data );
583
+ free (json_data );
584
+
585
+ return true;
586
+ }
587
+
493
588
void node_local_data_handler (uint16_t src , uint32_t dst ,
494
589
uint32_t iv_index , uint32_t seq_num ,
495
590
uint16_t app_idx , uint8_t * data , uint16_t len )
@@ -544,6 +639,7 @@ void node_local_data_handler(uint16_t src, uint32_t dst,
544
639
545
640
if (IS_GROUP (dst ) || IS_VIRTUAL (dst )) {
546
641
/* TODO: if subscription address, deliver to subscribers */
642
+ deliver_group_addr_type_data (src , dst , app_idx , data , len );
547
643
return ;
548
644
}
549
645
0 commit comments