# MTRSRP: Joint Design of Multi-Triangular Ring and Self-Routing Protocol for BLE Networks
## 4 The Proposed MTRSRP
### Multi-Triangular Ring Formation
#### Case 1: Only One B_inter and One B_intra Bridge exists between two piconets.
This phase is divided into node discovery (Step 1) and coordinator selection (Step 2). Step 1: Initially, each node randomly assumes the role of the advertiser or scanner and then switches roles after a specific duration, called the discovery timer T1, with a fixed  
Figure 4: An example of two interconnected triangular rings with dual inter-bridges for Case 3 networks. operational timer T2, meeting the maximum advertisement interval specified in the BLE 4.1 standard. The procedure involves advertisers broadcasting messages on channels 37, 38, and 39, which contain node IDs and neighbor counts. The scanning nodes receive these advertisement messages on channels 37, 38, and 39 and update their neighbor counts and tables accordingly. These neighbor counts and tables are then used in the next broadcast round. Initially, the neighbor count was set to zero. Algorithm 1 lists the pseudocode for the node discovery process. After exchanging information during the discovery cycle, any two nodes designate the node with the highest neighbor count as the master and the other as the slave. The master then collects information regarding the other nodes owned by the slave. ```
Input:\(N\) nodes are randomly deployed in a given area Output: Several masters are elected to own the neighbors' information Init: Start discovery timer \(T1\) while(\(T1>0\))  Nodes Start timer \(T2\) and randomly act as advertisers or scanners if(\(T2>0\)) if(Random_op = advertiser)  Advertising its own ID and the number of neighbors else  Scanning channels 37, 38, and 39 to update neighbor list endif else  Switch roles and repeat the above advertising and scanning process ifany two nodes exchange information with each other  Compare their neighbor lists ifthe node has the most neighbors, it becomes a master and resets timer \(T2\) else the node becomes a slave endif endif endif endwhile
```  
**Algorithm 1** Pseudocode of the node discovery process. Step 2: This step involves temporarily locking slaves to prevent them from establishing connection links and exchanging information with other nodes. Only the masters can re-enter the node discovery process from Step 1, competing for the master role based on higher neighbor counts and gathering information about the other nodes owned by the other master. Steps 1 and 2 are repeated until the final master, known as the coordinator, is determined at time T. The coordinator then possesses critical information about all other nodes in the network, including the timing, addresses, and number of nodes N. Algorithm 2 shows the pseudocode for the super-master selection process. (2) The scatternet formation phase:  
A two-stage selection scheme is proposed in this phase. First, the number of rings (\(Nr\)) is determined based on the number of nodes N, which is collected by the coordinator, and the relationship between the number of nodes and rings in the three cases. \(Nr\) is calculated using Equations (1)-(3). Subsequently, up to \(3\times N_{r}\) master nodes are selected, each with the highest number of neighbors, including the coordinator itself. Depending on the selected case, the coordinator computes a role table for each master node, records the roles of each node in the piconet, and distributes this table to each master node. This table contains information on B_intra and B_inter and the average distribution of slaves for each master in a piconet. From this table, the master nodes can send unicast connection request messages to the recorded members starting with the device with the smallest ID. This process establishes a piconet for each master and connects them to other masters in intra- and inter-ring scenarios, ultimately forming a scattered network. Algorithm 1 presents the pseudocode for the role allocation and formation process of the multi-ring network. Algorithm 2 presents the pseudocode for determining a coordinator and connecting the piconets to the multiple-ring networks.