vlm / asn1c

The ASN.1 Compiler
http://lionet.info/asn1c/
BSD 2-Clause "Simplified" License
1.03k stars 553 forks source link

Problem with Time64 (uint64_t) & "struct ASN__PRIMITIVE_TYPE_s" #457

Open yadav9997 opened 2 years ago

yadav9997 commented 2 years ago

Hi @velichkov @vlm ,

can you please help in sharing any information about which of the below conversion routines (from INTEGER.h) could be you used for the Uint64, thanks:

Uint64 ::= INTEGER (0..18446744073709551615) -- (hex) ff ff ff ff ff ff ff ff


-- -- Integers


Uint3 ::= INTEGER (0..7) -- (hex) 07 Uint8 ::= INTEGER (0..255) -- (hex) ff Uint16 ::= INTEGER (0..65535) -- (hex) ff ff Uint32 ::= INTEGER (0..4294967295)---- -- (hex) ff ff ff ff Uint64 ::= INTEGER (0..18446744073709551615) -- (hex) ff ff ff ff ff ff ff ff SequenceOfUint8 ::= SEQUENCE OF Uint8 SequenceOfUint16 ::= SEQUENCE OF Uint16


-- -- Time


Time32 ::= Uint32 Time64 ::= Uint64 ValidityPeriod ::= SEQUENCE { start Time32, duration Duration } Duration ::= CHOICE { microseconds Uint16, milliseconds Uint16, seconds Uint16, minutes Uint16, hours Uint16, sixtyHours Uint16, years Uint16 }

asn1c/skeletons/INTEGER.h

Lines 56 to 75 in 4cc779f /*

Natiwe size-independent conversion of native integers to/from INTEGER. (lsize) is in bytes. Returns 0 if it was possible to convert, -1 otherwise. -1/EINVAL: Mandatory argument missing -1/ERANGE: Value encoded is out of range for long representation -1/ENOMEM: Memory allocation failed (in asn2INTEGER()). / int asn_INTEGER2imax(const INTEGER_t i, intmax_t l); int asn_INTEGER2umax(const INTEGER_t i, uintmax_t l); int asn_imax2INTEGER(INTEGER_t *i, intmax_t l); int asn_umax2INTEGER(INTEGER_t i, uintmax_t l); /

Size-specific conversion helpers. / int asn_INTEGER2long(const INTEGER_t i, long l); int asn_INTEGER2ulong(const INTEGER_t i, unsigned long l); int asn_long2INTEGER(INTEGER_t i, long l); int asn_ulong2INTEGER(INTEGER_t *i, unsigned long l);

Thanks a lot, awaited for your valuable feedback

velichkov commented 2 years ago

Hi @yadav9997,

Problem with Time64 (uint64_t) & "struct ASN__PRIMITIVE_TYPE_s"

What is the exact problem?

which of the below conversion routines (from INTEGER.h) could be you used for the Uint64

You can use the uintmax_t variants.

yadav9997 commented 2 years ago

@velichkov Thanks a lot for the feedback.

I tried using the asn_umax2INTEGER(INTEGER_t i, uintmax_t l) for long long variable [as below example for Millisecond], when tried to print it only printed 10 digits not the 13 digits and also gave UPER encode error as " value too large " Millisecond = INTEGER (0..4398046511103);

i am trying to assign 13 digit value and then do UPER encode of this value. asn_encode_to_new_buffer(0,ATS_UNALIGNED_BASIC_PER, &asn_DEF_MessageFrame, msgf);

Example: uintmax_t v2 = 1718192021234; printf("size=%d, value=%ju\n",sizeof(v2),v2); asn_umax2INTEGER(&millisecond, v2);

velichkov commented 2 years ago

printf("size=%d, value=%ju\n",sizeof(v2),v2);

What are the size and value? Which architecture are you using - x86, x86_64, arm ... ? Which asn1c do you use, from which repository, branch, commit?

What asn1c parameters did you use to compile your asn1 files - -fwide-types, .... ?

asn_umax2INTEGER(&millisecond, v2);

Check the return value of asn_umax2INTEGER

Returns 0 if it was possible to convert, -1 otherwise.
-1/EINVAL: Mandatory argument missing
-1/ERANGE: Value encoded is out of range for long representation
-1/ENOMEM: Memory allocation failed (in asn_*2INTEGER()).
yadav9997 commented 2 years ago

@velichkov Apologies for delay in response.

please find below information:

please let me know if anything more information is needed, thanks alot @velichkov

yadav9997 commented 2 years ago

@velichkov apologies for following up, any possible feedback ?

velichkov commented 2 years ago
* Architecture is arm [arm-openwrt-linux-gnueabi] for Device [armv7l GNU/Linux]

So it is 32bit. Can you reproduce this on 32bit x86 processor or 64bit (arm or intel)?

* v0.9.29 of asn1c

Which repository and commit?

* Actually i am using the Makefile for compilation than using the asn1c command line with -fwide-types parameters. please find below Makefile link:
  https://github.com/mouse07410/asn1c/blob/vlm_master/examples/sample.source.J2735/Makefile

Do you have the same problem with vlm_master branch of mouse07410's fork?

* asn_umax2INTEGER returns as 0

OK.

* But when i add the "asn_check_constraints" it shows as below error on the arm device:
  MessageFrame constraint validation failed: Millisecond: value too large (Millisecond.c:26)

Can you provide a minimal, reproducible example (together with asn1, makefiles, etc...)

yadav9997 commented 2 years ago

Thanks a lot @velichkov. please find below details:

please find attached compiled .c and .h files.

yadav9997 commented 2 years ago

@velichkov apologies for following up, would it be possible to share any valuable feedback ?

yadav9997 commented 2 years ago

@velichkov tried with the latest master repo of the below git-repo and still it gives the same issue:

https://github.com/mouse07410/asn1c

mouse07410 commented 2 years ago

@yadav9997 If you want to encode/decode a large integer value, both this repo and https://github.com/mouse07410/asn1c will work well. However, if you're trying to use constraints that large, it will not work, sorry. Supporting that would require implementing constraints of type INTEGER_t (as opposed to int64_t or such) - the code to do that is not there.