# Research and Design of a Decentralized Edge-Computing-Assisted LoRa Gateway
## 3 Design of the EC-Assisted LoRa Gateway
### Edge Computing in the LoRa Gateway  
Using the LoRa gateway with edge computing capabilities, two modules were transferred from the network server to the LoRa gateway. Through network control (NC), which processes application packet data, and JS, which manages the connection operations of the  
Figure 2: LoRa gateway hardware system based on Zynq SoC.  
end devices using connection operations, the LoRa gateway generated and stored contextual data for the end devices. Conversely, the LoRa gateway required certain contextual data to perform application packet processing tasks.  
As shown in Figure 3, when the LoRa gateway receives a network request from an end device, it first verifies the legitimacy of the request. Then, the LoRa gateway creates session data for the end device, including DevAddr, two session keys, and some metadata. The LoRa gateway requests and creates a new block with a transaction containing these data. In the meantime, the LoRa gateway must produce and transmit a join accept message to the end device. The end device's successful acceptance of the join accept message shows that the join operation was successful. It may be sent from the network server to the LoRa gateway because the NC module is placed in the LoRa gateway, which is utilized for application data processing.  
Uplink Data Processing: When an end device reports application data, the NC processing module in the LoRa gateway divides the application into three parts: metadata, encrypted data, and the message integrity code (MIC) value. Then, the NC module checks the integrity of the application data by extracting the DevAddr field from the metadata and querying the session data of the end device to verify the authenticity of the MIC. If the MIC value of the application packet does not match, the packet is rejected. After the verification is passed, the LoRa gateway transmits the encrypted data applied by the end device to the network server. At the same time, the LoRa gateway must send an acknowledg message (ACK) to the end device, confirming that the application packet has been successfully received.  
Downlink Data Processing: When sending data to the end device, the network server first creates a new connection and encrypts the application data sent down. The encrypted data are then sent from the network server to the LoRa gateway. The LoRa gateway contains the downlink device application data packets, and the MIC value information is generated and calculated by the LoRa gateway, which is encapsulated in the NC module. When the end device reports data, the LoRa gateway obtains the target information of the end device, while the downlink application packets are sent to the end device through the wireless channel of the LoRa module.  
LoRa gateways that are deployed on near-end devices can improve the efficiency of cloud computing processing in the system by means of edge computing. Among them, the  
Figure 3: The EC-assisted LoRa Gateway workflow of data.  
LoRa gateway mainly handles the parsing and encapsulation of application packets from end devices and MIC calculations, which are no longer handled by the central cloud server. On the one hand, the computing resources in the LoRa gateway can be fully utilized to relieve the computing pressure in the cloud server, and at the same time, the LoRa gateway can perform pre-processing operations on the application data reported by the end devices, such as the verification of MIC, without affecting the processing of the cloud server or the transmission function of the application data.