## 4 The Proposed Protocol
### The Protocol Design
#### 4.2.2 Direct Firmware Update Distribution  
Four entities are involved in this protocol. They are the OCF device, IoT gateway, smart contract, and manufacturer. As shown in Figure 4, the distribution begins when the client initiates the update process to the OCF device. We put the detailed explanation of the direct firmware update protocol below:  
* _OCF device: initiate the firmware update._ First, the client will observe the state of softwareupgrade and pstat resource--whether it is idle or not. If softwareupgrade resource's state is idle and pstat resource's cm value is 0, the client will set the package URL (\(purl\)) in the softwareupgrade. This action will trigger the firmware update process by setting the pstat state's value to \"initiate secure software update.\" Then, pstat will forward it to the softwareupgrade. After the state of softwareupgrade and pstat show that it is ready to continue the process, the softwareupgrade resource will check if there is new firmware update by sending the \(purl\) and the current firmware version as parameters to the IoT gateway. \begin{table}
\begin{tabular}{c c} \hline \hline
**Name** & **Description** \\ \hline \(U_{id}\) & The update identifier \\ \(U_{bin}\) & Binary file of the new firmware update \\ \(f_{v}\) & Newest firmware version \\ \(M_{id}\) & The manufacturer identifier \\ \(dtype\) & The device type \\ \(purl\) & The package URL of the firmware update file \\ \(SK_{m}\) & Manufacturer’s secret key \\ \(SK_{g}\) & IoT gateway’s secret key \\ \(M_{sc}\) & Manufacturer’s smart contract \\ \hline \hline \end{tabular}
\end{table} 
Table 1: The notation in the proposed protocol. Figure 3: Creation of the firmware update smart contract. * _Check the firmware update to the smart contract and download the firmware update from the manufacturer._ After receiving an update request from the OCF device, the IoT gateway will check the newest firmware update to the smart contract (\(M_{sc}\)) for this particular device by sending the \(U_{id}\). If there is a firmware update contract for the device, \(M_{sc}\) will reply with the signed U that is stored in the contract to the IoT gateway. The IoT gateway will receive this message and verify the signature. If valid, it will send the signed \(U_{id}\) to the manufacturer to request the binary file. Then, the manufacturer will verify the signature. If verified, it will reply with the binary file (\(U_{bin}\)) to the IoT gateway. The IoT gateway will verify the binary file by comparing the hash value of \(U_{bin}\) and the \(U_{id}\) value from the manufacturer. If they are equal, the IoT gateway will send a notification to the OCF device. Figure 4: Direct firmware update distribution: gateway downloading a new firmware update from the manufacturer. * _OCF device: downloading and upgrading_. On the OCF device's side, as shown in Figure 1, the softwareupgrade resource will notify the pstat resource and the client of a new software update by sending NSA state. The pstat will set the cm value to \"new software available\" and notify the client. Moreover, the pstat will set its internal state of tm to \"initiate software version validation.\" Later, the pstat will relay this state to the client and change the cm value to \"software version validation.\" Subsequently, the pstat will notify the state's changing to softwareupgrade. Then, the softwareupgrade will inform the state's changing to the client by sending SVV as its state value. In the next step, the OCF IoT device will send \"retrieve the package\" request to the IoT gateway through the softwareupgrade resource. After the package has been downloaded, the softwareupgrade resource will send SVA state to the pstat resource and client. The pstat will set the cm value to \"valid version available.\" Afterward, it will set its internal \"initiate secure software update\" state and send the same state to the softwareupgrade. In order to upgrade the firmware, the pstat and softwareupgrade will send the upgrading state to the client.