blob: 6ffc5a3f420bed0d96a89908fb161613d392c5df [file] [log] [blame]
/******************************************************************************
* Copyright (c) 2000-2019 Ericsson Telecom AB 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
*
* Contributors:
* Mate Kovacs - initial implementation and initial documentation
* Antal Wu-Hen Chang
* Naum Spaseski
* Bence Janos Szabo - negative testing branch
******************************************************************************/
//
// File: CoAP_Types.ttcn
// Rev: R1A
// Prodnr: CNL 113 829
module CoAP_Types
{
external function f_CoAP_enc(in CoAP_Message msg, out octetstring str) return integer;
external function f_CoAP_dec(in octetstring str, out CoAP_Message msg) return integer;
external function f_CoAP_encode(in CoAP_Message msg, out octetstring str)
with {
extension "prototype(fast) encode(RAW)"
}
// RAW decode is not working correctly
external function f_CoAP_decode(in octetstring str, out CoAP_Message msg)
with {
extension "prototype(fast) decode(RAW)"
}
const Code EMPTY_MESSAGE:={ 0, 0 };
const Code METHOD_GET:={ 0, 1 };
const Code METHOD_POST:={ 0, 2 };
const Code METHOD_PUT:={ 0, 3 };
const Code METHOD_DELETE:={ 0, 4 };
const Code RESPONSE_CODE_Created:={ 2, 1 };
const Code RESPONSE_CODE_Deleted:={ 2, 2 };
const Code RESPONSE_CODE_Valid:={ 2, 3 };
const Code RESPONSE_CODE_Changed:={ 2, 4 };
const Code RESPONSE_CODE_Content:={ 2, 5 };
const Code RESPONSE_CODE_BadRequest:={ 4, 0 };
const Code RESPONSE_CODE_Unauthorized:={ 4, 1 };
const Code RESPONSE_CODE_BadOption:={ 4, 2 };
const Code RESPONSE_CODE_Forbidden:={ 4, 3 };
const Code RESPONSE_CODE_NotFound:={ 4, 4 };
const Code RESPONSE_CODE_MethodNotAllowed:={ 4, 5 };
const Code RESPONSE_CODE_NotAcceptable:={ 4, 6 };
const Code RESPONSE_CODE_PreconditionFailed:={ 4, 12 };
const Code RESPONSE_CODE_RequestEntityTooLarge:={ 4, 13 };
const Code RESPONSE_CODE_UnsupportedContentFormat:={ 4, 15 };
const Code RESPONSE_CODE_InternalServerError:={ 5, 0 };
const Code RESPONSE_CODE_NotImplemented:={ 5, 1 };
const Code RESPONSE_CODE_BadGateway:={ 5, 2 };
const Code RESPONSE_CODE_ServiceUnavailable:={ 5, 3 };
const Code RESPONSE_CODE_GatewayTimeout:={ 5, 4 };
const Code RESPONSE_CODE_ProxyingNotSupported:={ 5, 5 };
type octetstring OCT0 length (0);
type octetstring OCT0_8 length(0..8);
type octetstring OCT1_8 length(1..8);
type octetstring OCT0_2 length(0..2) with { variant "" };
type octetstring OCT0_INF with { variant "" };
type octetstring OCT1_MSB length(1) with { variant "FIELDLENGTH(1),BITORDER(msb)" };
type universal charstring UCHAR0_255 length(0..255);
type universal charstring UCHAR1_255 length(1..255);
type universal charstring UCHAR1_1034 length(1..1034);
type integer INT_BIT2_MSB (0..3) with { variant "FIELDLENGTH(2), BITORDER(msb)" };
type integer INT_BIT3_MSB (0..7) with { variant "FIELDLENGTH(3), BITORDER(msb)" };
type integer INT_BIT4_MSB (0..15) with { variant "FIELDLENGTH(4), BITORDER(msb)" };
type integer INT_BIT4 (0..15) with { variant "FIELDLENGTH(4), BYTEORDER(last)" };
type integer INT_BIT5_MSB (0..31) with { variant "FIELDLENGTH(5), BITORDER(msb)" };
type integer INT_BIT8_MSB (0..255) with { variant "FIELDLENGTH(8), BITORDER(msb)" };
type integer INT_BIT12_MSB (0..4095) with { variant "FIELDLENGTH(12), BYTEORDER(last)" };
type integer INT_BIT16_MSB (0..65335) with { variant "FIELDLENGTH(16), BITORDER(msb)" };
type integer INT_BIT20_MSB (0..1048575) with { variant "FIELDLENGTH(20), BYTEORDER(last)" };
type integer INT_BIT24_MSB with { variant "FIELDLENGTH(24), BITORDER(msb)" };
type integer INT_BIT32_MSB with { variant "FIELDLENGTH(32), BITORDER(msb)" };
type enumerated Type
{
CONFIRMABLE(0),
NON_CONFIRMABLE(1),
ACKNOWLEDGEMENT(2),
RESET(3)
} with { variant "FIELDLENGTH(2), BITORDER(msb)" };
type record Code
{
INT_BIT3_MSB class,
INT_BIT5_MSB detail
} with {
variant "FIELDORDER(msb)"
variant (class) "BITORDERINFIELD(msb)"
variant (detail) "BITORDERINFIELD(msb)"
}
type record UnknownOption
{
integer option_code,
octetstring option_value
}
type record INT_BIT_4_OR_12_OR_20_MSB {
INT_BIT4 int_bit4 optional,
INT_BIT12_MSB int_bit12 optional,
INT_BIT20_MSB int_bit20 optional
} with {
variant "FIELDORDER(msb)";
}
type record BlockOption
{
INT_BIT_4_OR_12_OR_20_MSB num,
boolean m,
INT_BIT3_MSB szx
} with {
variant "FIELDORDER(msb)";
variant (num) "BITORDERINFIELD(msb)";
variant (m) "BITORDERINFIELD(msb)";
variant (szx) "BITORDERINFIELD(msb)";
}
type union CoAP_Options
{
OCT0_8 if_match,
UCHAR1_255 uri_host,
OCT1_8 etag,
OCT0 if_none_match,
INT_BIT8_OR_16_OR_24_OR_32_MSB observe,
INT_BIT8_OR_16_OR_24_OR_32_MSB uri_port,
UCHAR0_255 location_path,
UCHAR0_255 uri_path,
INT_BIT8_OR_16_OR_24_OR_32_MSB content_format,
INT_BIT8_OR_16_OR_24_OR_32_MSB max_age,
UCHAR0_255 uri_query,
INT_BIT8_OR_16_OR_24_OR_32_MSB accept,
UCHAR0_255 location_query,
BlockOption block1,
BlockOption block2,
UCHAR1_1034 proxy_uri,
UCHAR1_255 proxy_scheme,
INT_BIT8_OR_16_OR_24_OR_32_MSB size1,
UnknownOption unknown_option
}
type union INT_BIT8_OR_16_OR_24_OR_32_MSB {
INT_BIT8_MSB int_bit8,
INT_BIT16_MSB int_bit16,
INT_BIT24_MSB int_bit24,
INT_BIT32_MSB int_bit32
} with {
variant (int_bit8) "BITORDERINFIELD(msb)";
variant (int_bit16) "BITORDERINFIELD(msb)";
variant (int_bit24) "BITORDERINFIELD(msb)";
variant (int_bit32) "BITORDERINFIELD(msb)";
}
// This enables fuzzing of the option_delta_ext and option_length_ext fields.
// For correct RAW encoding use the int_bit8 field for values from 0..255 and
// use the int_bit16 field for values from 256..35335
type union INT_BIT8_OR_BIT16_MSB {
INT_BIT8_MSB int_bit8,
INT_BIT16_MSB int_bit16
} with {
variant (int_bit8) "BITORDERINFIELD(msb)";
variant (int_bit16) "BITORDERINFIELD(msb)";
}
type record CoAP_OptionsExt
{
INT_BIT4_MSB option_delta,
INT_BIT4_MSB option_length,
INT_BIT8_OR_BIT16_MSB option_delta_ext optional,
INT_BIT8_OR_BIT16_MSB option_length_ext optional,
CoAP_Options option_value
} with {
variant "FIELDORDER(msb)"
variant (option_delta) "BITORDERINFIELD(msb)"
variant (option_length) "BITORDERINFIELD(msb)"
};
type set of CoAP_OptionsExt CoAP_OptionsExtList with {variant "" };
type record Payload
{
OCT1_MSB payloadMarker /*('FF'O)*/, // to enable the negative testing of the marker
octetstring payload length(1..infinity)
} with {variant "" }
type record CoAP_ReqResp
{
// header begin
INT_BIT2_MSB version,
Type msg_type,
INT_BIT4_MSB tkl,
Code code,
INT_BIT16_MSB message_id,
// header end
OCT0_8 token,
CoAP_OptionsExtList options optional,
Payload payload optional
} with {
variant "FIELDORDER(msb)"
variant (version) "BITORDERINFIELD(msb)";
variant (msg_type) "BITORDERINFIELD(msb)" ;
variant (tkl) "BITORDERINFIELD(msb)" ;
variant (message_id) "BITORDERINFIELD(msb)" ;
variant (token) "BITORDERINFIELD(lsb)" ;//!!
}
type union CoAP_Message
{
CoAP_ReqResp msg,
octetstring raw_message
} with {
variant ""
}
}
with {
encode "RAW"
}