blob: fe19c3ec7e77186c4ef3bbeb7cb4b3ba4f272738 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2019 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v2.0
// which accompanies this distribution, and is available at
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
///////////////////////////////////////////////////////////////////////////////
// File: LightweightM2M_Types.ttcn
// Description:
// Rev: R1A
// Prodnr: LPA 108 661
// Updated: 2019-08-27
// Contact: http://ttcn.ericsson.se
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Module: LightweightM2M_Types
//
// Purpose:
// This module contains type definitions for LWM2M PDUs
//
///////////////////////////////////////////////////////////////
module LightweightM2M_Types
{
import from CoAP_Types all;
import from LWM2M_TLV_Types all;
type universal charstring URN;
type record of universal charstring Location;
type record of integer Integer_List;
type union LWM2M_PDU
{
// -----
LWM2M_Register Register,
LWM2M_Update Update,
LWM2M_Deregister Deregister,
LWM2M_Response Response,
LWM2M_Notification Notification,
// -----
LWM2M_Read Read_,
LWM2M_Write Write,
LWM2M_Execute Execute,
// -----
LWM2M_Create Create,
LWM2M_Delete Delete,
//-----
LWM2M_BS_Request_Finish BS_Request_Finish,
LWM2M_BS_Delete BS_Delete,
LWM2M_BS_Discover BS_Discover
}
type record LWM2M_Register
{
URN endpointClientName,
integer lifetime optional,
charstring version optional,
BindingMode bindingMode optional,
integer smsNumber optional,
ObjectPath_List objectsAndObjectInstances
}
const LWM2M_PDU c_LWM2M_Register_init :=
{
Register := {
endpointClientName := "",
lifetime := omit,
version := omit,
bindingMode := omit,
smsNumber := omit,
objectsAndObjectInstances := {}
}
}
type record LWM2M_Update
{
Location location,
integer lifetime optional,
BindingMode bindingMode optional,
integer smsNumber optional,
ObjectPath_List objectsAndObjectInstances
}
const LWM2M_PDU c_LWM2M_Update_init :=
{
Update := {
location := {},
lifetime := omit,
bindingMode := omit,
smsNumber := omit,
objectsAndObjectInstances := {}
}
}
type record LWM2M_Read
{
ObjectPath path,
Integer_List accept,
boolean observe optional
}
const LWM2M_PDU c_LWM2M_Read_init :=
{
Read_ := {
path := {-1, omit, omit},
accept := {},
observe := omit
}
}
type record LWM2M_Write
{
ObjectPath path,
integer contentFormat,
LWM2M_Block block1 optional,
LwM2M_Resource_List resources
}
type record LWM2M_Block
{
BlockOption option,
octetstring content
}
const LWM2M_PDU c_LWM2M_Write_init :=
{
Write := {
path := { -1, omit, omit},
contentFormat := -1,
block1 := omit,
resources := {}
}
}
type record LWM2M_Execute
{
ObjectPath path
}
const LWM2M_PDU c_LWM2M_Execute_init :=
{
Execute := {
path := { -1, omit, omit}
}
}
type record LWM2M_Create
{
ObjectPath path,
integer contentFormat,
LwM2M_Resource_List resources
}
const LWM2M_PDU c_LWM2M_Create_init :=
{
Create := {
path := { -1, omit, omit},
contentFormat := -1,
resources := {}
}
}
type record LWM2M_Delete
{
ObjectPath path
}
const LWM2M_PDU c_LWM2M_Delete_init :=
{
Delete := {
path := { -1, omit, omit}
}
}
type record LWM2M_Deregister
{
Location location
}
type record LWM2M_Response
{
Location location,
integer code,
integer contentFormat optional,
boolean notification optional,
LwM2M_Resource_List resources
}
const LWM2M_PDU c_LWM2M_Response_init :=
{
Response := {
location := {},
code := 0,
contentFormat := omit,
notification := omit,
resources := {}
}
}
type record LWM2M_Notification
{
ObjectPath path,
integer code,
integer contentFormat optional,
LwM2M_Resource_List resources
}
const LWM2M_PDU c_LWM2M_Notification_init :=
{
Notification := {
path := { -1, omit, omit},
code := 0,
contentFormat := omit,
resources := {}
}
}
type record LWM2M_BS_Request_Finish
{
URN endpointClientName,
boolean isRequest
}
const LWM2M_PDU c_LWM2M_BS_Request_init :=
{
BS_Request_Finish :=
{
endpointClientName := "",
isRequest := true
}
}
const LWM2M_PDU c_LWM2M_BS_Finish_init :=
{
BS_Request_Finish :=
{
endpointClientName := "",
isRequest := false
}
}
type record LWM2M_BS_Delete
{
integer objectId optional,
integer objectInstanceId optional
}
const LWM2M_PDU c_LWM2M_BS_Delete_init :=
{
BS_Delete := {
objectId := omit,
objectInstanceId := omit
}
}
type record LWM2M_BS_Discover
{
integer objectId optional,
integer accept
}
const LWM2M_PDU c_LWM2M_BS_Discover_init :=
{
BS_Discover := {
objectId := omit,
accept := 40
}
}
type enumerated BindingMode
{
U, UQ, S, SQ, US, UQS
}
///////////////////////////////////////////////////////////
// Type: ObjectPath
//
// Purpose:
// Models an access path up to a resource
//
// Elements:
// objectId - *integer* - object id
// objectInstanceId - *integer* - object instance id (optional)
// resourceId - *integer* - resource id (optional)
///////////////////////////////////////////////////////////
type record ObjectPath
{
integer objectId,
integer objectInstanceId optional,
integer resourceId optional
}
///////////////////////////////////////////////////////////
// Type: ObjectPath_List
//
// Purpose:
// List of <ObjectPath>
///////////////////////////////////////////////////////////
type record of ObjectPath ObjectPath_List;
///////////////////////////////////////////////////////////
// Type: LwM2M_Resource
//
// Purpose:
// Models a smart resource
//
// Elements:
// id - *integer* - unique id of the smart resource
// objId - *integer* - object id
// objInstId - *integer* - object instance id
// observed - *boolean* - flag, true when observed
// dataSample - <LwM2M_DataSample_Information> - pointers to data sample values (optional)
// val - <LwM2M_ResourceValue> - value of the resource
//
// Related Functions:
// - <f_LwM2M_resourceHash_forResource> (*in* <LwM2M_Resource> p_res)
// - <f_LwM2M_Resource_setNextDataSample> (*inout* <LwM2M_Resource> p_res, *inout* <LwM2M_DataSamples_DB> p_db)
///////////////////////////////////////////////////////////
type record LwM2M_Resource
{
integer id,
integer objId,
integer objInstId,
boolean observed,
LwM2M_DataSample_Information dataSample optional,
LwM2M_ResourceValue val
}
type record LwM2M_Observe_Information
{
integer observe,
octetstring token
}
const LwM2M_Observe_Information c_LwM2M_Observe_Information_init :=
{
observe := -1,
token := ''O
}
type record LwM2M_DataSample_Information
{
charstring samplesName,
integer samplesPointer,
integer valuePointer
}
const LwM2M_DataSample_Information c_LwM2M_DataSample_Information_init :=
{
samplesName := "",
samplesPointer := -1,
valuePointer := -1
}
const LwM2M_Resource c_LwM2M_Resource_init :=
{
id := -1,
objId := -1,
objInstId := -1,
observed := false,
dataSample := omit,
val := { boolValue := false }
}
///////////////////////////////////////////////////////////
// Type: LwM2M_ResourceValue
//
// Purpose:
// Union for storing the value of a smart resource
//
// Elements:
// intValue - *integer*
// strValue - *charstring*
// floatValue - *float*
// opaqueValue - *octetstring*
// boolValue - *boolean*
///////////////////////////////////////////////////////////
type union LwM2M_ResourceValue
{
TLV_integer intValue,
charstring strValue,
float floatValue,
octetstring opaqueValue,
boolean boolValue
}
///////////////////////////////////////////////////////////
// Type: LwM2M_ResourceValue_List
//
// Purpose:
// List of <LwM2M_ResourceValue>
///////////////////////////////////////////////////////////
type record of LwM2M_ResourceValue LwM2M_ResourceValue_List;
///////////////////////////////////////////////////////////
// Type: LwM2M_Resource_List
//
// Purpose:
// List of <LwM2M_Resource>
///////////////////////////////////////////////////////////
type record of LwM2M_Resource LwM2M_Resource_List;
function f_LwM2M_ObjectPath_isResource(in ObjectPath p_path)
return boolean
{
return ispresent(p_path.objectInstanceId) and ispresent(p_path.resourceId)
}
function f_LwM2M_ObjectPath_isObjectInstance(in ObjectPath p_path)
return boolean
{
return ispresent(p_path.objectInstanceId) and not ispresent(p_path.resourceId)
}
function f_LwM2M_ObjectPath_isObject(in ObjectPath p_path)
return boolean
{
return not ispresent(p_path.objectInstanceId) and not ispresent(p_path.resourceId)
}
///////////////////////////////////////
// JSON representation and enc/dec
///////////////////////////////////////
function f_enc_LwM2M_Resources_to_JSON(in LwM2M_Resource_List p_res_list) return octetstring
{
var charstring v_result :=
"{\"bn\":\"/\",\n"&
"\"e\":[\n";
for (var integer i:=0; i<sizeof(p_res_list); i:=i+1)
{
v_result := v_result & f_enc_LwM2M_Resource_to_JSON(p_res_list[i]);
if (i != sizeof(p_res_list)-1) { v_result := v_result & ",\n"}
else { v_result := v_result & "\n"}
}
v_result := v_result & "]}";
return char2oct(v_result);
}
function f_enc_LwM2M_Resource_to_JSON(in LwM2M_Resource p_res) return charstring
{
var charstring v_ret := "";
// "n":"65/3/3"
var charstring v_name := "";
if (p_res.objId != -1) {
v_name := v_name & int2str(p_res.objId)
}
if (p_res.objInstId != -1) {
if (lengthof(v_name) > 0) { v_name := v_name & "/" & int2str(p_res.objInstId) }
else { v_name := int2str(p_res.objInstId) }
}
if (p_res.id != -1) {
if (lengthof(v_name) > 0) { v_name := v_name & "/" & int2str(p_res.id) }
else { v_name := int2str(p_res.id) }
}
v_name := "\"n\":\"" & v_name & "\"";
var charstring v_value := "";
if (ischosen(p_res.val.intValue)) {
v_value := "\"v\":" & int2str(p_res.val.intValue);
}
else if (ischosen(p_res.val.floatValue)) {
v_value := "\"v\":" & float2str(p_res.val.floatValue);
}
else if (ischosen(p_res.val.strValue)) {
v_value := "\"sv\":" & "\"" & p_res.val.strValue & "\"";
}
else if (ischosen(p_res.val.boolValue)) {
v_value := "\"bv\":" & "\"" & f_bool2str(p_res.val.boolValue) & "\"";
}
else if (ischosen(p_res.val.opaqueValue)) {
v_value := "\"ov\":" & "\"" & oct2str(p_res.val.opaqueValue) & "\"";
}
v_ret := "{" & v_name & ", " & v_value & "}";
return v_ret;
}
function f_bool2str(in boolean p_b) return charstring { if (p_b) {return "true"} else {return "false" }}
function f_enc_LwM2M_Resources_to_JSON_old(in LwM2M_Resource_List p_res_list) return octetstring
{
var LwM2M_JSON_Resources v_json_res_list;
v_json_res_list.e := {};
for (var integer i:=0; i<sizeof(p_res_list); i:=i+1)
{
v_json_res_list.e[sizeof(v_json_res_list.e)] := f_LwM2M_Resource_toJSONStructure(p_res_list[i]);
}
return f_enc_LwM2M_JSON_Resources(v_json_res_list);
}
function f_LwM2M_Resource_toJSONStructure(in LwM2M_Resource p_in)
return LwM2M_JSON_Resource
{
var LwM2M_JSON_Resource v_out;
v_out.n := "";
if (p_in.objId != -1) {
v_out.n := int2str(p_in.objId)
}
if (p_in.objInstId != -1) {
if (lengthof(v_out.n) > 0) { v_out.n := v_out.n & "/" & int2str(p_in.objInstId) }
else { v_out.n := int2str(p_in.objInstId) }
}
if (p_in.id != -1) {
if (lengthof(v_out.n) > 0) { v_out.n := v_out.n & "/" & int2str(p_in.id) }
else { v_out.n := int2str(p_in.id) }
}
if (ischosen(p_in.val.intValue)) { v_out.v := int2float(p_in.val.intValue) }
else if (ischosen(p_in.val.floatValue)) { v_out.v := p_in.val.floatValue }
else if (ischosen(p_in.val.strValue)) { v_out.sv := p_in.val.strValue }
else if (ischosen(p_in.val.boolValue)) { v_out.bv := p_in.val.boolValue }
else if (ischosen(p_in.val.opaqueValue)) { v_out.sv := oct2str(p_in.val.opaqueValue) }
return v_out;
}
function f_LwM2M_JSON_Resources_toResources(in LwM2M_JSON_Resources p_json_res_list)
return LwM2M_Resource_List
{
var LwM2M_Resource_List v_ret := {};
for (var integer i:=0; i<sizeof(p_json_res_list.e); i:=i+1) {
v_ret[sizeof(v_ret)] := f_LwM2M_JSON_Resource_toResource(p_json_res_list.e[i]);
}
return v_ret;
}
function f_LwM2M_JSON_Resource_toResource(in LwM2M_JSON_Resource p_json_res)
return LwM2M_Resource
{
var LwM2M_Resource v_ret := c_LwM2M_Resource_init;
if (ispresent(p_json_res.bv)) { v_ret.val.boolValue := p_json_res.bv; }
if (ispresent(p_json_res.sv)) { v_ret.val.strValue := p_json_res.sv; }
if (ispresent(p_json_res.v)) { v_ret.val.floatValue := p_json_res.v; }
return v_ret;
}
external function f_enc_LwM2M_JSON_Resources(in LwM2M_JSON_Resources p_res) return octetstring
with { extension "prototype(convert) encode(JSON) printing(pretty)" }
external function f_dec_LwM2M_JSON_Resources(in octetstring p_res) return LwM2M_JSON_Resources
with { extension "prototype(convert) decode(JSON)" }
type record LwM2M_JSON_Resources
{
LwM2M_JSON_Resource_List e
}
with { encode "JSON" }
type record of LwM2M_JSON_Resource LwM2M_JSON_Resource_List
with { encode "JSON" }
type record LwM2M_JSON_Resource
{
charstring n,
float v optional,
boolean bv optional,
charstring sv optional
}
with {
encode "JSON"
optional "implicit omit"
}
}