From 9c8ece1538d31dba9a416c9f29f88e18510f4c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Sat, 18 May 2019 16:32:20 +0300 Subject: Whole-project: partial implementation of protocol. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit is part of ticket #31. Branch is not in a compiling state. Work is being done on utility functions and protocol implementation. To be completed later. Signed-off-by: Ramūnas Mažeikis --- include/protocol.h | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/utils.h | 11 ++++++++ 2 files changed, 91 insertions(+) create mode 100644 include/protocol.h create mode 100644 include/utils.h (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h new file mode 100644 index 0000000..c1b786c --- /dev/null +++ b/include/protocol.h @@ -0,0 +1,80 @@ +/* + * Usurpataion --- client-server protocol interface. + * + * Copyright (C) 2019 Ramūnas Mažeikis + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifdef PROTOCOL_H_INCLUDED +#define PROTOCOL_H_INCLUDED + +#include + +#define SUCCESS (0) +#define TLV_OVERFLOW (1 << 0) + +enum packet_type { + REGURAL, + HEARTBEAT, + DISCOVERY +}; + +enum tlv_type { + TEXT, /* NULL-terminated string. */ + FPI1, /* Fixed point. 1 decimal digit of precision. */ + TIMESTAMP, + REQUEST, + REPLY, + UUID +}; + +struct packet_data { + enum packet_type type; + size_t packet_size; + char *data; /* Bytes representing tlv's */ +}; + +struct tlv { + enum tlv_type type; + size_t length; + void *data; +}; + +/* + * Reads last packets received, parses and stores them to be later retreived + * via get_tlv. + * */ +void get_last_data(void); + +/* Returns tlv's parsed by get_last_data. Returned tlv is only valid until + * next call to get_tlv. + * */ +struct tlv * get_tlv(void); + +/* Any modifications made to the pending outgoing packet are nullified. + * */ +void clear_data(void); + +/* Appends data to the next packet to be sent. Type of data is determined by + * enum tlv_type. + * */ +void push_data(char *data, enum tlv_type); + +/* Sends packet towards the other end. + * */ +void flush_data(void); + +#endif /* PROTOCOL_H_INCLUDED */ diff --git a/include/utils.h b/include/utils.h new file mode 100644 index 0000000..ca2d2ee --- /dev/null +++ b/include/utils.h @@ -0,0 +1,11 @@ +#ifdef PROJECT_UTILS_H +#define PROJECT_UTILS_H + +typedef int fpi1_t; + +fpi1_t add(fpi1_t a, fpi1_t b); +fpi1_t sub(fpi1_t a, fpi1_t b); +fpi1_t mul(fpi1_t a, fpi1_t b); +fpi1_t div(fpi1_t a, fpi1_t b); + +#endif /* PROJECT_UTILS_H */ -- cgit v1.2.3 From b4165ee0b257aaa9064c5ac82200ff2569a02955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Sun, 19 May 2019 13:52:43 +0300 Subject: Protocol: more work on protocol implementation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Additional functions implemented for protocol and basic functions to work with uuid. Source is buildable but actual build files are not edited to accomodate the changes. Signed-off-by: Ramūnas Mažeikis --- include/protocol.h | 23 ++++++++++++++++++++--- include/utils.h | 15 ++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index c1b786c..5872fa3 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifdef PROTOCOL_H_INCLUDED +#ifndef PROTOCOL_H_INCLUDED #define PROTOCOL_H_INCLUDED #include @@ -33,11 +33,28 @@ enum packet_type { }; enum tlv_type { - TEXT, /* NULL-terminated string. */ - FPI1, /* Fixed point. 1 decimal digit of precision. */ + /* NULL-terminated string. */ + TEXT, + + /* Fixed point. 1 decimal digit of precision. */ + FPI1, + + /* Literally time_t*/ TIMESTAMP, + + /* Represents a request for lost message. Data is unsigned integer + * that uniquely identifies the message. + */ REQUEST, + + /* Response to request. Begins with unsigned integer that represents + * which message is begin repeated and the actual null-terminated + * message after that. + */ REPLY, + + /* UUID that represents a particular device. + */ UUID }; diff --git a/include/utils.h b/include/utils.h index ca2d2ee..daea864 100644 --- a/include/utils.h +++ b/include/utils.h @@ -1,6 +1,19 @@ -#ifdef PROJECT_UTILS_H +#ifndef PROJECT_UTILS_H #define PROJECT_UTILS_H +#include + +typedef struct uuid_s { + uint64_t low; + uint64_t hi; +} uuid_t; + +int cmp_uuid(uuid_t *first, uuid_t *second); + +/* Prints uuid in cannonical format. + */ +void uuid_to_str(uuid_t *to_print, char *buf); + typedef int fpi1_t; fpi1_t add(fpi1_t a, fpi1_t b); -- cgit v1.2.3 From 031caaf9b7745bfc552cc86fb475de1f18d0fd6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Sun, 19 May 2019 17:50:53 +0300 Subject: Protocol: Implemented protocol error reporting. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now public functions of the protocol can return an error code. More work is done on actual logic. Protocol code has bare-bones doxygen documentation. Signed-off-by: Ramūnas Mažeikis --- include/protocol.h | 32 ++++++++++++++++---------------- include/utils.h | 7 +------ 2 files changed, 17 insertions(+), 22 deletions(-) (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index 5872fa3..9d5b518 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -23,8 +23,8 @@ #include -#define SUCCESS (0) -#define TLV_OVERFLOW (1 << 0) +#define E_TLV_OVERFLOW (1 << 0) +#define E_UNKNOWN_TYPE (1 << 1) enum packet_type { REGURAL, @@ -33,27 +33,27 @@ enum packet_type { }; enum tlv_type { - /* NULL-terminated string. */ + /** NULL-terminated string. */ TEXT, - - /* Fixed point. 1 decimal digit of precision. */ + + /** Fixed point. 1 decimal digit of precision. */ FPI1, - - /* Literally time_t*/ + + /** Literally time_t*/ TIMESTAMP, - - /* Represents a request for lost message. Data is unsigned integer - * that uniquely identifies the message. + + /** Represents a request for lost message. Data is unsigned integer + * that uniquely identifies the message. */ REQUEST, - - /* Response to request. Begins with unsigned integer that represents - * which message is begin repeated and the actual null-terminated + + /** Response to request. Begins with unsigned integer that represents + * which message is being repeated and the actual null-terminated * message after that. */ REPLY, - - /* UUID that represents a particular device. + + /** UUID that represents a particular device. */ UUID }; @@ -88,7 +88,7 @@ void clear_data(void); /* Appends data to the next packet to be sent. Type of data is determined by * enum tlv_type. * */ -void push_data(char *data, enum tlv_type); +int push_data(const char *data, enum tlv_type); /* Sends packet towards the other end. * */ diff --git a/include/utils.h b/include/utils.h index daea864..e4feb9a 100644 --- a/include/utils.h +++ b/include/utils.h @@ -4,16 +4,11 @@ #include typedef struct uuid_s { - uint64_t low; - uint64_t hi; + char bytes[16]; } uuid_t; int cmp_uuid(uuid_t *first, uuid_t *second); -/* Prints uuid in cannonical format. - */ -void uuid_to_str(uuid_t *to_print, char *buf); - typedef int fpi1_t; fpi1_t add(fpi1_t a, fpi1_t b); -- cgit v1.2.3 From bb70fccb66f55e9cc2b9ed0bf366479828f41346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Mon, 20 May 2019 21:50:19 +0300 Subject: Protocol: implemented request and reply pushing to packet. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First implementation of complete protocol interface. While the first implementation does compile, the interface might change due to demands from other parts of the project. For now reqest is a tlv that is an unsigned int which represents what message to repeat from daemon. A reply is also a tlv made of two parts --- message sequence number of type msg_ixd_t and the actual null terminated string. All of the above is subject to change. More docs. Doxygen is on the way. Signed-off-by: Ramūnas Mažeikis --- include/protocol.h | 7 +++++++ include/utils.h | 3 +++ 2 files changed, 10 insertions(+) (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index 9d5b518..ac83154 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -32,6 +32,13 @@ enum packet_type { DISCOVERY }; +/** + * Message sequence number since beggining of sesssion. + * + * Mainly used for identifying lost messages. + */ +typedef unsigned int msg_idx_t; + enum tlv_type { /** NULL-terminated string. */ TEXT, diff --git a/include/utils.h b/include/utils.h index e4feb9a..f92e0fa 100644 --- a/include/utils.h +++ b/include/utils.h @@ -9,6 +9,9 @@ typedef struct uuid_s { int cmp_uuid(uuid_t *first, uuid_t *second); +/** + * Fixed point number with one decimal digit of precision. + */ typedef int fpi1_t; fpi1_t add(fpi1_t a, fpi1_t b); -- cgit v1.2.3 From cabb90c1240015ee5cd17d91573588527bcc2482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Tue, 21 May 2019 17:41:21 +0300 Subject: Protocol: changes to interface and some re-implementation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most functions exposed in protocol.h take a connection descriptor (cd_t) as first argument. This allows for multiple connections. Device gets only one connection which means that cd_t is effectively 0 all the time. Additionaly, any function that actually does anything with a connection descriptor instead of just passing it to another function must be implemented separately in device and daemon. Signed-off-by: Ramūnas Mažeikis --- include/protocol.h | 58 ++++++++++++++++++++++++++++++++++++++++-------------- include/utils.h | 8 ++++---- 2 files changed, 47 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index ac83154..60d31ea 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -23,15 +23,28 @@ #include -#define E_TLV_OVERFLOW (1 << 0) -#define E_UNKNOWN_TYPE (1 << 1) +#define E_TLV_OVERFLOW (1 << 0) +#define E_UNKNOWN_TYPE (1 << 1) +#define E_IVALID_DESCRIPTOR (1 << 2) +/** + * Regular packets contain tlv's defined by tlv_type. + * + * Hearbeat packet tell daemon that device is still alive and listening. + * + * Discovery packets are used for what they say. + */ enum packet_type { REGURAL, HEARTBEAT, DISCOVERY }; +/** + * Connection descriptor. + */ +typedef unsigned int cd_t; + /** * Message sequence number since beggining of sesssion. * @@ -40,13 +53,16 @@ enum packet_type { typedef unsigned int msg_idx_t; enum tlv_type { - /** NULL-terminated string. */ + /** + * NULL-terminated string. To be put in a queue to display on the + * screen. + */ TEXT, /** Fixed point. 1 decimal digit of precision. */ FPI1, - /** Literally time_t*/ + /** Literally time_t */ TIMESTAMP, /** Represents a request for lost message. Data is unsigned integer @@ -54,51 +70,63 @@ enum tlv_type { */ REQUEST, - /** Response to request. Begins with unsigned integer that represents + /** + * Response to request. Begins with unsigned integer that represents * which message is being repeated and the actual null-terminated * message after that. */ REPLY, - /** UUID that represents a particular device. + /** + * UUID that represents a particular device. */ UUID }; +/** + * Packet data itself is a special type of tlv. A packet is either regular, + * hearbeat or discovery. + */ struct packet_data { enum packet_type type; size_t packet_size; char *data; /* Bytes representing tlv's */ }; +/** + * Literally type-length-value + * */ struct tlv { enum tlv_type type; size_t length; void *data; }; -/* +/** * Reads last packets received, parses and stores them to be later retreived * via get_tlv. * */ -void get_last_data(void); +void get_last_data(cd_t connection); -/* Returns tlv's parsed by get_last_data. Returned tlv is only valid until +/** Returns tlv's parsed by get_last_data. Returned tlv is only valid until * next call to get_tlv. * */ struct tlv * get_tlv(void); -/* Any modifications made to the pending outgoing packet are nullified. +/** + * Any modifications made to the pending outgoing packet are nullified. * */ -void clear_data(void); +void clear_data(cd_t connection); -/* Appends data to the next packet to be sent. Type of data is determined by +/** + * Appends data to the next packet to be sent. Type of data is determined by * enum tlv_type. * */ -int push_data(const char *data, enum tlv_type); +int push_data(cd_t connection, const char *data, enum tlv_type); -/* Sends packet towards the other end. +/** + * Sends packet towards the other end. * */ -void flush_data(void); +void flush_data(cd_t connection); #endif /* PROTOCOL_H_INCLUDED */ diff --git a/include/utils.h b/include/utils.h index f92e0fa..c769917 100644 --- a/include/utils.h +++ b/include/utils.h @@ -14,9 +14,9 @@ int cmp_uuid(uuid_t *first, uuid_t *second); */ typedef int fpi1_t; -fpi1_t add(fpi1_t a, fpi1_t b); -fpi1_t sub(fpi1_t a, fpi1_t b); -fpi1_t mul(fpi1_t a, fpi1_t b); -fpi1_t div(fpi1_t a, fpi1_t b); +fpi1_t fpi1_add(fpi1_t a, fpi1_t b); +fpi1_t fpi1_sub(fpi1_t a, fpi1_t b); +fpi1_t fpi1_mul(fpi1_t a, fpi1_t b); +fpi1_t fpi1_div(fpi1_t a, fpi1_t b); #endif /* PROJECT_UTILS_H */ -- cgit v1.2.3 From 36b3e7f310c624b7b4e31829090dd02131c528d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Tue, 21 May 2019 19:16:22 +0300 Subject: Protocol: implementation of device-side protocol. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parts of protocol specific for device are implementepd to reflect the fact that the device is a client. This effectively means that device gets a single connection only and severe memory restrictions about which the daemon might get informed about in the future. Signed-off-by: Ramūnas Mažeikis --- include/net.h | 14 +++++++++++++- include/protocol.h | 6 ++++-- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/net.h b/include/net.h index 34f557a..6860455 100644 --- a/include/net.h +++ b/include/net.h @@ -33,9 +33,21 @@ enum response { TMPFILE, }; - +/** + * Initialises connection with daemon and returns a network descriptor. + */ int net_init(const unsigned short int port); + +/** + * Closes connection associated with network descriptor. + */ int net_close(int nd); + +/** + * Get last data received from connection associated with network descriptor. + * Function mallocates a buffer for data received from packet. Don't forget to + * free the buffer. + */ int net_getlastdata(int nd, char * const data); #endif /* NET_H_INCLUDED */ diff --git a/include/protocol.h b/include/protocol.h index 60d31ea..c5e657b 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -106,12 +106,12 @@ struct tlv { * Reads last packets received, parses and stores them to be later retreived * via get_tlv. * */ -void get_last_data(cd_t connection); +int get_last_data(cd_t connection); /** Returns tlv's parsed by get_last_data. Returned tlv is only valid until * next call to get_tlv. * */ -struct tlv * get_tlv(void); +struct tlv * get_tlv(cd_t cd); /** * Any modifications made to the pending outgoing packet are nullified. @@ -129,4 +129,6 @@ int push_data(cd_t connection, const char *data, enum tlv_type); * */ void flush_data(cd_t connection); +cd_t protocol_init(void); + #endif /* PROTOCOL_H_INCLUDED */ -- cgit v1.2.3 From fe71239fc0d1e65e06ba9dcf2fb35239bff21466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Tue, 21 May 2019 20:01:08 +0300 Subject: Protocol: moved udp code out of main. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An effor was made to increase modularity of device code. It was a partial success. IP adress, communications port, and wifi login details had to be made static and visible in main. Time is scarce and I am not about to push this further. Signed-off-by: Ramūnas Mažeikis --- include/protocol.h | 4 ++-- include/udp.h | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100755 include/udp.h (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index c5e657b..8d5c535 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -116,7 +116,7 @@ struct tlv * get_tlv(cd_t cd); /** * Any modifications made to the pending outgoing packet are nullified. * */ -void clear_data(cd_t connection); +int clear_data(cd_t connection); /** * Appends data to the next packet to be sent. Type of data is determined by @@ -127,7 +127,7 @@ int push_data(cd_t connection, const char *data, enum tlv_type); /** * Sends packet towards the other end. * */ -void flush_data(cd_t connection); +int flush_data(cd_t connection); cd_t protocol_init(void); diff --git a/include/udp.h b/include/udp.h new file mode 100755 index 0000000..358e585 --- /dev/null +++ b/include/udp.h @@ -0,0 +1,16 @@ +#ifndef DEVICE_UDP_H +#define DEVICE_UDP_H + +#include +#include + +static const int com_port = 6996; +IPAddress ip; /* Daemon IP */ +WiFiUDP Udp; + +extern void discover_client(const int port); +extern void udp_init_packet(IPAddress ip, const int port); +extern void udp_push(const void * const data, const size_t size); +extern int udp_flush(void); + +#endif /* DEVICE_UDP_H */ \ No newline at end of file -- cgit v1.2.3 From 4bf68f9e9d553c924924296375269703c70c500a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Tue, 21 May 2019 20:04:52 +0300 Subject: Protocol: forgot to commit updated udp.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- include/udp.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/udp.h b/include/udp.h index 358e585..9b3f785 100755 --- a/include/udp.h +++ b/include/udp.h @@ -5,8 +5,8 @@ #include static const int com_port = 6996; -IPAddress ip; /* Daemon IP */ -WiFiUDP Udp; +extern IPAddress ip; /* Daemon IP */ +extern WiFiUDP Udp; extern void discover_client(const int port); extern void udp_init_packet(IPAddress ip, const int port); -- cgit v1.2.3 From 3703a6f28d48ac3f2c28d07405fab17a2a402df4 Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Wed, 22 May 2019 14:44:00 +0300 Subject: device: actually make it all build and such. Signed-off-by: Gediminas Jakutis --- include/meson.build | 7 +++++++ include/udp.h | 16 ---------------- 2 files changed, 7 insertions(+), 16 deletions(-) create mode 100644 include/meson.build delete mode 100755 include/udp.h (limited to 'include') diff --git a/include/meson.build b/include/meson.build new file mode 100644 index 0000000..33e9426 --- /dev/null +++ b/include/meson.build @@ -0,0 +1,7 @@ +header_filenames = [ + 'utils.h', + 'net.h', + 'protocol.h' +] + +fw_headers = files(header_filenames) diff --git a/include/udp.h b/include/udp.h deleted file mode 100755 index 9b3f785..0000000 --- a/include/udp.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef DEVICE_UDP_H -#define DEVICE_UDP_H - -#include -#include - -static const int com_port = 6996; -extern IPAddress ip; /* Daemon IP */ -extern WiFiUDP Udp; - -extern void discover_client(const int port); -extern void udp_init_packet(IPAddress ip, const int port); -extern void udp_push(const void * const data, const size_t size); -extern int udp_flush(void); - -#endif /* DEVICE_UDP_H */ \ No newline at end of file -- cgit v1.2.3 From 28b26ca86cf18947d6d9543ad753ef112ff4da89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 22 May 2019 20:33:08 +0300 Subject: Protocol: interface redesign. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every function is a stub now. Reimplementaion coming up. Signed-off-by: Ramūnas Mažeikis --- include/protocol.h | 45 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index 8d5c535..d8f395d 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -23,9 +23,9 @@ #include -#define E_TLV_OVERFLOW (1 << 0) -#define E_UNKNOWN_TYPE (1 << 1) -#define E_IVALID_DESCRIPTOR (1 << 2) +#define E_TLV_OVERFLOW (1 << 0) +#define E_UNKNOWN_TYPE (1 << 1) +#define E_IVALID_DESCRIPTOR (1 << 2) /** * Regular packets contain tlv's defined by tlv_type. @@ -40,11 +40,6 @@ enum packet_type { DISCOVERY }; -/** - * Connection descriptor. - */ -typedef unsigned int cd_t; - /** * Message sequence number since beggining of sesssion. * @@ -86,10 +81,13 @@ enum tlv_type { /** * Packet data itself is a special type of tlv. A packet is either regular, * hearbeat or discovery. + * + * May be used to send data. */ -struct packet_data { +struct tlv_packet { enum packet_type type; size_t packet_size; + size_t offset; char *data; /* Bytes representing tlv's */ }; @@ -102,33 +100,18 @@ struct tlv { void *data; }; -/** - * Reads last packets received, parses and stores them to be later retreived - * via get_tlv. - * */ -int get_last_data(cd_t connection); - -/** Returns tlv's parsed by get_last_data. Returned tlv is only valid until - * next call to get_tlv. - * */ -struct tlv * get_tlv(cd_t cd); +struct tlv_parser { + char *data; + size_t offset; + size_t size; +}; -/** - * Any modifications made to the pending outgoing packet are nullified. - * */ -int clear_data(cd_t connection); +int get_tlv(struct tlv_parser *parser, struct tlv *ret); /** * Appends data to the next packet to be sent. Type of data is determined by * enum tlv_type. * */ -int push_data(cd_t connection, const char *data, enum tlv_type); - -/** - * Sends packet towards the other end. - * */ -int flush_data(cd_t connection); - -cd_t protocol_init(void); +int push_tlv(struct tlv_packet *packet, const char *data, enum tlv_type); #endif /* PROTOCOL_H_INCLUDED */ -- cgit v1.2.3 From dd7556097b373bc62f646016a9b368899043dcc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 22 May 2019 20:48:42 +0300 Subject: Protocol: reimplemented push_string and push_fpi1. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- include/protocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index d8f395d..bf2a943 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -86,7 +86,7 @@ enum tlv_type { */ struct tlv_packet { enum packet_type type; - size_t packet_size; + size_t size; size_t offset; char *data; /* Bytes representing tlv's */ }; -- cgit v1.2.3 From 54f0ba9d41b446b83090dc0f3b220db9c82491d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 22 May 2019 20:52:26 +0300 Subject: Protocol: tossed a bunch of function out the window. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- include/protocol.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index bf2a943..4721a22 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -114,4 +114,6 @@ int get_tlv(struct tlv_parser *parser, struct tlv *ret); * */ int push_tlv(struct tlv_packet *packet, const char *data, enum tlv_type); +void clear_data(struct tlv_packet *packet); + #endif /* PROTOCOL_H_INCLUDED */ -- cgit v1.2.3 From db5f3e534c1efd31a582d2309b2bc892cc2c8317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 22 May 2019 21:13:45 +0300 Subject: Protocol: reimplemented get_tlv and added tlv_data_size. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- include/protocol.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index 4721a22..1f941a4 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -112,8 +112,10 @@ int get_tlv(struct tlv_parser *parser, struct tlv *ret); * Appends data to the next packet to be sent. Type of data is determined by * enum tlv_type. * */ -int push_tlv(struct tlv_packet *packet, const char *data, enum tlv_type); +int push_data(struct tlv_packet *packet, enum tlv_type type, char *data); void clear_data(struct tlv_packet *packet); +size_t tlv_data_size(struct tlv_parser *parser); + #endif /* PROTOCOL_H_INCLUDED */ -- cgit v1.2.3 From 446157d793c30386f994743f5a8e6ab64e66507f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 22 May 2019 21:35:46 +0300 Subject: Protocol: updated docs for functions that survived redesign. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- include/protocol.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index 1f941a4..cd28e2d 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -111,6 +111,11 @@ int get_tlv(struct tlv_parser *parser, struct tlv *ret); /** * Appends data to the next packet to be sent. Type of data is determined by * enum tlv_type. + * + * In case of overflow return E_TLV_OVERFLOW. + * + * Overflow can be detected after forming tlv header. This means that the + * packet may have changes. * */ int push_data(struct tlv_packet *packet, enum tlv_type type, char *data); -- cgit v1.2.3 From 3397ca1e68f69259cca56751af73f3f0706b6831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 22 May 2019 21:46:23 +0300 Subject: Protocol: updated get_tlv and more docs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- include/protocol.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index cd28e2d..598b8e3 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -26,6 +26,7 @@ #define E_TLV_OVERFLOW (1 << 0) #define E_UNKNOWN_TYPE (1 << 1) #define E_IVALID_DESCRIPTOR (1 << 2) +#define END_OF_PACKET (1 << 3) /** * Regular packets contain tlv's defined by tlv_type. @@ -114,13 +115,23 @@ int get_tlv(struct tlv_parser *parser, struct tlv *ret); * * In case of overflow return E_TLV_OVERFLOW. * + * On next call after retreiving last packet returns END_OF_PACKET. + * * Overflow can be detected after forming tlv header. This means that the * packet may have changes. * */ int push_data(struct tlv_packet *packet, enum tlv_type type, char *data); + +/** + * Resets offset to 0 and set entire buffer to 0. + */ void clear_data(struct tlv_packet *packet); + +/** + * Tells what size of buffer is needed for next tlv. + */ size_t tlv_data_size(struct tlv_parser *parser); #endif /* PROTOCOL_H_INCLUDED */ -- cgit v1.2.3 From b25865cc827f4a6a9c31f3d92a4e443485fd5d93 Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Sun, 26 May 2019 14:46:36 +0300 Subject: common: cosmetic changes. Signed-off-by: Gediminas Jakutis --- include/net.h | 6 +++--- include/protocol.h | 6 +++--- include/utils.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/net.h b/include/net.h index 6860455..59071a5 100644 --- a/include/net.h +++ b/include/net.h @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef NET_H_INCLUDED -#define NET_H_INCLUDED +#ifndef USURPATION_NET_H_INCLUDED +#define USURPATION_NET_H_INCLUDED #define dgsize 512 @@ -50,4 +50,4 @@ int net_close(int nd); */ int net_getlastdata(int nd, char * const data); -#endif /* NET_H_INCLUDED */ +#endif /* USURPATION_NET_H_INCLUDED */ diff --git a/include/protocol.h b/include/protocol.h index 598b8e3..34ad4a3 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef PROTOCOL_H_INCLUDED -#define PROTOCOL_H_INCLUDED +#ifndef USURPATION_PROTOCOL_H_INCLUDED +#define USURPATION_PROTOCOL_H_INCLUDED #include @@ -134,4 +134,4 @@ void clear_data(struct tlv_packet *packet); */ size_t tlv_data_size(struct tlv_parser *parser); -#endif /* PROTOCOL_H_INCLUDED */ +#endif /* USURPATION_PROTOCOL_H_INCLUDED */ diff --git a/include/utils.h b/include/utils.h index c769917..95b553d 100644 --- a/include/utils.h +++ b/include/utils.h @@ -1,5 +1,5 @@ -#ifndef PROJECT_UTILS_H -#define PROJECT_UTILS_H +#ifndef USURPATION_UTILS_H +#define USURPATION_UTILS_H #include @@ -19,4 +19,4 @@ fpi1_t fpi1_sub(fpi1_t a, fpi1_t b); fpi1_t fpi1_mul(fpi1_t a, fpi1_t b); fpi1_t fpi1_div(fpi1_t a, fpi1_t b); -#endif /* PROJECT_UTILS_H */ +#endif /* USURPATION_UTILS_H */ -- cgit v1.2.3