# Adaptive Emergency Call Service for Disaster Management
## 4 Adaptive Multi-Hop Emergency Call Protocol: 5G-SOS
```
1:Input data: my srcID, emergency data, GPS localization, RSSI, \(T_{0}\), \(RS_{\text{threshold}}\), \(I_{\text{TRP}}\), RIV, MCS, \(n_{0}\)
2:DATA.content \(\in\) [emergency data, localization, RSSI] Generation
3:DATA.srcID = my srcID, DATA.callID = callIDGenerator()
4:if I am out of coverage then
5: nbAttempts=0
6:repeat
7: send PSCCH with \(I_{\text{TRP}}\), RIV, MCS
8: send DATA by PSSCH channel
9: start = now()
10:while now()-start \(<T_{0}\)do
11:if I receive PSSCH then
12: mess = received DATA
13:if mess.srcID == my srcID then
14:\(N_{RS}++\)
15:endif
16:endif
17:endwhile
18:if\(N_{RS}\geq RS_{\text{th}}\)then
19: EXIT
20:endif
21:nbAttempts++
22:DATA.callID = callIDGenerator()
23:until nbAttempts \(>n_{0}\)
24:else
25: send DATA using ordinary link (RACH + PUSCH)
26:endif
```  
**Algorithm 1** On emergency call generation  
```
1:if (\(\chi\).contains(DATA.srcID, DATA.callID)) then
2:\(\chi\).Push(DATA)
3:if\(\eta\).size() \(<\) 3 then
4: Compute \(T_{r}\)
5: DATA.deadline = \(T_{r}\) + now ()
6: DATA.\(N_{RS}=0\)
7:\(\eta\).Push(DATA)
8:endif
9:elseif\(\exists\) waitingCall \(\in\)\(\eta\) such as (DATA.srcID, DATA.callID) = (waitingCall.srcID, waitingCall.callID) then
10:waitingCall.\(N_{RS}++\)
11:if waitingCall.\(N_{RS}\geq RS_{\text{th}}\)then
12:\(\eta\).Remove(waitingCall)
13:endif
14:endif
```  
**Algorithm 2** On receiving an emergency call, DATA  
```
1:if (\(\chi\).contains(DATA.srcID, DATA.callID)) then
2:\(\chi\).Push(DATA)
3:if\(\eta\).size() \(<\) 3 then
4: Compute \(T_{r}\)
5: DATA.deadline = \(T_{r}\) + now ()
6: DATA.\(N_{RS}=0\)
7:\(\eta\).Push(DATA)
8:endif
9:elseif\(\exists\) waitingCall \(\in\)\(\eta\) such as (DATA.srcID, DATA.callID) = (waitingCall.srcID, waitingCall.callID) then
10:waitingCall.\(N_{RS}++\)
11:if waitingCall.\(N_{RS}\geq RS_{\text{th}}\)then
12:\(\eta\).Remove(waitingCall)
13:endif
14:endif
```  
**Algorithm 3** On the operation of the _DATA.srcID_, _DATA.callID_. As described in Algorithm 2, once an emergency call is received, the relay device, \(r\), studies the opportunity of forwarding it. First, \(r\) checks if the \((DATA.srcID,DATA.callID)\) of the received \(DATA\) is in the already received calls list, \(\chi\). If it is a new emergency call, \(r\) stores the received message \(DATA\) in the list of considered calls, \(\eta\). \(\eta\) allows managing up to three emergency calls simultaneously. Each emergency call in \(\eta\) is associated with two new fields: \(N_{RS}\) and \(deadline\). \(N_{RS}\) is initialized to 0 and stores the number of times that the message \(DATA\) is relayed by other neighbors. \(deadline\) gives the limit date of the call in \(\eta\). \(deadline\) is computed using the maximum waiting duration, \(T_{r}\), as shown in line 5 of Algorithm 2. If the received message is already received (line 9 of Algorithm 2), \(r\) checks if the message belongs to the being considered messages \(\eta\). If so, the number of times the waiting call is relayed \(waitingCall.N_{RS}\) is incremented and the call is removed from \(\eta\) if this number reaches the relay threshold \(RS_{th}\). Every second, the relay phone \(r\) checks its \(\eta\) list as explained in Algorithm 3. If the \(waitingCall.deadline\) of a being-considered call, \(waitingCall\), is reached, then the call is relayed after including, in the \(DATA.relay\) field, the relay's data, such as the RSSI, GPS location, and srcID and in \(DATA.content\) the content of the received call \(waitingCall\). According to whether \(r\) is in-coverage or not, the \(DATA\) is transmitted using the classic or D2D mode. Moreover, only one emergency call is transmitted at a time and each device is associated with a state variable (my State) initialized to \"idle\". When the device starts to transmit an emergency call, the state is turned to \"busy\". During the busy state, the device continues to receive and queue emergency call requests.