Skip to content

Commit

Permalink
enable BBR to support multicast registration in non commercial networ…
Browse files Browse the repository at this point in the history
…ks (ARMmbed#1509)

pbbr can be started in two modes depending the settings
Multicast support in home network
DUA support with backbone queries in commercial network
NMKP and relay enabled in commercial network only

Fixed TRI uri for latest specification
  • Loading branch information
Mika Tervonen authored Dec 7, 2017
1 parent 4ea2bf8 commit eeb2d39
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions source/6LoWPAN/Thread/thread_extension_bbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,15 @@ static int thread_extension_bbr_pbbr_stop(thread_pbbr_t *this)

coap_service_unregister_uri(this->coap_service_id, THREAD_URI_BBR_TRI_RX_NTF);
coap_service_unregister_uri(this->coap_service_id, THREAD_URI_BBR_NMK_RX_NTF);
coap_service_unregister_uri(this->coap_service_id, THREAD_URI_BBR_DOMAIN_ADDRESS_REGISTRATION);
coap_service_unregister_uri(this->coap_service_id, THREAD_URI_BBR_MCAST_LISTENER_REPORT);

coap_service_delete(this->br_bb_service_id);
this->br_bb_service_id = -1;

coap_service_delete(this->coap_nmkp_virtual_service_id);
this->coap_nmkp_virtual_service_id = -1;

this->pbbr_started = false;
return 0;
}
Expand All @@ -856,39 +862,46 @@ static int thread_extension_bbr_pbbr_start(thread_pbbr_t *this)
//If started only refresh network data
return 0;
}
// Register Primary BBR backbone multicast address
// Allow only filtered addresses to be forwarded
multicast_fwd_full_for_scope(this->interface_id, 0x10);
//multicast_fwd_full_for_scope(this->backbone_interface_id, 0x10);

//Register baseline 1.2 features
coap_service_register_uri(this->coap_service_id, THREAD_URI_BBR_MCAST_LISTENER_REPORT, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_extension_bbr_mlr_cb);
this->pbbr_started = true;

// Generate pbbr multicast address
memset(this->pbbr_multicast_address, 0, 16);
this->pbbr_multicast_address[0] = 0xff;
this->pbbr_multicast_address[1] = 0x30 | 3; //Thread specification says p and t bits are 1 Scope is 3
this->pbbr_multicast_address[2] = 0x00; //Reserved
this->pbbr_multicast_address[3] = 0x40; //Prefix length 64 bits
this->pbbr_multicast_address[15] = 2;
if (0 != thread_extension_network_prefix_get(this->interface_id, NULL, &this->pbbr_multicast_address[4], NULL)) {
//No domain prefix in settings
tr_warn("invalid config");
return -1;
//No domain prefix in settings DUA handling not used
tr_info("pBBR service started (Home network)");
return 0;
}
tr_info("pBBR service started (Commercial network)");
// Start commercial mode features
multicast_add_address(this->pbbr_multicast_address, false);

this->pbbr_multicast_address[15] = 2;

// Register to backbone CoAP URIs
// Register to backbone CoAP service
this->br_bb_service_id = coap_service_initialize(this->backbone_interface_id, this->pbbr_port, COAP_SERVICE_OPTIONS_SELECT_SOCKET_IF, NULL, NULL);
if(this->br_bb_service_id < 0) {
tr_error("pBBR service start failed");
tr_error("pBBR Commercial service start failed");
thread_extension_bbr_pbbr_stop(this);
return -1;
}
multicast_add_address(this->pbbr_multicast_address, false);
// Allow only filtered addresses to be forwarded
multicast_fwd_full_for_scope(this->interface_id, 0x10);
multicast_fwd_full_for_scope(this->backbone_interface_id, 0x10);
// Register Primary BBR backbone multicast address

// Register commercial features
coap_service_register_uri(this->br_bb_service_id, THREAD_URI_BBR_BB_QRY_NTF, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_pbbr_bb_qry_cb);
coap_service_register_uri(this->br_bb_service_id, THREAD_URI_BBR_BB_ANS_NTF, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_pbbr_bb_ans_cb);
coap_service_register_uri(this->br_bb_service_id, THREAD_URI_TRI_TX_NTF, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_pbbr_relay_from_tri_cb);
coap_service_register_uri(this->br_bb_service_id, THREAD_URI_BBR_BMLR_NTF, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_extension_bbr_bmlr_cb);

// Register Mesh address registration URI
coap_service_register_uri(this->coap_service_id, THREAD_URI_BBR_MCAST_LISTENER_REPORT, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_extension_bbr_mlr_cb);
coap_service_register_uri(this->coap_service_id, THREAD_URI_BBR_BMLR_NTF, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_extension_bbr_bmlr_cb);
coap_service_register_uri(this->coap_service_id, THREAD_URI_BBR_DOMAIN_ADDRESS_REGISTRATION, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_extension_bbr_dua_cb);
// Register Mesh side relay URI
coap_service_register_uri(this->coap_service_id, THREAD_URI_BBR_TRI_RX_NTF, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_pbbr_relay_to_tri_cb);
Expand All @@ -901,8 +914,6 @@ static int thread_extension_bbr_pbbr_start(thread_pbbr_t *this)
coap_service_register_uri(this->coap_nmkp_virtual_service_id, THREAD_URI_BBR_NMKP_REQ, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_pbbr_nmkp_req_recv_cb);
coap_service_virtual_socket_set_cb(this->coap_nmkp_virtual_service_id, thread_pbbr_nmkp_virtual_socket_send_cb);
// Set the partition weight to be 72
tr_info("pBBR service started");
this->pbbr_started = true;
return 0;
}

Expand Down Expand Up @@ -935,6 +946,8 @@ int8_t thread_extension_bbr_init(int8_t interface_id, int8_t backbone_interface_
memcpy(this->tri_address,ADDR_LINK_LOCAL_ALL_ROUTERS,16);
this->tri_port = THREAD_BBR_BACKBONE_PORT;
this->joiner_router_rloc = 0xffff;
this->coap_nmkp_virtual_service_id = -1;
this->br_bb_service_id = -1;

this->coap_service_id = coap_service_initialize(this->interface_id, THREAD_MANAGEMENT_PORT, COAP_SERVICE_OPTIONS_NONE, NULL, NULL);
if (this->coap_service_id < 0) {
Expand All @@ -944,11 +957,6 @@ int8_t thread_extension_bbr_init(int8_t interface_id, int8_t backbone_interface_
}
ns_list_add_to_start(&pbbr_instance_list, this);

if (0 != thread_extension_network_prefix_get(this->interface_id, NULL, NULL, NULL)) {
// Not in Commercial network
return 0;
}

return 0;
}

Expand Down Expand Up @@ -1001,10 +1009,6 @@ void thread_extension_bbr_seconds_timer(int8_t interface_id, uint32_t seconds)
return;
}

if (0 != thread_extension_network_prefix_get(this->interface_id, NULL, NULL, NULL)) {
// Not in commercial network
return;
}
protocol_interface_info_entry_t *cur;
cur = protocol_stack_interface_info_get_by_id(this->interface_id);
if (!cur) {
Expand Down Expand Up @@ -1033,6 +1037,12 @@ void thread_extension_bbr_seconds_timer(int8_t interface_id, uint32_t seconds)

thread_extension_bbr_pbbr_start(this);
} else {
if(this->br_bb_service_id < 0 &&
thread_extension_network_prefix_get(cur->id, NULL, NULL, NULL) == 0) {
// Settings changed to commercial
thread_extension_bbr_pbbr_stop(this);
thread_extension_bbr_pbbr_start(this);
}
if (thread_extension_bbr_downgrade_to_secondary(cur)) {
tr_info("pbbr downgraded");
thread_extension_bbr_pbbr_stop(this);
Expand Down

0 comments on commit eeb2d39

Please sign in to comment.