# Identifying Misbehaving Greedy Nodes in IoT Networks
## 3 Selfish Behaviour in IEEE 802.15.4
### Greedy Behaviour Algorithm  
Before explaining the operation of the greedy node, it is necessary to present the algorithm of the unslotted CSMA/CA protocol, since the greedy node falsifies several parameters of the protocol in order to gain bandwidth. The main parameters used in unslotted CSMA/CA are:  
* Backoff Exponent (BE): It is a value used in the calculation of the backoff delay.
* Clear Channel Assessment (CCA): The CCA is performed by each node in the network in order to check if the channel is free before transmitting. The CCA duration is equal to 8 symbols.
* Number of Backoff (NB): It is a counter of the number of failed channel access attempts.
* MacMinBE: It is the minimum value of BE. This value varies between 0 and 3. By default, CSMA/CA uses 3.
* MacMaxBE: It is the maximum value of BE. It is equal to 5.
* MacMaxCSMABackoffs: It is the maximum number of attempts to access the channel.
* UnitBackoffPeriod: It is equal to 20 symbols by default.  
In order to ensure the equitable sharing of the medium, unslotted CSMA/CA carries out the following steps. The first step is to initialize the parameters NB to 0, and BE to MacMinBE. Then, a backoff period is calculated in the second step in order to avoid collisions. The algorithm randomly chooses a value in the interval (0, (\(2^{\text{BE}}~{}-~{}1\))). This value is multiplied by UnitBackoffPeriod to obtain the duration of the backoff.  
The third step of the algorithm is the CCA procedure. If after the execution of a CCA the channel is free, the node starts sending its packets by executing the fifth step of the CSMA/CA algorithm. Otherwise, it is the fourth step which is executed and which consists in incrementing NB by 1, and assigning to BE the minimum value between BE+1 and MacMaxBE. If NB has reached its maximum value MacMaxCSMABackoffs, the packet is dropped, and an error message is transmitted to the upper layer. Otherwise, go to step 2, i.e., recalculate the backoff period.  
The fifth step is the transmission of the packets, after having checked that the channel is free by the CCA procedure. Note that collisions can occur at this stage if two or more nodes are transmitting at the same time.  
The ultimate goal of the greedy node is to monopolize the transmission channel in order to deprive other legitimate nodes from transmitting their packets. For this, the greedy node tries to increase its chances of accessing the channel compared to other legitimate nodes of the network, and doing this by reducing both its backoff period and the duration of the CCA, and by increasing its attempts to access to the medium. For this purpose, the UnitBackoffPeriod parameter is divided by 4. It will therefore be equal to only 5 symbols instead of 20. Then, the two parameters, MacMinBE and MacMaxBE, will be respectively equal to 0 and 1. Therefore, the value of BE will vary between 0 and 1. Hence, the maximum duration of the backoff executed by the greedy node will be 80 us (5 symbols). The duration of the CCA is also divided by 4, and will therefore be equal to 2 symbols. Finally, the number of channel access attempts is doubled by doubling the MacMaxCSMSBackoff value which will be equal to 10 instead of 5.  
The Figure 1 demonstrates the difference between the CSMA/CA algorithm of a legitimate and greedy node.