Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The attribute type tag numbering does not follow the standard: starts from 0 instead of 1 #56

Open
georgeslabreche opened this issue Aug 24, 2021 · 2 comments

Comments

@georgeslabreche
Copy link

The attribute type tag numbering starts from 0 instead of 1:

#define MAL_BLOB_ATTRIBUTE_TAG 0
#define MAL_BOOLEAN_ATTRIBUTE_TAG 1
#define MAL_DURATION_ATTRIBUTE_TAG 2
#define MAL_FLOAT_ATTRIBUTE_TAG 3
#define MAL_DOUBLE_ATTRIBUTE_TAG 4
#define MAL_IDENTIFIER_ATTRIBUTE_TAG 5
#define MAL_OCTET_ATTRIBUTE_TAG 6
#define MAL_UOCTET_ATTRIBUTE_TAG 7
#define MAL_SHORT_ATTRIBUTE_TAG 8
#define MAL_USHORT_ATTRIBUTE_TAG 9
#define MAL_INTEGER_ATTRIBUTE_TAG 10
#define MAL_UINTEGER_ATTRIBUTE_TAG 11
#define MAL_LONG_ATTRIBUTE_TAG 12
#define MAL_ULONG_ATTRIBUTE_TAG 13
#define MAL_STRING_ATTRIBUTE_TAG 14
#define MAL_TIME_ATTRIBUTE_TAG 15
#define MAL_FINETIME_ATTRIBUTE_TAG 16
#define MAL_URI_ATTRIBUTE_TAG 17

See section 4.3 ATTRIBUTES of the recommended standard:
https://public.ccsds.org/Pubs/521x0b2e1.pdf

This issue causes type casting errors in malbinary_decoder.c's malbinary_decoder_decode_attribute function:

int malbinary_decoder_decode_attribute(mal_decoder_t *decoder, void *cursor,
unsigned char attribute_tag, union mal_attribute_t *self) {
int rc = 0;
switch (attribute_tag) {
case MAL_BLOB_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_blob(decoder, cursor, &self->blob_value);
break;
case MAL_BOOLEAN_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_boolean(decoder, cursor, &self->boolean_value);
break;
case MAL_DURATION_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_duration(decoder, cursor, &self->duration_value);
break;
case MAL_FLOAT_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_float(decoder, cursor, &self->float_value);
break;
case MAL_DOUBLE_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_double(decoder, cursor, &self->double_value);
break;
case MAL_IDENTIFIER_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_identifier(decoder, cursor, &self->identifier_value);
break;
case MAL_OCTET_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_octet(decoder, cursor, &self->octet_value);
break;
case MAL_UOCTET_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_uoctet(decoder, cursor, &self->uoctet_value);
break;
case MAL_SHORT_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_short(decoder, cursor, &self->short_value);
break;
case MAL_USHORT_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_ushort(decoder, cursor, &self->ushort_value);
break;
case MAL_INTEGER_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_integer(decoder, cursor, &self->integer_value);
break;
case MAL_UINTEGER_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_uinteger(decoder, cursor, &self->uinteger_value);
break;
case MAL_LONG_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_long(decoder, cursor, &self->long_value);
break;
case MAL_ULONG_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_ulong(decoder, cursor, &self->ulong_value);
break;
case MAL_STRING_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_string(decoder, cursor, &self->string_value);
break;
case MAL_TIME_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_time(decoder, cursor, &self->time_value);
break;
case MAL_FINETIME_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_finetime(decoder, cursor, &self->finetime_value);
break;
case MAL_URI_ATTRIBUTE_TAG:
rc = malbinary_decoder_decode_uri(decoder, cursor, &self->uri_value);
break;
default:
clog_error(decoder->logger, "Unexpected attribute tag value: %d\n", attribute_tag);
return -1;
}
return rc;
}

However, the short forms are numbered correctly:

#define MAL_BLOB_SHORT_FORM 0x1000001000001L
#define MAL_BOOLEAN_SHORT_FORM 0x1000001000002L
#define MAL_DURATION_SHORT_FORM 0x1000001000003L
#define MAL_FLOAT_SHORT_FORM 0x1000001000004L
#define MAL_DOUBLE_SHORT_FORM 0x1000001000005L
#define MAL_IDENTIFIER_SHORT_FORM 0x1000001000006L
#define MAL_OCTET_SHORT_FORM 0x1000001000007L
#define MAL_UOCTET_SHORT_FORM 0x1000001000008L
#define MAL_SHORT_SHORT_FORM 0x1000001000009L
#define MAL_USHORT_SHORT_FORM 0x100000100000AL
#define MAL_INTEGER_SHORT_FORM 0x100000100000BL
#define MAL_UINTEGER_SHORT_FORM 0x100000100000CL
#define MAL_LONG_SHORT_FORM 0x100000100000DL
#define MAL_ULONG_SHORT_FORM 0x100000100000EL
#define MAL_STRING_SHORT_FORM 0x100000100000FL
#define MAL_TIME_SHORT_FORM 0x1000001000010L
#define MAL_FINETIME_SHORT_FORM 0x1000001000011L
#define MAL_URI_SHORT_FORM 0x1000001000012L

This was done correctly for malgo:
https://github.com/CNES/ccsdsmo-malgo/blob/7c8058ce0673fe0ebe45a94a9e448b9a9c5ca0f1/mal/newmapping.go#L36-L156

@freyssin
Copy link
Collaborator

I don't think this is a mistake.
In the MAL / CZMQ implementation the MAL__ATTRIBUTE_TAG constants correspond to the type selector in the mal_attribute_t union. These constants should probably not be used outside of the MAL / CZMQ implementation.
Their use during encoding are described in the corresponding specification documents, for example for split-binary encoding document CCSDS 524.2-R-1 section 5.2:
image

Did you notice an error during your tests? If so can you describe it?

@georgeslabreche
Copy link
Author

Oh that's interesting, thanks for bringing this up! It looks like there's a difference between short form and tag that's being mixed up. I'm interacting with something called the NanoSat MO Framework (NMF) and the response to my request includes the attribute type's short form values which are decoded as attribute tags in malbinary_decoder_decode_attribute. It could be that NMF is responding with short form values instead of tag values. I'll have a closer look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants