module SBC_AP_Templates {

import from General_Types all;
import from Osmocom_Types all;

import from SBC_AP_IEs all;
import from SBC_AP_Constants all;
import from SBC_AP_Containers all;
import from SBC_AP_PDU_Contents all;
import from SBC_AP_PDU_Descriptions all;

import from SBC_AP_Types all;

/* 3GPP TS 36.413 9.2.1.38 */
template (value) EUTRAN_CGI ts_SBCAP_ECGI(PLMNidentity plmn_id := '09F107'O, integer cell_id := 1) := {
	pLMNidentity := plmn_id,
	cell_ID := int2bit(cell_id, 28),
	iE_Extensions := omit
}

/* 3GPP TS 36.413 9.2.3.16 */
template (value) TAI ts_SBCAP_TAI(PLMNidentity plmn_id := '09F107'O, uint16_t tac := 1) := {
	pLMNidentity := plmn_id,
	tAC := int2oct(tac, 2),
	iE_Extensions := omit
}

/* 3GPP TS 36.413 9.2.1.54 */
template (value) CellId_Broadcast_List_Item ts_SBCAP_CellId_Broadcast_List_Item(
	template (value) EUTRAN_CGI ecgi := ts_SBCAP_ECGI()) := {
	eCGI := ecgi,
	iE_Extensions := omit
}
template (value) Broadcast_Scheduled_Area_List ts_SBCAP_Broadcast_Scheduled_Area_List(
		template (value) CellId_Broadcast_List cell_id_li := {ts_SBCAP_CellId_Broadcast_List_Item()})
:= {
	cellId_Broadcast_List := cell_id_li,
	tAI_Broadcast_List := omit,
	emergencyAreaID_Broadcast_List := omit,
	iE_Extensions := omit
}

template (value) Global_ENB_ID ts_Global_ENB_ID_MACRO(PLMNidentity plmn_id,
						      integer macro_enb_id)

:= {
	pLMNidentity := plmn_id,
	eNB_ID := {
		macroENB_ID := int2bit(macro_enb_id, 20)
	},
	iE_Extensions := omit
}

template (value) SBC_AP_PDU
ts_SBCAP_PWS_RESTART(
			template (value) Restarted_Cell_List restart_cl,
			template (value) Global_ENB_ID global_enb_id) := {
	initiatingMessage := {
		procedureCode := id_PWS_Restart_Indication,
		criticality := reject,
		value_ := {
			PWS_Restart_Indication := {
				protocolIEs := {
					{
						id := SBC_AP_Constants.id_Restarted_Cell_List,
						criticality := reject,
						value_ := { Restarted_Cell_List := restart_cl }
					}, {
						id := SBC_AP_Constants.id_Global_ENB_ID,
						criticality := reject,
						value_ := { Global_ENB_ID := global_enb_id }
					}
					/* List of TAIs (mandatory) */
					/* List of EAIs (optional) */
				},
				protocolExtensions := omit
			}
		}
	}
}

template (value) SBC_AP_PDU
ts_SBCAP_PWS_FAILURE(
			template (value) Failed_Cell_List fail_cl,
			template (value) Global_ENB_ID global_enb_id) := {
	initiatingMessage := {
		procedureCode := id_PWS_Failure_Indication,
		criticality := reject,
		value_ := {
			PWS_Failure_Indication := {
				protocolIEs := {
					{
						id := SBC_AP_Constants.id_Failed_Cell_List,
						criticality := reject,
						value_ := { Failed_Cell_List := fail_cl }
					}, {
						id := SBC_AP_Constants.id_Global_ENB_ID,
						criticality := reject,
						value_ := { Global_ENB_ID := global_enb_id }
					}
				},
				protocolExtensions := omit
			}
		}
	}
}

/* 4.3.4.2.1 WRITE-REPLACE WARNING REQUEST */
template (value) SBC_AP_PDU
ts_SBCAP_WRITE_WARNING(template (value) BIT16 p_msg_id, template (value) BIT16 p_ser_nr,
		       template (value) uint12_t p_rep_per, template (value) uint16_t p_num_bcast,
		       template (value) OCT2 p_w_type, OCT1 p_dcs,
		       template (value) octetstring p_msg_content) := {
	initiatingMessage := {
		procedureCode := id_Write_Replace_Warning,
		criticality := reject,
		value_ := {
			write_Replace_Warning_Request := {
				protocolIEs := {
					{
						id := SBC_AP_Constants.id_Message_Identifier,
						criticality := reject,
						value_ := { Message_Identifier := p_msg_id }
					}, {
						id := SBC_AP_Constants.id_Serial_Number,
						criticality := reject,
						value_ := { Serial_Number := p_ser_nr }
						/* List of TAIs */
						/* Warning Area List */
					}, {
						id := SBC_AP_Constants.id_Repetition_Period,
						criticality := reject,
						value_ := { Repetition_Period := p_rep_per }
						/* Extended Repetition Period */
					}, {
						id := SBC_AP_Constants.id_Number_of_Broadcasts_Requested,
						criticality := reject,
						value_ := { Number_of_Broadcasts_Requested := p_num_bcast }
					}, {
						id := SBC_AP_Constants.id_Warning_Type,
						criticality := ignore,
						value_ := { Warning_Type := p_w_type }
					}, {
						/* Warning Security Info */
						/* Data Coding Scheme */
						id := SBC_AP_Constants.id_Data_Coding_Scheme,
						criticality := ignore,
						value_ := { Data_Coding_Scheme := oct2bit(p_dcs) }
					}, {
						/* Warning Message Content */
						id := SBC_AP_Constants.id_Warning_Message_Content,
						criticality := ignore,
						value_ := { Warning_Message_Content := p_msg_content }
					}
						/* OMC ID */
						/* Concurrent Warning Message Indicator */
						/* Send Write Replace Warning Indication */
						/* Global eNB ID */
						/* Warning Area Coordinates */
				},
				protocolExtensions := omit
			}
		}
	}
}

/* 4.3.4.2.1 WRITE-REPLACE WARNING REQUEST */
template (present) SBC_AP_PDU
tr_SBCAP_WRITE_WARNING_REQ_CBS(template (present) BIT16 p_msg_id, template (present) BIT16 p_ser_nr,
			template (present) uint12_t p_rep_per,
			template (present) uint16_t p_num_bcast,
			template (present) BIT8 dcs := ?,
			template (present) octetstring p_msg_content := ?,
			template (present) Send_Write_Replace_Warning_Indication send_ind := ?,
			template (present) Concurrent_Warning_Message_Indicator concurrent_ind := ?
			) := {
	initiatingMessage := {
		procedureCode := id_Write_Replace_Warning,
		criticality := reject,
		value_ := {
			write_Replace_Warning_Request := {
				protocolIEs := {
					{
						id := SBC_AP_Constants.id_Message_Identifier,
						criticality := reject,
						value_ := { Message_Identifier := p_msg_id }
					}, {
						id := SBC_AP_Constants.id_Serial_Number,
						criticality := reject,
						value_ := { Serial_Number := p_ser_nr }
						/* List of TAIs */
						/* Warning Area List */
					}, {
						id := SBC_AP_Constants.id_Repetition_Period,
						criticality := reject,
						value_ := { Repetition_Period := p_rep_per }
						/* Extended Repetition Period */
					}, {
						id := SBC_AP_Constants.id_Number_of_Broadcasts_Requested,
						criticality := reject,
						value_ := { Number_of_Broadcasts_Requested := p_num_bcast }
					}, {
						id := SBC_AP_Constants.id_Data_Coding_Scheme,
						criticality := ignore,
						value_ := { Data_Coding_Scheme := dcs }
					}, {
						/* Warning Message Content */
						id := SBC_AP_Constants.id_Warning_Message_Content,
						criticality := ignore,
						value_ := { Warning_Message_Content := p_msg_content }
						/* OMC ID */
						/* Concurrent Warning Message Indicator */
					}, {
						id := SBC_AP_Constants.id_Concurrent_Warning_Message_Indicator,
						criticality := reject,
						value_ := { Concurrent_Warning_Message_Indicator := concurrent_ind }
					}, {
						id := SBC_AP_Constants.id_Send_Write_Replace_Warning_Indication,
						criticality := ignore,
						value_ := { Send_Write_Replace_Warning_Indication := send_ind }
					}
						/* Global eNB ID */
						/* Warning Area Coordinates */
				},
				protocolExtensions := omit
			}
		}
	}
}

template (present) SBC_AP_PDU
tr_SBCAP_WRITE_WARNING_REQ_ETWS(template (present) BIT16 p_msg_id, template (present) BIT16 p_ser_nr,
			template (present) uint12_t p_rep_per,
			template (present) uint16_t p_num_bcast,
			template (present) Warning_Type warn_type := ?,
			template (present) Send_Write_Replace_Warning_Indication send_ind := ?
			) := {
	initiatingMessage := {
		procedureCode := id_Write_Replace_Warning,
		criticality := reject,
		value_ := {
			write_Replace_Warning_Request := {
				protocolIEs := {
					{
						id := SBC_AP_Constants.id_Message_Identifier,
						criticality := reject,
						value_ := { Message_Identifier := p_msg_id }
					}, {
						id := SBC_AP_Constants.id_Serial_Number,
						criticality := reject,
						value_ := { Serial_Number := p_ser_nr }
						/* List of TAIs */
						/* Warning Area List */
					}, {
						id := SBC_AP_Constants.id_Repetition_Period,
						criticality := reject,
						value_ := { Repetition_Period := p_rep_per }
						/* Extended Repetition Period */
					}, {
						id := SBC_AP_Constants.id_Number_of_Broadcasts_Requested,
						criticality := reject,
						value_ := { Number_of_Broadcasts_Requested := p_num_bcast }
					}, {
						id := SBC_AP_Constants.id_Warning_Type,
						criticality := ignore,
						value_ := { Warning_Type := warn_type }
					}, {
						id := SBC_AP_Constants.id_Warning_Security_Information,
						criticality := ignore,
						value_ := { Warning_Security_Information := ? }
					}, {
						id := SBC_AP_Constants.id_Send_Write_Replace_Warning_Indication,
						criticality := ignore,
						value_ := { Send_Write_Replace_Warning_Indication := send_ind }
					}
						/* Global eNB ID */
						/* Warning Area Coordinates */
				},
				protocolExtensions := omit
			}
		}
	}
}

/* 4.3.4.2.5 WRITE REPLACE WARNING INDICATION */
template (value) SBC_AP_PDU
ts_SBCAP_WRITE_WARNING_IND(template (value) BIT16 p_msg_id, template (value) BIT16 p_ser_nr,
		       template (value) SBC_AP_Cause cause := SBC_AP_Cause_message_accepted,
		       template (value) CellId_Broadcast_List bcast_cell_id_li := {ts_SBCAP_CellId_Broadcast_List_Item()}) := {
	initiatingMessage := {
		procedureCode := id_Write_Replace_Warning_Indication,
		criticality := ignore,
		value_ := {
			write_Replace_Warning_Indication := {
				protocolIEs := {
					{
						id := SBC_AP_Constants.id_Message_Identifier,
						criticality := reject,
						value_ := { Message_Identifier := p_msg_id }
					}, {
						id := SBC_AP_Constants.id_Serial_Number,
						criticality := reject,
						value_ := { Serial_Number := p_ser_nr }
					}, {
						id := SBC_AP_Constants.id_Broadcast_Scheduled_Area_List,
						criticality := reject,
						value_ := { broadcast_Scheduled_Area_List := ts_SBCAP_Broadcast_Scheduled_Area_List(bcast_cell_id_li) }
					}
				},
				protocolExtensions := omit
			}
		}
	}
}

/* 4.3.4.2.2 WRITE-REPLACE WARNING RESPONSE */
template (value) SBC_AP_PDU
ts_SBCAP_WRITE_WARNING_RESP(template (value) BIT16 p_msg_id, template (value) BIT16 p_ser_nr,
		       template (value) SBC_AP_Cause cause := SBC_AP_Cause_message_accepted) := {
	successfulOutcome := {
		procedureCode := id_Write_Replace_Warning,
		criticality := reject,
		value_ := {
			write_Replace_Warning_Response := {
				protocolIEs := {
					{
						id := SBC_AP_Constants.id_Message_Identifier,
						criticality := reject,
						value_ := { Message_Identifier := p_msg_id }
					}, {
						id := SBC_AP_Constants.id_Serial_Number,
						criticality := reject,
						value_ := { Serial_Number := p_ser_nr }
					}, {
						id := SBC_AP_Constants.id_Cause,
						criticality := reject,
						value_ := { Cause := enum2int(valueof(cause)) }
					}
				},
				protocolExtensions := omit
			}
		}
	}
}

template (value) SBC_AP_PDU
ts_SBCAP_WRITE_WARNING_RESP_UNKNOWN_TAI(template (value) BIT16 p_msg_id, template (value) BIT16 p_ser_nr,
		       template (value) SBC_AP_Cause cause := SBC_AP_Cause_message_accepted,
		       template (value) List_of_TAIs unknown_tai_list := {{ts_SBCAP_TAI}})
modifies ts_SBCAP_WRITE_WARNING_RESP := {
	successfulOutcome := {
		value_ := {
			write_Replace_Warning_Response := {
				protocolIEs := {
					{
						id := SBC_AP_Constants.id_Message_Identifier,
						criticality := reject,
						value_ := { Message_Identifier := p_msg_id }
					}, {
						id := SBC_AP_Constants.id_Serial_Number,
						criticality := reject,
						value_ := { Serial_Number := p_ser_nr }
					}, {
						id := SBC_AP_Constants.id_Cause,
						criticality := reject,
						value_ := { Cause := enum2int(valueof(cause)) }
					}, {
						id := SBC_AP_Constants.id_Unknown_Tracking_Area_List,
						criticality := ignore,
						value_ := { List_of_TAIs := unknown_tai_list }
					}
				}
			}
		}
	}
}

/* 4.3.4.2.3 STOP WARNING REQUEST */
template (present) SBC_AP_PDU
tr_SBCAP_STOP_WARNING(template (present) BIT16 p_msg_id, template (present) BIT16 p_ser_nr) := {
	initiatingMessage := {
		procedureCode := id_Stop_Warning,
		criticality := reject,
		value_ := {
			stop_Warning_Request := {
				protocolIEs := {
					{
						id := SBC_AP_Constants.id_Message_Identifier,
						criticality := reject,
						value_ := { Message_Identifier := p_msg_id }
					}, {
						id := SBC_AP_Constants.id_Serial_Number,
						criticality := reject,
						value_ := { Serial_Number := p_ser_nr }
						/* List of TAIs */
						/* Warning Area List */
					}
				},
				protocolExtensions := omit
			}
		}
	}
}

/* 4.3.4.2.4 STOP WARNING RESPONSE */
template (value) SBC_AP_PDU
ts_SBCAP_STOP_WARNING_RESP(template (value) BIT16 p_msg_id, template (value) BIT16 p_ser_nr,
		       template (value) SBC_AP_Cause cause := SBC_AP_Cause_message_accepted) := {
	successfulOutcome := {
		procedureCode := id_Stop_Warning,
		criticality := reject,
		value_ := {
			stop_Warning_Response := {
				protocolIEs := {
					{
						id := SBC_AP_Constants.id_Message_Identifier,
						criticality := reject,
						value_ := { Message_Identifier := p_msg_id }
					}, {
						id := SBC_AP_Constants.id_Serial_Number,
						criticality := reject,
						value_ := { Serial_Number := p_ser_nr }
					}, {
						id := SBC_AP_Constants.id_Cause,
						criticality := reject,
						value_ := { Cause := enum2int(valueof(cause)) }
					}
				},
				protocolExtensions := omit
			}
		}
	}
}

}