# An Efficient Adaptive Data-Link-Layer Architecture for LoRa Networks
## 4 Data Link Layer Design
### MAC Protocol
The method used to allocate slots to the end nodes is exemplified in Figure 6. This method starts by spreading the transmissions as much as possible, and new slot allocations are intercalated between the previous ones. The admission control mechanism of the MAC protocol prevents the allocation of slots to new end nodes in the LoRa network when its maximum capacity is reached, i.e., when it would not be possible for an end node to make a transmission with the maximum ToA without overlapping with a new end node's allocation. A short end-node address (\(n\)) is attributed to each new node by the packet forwarder. The value starts from 1 and is increased at each new slot allocation request the packet forwarder receives. This address serves two purposes: it reduces the size of the data packets  
Figure 6: Timing for the configuration of end nodes. in comparison to the long end node address, and it identifies the position of the allocated slot inside the superframe according to Equation (7), where \(T_{slot}\) is the start of the slot (relative to the start of the superframe) and \(T_{s}\) is the superframe period. The exception for this equation is the value of \(T_{slot}\) for the first node (1), which is zero (i.e., the start of the superframe). The maximum value of \(n\) (i.e., the maximum number of end nodes supported by the network) is not restricted by Equation (7) but is limited by the admission control mechanism of the MAC protocol, as explained before. \[T_{slot}(n)=\left(\frac{n-0.5}{2^{floor(log_{2}(n-1))}}-1\right)*T_{s}\quad(s) \tag{7}\]  
Before the deployment of the network nodes, the application-specific parameter values obtained with the LoRa parameter calculator are configured into both the end nodes and the packet forwarders. Then, when the end nodes are turned on at their installation sites, they start by sending a slot allocation request in order to join the network. The developed MAC protocol defines two sets of uplink and downlink packets, one for the initial slot allocation and the other for the periodic data transmission and for the ACK packet feedback. The format of these packets can be observed in Figure 7.  
The allocation request packet is composed of two fields: packet type (slot allocation request) and the long end node address, which is unique for each device. The allocation response includes the following five fields: packet type (slot allocation response), the network address (each packet forwarder has one), the short end node address (attributed to the node by the packet forwarder, as described before), the superframe period, and the superframe synchronization field. The data packet contains the packet type (data), the network address, the short end-node address, the data (samples from its sensors), and an options field (used by the end nodes to request a response packet from the packet forwarder), whereas the ACK packet contains the packet type (ACK), the network address, the short end-node address, the superframe resynchronization field, and the updated parameter values (spreading factor and transmission power) calculated by the ADL mechanism. The superframe synchronization field of the allocation packet contains an offset value (time elapsed since the start of the superframe). Using this offset value, the time of reception of the allocation response and the short end-node address, the end node can determine the precise time to transmit each of its data packets using Equation (7). In a similar manner, the purpose of the superframe resynchronization field of the ACK packets is to prevent the end node from losing synchronization over extended periods due to clock drift. Figure 7: High-level description of the developed protocol.