From: Laurent Mazet Date: Tue, 8 Apr 2025 22:15:09 +0000 (+0200) Subject: all pdu defined X-Git-Tag: v1.0~57 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=b398cc04daa701cda64f240e3b20a226bee2659a;p=morep.git all pdu defined --- diff --git a/morep_valid.c b/morep_valid.c index 51e9736..bfd84ad 100644 --- a/morep_valid.c +++ b/morep_valid.c @@ -14,8 +14,8 @@ /* depend: */ /* cflags: */ -/* linker: morep.o parse.o payload.o raw_data.o */ -/* winlnk: morep.o parse.o payload.o raw_data.o */ +/* linker: morep.o parse.o pdu_raw_data.o */ +/* winlnk: morep.o parse.o pdu_raw_data.o */ #include #include @@ -29,7 +29,7 @@ #include "parse.h" #include "verbose.h" -#include "raw_data.h" +#include "pdu_raw_data.h" char *progname = NULL; diff --git a/parse.h b/parse.h index 53c6a32..d2e3046 100644 --- a/parse.h +++ b/parse.h @@ -121,6 +121,19 @@ __BEGIN_DECLS buf##_len = parse_array (val, buf, sizeof (buf)); \ } +/** + @ingroup MESSAGES + + Parsing macro for fix table size field + + @param name field name + @param buf preallocated storage +*/ +#define PARSE_TAB(name, buf) \ + else if (strcmp (var, name) == 0) { \ + parse_array (val, buf, sizeof (buf)); \ + } + /** @ingroup MESSAGES @@ -191,6 +204,20 @@ __BEGIN_DECLS VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", #field)); \ } +/** + @ingroup MESSAGES + + Format an fix table size field + + @param name field name + @param field data from structure +*/ +#define FORMAT_TAB(name, field) \ + len += snprint_array (_buffer, _maxlen - len, field, sizeof (field)); \ + if (len == _maxlen) { \ + VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", #field)); \ + } + /** @ingroup MESSAGES @@ -220,34 +247,34 @@ __BEGIN_DECLS @param name field name @param field data from structure */ -#define SERIAL_INT(name, field) \ - switch (sizeof (field)) { \ - case 1: \ - if (len < _maxlen) { \ - _buffer[len++] = field; \ - } else { \ - VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \ - len = _maxlen; \ - } \ - break; \ - case 2: \ - if (len + 1 < _maxlen) { \ - *((uint16_t *)(_buffer + len)) = htons ((uint16_t)field); \ - len += 2; \ - } else { \ - VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \ - len = _maxlen; \ - } \ - break; \ - case 4: \ - if (len + 3 < _maxlen) { \ - *((uint32_t *)(_buffer + len)) = htonl ((uint32_t)field); \ - len += 4; \ - } else { \ - VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \ - len = _maxlen; \ - } \ - break; \ +#define SERIAL_INT(name, field) \ + switch (sizeof (field)) { \ + case 1: \ + if (len < _maxlen) { \ + _buffer[len++] = field; \ + } else { \ + VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \ + len = _maxlen; \ + } \ + break; \ + case 2: \ + if (len + 1 < _maxlen) { \ + *((uint16_t *)(_buffer + len)) = htons ((uint16_t)field); \ + len += 2; \ + } else { \ + VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \ + len = _maxlen; \ + } \ + break; \ + case 4: \ + if (len + 3 < _maxlen) { \ + *((uint32_t *)(_buffer + len)) = htonl ((uint32_t)field); \ + len += 4; \ + } else { \ + VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \ + len = _maxlen; \ + } \ + break; \ } /** @@ -258,26 +285,26 @@ __BEGIN_DECLS @param name field name @param field data from structure */ -#define SERIAL_DOUBLE(name, field) \ - switch (sizeof (field)) { \ - case 4: \ - if (len + 3 < _maxlen) { \ - *((float *)(_buffer + len)) = field; \ - len += 4; \ - } else { \ - VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \ - len = _maxlen; \ - } \ - break; \ - case 8: \ - if (len + 7 < _maxlen) { \ - *((double *)(_buffer + len)) = field; \ - len += 8; \ - } else { \ - VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \ - len = _maxlen; \ - } \ - break; \ +#define SERIAL_DOUBLE(name, field) \ + switch (sizeof (field)) { \ + case 4: \ + if (len + 3 < _maxlen) { \ + *((float *)(_buffer + len)) = field; \ + len += 4; \ + } else { \ + VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \ + len = _maxlen; \ + } \ + break; \ + case 8: \ + if (len + 7 < _maxlen) { \ + *((double *)(_buffer + len)) = field; \ + len += 8; \ + } else { \ + VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \ + len = _maxlen; \ + } \ + break; \ } /** @@ -288,14 +315,30 @@ __BEGIN_DECLS @param name field name @param field data from structure */ -#define SERIAL_ARRAY(name, field) \ - { \ - int _l = (field##_len < _maxlen - len) ? field##_len : _maxlen - len; \ - memcpy (_buffer + len, field, _l); \ - len += _l; \ - } \ - if (len == _maxlen) { \ - VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \ +#define SERIAL_ARRAY(name, field) \ + if (field##_len < _maxlen - len) { \ + memcpy (_buffer + len, field, field##_len); \ + len += field##_len; \ + } else { \ + VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \ + len = _maxlen; \ + } + +/** + @ingroup MESSAGES + + Serialyze an fix table size field + + @param name field name + @param field data from structure +*/ +#define SERIAL_TAB(name, field) \ + if (sizeof (field) < _maxlen - len) { \ + memcpy (_buffer + len, field, sizeof (field)); \ + len += sizeof (field); \ + } else { \ + VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \ + len = _maxlen; \ } /** @@ -303,7 +346,7 @@ __BEGIN_DECLS End of serialisation section */ -#define END_SERIAL() \ +#define END_SERIAL() \ return len; /** @@ -325,7 +368,7 @@ __BEGIN_DECLS Deserialyze to an integer field @param name field name - @param field data from structure + @param field structure storage */ #define DESERIAL_INT(name, field) \ switch (sizeof (field)) { \ @@ -363,7 +406,7 @@ __BEGIN_DECLS Deserialyze to a floating point field @param name field name - @param field data from structure + @param field structure storage */ #define DESERIAL_DOUBLE(name, field) \ switch (sizeof (field)) { \ @@ -387,13 +430,32 @@ __BEGIN_DECLS break; \ } +/** + @ingroup MESSAGES + + Deserialyze to a fix size table field + + @param name field name + @param field structure storage + @param len table length +*/ +#define DESERIAL_TAB(name, field) \ + if (sizeof (field) < end - ptr) { \ + memcpy (field, ptr, sizeof (field)); \ + field##_len = sizeof (field); \ + ptr += field##_len; \ + } else { \ + VERBOSE (morep, WARNING, PRINTF ("no data for field '%s'\n", name)); \ + ptr = end + 1; \ + } + /** @ingroup MESSAGES Deserialyze to an array field @param name field name - @param field data from structure + @param field structure storage */ #define DESERIAL_ARRAY(name, field) \ if (field##_len == 0) { \ @@ -405,6 +467,7 @@ __BEGIN_DECLS ptr += field##_len; \ } else { \ VERBOSE (morep, WARNING, PRINTF ("no data for field '%s'\n", name)); \ + ptr = end + 1; \ } /** diff --git a/pdu_channel.c b/pdu_channel.c new file mode 100644 index 0000000..39162ee --- /dev/null +++ b/pdu_channel.c @@ -0,0 +1,53 @@ +/* + File name : pdu_channel.c + Projet : MERLIN + Date of creation : 2025/04/08 + Version : 1.0 + Copyright : Thales SIX + Author : Laurent Mazet + + Description : This file contains functions for channel pdu + + History : + - initial version +*/ + +#include + +#include "parse.h" + +#include "pdu_channel.h" + +int parse_channel (char *line, CHANNEL_t *out) +{ + BEGIN_PARSE (line) + PARSE_INT ("CHANNELID", out->channel_id) + PARSE_INT ("KEYID", out->key_id) + END_PARSE () +} + +int format_channel (CHANNEL_t *in, char *buffer, int maxlen) +{ + BEGIN_FORMAT (buffer, maxlen) + FORMAT_INT ("CHANNELID", in->channel_id) + FORMAT_INT ("KEYID", in->key_id) + END_FORMAT () +} + +int serial_channel (CHANNEL_t *in, uint8_t *buffer, int maxlen) +{ + BEGIN_SERIAL (buffer, maxlen) + SERIAL_INT ("CHANNELID", in->channel_id) + SERIAL_INT ("KEYID", in->key_id) + END_SERIAL () +} + +int deserial_channel (uint8_t *buffer, int len, CHANNEL_t *out) +{ + BEGIN_DESERIAL (buffer, len) + DESERIAL_INT ("CHANNELID", out->channel_id) + DESERIAL_INT ("KEYID", out->key_id) + END_DESERIAL () +} + +/* vim: set ts=4 sw=4 si et: */ diff --git a/pdu_channel.h b/pdu_channel.h index 4a7eb79..3f15847 100644 --- a/pdu_channel.h +++ b/pdu_channel.h @@ -1,12 +1,12 @@ /* - File name : channel.h + File name : pdu_channel.h Projet : MERLIN Date of creation : 2025/04/08 Version : 1.0 Copyright : Thales SIX Author : Laurent Mazet - Description : This file contains message definition + Description : This file contains functions for channel pdu History : - initial version @@ -71,11 +71,11 @@ int serial_channel (CHANNEL_t *in, uint8_t *buffer, int maxlen); Deserial channel type fields from a network stream @param buffer network stream - @param maxlen buffer limit + @param len buffer length @param out output structure @return 0 on success */ -int deserial_channel (uint8_t *buffer, int maxlen, CHANNEL_t *out); +int deserial_channel (uint8_t *buffer, int len, CHANNEL_t *out); __END_DECLS diff --git a/pdu_clear_data.c b/pdu_clear_data.c index f5840bc..4a64fab 100644 --- a/pdu_clear_data.c +++ b/pdu_clear_data.c @@ -16,33 +16,46 @@ #include "parse.h" -#include "clear_data.h" +#include "pdu_clear_data.h" int parse_clear_data (char *line, CLEAR_DATA_t *out) { BEGIN_PARSE (line) PARSE_INT ("CHANNEL", out->channel_id) - PARSE_INT ("BYPASS", out->bypass) + PARSE_INT ("BYPASSLEN", out->bypass_len) + PARSE_ARRAY ("BYPASS", out->bypass) PARSE_ARRAY ("DATA", out->data) END_PARSE () } int format_clear_data (CLEAR_DATA_t *in, char *buffer, int maxlen) { - BEGIN_FORMAT (buffer, maxlen); - FORMAT_INT ("CHANNEL", out->channel_id) - FORMAT_INT ("BYPASS", out->bypass) - FORMAT_ARRAY ("DATA", out->data) + BEGIN_FORMAT (buffer, maxlen) + FORMAT_INT ("CHANNEL", in->channel_id) + FORMAT_INT ("BYPASSLEN", in->bypass_len) + FORMAT_ARRAY ("BYPASS", in->bypass) + FORMAT_ARRAY ("DATA", in->data) END_FORMAT () } int serial_clear_data (CLEAR_DATA_t *in, uint8_t *buffer, int maxlen) { - BEGIN_SERIAL (buffer, maxlen); - SERIAL_INT (out->channel_id) - SERIAL_INT (out->bypass) - SERIAL_ARRAY (out->data) + BEGIN_SERIAL (buffer, maxlen) + SERIAL_INT ("CHANNEL", in->channel_id) + SERIAL_INT ("BYPASSLEN", in->bypass_len) + SERIAL_ARRAY ("BYPASS", in->bypass) + SERIAL_ARRAY ("DATA", in->data) END_SERIAL () } +int deserial_clear_data (uint8_t *buffer, int len, CLEAR_DATA_t *out) +{ + BEGIN_DESERIAL (buffer, len) + DESERIAL_INT ("CHANNEL", out->channel) + DESERIAL_INT ("BYPASSLEN", out->bypass_len) + DESERIAL_ARRAY ("BYPASS", out->bypass) + DESERIAL_ARRAY ("DATA", out->data) + END_DESERIAL () +} + /* vim: set ts=4 sw=4 si et: */ diff --git a/pdu_clear_data.h b/pdu_clear_data.h index 29da2f9..1802156 100644 --- a/pdu_clear_data.h +++ b/pdu_clear_data.h @@ -1,12 +1,12 @@ /* - File name : clear_data.h + File name : pdu_clear_data.h Projet : MERLIN Date of creation : 2025/04/07 Version : 1.0 Copyright : Thales SIX Author : Laurent Mazet - Description : This file contains definition of clear data type + Description : This file contains functions for clear data pdu History : - initial version @@ -74,11 +74,11 @@ int serial_clear_data (CLEAR_DATA_t *in, uint8_t *buffer, int maxlen); Deserial clear data type fields from a network stream @param buffer network stream - @param maxlen buffer limit + @param len buffer length @param out output structure @return 0 on success */ -int deserial_clear_data (uint8_t *buffer, int maxlen, CLEAR_DATA_t *out); +int deserial_clear_data (uint8_t *buffer, int len, CLEAR_DATA_t *out); __END_DECLS diff --git a/pdu_encrypted_data.c b/pdu_encrypted_data.c new file mode 100644 index 0000000..7382220 --- /dev/null +++ b/pdu_encrypted_data.c @@ -0,0 +1,65 @@ +/* + File name : encrypted_data.c + Projet : MERLIN + Date of creation : 2025/04/08 + Version : 1.0 + Copyright : Thales SIX + Author : Laurent Mazet + + Description : This file contains definition of encrypted data type + + History : + - initial version +*/ + +#include + +#include "parse.h" + +#include "pdu_encrypted_data.h" + +int parse_encrypted_data (char *line, ENCRYPTED_DATA_t *out) +{ + BEGIN_PARSE (line) + PARSE_INT ("CHANNEL", out->channel_id) + PARSE_TAB ("IV", out->iv) + PARSE_INT ("BYPASSLEN", out->bypass_len) + PARSE_ARRAY ("BYPASS", out->bypass) + PARSE_ARRAY ("DATA", out->data) + END_PARSE () +} + +int format_encrypted_data (ENCRYPTED_DATA_t *in, char *buffer, int maxlen) +{ + BEGIN_FORMAT (buffer, maxlen) + FORMAT_INT ("CHANNEL", in->channel_id) + FORMAT_TAB ("IV", in->iv) + FORMAT_INT ("BYPASSLEN", in->bypass_len) + FORMAT_ARRAY ("BYPASS", in->bypass) + FORMAT_ARRAY ("DATA", in->data) + END_FORMAT () +} + +int serial_encrypted_data (ENCRYPTED_DATA_t *in, uint8_t *buffer, int maxlen) +{ + BEGIN_SERIAL (buffer, maxlen) + SERIAL_INT ("CHANNEL", in->channel_id) + SERIAL_TAB ("IV", in->iv) + SERIAL_INT ("BYPASSLEN", in->bypass_len) + SERIAL_ARRAY ("BYPASS", in->bypass) + SERIAL_ARRAY ("DATA", in->data) + END_SERIAL () +} + +int deserial_encrypted_data (uint8_t *buffer, int len, ENCRYPTED_DATA_t *out) +{ + BEGIN_DESERIAL (buffer, len) + DESERIAL_INT ("CHANNEL", out->channel) + DESERIAL_TAB ("IV", out->iv) + DESERIAL_INT ("BYPASSLEN", out->bypass_len) + DESERIAL_ARRAY ("BYPASS", out->bypass) + DESERIAL_ARRAY ("DATA", out->data) + END_DESERIAL () +} + +/* vim: set ts=4 sw=4 si et: */ diff --git a/pdu_encrypted_data.h b/pdu_encrypted_data.h index f4780a2..6cc93d0 100644 --- a/pdu_encrypted_data.h +++ b/pdu_encrypted_data.h @@ -1,19 +1,19 @@ /* - File name : message.h + File name : pdu_encrypted_data.h Projet : MERLIN - Date of creation : 2025/04/03 + Date of creation : 2025/04/08 Version : 1.0 Copyright : Thales SIX Author : Laurent Mazet - Description : This file contains message definition + Description : This file contains functions for encrypted data pdu History : - initial version */ -#ifndef __MESSAGE_H__ -#define __MESSAGE_H__ +#ifndef __ENCRYPTED_DATA_H__ +#define __ENCRYPTED_DATA_H__ #include #include @@ -27,62 +27,62 @@ __BEGIN_DECLS */ typedef struct { uint8_t channel_id; /**< channel index */ + uint8_t iv[12]; /**< initial vector */ uint8_t bypass_len; /**< attached bypass message length */ uint8_t bypass_msg[255]; /**< attached bypass message */ uint8_t data_len; /**< data length (must be aligned to 16 bytes) */ uint8_t data[1472]; /**< data message */ - uint8_t iv[12]; /**< initial vector */ } ENCRYPTED_DATA_t; /** @ingroup MESSAGES - Parse a string containing some clear data type fields + Parse a string containing some encrypted data type fields @param line string to analyse @param out output structure @return 0 on success */ -int parse_clear_data (char *line, CLEAR_DATA_t *out); +int parse_encrypted_data (char *line, ENCRYPTED_DATA_t *out); /** @ingroup MESSAGES - Format clear data type fields into a string + Format encrypted data type fields into a string @param in input structure @param buffer output string @param maxlen buffer limit @return 0 on success */ -int format_clear_data (CLEAR_DATA_t *in, char *buffer, int maxlen); +int format_encrypted_data (ENCRYPTED_DATA_t *in, char *buffer, int maxlen); /** @ingroup MESSAGES - Serial clear data type fields into a network stream + Serial encrypted data type fields into a network stream @param in input structure @param buffer network stream @param maxlen buffer limit @return buffer length */ -int serial_clear_data (CLEAR_DATA_t *in, uint8_t *buffer, int maxlen); +int serial_encrypted_data (ENCRYPTED_DATA_t *in, uint8_t *buffer, int maxlen); /** @ingroup MESSAGES - Deserial clear data type fields from a network stream + Deserial encrypted data type fields from a network stream @param buffer network stream - @param maxlen buffer limit + @param len buffer length @param out output structure @return 0 on success */ -int deserial_clear_data (uint8_t *buffer, int maxlen, CLEAR_DATA_t *out); +int deserial_encrypted_data (uint8_t *buffer, int len, ENCRYPTED_DATA_t *out); __END_DECLS -#endif /* __MESSAGE_H__ */ +#endif /* __ENCRYPTED_DATA_H__ */ /* vim: set ts=4 sw=4 si et: */ diff --git a/pdu_key.c b/pdu_key.c new file mode 100644 index 0000000..d5089aa --- /dev/null +++ b/pdu_key.c @@ -0,0 +1,57 @@ +/* + File name : pdu_key.c + Projet : MERLIN + Date of creation : 2025/04/08 + Version : 1.0 + Copyright : Thales SIX + Author : Laurent Mazet + + Description : This file contains functions for key pdu + + History : + - initial version +*/ + +#include + +#include "parse.h" + +#include "pdu_key.h" + +int parse_key (char *line, KEY_t *out) +{ + BEGIN_PARSE (line) + PARSE_INT ("KEYID", out->key_id) + PARSE_INT ("KEYLEN", out->key_len) + PARSE_ARRAY ("KEY", out->key) + END_PARSE () +} + +int format_key (KEY_t *in, char *buffer, int maxlen) +{ + BEGIN_FORMAT (buffer, maxlen) + FORMAT_INT ("KEYID", in->key_id) + FORMAT_INT ("KEYLEN", in->key_len) + FORMAT_ARRAY ("KEY", in->key) + END_FORMAT () +} + +int serial_key (KEY_t *in, uint8_t *buffer, int maxlen) +{ + BEGIN_SERIAL (buffer, maxlen) + SERIAL_INT ("KEYID", in->key_id) + SERIAL_INT ("KEYLEN", in->key_len) + SERIAL_ARRAY ("KEY", in->key) + END_SERIAL () +} + +int deserial_key (uint8_t *buffer, int len, KEY_t *out) +{ + BEGIN_DESERIAL (buffer, len) + DESERIAL_INT ("KEYID", out->key_id) + DESERIAL_INT ("KEYLEN", out->key_len) + DESERIAL_ARRAY ("KEY", out->key) + END_DESERIAL () +} + +/* vim: set ts=4 sw=4 si et: */ diff --git a/pdu_key.h b/pdu_key.h index 560fc9c..fb23468 100644 --- a/pdu_key.h +++ b/pdu_key.h @@ -1,19 +1,19 @@ /* - File name : message.h + File name : pdu_key.h Projet : MERLIN - Date of creation : 2025/04/03 + Date of creation : 2025/04/08 Version : 1.0 Copyright : Thales SIX Author : Laurent Mazet - Description : This file contains message definition + Description : This file contains functions for key pdu History : - initial version */ -#ifndef __MESSAGE_H__ -#define __MESSAGE_H__ +#ifndef __KEY_H__ +#define __KEY_H__ #include #include @@ -26,6 +26,7 @@ __BEGIN_DECLS Key type */ typedef struct { + uint8_t key_id; /**< key id */ uint16_t key_len; /**< key length */ uint8_t key[1495]; /**< raw key */ } KEY_t; @@ -33,52 +34,52 @@ typedef struct { /** @ingroup MESSAGES - Parse a string containing some clear data type fields + Parse a string containing some key type fields @param line string to analyse @param out output structure @return 0 on success */ -int parse_clear_data (char *line, CLEAR_DATA_t *out); +int parse_key (char *line, KEY_t *out); /** @ingroup MESSAGES - Format clear data type fields into a string + Format key type fields into a string @param in input structure @param buffer output string @param maxlen buffer limit @return 0 on success */ -int format_clear_data (CLEAR_DATA_t *in, char *buffer, int maxlen); +int format_key (KEY_t *in, char *buffer, int maxlen); /** @ingroup MESSAGES - Serial clear data type fields into a network stream + Serial key type fields into a network stream @param in input structure @param buffer network stream @param maxlen buffer limit @return buffer length */ -int serial_clear_data (CLEAR_DATA_t *in, uint8_t *buffer, int maxlen); +int serial_key (KEY_t *in, uint8_t *buffer, int maxlen); /** @ingroup MESSAGES - Deserial clear data type fields from a network stream + Deserial key type fields from a network stream @param buffer network stream - @param maxlen buffer limit + @param len buffer length @param out output structure @return 0 on success */ -int deserial_clear_data (uint8_t *buffer, int maxlen, CLEAR_DATA_t *out); +int deserial_key (uint8_t *buffer, int len, KEY_t *out); __END_DECLS -#endif /* __MESSAGE_H__ */ +#endif /* __KEY_H__ */ /* vim: set ts=4 sw=4 si et: */ diff --git a/pdu_prng_param.c b/pdu_prng_param.c new file mode 100644 index 0000000..9425bbd --- /dev/null +++ b/pdu_prng_param.c @@ -0,0 +1,57 @@ +/* + File name : pdu_prng_param.c + Projet : MERLIN + Date of creation : 2025/04/08 + Version : 1.0 + Copyright : Thales SIX + Author : Laurent Mazet + + Description : This file contains functions for PRNG parameter pdu + + History : + - initial version +*/ + +#include + +#include "parse.h" + +#include "pdu_key.h" + +int parse_prng_param (char *line, PRNG_PARAM_t *out) +{ + BEGIN_PARSE (line) + PARSE_INT ("PRNGID", out->prng_id) + PARSE_INT ("SEEDLEN", out->seed_len) + PARSE_ARRAY ("SEED", out->seed) + END_PARSE () +} + +int format_prng_param (PRNG_PARAM_t *in, char *buffer, int maxlen) +{ + BEGIN_FORMAT (buffer, maxlen) + FORMAT_INT ("PRNGID", in->prng_id) + FORMAT_INT ("SEEDLEN", in->seed_len) + FORMAT_ARRAY ("SEED", in->seed) + END_FORMAT () +} + +int serial_prng_param (PRNG_PARAM_t *in, uint8_t *buffer, int maxlen) +{ + BEGIN_SERIAL (buffer, maxlen) + SERIAL_INT ("PRNGID", in->prng_id) + SERIAL_INT ("SEEDLEN", in->seed_len) + SERIAL_ARRAY ("SEED", in->seed) + END_SERIAL () +} + +int deserial_prng_param (uint8_t *buffer, int len, PRNG_PARAM_t *out) +{ + BEGIN_DESERIAL (buffer, len) + DESERIAL_INT ("PRNGID", out->prng_id) + DESERIAL_INT ("SEEDLEN", out->seed_len) + DESERIAL_ARRAY ("SEED", out->seed) + END_DESERIAL () +} + +/* vim: set ts=4 sw=4 si et: */ diff --git a/pdu_prng_param.h b/pdu_prng_param.h index 79335cd..319d901 100644 --- a/pdu_prng_param.h +++ b/pdu_prng_param.h @@ -1,19 +1,19 @@ /* - File name : message.h + File name : pdu_prng_param.h Projet : MERLIN - Date of creation : 2025/04/03 + Date of creation : 2025/04/08 Version : 1.0 Copyright : Thales SIX Author : Laurent Mazet - Description : This file contains message definition + Description : This file contains functions for PRNG parameter PDU History : - initial version */ -#ifndef __MESSAGE_H__ -#define __MESSAGE_H__ +#ifndef __PRNG_PARAM_H__ +#define __PRNG_PARAM_H__ #include #include @@ -34,52 +34,52 @@ typedef struct { /** @ingroup MESSAGES - Parse a string containing some clear data type fields + Parse a string containing some PRNG parameter type fields @param line string to analyse @param out output structure @return 0 on success */ -int parse_clear_data (char *line, CLEAR_DATA_t *out); +int parse_prng_param (char *line, PRNG_PARAM_t *out); /** @ingroup MESSAGES - Format clear data type fields into a string + Format PRNG parameter type fields into a string @param in input structure @param buffer output string @param maxlen buffer limit @return 0 on success */ -int format_clear_data (CLEAR_DATA_t *in, char *buffer, int maxlen); +int format_prng_param (PRNG_PARAM_t *in, char *buffer, int maxlen); /** @ingroup MESSAGES - Serial clear data type fields into a network stream + Serial PRNG parameter type fields into a network stream @param in input structure @param buffer network stream @param maxlen buffer limit @return buffer length */ -int serial_clear_data (CLEAR_DATA_t *in, uint8_t *buffer, int maxlen); +int serial_prng_param (PRNG_PARAM_t *in, uint8_t *buffer, int maxlen); /** @ingroup MESSAGES - Deserial clear data type fields from a network stream + Deserial PRNG parameter type fields from a network stream @param buffer network stream - @param maxlen buffer limit + @param len buffer length @param out output structure @return 0 on success */ -int deserial_clear_data (uint8_t *buffer, int maxlen, CLEAR_DATA_t *out); +int deserial_prng_param (uint8_t *buffer, int len, PRNG_PARAM_t *out); __END_DECLS -#endif /* __MESSAGE_H__ */ +#endif /* __PRNG_PARAM_H__ */ /* vim: set ts=4 sw=4 si et: */ diff --git a/pdu_raw_data.c b/pdu_raw_data.c index b9c6ec2..8a78789 100644 --- a/pdu_raw_data.c +++ b/pdu_raw_data.c @@ -16,7 +16,7 @@ #include "parse.h" -#include "raw_data.h" +#include "pdu_raw_data.h" int parse_raw_data (char *line, RAW_DATA_t *out) { @@ -39,9 +39,9 @@ int serial_raw_data (RAW_DATA_t *in, uint8_t *buffer, int maxlen) END_SERIAL () } -int deserial_raw_data (uint8_t *buffer, int maxlen, RAW_DATA_t *out) +int deserial_raw_data (uint8_t *buffer, int len, RAW_DATA_t *out) { - BEGIN_DESERIAL (buffer, maxlen) + BEGIN_DESERIAL (buffer, len) DESERIAL_ARRAY ("DATA", out->data) END_DESERIAL () } diff --git a/pdu_raw_data.h b/pdu_raw_data.h index 1153888..cf525cd 100644 --- a/pdu_raw_data.h +++ b/pdu_raw_data.h @@ -1,12 +1,12 @@ /* - File name : raw_data.h + File name : pdu_raw_data.h Projet : MERLIN Date of creation : 2025/04/07 Version : 1.0 Copyright : Thales SIX Author : Laurent Mazet - Description : This file contains definition of raw data type + Description : This file contains functions for raw data pdu History : - initial version @@ -71,11 +71,11 @@ int serial_raw_data (RAW_DATA_t *in, uint8_t *buffer, int maxlen); Deserial raw data type fields from a network stream @param buffer network stream - @param maxlen buffer limit + @param len buffer length @param out output structure @return 0 on success */ -int deserial_raw_data (uint8_t *buffer, int maxlen, RAW_DATA_t *out); +int deserial_raw_data (uint8_t *buffer, int len, RAW_DATA_t *out); __END_DECLS diff --git a/pdu_status.c b/pdu_status.c new file mode 100644 index 0000000..ba17b23 --- /dev/null +++ b/pdu_status.c @@ -0,0 +1,49 @@ +/* + File name : pdu_status.c + Projet : MERLIN + Date of creation : 2025/04/08 + Version : 1.0 + Copyright : Thales SIX + Author : Laurent Mazet + + Description : This file contains functions for status pdu + + History : + - initial version +*/ + +#include + +#include "parse.h" + +#include "pdu_status.h" + +int parse_status (char *line, STATUS_t *out) +{ + BEGIN_PARSE (line) + PARSE_INT ("STATUS", out->status) + END_PARSE () +} + +int format_status (STATUS_t *in, char *buffer, int maxlen) +{ + BEGIN_FORMAT (buffer, maxlen) + FORMAT_INT ("STATUS", in->status) + END_FORMAT () +} + +int serial_status (STATUS_t *in, uint8_t *buffer, int maxlen) +{ + BEGIN_SERIAL (buffer, maxlen) + SERIAL_INT ("STATUS", in->status) + END_SERIAL () +} + +int deserial_status (uint8_t *buffer, int len, STATUS_t *out) +{ + BEGIN_DESERIAL (buffer, len) + DESERIAL_INT ("STATUS", out->status) + END_DESERIAL () +} + +/* vim: set ts=4 sw=4 si et: */ diff --git a/pdu_status.h b/pdu_status.h index 5b3d326..218620f 100644 --- a/pdu_status.h +++ b/pdu_status.h @@ -1,19 +1,19 @@ /* - File name : message.h + File name : pdu_status.h Projet : MERLIN - Date of creation : 2025/04/03 + Date of creation : 2025/04/08 Version : 1.0 Copyright : Thales SIX Author : Laurent Mazet - Description : This file contains message definition + Description : This file contains functions for status pdu History : - initial version */ -#ifndef __MESSAGE_H__ -#define __MESSAGE_H__ +#ifndef __STATUS_H__ +#define __STATUS_H__ #include #include @@ -32,52 +32,52 @@ typedef struct { /** @ingroup MESSAGES - Parse a string containing some clear data type fields + Parse a string containing some status type fields @param line string to analyse @param out output structure @return 0 on success */ -int parse_clear_data (char *line, CLEAR_DATA_t *out); +int parse_status (char *line, STATUS_t *out); /** @ingroup MESSAGES - Format clear data type fields into a string + Format status type fields into a string @param in input structure @param buffer output string @param maxlen buffer limit @return 0 on success */ -int format_clear_data (CLEAR_DATA_t *in, char *buffer, int maxlen); +int format_status (STATUS_t *in, char *buffer, int maxlen); /** @ingroup MESSAGES - Serial clear data type fields into a network stream + Serial status type fields into a network stream @param in input structure @param buffer network stream @param maxlen buffer limit @return buffer length */ -int serial_clear_data (CLEAR_DATA_t *in, uint8_t *buffer, int maxlen); +int serial_status (STATUS_t *in, uint8_t *buffer, int maxlen); /** @ingroup MESSAGES - Deserial clear data type fields from a network stream + Deserial status type fields from a network stream @param buffer network stream - @param maxlen buffer limit + @param len buffer length @param out output structure @return 0 on success */ -int deserial_clear_data (uint8_t *buffer, int maxlen, CLEAR_DATA_t *out); +int deserial_status (uint8_t *buffer, int len, STATUS_t *out); __END_DECLS -#endif /* __MESSAGE_H__ */ +#endif /* __STATUS_H__ */ /* vim: set ts=4 sw=4 si et: */