## 3 Security Level
### Dynamic Selection of Cluster Heads  
Based on what was explained at the beginning of this section, what the 6 LoWPAN protocol does is connect WSN nodes in the network to each other and send data to an AP using the RPL routing protocol [8]. This protocol (RPL) divides the network topology on a hierarchical basis, where the AP is the top of the hierarchy and the level of the WSN nodes continues to decrease until it reaches the final nodes (maximum). All WSN nodes in Standard 6 LoWPAN have the same tasks and priority, but they differ in the level of permission to transfer data. As WSN nodes near the AP allow data from all lower levels, as well as their own data, to be passed to the AP. Moreover, since we propose to improve QoS, save energy and maintain WSN security, we will use cluster technology between WSN nodes. In addition, we will modify the RPL routing protocol to cover only interconnected CH nodes. Furthermore, the choice of CH will depend on several different factors, the most important of which is that the candidate WSN node must belong to the trusted nodes. Other factors are the residual power in the node, the number of adjacent nodes and the distance between the adjacent CH nodes. The proposed process of selecting the CH node is as follows:  
1. The radio frequency computing power (\(P\)) model for the proposed is based on [21]. As most of the energy consumption of the WSN nodes is caused by the correspondence between them. Moreover, distance affects how much power is consumed for both WSN nodes (transmitter and receiver). The relationship based on the power consumption of the transmitter and receiver with distance and message size is shown in Equation (7) [17]. \[P_{TX}(q,d)=P_{TX-{\it{elec}}}(q)\times P_{TX-{\it{amp}}}(q,d)\] (7) where \(q\) is the message size, \(d\) is the distance between transmitter and receiver, \(P_{TX}\) is the total power consumption through sending \(q\) over distance \((d)\), \(P_{TX-{\it{elec}}}\) is the node transmitter circuit consumption based on \(q\) size and \(P_{TX-{\it{amp}}}\) is the node transmitter  
Figure 4: Flowchart of security procedure in WSN nodes. circuit consumption based on signal amplification. Moreover, the \(P_{TX-amp}\) will be equal to either \(\beta_{fsm}\) for a free space model or to \(\beta_{trm}\) for the two-ray grounded propagation models depending on the \(d\) between the transmitter and receiver. Moreover, the WSN node is responsible for receiving data messages from other nodes. Equation (8) [17] can be used to compute the power \(P_{RX}\) needed to receive \(q\) the message: \[P_{RX}(q)=P_{RX-elec}(q)=P_{elec}\times q\] (8) where \(P_{RX}\) is the power consumed when the node receives the message, \(P_{elec}\) is the power expanded by transmitter and receiver in \(\mathrm{nJ}/\mathrm{bit}\) and \(P_{RX-elec}\) is the power dissipated by the receiving node in the reception of \(q\). 2. The WSN node energy threshold \((Th)\) Since the CH node works centrally to the neighboring WSN nodes, the power consumption and computations will be higher, thus we must keep the node from collapsing by choosing the \(Th\) value. If the node energy reaches that value, it will be excluded from running for the CH position. Moreover, if it is also in this position and the amount of energy falls below the \(Th\) value, it is also replaced. This factor balances energy consumption between the nodes and maintains the lifetime of the entire network. The \((Th)\) for each WSN node is calculated in Equation (9) [17]. \[Th(n)=N_{adj}\times q\times P_{elec}+N_{adj}\times q\times[P_{elec}+\beta_{fsm} ]\times d^{2}\] (9) where \(Th(n)\) is the power threshold of a node, \(N_{adj}\) is the number of neighbouring nodes and \(\beta_{fsm}\) is a free space model. Furthermore, each node (\(N\)) sends the identifier (ID) and power level to all trusted nodes by _data_message_ which is used to compute and update the table of trusted nodes in each session. 3. The average of the set of interactive factors. The number of adjacent nodes (\(\alpha\)) for each trusted node.