Skip to content

Commit

Permalink
New message type
Browse files Browse the repository at this point in the history
  • Loading branch information
RReichert committed Aug 14, 2024
1 parent 1250e65 commit 74dc673
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,12 @@ bool (((m.internal_decode_fn)))(sbp_decode_ctx_t *ctx, (((m.type_name))) *msg)
if (!(((f.decode_fn)))(ctx, &(((field)))[i])) { return false; }
}
((*- elif f.packing == "variable-array" *))
((*- if f.generate_size_fn *))
if ( ((ctx->buf_len - ctx->offset) % (((f.encoded_len_macro)))) != 0) {
return false;
}
msg->(((f.size_fn))) = (uint8_t)((ctx->buf_len - ctx->offset) / (((f.encoded_len_macro))));
((*- endif *))
for (uint8_t i = 0; i < msg->(((f.size_fn))); i++) {
if (!(((f.decode_fn)))(ctx, &(((field)))[i])) { return false; }
}
Expand Down
41 changes: 0 additions & 41 deletions generator/sbpg/targets/resources/c/test/sbp_cpp_test.cc.j2
Original file line number Diff line number Diff line change
Expand Up @@ -495,47 +495,6 @@ TEST_F( ((( fixture_name ))), DecodeFromBufWithoutNread) {
EXPECT_EQ(msg, info.test_msg);
}

((*- if t.fields|length > 0 *))
TEST_F( ((( fixture_name ))), DecodeFromBufUnderflow) {
auto info = get_test_msg_info();
((( t.struct_name ))) msg{};

for (uint8_t i = 0; i < info.payload_len; i++) {
int expected_return = SBP_DECODE_ERROR;

((*- for f in t.c_decoded_fieldskeys *))
((*- set ff = t.c_decoded_fields[f] *))
((*- if ff is dict_type *))
((*- if ff.handle_as and ff.handle_as == "vararray-len" *))
((*- set relates_to = ff.relates_to *))
size_t overhead = []()->size_t{(((t.struct_name))) t{}; return (((t.fn_prefix)))_encoded_len(&t); }();
size_t elem_size = []()->size_t{(((t.struct_name))) t{}; t.(((f))) = 1; return (((t.fn_prefix)))_encoded_len(&t); }() - overhead;

if (i >= overhead) {
if ( ((i - overhead) % elem_size) == 0) {
expected_return = SBP_OK;
}
}
((*- elif ff.handle_as and ff.handle_as == "encoded-string" *))
size_t overhead = SBP_(((t.canonical_name)))_ENCODED_OVERHEAD;
//size_t overhead = []()->size_t{(((t.struct_name))) t{}; return (((t.fn_prefix)))_encoded_len(&t); }();
((*- if ff.min_len *))
overhead += (((ff.min_len)));
((*- endif *))
if (i >= overhead) {
expected_return = SBP_OK;
}
((*- endif *))
((*- endif *))
((*- endfor *))

EXPECT_EQ(
((( t.fn_prefix )))_decode(&info.encoded_payload[0], i, nullptr, &msg),
expected_return);
}
}
((*- endif *))

TEST_F( ((( fixture_name ))), ReceiveThroughSbpState) {
auto info = get_test_msg_info();
sbp_state_t state;
Expand Down
2 changes: 1 addition & 1 deletion python/tests/sbp/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_table_count():
Test number of available messages to deserialize.
"""
number_of_messages = 237
number_of_messages = 238
assert len(_SBP_TABLE) == number_of_messages

def test_table_unqiue_count():
Expand Down
57 changes: 57 additions & 0 deletions spec/tests/yaml/swiftnav/sbp/signing/test_MsgDigitalSignature.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
description: Unit tests for swiftnav.sbp.signing MsgDigitalSignature
generated_on: '2023-03-17 19:24:46.292191'
package: sbp.signing
tests:
- msg:
c_decoded_fields:
n_signed_messages:
handle_as: vararray-len
relates_to: signed_messages
value: 3
fields:
stream_counter: 1
on_demand_counter: 2
certificate_id:
- 1
- 2
- 3
- 4
algorithm: 0
signature_length: 16
signature:
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
flags: 0
signed_messages:
- 11
- 22
- 33
module: sbp.signing
name: MsgDigitalSignature
msg_type: '0xC10'
raw_json: '{"preamble": 85, "msg_type": 3080, "sender": 66, "length": 83, "payload":
"AAECAQIDBEgAAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkcKFRc=",
"crc": 33768, "flags": 0, "stream_counter": 1, "on_demand_counter": 2, "certificate_id":
[1, 2, 3, 4], "signature": {"len": 72, "data": [0, 11]}, "signed_messages": [10, 21, 23]}'
raw_packet: VRAMQgAcAQIBAgMEABAAAQIDBAUGBwgJCgsMDQ4PAAsWIZo5
sbp:
crc: '0x399A'
length: 28
msg_type: '0xC10'
payload: AQIBAgMEABAAAQIDBAUGBwgJCgsMDQ4PAAsWIQ==
preamble: '0x55'
sender: '0x42'
61 changes: 61 additions & 0 deletions spec/yaml/swiftnav/sbp/signing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,67 @@ definitions:
`expiration`. This certificate chain (allow list) can also be
validated by fetching it from `http(s)://certs.swiftnav.com/chain`.
- MSG_DIGITAL_SIGNATURE:
id: 0x0C10
short_desc: Digital signature
desc: Digital signature used for data integrity.
fields:
- stream_counter:
type: u8
desc: >
Signature message counter. Zero indexed and incremented with each
signature message. The counter will not increment if this message
was in response to an on demand request. The counter will roll
over after 256 messages. Upon connection, the value of the counter
may not initially be zero.
- on_demand_counter:
type: u8
desc: >
On demand message counter. Zero indexed and incremented with each
signature message sent in response to an on demand message. The
counter will roll over after 256 messages. Upon connection, the
value of the counter may not initially be zero.
- certificate_id:
type: array
fill: u8
size: 4
desc: The last 4 bytes of the certificate's SHA-1 fingerprint
- algorithm:
type: u8
desc: Algorithm used to generate the digital signature.
fields:
- 0-7:
values:
- 0: DER encoded ECDSA SHA-256
- 1: AES-CMAC 128
- signature_length:
type: u8
desc: Number of bytes making up the signature
- signature:
type: array
fill: u8
size_fn: signature_length
desc: Signature
- flags:
type: u8
desc: Describes the format of the 'signed messages' field below.
fields:
- 0-1:
desc: CRC type
values:
- 0: 24-bit CRCs from RTCM framing
- 1: 16-bit CRCs from SBP framing
- signed_messages:
type: array
fill: u8
desc: >
CRCs of the messages covered by this signature. For Skylark,
which delivers SBP messages wrapped in Swift's proprietary RTCM
message, these are the 24-bit CRCs from the RTCM message framing.
For SBP only streams, this will be 16-bit CRCs from the SBP
framing. See the `flags` field to determine the type of CRCs
covered.
- MSG_ECDSA_SIGNATURE:
id: 0x0C08
short_desc: An ECDSA signature
Expand Down

0 comments on commit 74dc673

Please sign in to comment.