Skip to content

Commit c6f561f

Browse files
committed
Use balcklist for the mesh proxy service and add logging support of mesh pdu(dest is group address)
1 parent 8994b7f commit c6f561f

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,5 @@ android/test-*.trs
166166
cscope.in.out
167167
cscope.out
168168
cscope.po.out
169+
170+
.vscode/*

mesh/net.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,20 @@ static void setup_whitelist()
953953
net_ctl_msg_send(0, 0, 0, white.data, white.len);
954954
}
955955

956+
static void setup_blacklist()
957+
{
958+
struct build_whitelist white;
959+
960+
white.len = 0;
961+
962+
/* Enable (and Clear) Proxy Whitelist */
963+
white.data[white.len++] = FILTER_SETUP;
964+
white.data[white.len++] = BLACKLIST_FILTER;
965+
966+
net_ctl_msg_send(0, 0, 0, white.data, white.len);
967+
}
968+
969+
956970
static void beacon_update(bool first, bool iv_update, uint32_t iv_index)
957971
{
958972

@@ -1002,7 +1016,8 @@ static void beacon_update(bool first, bool iv_update, uint32_t iv_index)
10021016

10031017
if (first) {
10041018
/* Must be done once per Proxy Connection after Beacon RXed */
1005-
setup_whitelist();
1019+
// setup_whitelist();
1020+
setup_blacklist();
10061021
if (net.open_cb)
10071022
net.open_cb(0);
10081023
}

mesh/node.c

+96
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,101 @@ static bool deliver_model_data(struct mesh_element* element, uint16_t src,
490490
return false;
491491
}
492492

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+
493588
void node_local_data_handler(uint16_t src, uint32_t dst,
494589
uint32_t iv_index, uint32_t seq_num,
495590
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,
544639

545640
if (IS_GROUP(dst) || IS_VIRTUAL(dst)) {
546641
/* TODO: if subscription address, deliver to subscribers */
642+
deliver_group_addr_type_data(src, dst, app_idx, data, len);
547643
return;
548644
}
549645

0 commit comments

Comments
 (0)