├── .gitignore ├── CONTRIBUTION.pdf ├── COPYING ├── Makefile ├── README.md ├── debian ├── changelog ├── compat ├── control ├── copyright ├── docs ├── libsml-dev.examples ├── libsml-dev.install ├── libsml1.install ├── rules ├── source │ ├── format │ └── options └── watch ├── examples ├── Makefile └── sml_server.c ├── sml.pc ├── sml ├── Makefile ├── include │ └── sml │ │ ├── sml_attention_response.h │ │ ├── sml_boolean.h │ │ ├── sml_close_request.h │ │ ├── sml_close_response.h │ │ ├── sml_crc16.h │ │ ├── sml_file.h │ │ ├── sml_get_list_request.h │ │ ├── sml_get_list_response.h │ │ ├── sml_get_proc_parameter_request.h │ │ ├── sml_get_proc_parameter_response.h │ │ ├── sml_get_profile_list_request.h │ │ ├── sml_get_profile_list_response.h │ │ ├── sml_get_profile_pack_request.h │ │ ├── sml_get_profile_pack_response.h │ │ ├── sml_list.h │ │ ├── sml_message.h │ │ ├── sml_number.h │ │ ├── sml_octet_string.h │ │ ├── sml_open_request.h │ │ ├── sml_open_response.h │ │ ├── sml_set_proc_parameter_request.h │ │ ├── sml_shared.h │ │ ├── sml_status.h │ │ ├── sml_time.h │ │ ├── sml_transport.h │ │ ├── sml_tree.h │ │ └── sml_value.h ├── lib │ └── .gitdir └── src │ ├── sml_attention_response.c │ ├── sml_boolean.c │ ├── sml_close_request.c │ ├── sml_close_response.c │ ├── sml_crc16.c │ ├── sml_file.c │ ├── sml_get_list_request.c │ ├── sml_get_list_response.c │ ├── sml_get_proc_parameter_request.c │ ├── sml_get_proc_parameter_response.c │ ├── sml_get_profile_list_request.c │ ├── sml_get_profile_list_response.c │ ├── sml_get_profile_pack_request.c │ ├── sml_get_profile_pack_response.c │ ├── sml_list.c │ ├── sml_message.c │ ├── sml_number.c │ ├── sml_octet_string.c │ ├── sml_open_request.c │ ├── sml_open_response.c │ ├── sml_set_proc_parameter_request.c │ ├── sml_shared.c │ ├── sml_status.c │ ├── sml_time.c │ ├── sml_transport.c │ ├── sml_tree.c │ └── sml_value.c └── test ├── Makefile ├── src ├── sml_boolean_test.c ├── sml_buffer_test.c ├── sml_file_test.c ├── sml_get_profile_pack_request_test.c ├── sml_list_test.c ├── sml_message_test.c ├── sml_number_test.c ├── sml_octet_string_test.c ├── sml_open_request_test.c ├── sml_status_test.c ├── sml_time_test.c ├── sml_tree_test.c ├── sml_value_test.c ├── test_helper.c └── test_helper.h ├── test_main.c └── unity ├── license.txt ├── unity.c ├── unity.h ├── unity_fixture.c ├── unity_fixture.h ├── unity_fixture_internals.h ├── unity_fixture_malloc_overrides.h └── unity_internals.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Debian Packaging 2 | /.pc/ 3 | 4 | # Binaries 5 | /test/test 6 | /examples/sml_server 7 | 8 | # Compiled Object files 9 | *.slo 10 | *.lo 11 | *.o 12 | 13 | # Compiled Dynamic libraries 14 | *.so.* 15 | *.so 16 | 17 | # Compiled Static libraries 18 | *.lai 19 | *.la 20 | *.a 21 | 22 | -------------------------------------------------------------------------------- /CONTRIBUTION.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dailab/libsml/550aa8216295ff76076f35ce2eb00872dfd83f8f/CONTRIBUTION.pdf -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | @$(MAKE) -C sml 4 | @$(MAKE) -C examples 5 | @$(MAKE) -C test 6 | 7 | .PHONY: clean 8 | clean : 9 | @$(MAKE) -C sml clean 10 | @$(MAKE) -C examples clean 11 | @$(MAKE) -C test clean 12 | 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | libSML 2 | ====== 3 | 4 | libSML is a library which implements the Smart Message Language (SML) protocol specified by VDE's Forum Netztechnik/Netzbetrieb (FNN). 5 | It can be utilized to communicate to FNN specified Smart Meters or Smart Meter components (EDL/MUC). 6 | 7 | ### Usage 8 | An example how to use libSML is in the examples directory. 9 | 10 | #### Dependencies 11 | Ubuntu 12 | 13 | apt-get install uuid-dev uuid-runtime 14 | 15 | #### Compilation 16 | 17 | make 18 | 19 | The resulting binaries are located in sml/lib 20 | 21 | ### License 22 | Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed - DAI-Labor, TU-Berlin 23 | 24 | libSML is licensed with the GPL, other licenses are available. 25 | 26 | ### Thanks 27 | Steffen Vogel, Thorben Thuermer, Daniel Pauli, He Bowei 28 | 29 | #### Thirdparty Acknowledgements 30 | This product includes software developed for the Unity Project, by Mike Karlesky, Mark VanderVoord, and Greg Williams and other contributors -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | libsml (0.1.1-1~wip) unstable; urgency=low 2 | 3 | * Added sml_value_to_double() 4 | * Implemented sml_octet_string_generate_uuid() when not linking against libuuid 5 | * Removed trailing whitespaces & unified codestyle 6 | * implemented sml profile stuff 7 | 8 | -- Steffen Vogel Fri, 30 Sep 2011 19:16:59 +0200 9 | 10 | libsml (0.1-5~wip) unstable; urgency=low 11 | 12 | * Adapted sml_transport_ for vzlogger 13 | 14 | -- Steffen Vogel Fri, 09 Sep 2011 14:52:56 +0200 15 | 16 | libsml (0.1-4~wip) unstable; urgency=low 17 | 18 | * Fixed bug in sml_message_body_free (#1) 19 | * Fixed bug in sml_list_entry_parse (#2) 20 | 21 | -- Steffen Vogel Thu, 01 Sep 2011 23:22:33 +0200 22 | 23 | libsml (0.1-3~wip) unstable; urgency=low 24 | 25 | * fixed invalid destination for libs 26 | * added SONAME to shared library 27 | 28 | -- Steffen Vogel Thu, 01 Sep 2011 21:05:40 +0200 29 | 30 | libsml (0.1-2~wip) unstable; urgency=low 31 | 32 | * Added information for pkg-config 33 | * Eased dependency for libuuid from version 2.17 to 2.16 34 | as there were no changes in the symbols 35 | * Changed architecture for developement files to 'all' 36 | 37 | -- Steffen Vogel Thu, 01 Sep 2011 12:06:39 +0200 38 | 39 | libsml (0.1-1~wip) unstable; urgency=low 40 | 41 | * Work in Progress of current git commit 42 | * No ITP issue yet available 43 | 44 | -- Steffen Vogel Wed, 31 Aug 2011 18:59:39 +0200 45 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: libsml 2 | Priority: extra 3 | Maintainer: Steffen Vogel 4 | Build-Depends: debhelper (>= 7.0.50~), uuid-dev (>= 2.16) 5 | Standards-Version: 3.9.2 6 | Section: libs 7 | Homepage: http://github.com/dailab/libsml 8 | Vcs-Git: git://github.com/dailab/libsml.git 9 | Vcs-Browser: http://github.com/dailab/libsml 10 | 11 | Package: libsml-dev 12 | Section: libdevel 13 | Architecture: any 14 | Depends: libsml1 (= ${binary:Version}), uuid-dev (>= 2.16), ${misc:Depends} 15 | Description: Header files for libSML 16 | This package includes header include files 17 | and an example for libSML 18 | 19 | Package: libsml1 20 | Section: libs 21 | Architecture: any 22 | Depends: ${shlibs:Depends}, ${misc:Depends} 23 | Description: Library for the Smart Messaging Language (SML) 24 | libSML is a library which implements the Smart Messaging Language (SML) 25 | protocol specified by VDE's Forum Netztechnik/Netzbetrieb (FNN). 26 | It can be utilized to communicate to FNN specified Smart Meters 27 | or Smart Meter components (EDL/MUC). 28 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | This work was packaged for Debian by: 2 | 3 | Steffen Vogel on Wed, 31 Aug 2011 18:59:39 +0200 4 | 5 | It was downloaded from: 6 | 7 | https://github.com/dailab/libsml 8 | 9 | Upstream Authors: 10 | 11 | Juri Glass, 12 | Mathias Runge, 13 | Nadim El Sayed, 14 | Steffen Vogel 15 | 16 | Copyright: 17 | 18 | Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed - DAI-Labor, TU-Berlin 19 | 20 | License: 21 | 22 | This program is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU General Public License as published by 24 | the Free Software Foundation, either version 3 of the License, or 25 | (at your option) any later version. 26 | 27 | This package is distributed in the hope that it will be useful, 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | GNU General Public License for more details. 31 | 32 | You should have received a copy of the GNU General Public License 33 | along with this program. If not, see . 34 | 35 | On Debian systems, the complete text of the GNU General 36 | Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". 37 | 38 | The Debian packaging is: 39 | 40 | Copyright (C) 2011 Steffen Vogel 41 | 42 | and is licensed under the GPL version 3, see above. 43 | 44 | -------------------------------------------------------------------------------- /debian/docs: -------------------------------------------------------------------------------- 1 | README.md 2 | -------------------------------------------------------------------------------- /debian/libsml-dev.examples: -------------------------------------------------------------------------------- 1 | examples/*.c 2 | examples/Makefile 3 | -------------------------------------------------------------------------------- /debian/libsml-dev.install: -------------------------------------------------------------------------------- 1 | sml/include/* /usr/include 2 | sml.pc /usr/lib/pkgconfig 3 | -------------------------------------------------------------------------------- /debian/libsml1.install: -------------------------------------------------------------------------------- 1 | sml/lib/libsml.* /usr/lib 2 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # -*- makefile -*- 3 | # Sample debian/rules that uses debhelper. 4 | # This file was originally written by Joey Hess and Craig Small. 5 | # As a special exception, when this file is copied by dh-make into a 6 | # dh-make output file, you may use that output file without restriction. 7 | # This special exception was added by Craig Small in version 0.37 of dh-make. 8 | 9 | # Uncomment this to turn on verbose mode. 10 | #export DH_VERBOSE=1 11 | 12 | %: 13 | dh $@ 14 | 15 | # Skip some commands 16 | override_dh_pysupport: 17 | override_dh_installwm: 18 | override_dh_installxfonts: 19 | override_dh_installgsettings: 20 | override_dh_installmenu: 21 | override_dh_icons: 22 | override_dh_gconf: 23 | override_dh_installcron: 24 | override_dh_installdebconf: 25 | override_dh_installemacsen: 26 | override_dh_installifupdown: 27 | override_dh_installinit: 28 | override_dh_installmime: 29 | override_dh_installmodules: 30 | override_dh_installlogcheck: 31 | override_dh_installlogrotate: 32 | override_dh_installpam: 33 | override_dh_installppp: 34 | override_dh_installudev: 35 | override_dh_perl: 36 | 37 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /debian/source/options: -------------------------------------------------------------------------------- 1 | single-debian-patch 2 | -------------------------------------------------------------------------------- /debian/watch: -------------------------------------------------------------------------------- 1 | # Example watch control file for uscan 2 | # Rename this file to "watch" and then you can run the "uscan" command 3 | # to check for upstream updates and more. 4 | # See uscan(1) for format 5 | 6 | # Compulsory line, this is a version 3 file 7 | version=3 8 | 9 | # Find new releases on GitHub 10 | # (uses redirector service from Gunnar Wolf: 11 | # http://githubredir.debian.net) 12 | http://githubredir.debian.net/githubredir.cgi?author=dailab&project=libsml (.*).tar.gz 13 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | UNAME := $(shell uname) 2 | CFLAGS += -I../sml/include/ -g -Wall 3 | OBJS = sml_server.o 4 | LIBSML = ../sml/lib/libsml.a 5 | 6 | ifeq ($(UNAME), Linux) 7 | LIBS = -luuid 8 | endif 9 | 10 | sml_server : $(OBJS) $(LIBSML) 11 | $(CC) $(CFLAGS) $(OBJS) $(LIBS) $(LIBSML) -o sml_server 12 | 13 | %.o : %.c 14 | $(CC) $(CFLAGS) -c $^ -o $@ 15 | 16 | .PHONY: clean 17 | clean: 18 | @rm -f *.o 19 | @rm -f sml_server 20 | -------------------------------------------------------------------------------- /examples/sml_server.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | int serial_port_open(const char* device) { 32 | int bits; 33 | struct termios config; 34 | memset(&config, 0, sizeof(config)); 35 | 36 | int fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); 37 | if (fd < 0) { 38 | printf("error: open(%s): %s\n", device, strerror(errno)); 39 | return -1; 40 | } 41 | 42 | // set RTS 43 | ioctl(fd, TIOCMGET, &bits); 44 | bits |= TIOCM_RTS; 45 | ioctl(fd, TIOCMSET, &bits); 46 | 47 | tcgetattr( fd, &config ) ; 48 | 49 | // set 8-N-1 50 | config.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); 51 | config.c_oflag &= ~OPOST; 52 | config.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); 53 | config.c_cflag &= ~(CSIZE | PARENB | PARODD | CSTOPB); 54 | config.c_cflag |= CS8; 55 | 56 | // set speed to 9600 baud 57 | cfsetispeed( &config, B9600); 58 | cfsetospeed( &config, B9600); 59 | 60 | tcsetattr(fd, TCSANOW, &config); 61 | return fd; 62 | } 63 | 64 | void transport_receiver(unsigned char *buffer, size_t buffer_len) { 65 | // the buffer contains the whole message, with transport escape sequences. 66 | // these escape sequences are stripped here. 67 | sml_file *file = sml_file_parse(buffer + 8, buffer_len - 16); 68 | // the sml file is parsed now 69 | 70 | // read here some values .. 71 | 72 | // this prints some information about the file 73 | sml_file_print(file); 74 | 75 | // free the malloc'd memory 76 | sml_file_free(file); 77 | } 78 | 79 | int main(int argc, char **argv) { 80 | // this example assumes that a EDL21 meter sending SML messages via a 81 | // serial device. Adjust as needed. 82 | char *device = "/dev/cu.usbserial"; 83 | int fd = serial_port_open(device); 84 | 85 | if (fd > 0) { 86 | // listen on the serial device, this call is blocking. 87 | sml_transport_listen(fd, &transport_receiver); 88 | close(fd); 89 | } 90 | 91 | return 0; 92 | } 93 | 94 | -------------------------------------------------------------------------------- /sml.pc: -------------------------------------------------------------------------------- 1 | prefix=/usr 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: libSML 7 | Description: Library for the Smart Messaging Language (SML) 8 | Version: 0.1 9 | URL: http://github.com/dailab/libsml 10 | Requires: uuid >= 2.16 11 | Libs: -L${libdir} -lsml 12 | Libs.private: -luuid 13 | Cflags: -I${includedir}/sml 14 | -------------------------------------------------------------------------------- /sml/Makefile: -------------------------------------------------------------------------------- 1 | UNAME := $(shell uname) 2 | CFLAGS += -I./include/ -fPIC -fno-stack-protector -g -Wall 3 | 4 | # Available Flags: 5 | # _NO_UUID_LIB - compile without uuid lib 6 | 7 | ifeq ($(UNAME), Linux) 8 | LIBS=-luuid 9 | endif 10 | 11 | NAME=libsml 12 | SOVERSION=1 13 | SONAME=$(NAME).so.$(SOVERSION) 14 | 15 | LIB_DIR=./lib 16 | OBJ_LIB=$(LIB_DIR)/$(NAME).o 17 | DYN_LIB=$(LIB_DIR)/$(SONAME) 18 | ST_LIB=$(LIB_DIR)/$(NAME).a 19 | 20 | OBJS = \ 21 | src/sml_file.o \ 22 | src/sml_attention_response.o \ 23 | src/sml_transport.o \ 24 | src/sml_octet_string.o \ 25 | src/sml_shared.o \ 26 | src/sml_number.o \ 27 | src/sml_message.o \ 28 | src/sml_time.o \ 29 | src/sml_list.o \ 30 | src/sml_status.o \ 31 | src/sml_value.o \ 32 | src/sml_tree.o \ 33 | src/sml_boolean.o \ 34 | src/sml_crc16.o \ 35 | src/sml_open_request.o \ 36 | src/sml_open_response.o \ 37 | src/sml_get_list_request.o \ 38 | src/sml_get_list_response.o \ 39 | src/sml_close_request.o \ 40 | src/sml_close_response.o \ 41 | src/sml_set_proc_parameter_request.o \ 42 | src/sml_get_proc_parameter_request.o \ 43 | src/sml_get_proc_parameter_response.o \ 44 | src/sml_get_profile_pack_request.o \ 45 | src/sml_get_profile_pack_response.o \ 46 | src/sml_get_profile_list_request.o \ 47 | src/sml_get_profile_list_response.o 48 | 49 | ifeq ($(UNAME), Linux) 50 | libsml: $(DYN_LIB) $(ST_LIB) $(OBJ_LIB) 51 | endif 52 | ifeq ($(UNAME), Darwin) 53 | libsml: $(ST_LIB) $(OBJ_LIB) 54 | endif 55 | 56 | $(DYN_LIB): $(OBJS) 57 | $(LD) $(LIBS) -shared -soname $(SONAME) -o $@ $^ 58 | 59 | $(OBJ_LIB): $(OBJS) 60 | $(LD) -r -o $@ $^ 61 | 62 | $(ST_LIB): $(OBJS) 63 | $(AR) -rs $@ $^ 64 | 65 | .PHONY: clean 66 | clean: 67 | @rm -f src/*.o 68 | @rm -f $(DYN_LIB) $(OBJ_LIB) $(ST_LIB) 69 | 70 | -------------------------------------------------------------------------------- /sml/include/sml/sml_attention_response.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #ifndef _SML_ATTENTION_RESPONSE_H_ 21 | #define _SML_ATTENTION_RESPONSE_H_ 22 | 23 | #include "sml_shared.h" 24 | #include "sml_octet_string.h" 25 | #include "sml_tree.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | 32 | typedef struct { 33 | octet_string *server_id; 34 | octet_string *attention_number; 35 | octet_string *attention_message; // optional 36 | sml_tree *attention_details; // optional 37 | } sml_attention_response; 38 | 39 | sml_attention_response *sml_attention_response_init(); 40 | sml_attention_response *sml_attention_response_parse(sml_buffer *buf); 41 | void sml_attention_response_write(sml_attention_response *msg, sml_buffer *buf); 42 | void sml_attention_response_free(sml_attention_response *msg); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | 49 | #endif /* _SML_ATTENTION_RESPONSE_H_ */ 50 | 51 | -------------------------------------------------------------------------------- /sml/include/sml/sml_boolean.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_BOOLEAN_H_ 20 | #define _SML_BOOLEAN_H_ 21 | 22 | #define SML_BOOLEAN_TRUE 0xFF 23 | #define SML_BOOLEAN_FALSE 0x00 24 | 25 | #include "sml_shared.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | typedef u8 sml_boolean; 32 | 33 | sml_boolean *sml_boolean_init(u8 b); 34 | sml_boolean *sml_boolean_parse(sml_buffer *buf); 35 | void sml_boolean_write(sml_boolean *boolean, sml_buffer *buf); 36 | void sml_boolean_free(sml_boolean *b); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | 43 | #endif /* _SML_BOOLEAN_H_ */ 44 | 45 | -------------------------------------------------------------------------------- /sml/include/sml/sml_close_request.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_CLOSE_REQUEST_H_ 20 | #define _SML_CLOSE_REQUEST_H_ 21 | 22 | #include "sml_shared.h" 23 | #include "sml_octet_string.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | typedef struct { 30 | sml_signature *global_signature; // optional 31 | } sml_close_request; 32 | 33 | sml_close_request *sml_close_request_init(); 34 | sml_close_request * sml_close_request_parse(sml_buffer *buf); 35 | void sml_close_request_write(sml_close_request *msg, sml_buffer *buf); 36 | void sml_close_request_free(sml_close_request *msg); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | 43 | #endif /* _SML_CLOSE_REQUEST_H_ */ 44 | 45 | -------------------------------------------------------------------------------- /sml/include/sml/sml_close_response.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #ifndef _SML_CLOSE_RESPONSE_H_ 21 | #define _SML_CLOSE_RESPONSE_H_ 22 | 23 | #include "sml_close_request.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | typedef sml_close_request sml_close_response; 30 | 31 | sml_close_response *sml_close_response_init(); 32 | sml_close_response *sml_close_response_parse(sml_buffer *buf); 33 | void sml_close_response_write(sml_close_response *msg, sml_buffer *buf); 34 | void sml_close_response_free(sml_close_response *msg); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | 41 | #endif /* _SML_CLOSE_RESPONSE_H_ */ 42 | 43 | -------------------------------------------------------------------------------- /sml/include/sml/sml_crc16.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_CRC16_H_ 20 | #define _SML_CRC16_H_ 21 | 22 | #include "sml_shared.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | // CRC16 FSC implementation based on DIN 62056-46 29 | u16 sml_crc16_calculate(unsigned char *cp, int len) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | 36 | #endif /* _SML_CRC16_H_ */ 37 | 38 | -------------------------------------------------------------------------------- /sml/include/sml/sml_file.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_FILE_H_ 20 | #define _SML_FILE_H_ 21 | 22 | #include "sml_message.h" 23 | #include "sml_shared.h" 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | // a SML file consist of multiple SML messages 31 | typedef struct { 32 | sml_message **messages; 33 | short messages_len; 34 | sml_buffer *buf; 35 | } sml_file; 36 | 37 | sml_file *sml_file_init(); 38 | // parses a SML file. 39 | sml_file *sml_file_parse(unsigned char *buffer, size_t buffer_len); 40 | void sml_file_add_message(sml_file *file, sml_message *message); 41 | void sml_file_write(sml_file *file); 42 | void sml_file_free(sml_file *file); 43 | void sml_file_print(sml_file *file); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | 50 | #endif /* _SML_FILE_H_ */ 51 | 52 | -------------------------------------------------------------------------------- /sml/include/sml/sml_get_list_request.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_GET_LIST_REQUEST_H_ 20 | #define _SML_GET_LIST_REQUEST_H_ 21 | 22 | #include "sml_shared.h" 23 | #include "sml_octet_string.h" 24 | #include "sml_time.h" 25 | #include "sml_list.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | typedef struct { 32 | octet_string *client_id; 33 | octet_string *server_id; // optional 34 | octet_string *username; // optional 35 | octet_string *password; // optional 36 | octet_string *list_name; // optional 37 | } sml_get_list_request; 38 | 39 | sml_get_list_request* sml_get_list_request_init(); 40 | sml_get_list_request *sml_get_list_request_parse(sml_buffer *buf); 41 | void sml_get_list_request_write(sml_get_list_request *msg, sml_buffer *buf); 42 | void sml_get_list_request_free(sml_get_list_request *msg); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | 49 | #endif /* _SML_GET_LIST_REQUEST_H_ */ 50 | 51 | -------------------------------------------------------------------------------- /sml/include/sml/sml_get_list_response.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_GET_LIST_RESPONSE_H_ 20 | #define _SML_GET_LIST_RESPONSE_H_ 21 | 22 | #include "sml_shared.h" 23 | #include "sml_octet_string.h" 24 | #include "sml_time.h" 25 | #include "sml_list.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | typedef struct { 32 | octet_string *client_id; // optional 33 | octet_string *server_id; 34 | octet_string *list_name; // optional 35 | sml_time *act_sensor_time; // optional 36 | sml_list *val_list; 37 | sml_signature *list_signature; // optional 38 | sml_time *act_gateway_time; // optional 39 | } sml_get_list_response; 40 | 41 | sml_get_list_response *sml_get_list_response_init(); 42 | sml_get_list_response *sml_get_list_response_parse(sml_buffer *buf); 43 | void sml_get_list_response_write(sml_get_list_response *msg, sml_buffer *buf); 44 | void sml_get_list_response_free(sml_get_list_response *msg); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | 51 | #endif /* _SML_GET_LIST_RESPONSE_H_ */ 52 | 53 | -------------------------------------------------------------------------------- /sml/include/sml/sml_get_proc_parameter_request.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_GET_PROC_PARAMETER_REQUEST_H_ 20 | #define _SML_GET_PROC_PARAMETER_REQUEST_H_ 21 | 22 | #include "sml_shared.h" 23 | #include "sml_octet_string.h" 24 | #include "sml_tree.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | typedef struct { 31 | octet_string *server_id; // optional 32 | octet_string *username; // optional 33 | octet_string *password; // optional 34 | sml_tree_path *parameter_tree_path; 35 | octet_string *attribute; // optional 36 | } sml_get_proc_parameter_request; 37 | 38 | sml_get_proc_parameter_request *sml_get_proc_parameter_request_init(); 39 | sml_get_proc_parameter_request *sml_get_proc_parameter_request_parse(sml_buffer *buf); 40 | void sml_get_proc_parameter_request_write(sml_get_proc_parameter_request *msg, sml_buffer *buf); 41 | void sml_get_proc_parameter_request_free(sml_get_proc_parameter_request *msg); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | 48 | #endif /* _SML_GET_PROC_PARAMETER_REQUEST_H_ */ 49 | 50 | -------------------------------------------------------------------------------- /sml/include/sml/sml_get_proc_parameter_response.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_GET_PROC_PARAMETER_RESPONSE_H_ 20 | #define _SML_GET_PROC_PARAMETER_RESPONSE_H_ 21 | 22 | #include "sml_shared.h" 23 | #include "sml_octet_string.h" 24 | #include "sml_tree.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | typedef struct { 31 | octet_string *server_id; 32 | sml_tree_path *parameter_tree_path; 33 | sml_tree *parameter_tree; 34 | } sml_get_proc_parameter_response; 35 | 36 | sml_get_proc_parameter_response *sml_get_proc_parameter_response_init(); 37 | sml_get_proc_parameter_response *sml_get_proc_parameter_response_parse(sml_buffer *buf); 38 | void sml_get_proc_parameter_response_write(sml_get_proc_parameter_response *msg, sml_buffer *buf); 39 | void sml_get_proc_parameter_response_free(sml_get_proc_parameter_response *msg); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | 46 | #endif /* _SML_GET_PROC_PARAMETER_RESPONSE_H_ */ 47 | 48 | -------------------------------------------------------------------------------- /sml/include/sml/sml_get_profile_list_request.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_GET_PROFILE_LIST_REQUEST_H_ 20 | #define _SML_GET_PROFILE_LIST_REQUEST_H_ 21 | 22 | #include "sml_get_profile_pack_request.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | // Apparently SML_GetProfilePack.Req is the same as SML_GetProfileList.Req 29 | typedef sml_get_profile_pack_request sml_get_profile_list_request; 30 | 31 | #define sml_get_profile_list_request_init() sml_get_profile_pack_request_init() 32 | #define sml_get_profile_list_request_parse(buf) sml_get_profile_pack_request_parse(buf) 33 | #define sml_get_profile_list_request_write(msg, buf) sml_get_profile_pack_request_write(msg, buf) 34 | #define sml_get_profile_list_request_free(msg) sml_get_profile_pack_request_free(msg) 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | 41 | #endif /* _SML_GET_PROFILE_LIST_REQUEST_H_ */ 42 | 43 | -------------------------------------------------------------------------------- /sml/include/sml/sml_get_profile_list_response.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_GET_PROFILE_LIST_RESPONSE_H_ 20 | #define _SML_GET_PROFILE_LIST_RESPONSE_H_ 21 | 22 | #include "sml_shared.h" 23 | #include "sml_octet_string.h" 24 | #include "sml_time.h" 25 | #include "sml_list.h" 26 | #include "sml_tree.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | typedef struct { 33 | octet_string *server_id; 34 | sml_time *act_time; 35 | u32 *reg_period; 36 | sml_tree_path *parameter_tree_path; 37 | sml_time *val_time; 38 | u64 *status; 39 | sml_sequence *period_list; 40 | octet_string *rawdata; 41 | sml_signature *period_signature; 42 | } sml_get_profile_list_response; 43 | 44 | sml_get_profile_list_response *sml_get_profile_list_response_init(); 45 | sml_get_profile_list_response *sml_get_profile_list_response_parse(sml_buffer *buf); 46 | void sml_get_profile_list_response_write(sml_get_profile_list_response *msg, sml_buffer *buf); 47 | void sml_get_profile_list_response_free(sml_get_profile_list_response *msg); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | 54 | #endif /* _SML_GET_PROFILE_LIST_RESPONSE_H_ */ 55 | 56 | -------------------------------------------------------------------------------- /sml/include/sml/sml_get_profile_pack_request.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_GET_PROFILE_PACK_REQUEST_H_ 20 | #define _SML_GET_PROFILE_PACK_REQUEST_H_ 21 | 22 | #include "sml_shared.h" 23 | #include "sml_octet_string.h" 24 | #include "sml_time.h" 25 | #include "sml_list.h" 26 | #include "sml_tree.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | typedef octet_string sml_obj_req_entry; 33 | #define sml_obj_req_entry_parse(buf) sml_octet_string_parse(buf) 34 | #define sml_obj_req_entry_write(p, buf) sml_octet_string_write(p, buf) 35 | #define sml_obj_req_entry_free(p) sml_octet_string_free(p) 36 | 37 | typedef struct sml_obj_req_entry_list_entry { 38 | sml_obj_req_entry *object_list_entry; 39 | 40 | // list specific 41 | struct sml_obj_req_entry_list_entry *next; 42 | } sml_obj_req_entry_list; 43 | 44 | typedef struct { 45 | octet_string *server_id; // optional 46 | octet_string *username; // optional 47 | octet_string *password; // optional 48 | sml_boolean *with_rawdata; // optional 49 | sml_time *begin_time; // optional 50 | sml_time *end_time; // optional 51 | sml_tree_path *parameter_tree_path; 52 | sml_obj_req_entry_list *object_list; // optional 53 | sml_tree *das_details; // optional 54 | } sml_get_profile_pack_request; 55 | 56 | 57 | sml_get_profile_pack_request *sml_get_profile_pack_request_parse(sml_buffer *buf); 58 | sml_get_profile_pack_request *sml_get_profile_pack_request_init(); 59 | void sml_get_profile_pack_request_write(sml_get_profile_pack_request *msg, sml_buffer *buf); 60 | void sml_get_profile_pack_request_free(sml_get_profile_pack_request *msg); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | 67 | #endif /* _SML_GET_PROFILE_PACK_REQUEST_H_ */ 68 | 69 | -------------------------------------------------------------------------------- /sml/include/sml/sml_get_profile_pack_response.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_GET_PROFILE_PACK_RESPONSE_H_ 20 | #define _SML_GET_PROFILE_PACK_RESPONSE_H_ 21 | 22 | #include "sml_shared.h" 23 | #include "sml_octet_string.h" 24 | #include "sml_time.h" 25 | #include "sml_list.h" 26 | #include "sml_tree.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | typedef struct { 33 | octet_string *server_id; 34 | sml_time *act_time; // specified by germans (current time was meant) ;) 35 | u32 *reg_period; 36 | sml_tree_path *parameter_tree_path; 37 | sml_sequence *header_list; // list of sml_prof_obj_header_entry 38 | sml_sequence *period_list; // list of sml_prof_obj_period_entry 39 | octet_string *rawdata; // optional 40 | sml_signature *profile_signature; // optional 41 | 42 | } sml_get_profile_pack_response; 43 | 44 | sml_get_profile_pack_response *sml_get_profile_pack_response_init(); 45 | sml_get_profile_pack_response *sml_get_profile_pack_response_parse(sml_buffer *buf); 46 | void sml_get_profile_pack_response_write(sml_get_profile_pack_response *msg, sml_buffer *buf); 47 | void sml_get_profile_pack_response_free(sml_get_profile_pack_response *msg); 48 | 49 | typedef struct { 50 | octet_string *obj_name; 51 | sml_unit *unit; 52 | i8 *scaler; 53 | } sml_prof_obj_header_entry; 54 | 55 | sml_prof_obj_header_entry *sml_prof_obj_header_entry_init(); 56 | sml_prof_obj_header_entry *sml_prof_obj_header_entry_parse(sml_buffer *buf); 57 | void sml_prof_obj_header_entry_write(sml_prof_obj_header_entry *entry, sml_buffer *buf); 58 | void sml_prof_obj_header_entry_free(sml_prof_obj_header_entry *entry); 59 | 60 | typedef struct { 61 | sml_time *val_time; 62 | u64 *status; 63 | sml_sequence *value_list; 64 | sml_signature *period_signature; 65 | } sml_prof_obj_period_entry; 66 | 67 | sml_prof_obj_period_entry *sml_prof_obj_period_entry_init(); 68 | sml_prof_obj_period_entry *sml_prof_obj_period_entry_parse(sml_buffer *buf); 69 | void sml_prof_obj_period_entry_write(sml_prof_obj_period_entry *entry, sml_buffer *buf); 70 | void sml_prof_obj_period_entry_free(sml_prof_obj_period_entry *entry); 71 | 72 | typedef struct { 73 | sml_value *value; 74 | sml_signature *value_signature; 75 | } sml_value_entry; 76 | 77 | sml_value_entry *sml_value_entry_init(); 78 | sml_value_entry *sml_value_entry_parse(sml_buffer *buf); 79 | void sml_value_entry_write(sml_value_entry *entry, sml_buffer *buf); 80 | void sml_value_entry_free(sml_value_entry *entry); 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | 87 | #endif /* _SML_GET_PROFILE_PACK_RESPONSE_H_ */ 88 | 89 | -------------------------------------------------------------------------------- /sml/include/sml/sml_list.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #ifndef _SML_LIST_H_ 21 | #define _SML_LIST_H_ 22 | 23 | #include "sml_time.h" 24 | #include "sml_octet_string.h" 25 | #include "sml_number.h" 26 | #include "sml_status.h" 27 | #include "sml_value.h" 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | typedef struct { 34 | void **elems; 35 | int elems_len; 36 | void (*elem_free) (void *elem); 37 | } sml_sequence; 38 | 39 | sml_sequence *sml_sequence_init(void (*elem_free) (void *elem)); 40 | sml_sequence *sml_sequence_parse(sml_buffer *buf, void *(*elem_parse) (sml_buffer *buf), void (*elem_free) (void *elem)); 41 | void sml_sequence_write(sml_sequence *seq, sml_buffer *buf, void (*elem_write) (void *elem, sml_buffer *buf)); 42 | void sml_sequence_free(sml_sequence *seq); 43 | void sml_sequence_add(sml_sequence *list, void *new_entry); 44 | 45 | typedef struct sml_list_entry { 46 | octet_string *obj_name; 47 | sml_status *status; // optional 48 | sml_time *val_time; // optional 49 | sml_unit *unit; // optional 50 | i8 *scaler; // optional 51 | sml_value *value; 52 | sml_signature *value_signature; // optional 53 | 54 | // list specific 55 | struct sml_list_entry *next; 56 | } sml_list; 57 | 58 | sml_list *sml_list_init(); 59 | sml_list *sml_list_parse(sml_buffer *buf); 60 | void sml_list_write(sml_list *list, sml_buffer *buf); 61 | void sml_list_add(sml_list *list, sml_list *new_entry); 62 | void sml_list_free(sml_list *list); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | 69 | #endif /* _SML_LIST_H_ */ 70 | 71 | -------------------------------------------------------------------------------- /sml/include/sml/sml_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #ifndef _SML_MESSAGE_H_ 21 | #define _SML_MESSAGE_H_ 22 | 23 | #include 24 | #include "sml_octet_string.h" 25 | #include "sml_time.h" 26 | #include "sml_list.h" 27 | #include "sml_tree.h" 28 | 29 | #include "sml_open_request.h" 30 | #include "sml_open_response.h" 31 | #include "sml_close_request.h" 32 | #include "sml_close_response.h" 33 | #include "sml_get_profile_pack_request.h" 34 | #include "sml_get_profile_pack_response.h" 35 | #include "sml_get_profile_list_request.h" 36 | #include "sml_get_profile_list_response.h" 37 | #include "sml_get_proc_parameter_request.h" 38 | #include "sml_get_proc_parameter_response.h" 39 | #include "sml_set_proc_parameter_request.h" 40 | #include "sml_get_list_request.h" 41 | #include "sml_get_list_response.h" 42 | #include "sml_attention_response.h" 43 | 44 | #define SML_MESSAGE_OPEN_REQUEST 0x00000100 45 | #define SML_MESSAGE_OPEN_RESPONSE 0x00000101 46 | #define SML_MESSAGE_CLOSE_REQUEST 0x00000200 47 | #define SML_MESSAGE_CLOSE_RESPONSE 0x00000201 48 | #define SML_MESSAGE_GET_PROFILE_PACK_REQUEST 0x00000300 49 | #define SML_MESSAGE_GET_PROFILE_PACK_RESPONSE 0x00000301 50 | #define SML_MESSAGE_GET_PROFILE_LIST_REQUEST 0x00000400 51 | #define SML_MESSAGE_GET_PROFILE_LIST_RESPONSE 0x00000401 52 | #define SML_MESSAGE_GET_PROC_PARAMETER_REQUEST 0x00000500 53 | #define SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE 0x00000501 54 | #define SML_MESSAGE_SET_PROC_PARAMETER_REQUEST 0x00000600 55 | #define SML_MESSAGE_SET_PROC_PARAMETER_RESPONSE 0x00000601 // This doesn't exist in the spec 56 | #define SML_MESSAGE_GET_LIST_REQUEST 0x00000700 57 | #define SML_MESSAGE_GET_LIST_RESPONSE 0x00000701 58 | #define SML_MESSAGE_ATTENTION_RESPONSE 0x0000FF01 59 | 60 | #ifdef __cplusplus 61 | extern "C" { 62 | #endif 63 | 64 | typedef struct { 65 | u32 *tag; 66 | void *data; 67 | } sml_message_body; 68 | 69 | typedef struct { 70 | octet_string *transaction_id; 71 | u8 *group_id; 72 | u8 *abort_on_error; 73 | sml_message_body *message_body; 74 | u16 *crc; 75 | /* end of message */ 76 | } sml_message; 77 | 78 | // SML MESSAGE 79 | sml_message *sml_message_parse(sml_buffer *buf); 80 | sml_message *sml_message_init(); // Sets a transaction id. 81 | void sml_message_free(sml_message *msg); 82 | void sml_message_write(sml_message *msg, sml_buffer *buf); 83 | 84 | // SML_MESSAGE_BODY 85 | sml_message_body *sml_message_body_parse(sml_buffer *buf); 86 | sml_message_body *sml_message_body_init(u32 tag, void *data); 87 | void sml_message_body_free(sml_message_body *message_body); 88 | void sml_message_body_write(sml_message_body *message_body, sml_buffer *buf); 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | 95 | #endif /* _SML_MESSAGE_H_ */ 96 | 97 | -------------------------------------------------------------------------------- /sml/include/sml/sml_number.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #ifndef _SML_NUMBER_H_ 21 | #define _SML_NUMBER_H_ 22 | 23 | #include "sml_shared.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | void *sml_number_init(u64 number, unsigned char type, int size); 30 | 31 | // Parses a number. Identified by type (SML_TYPE_INTEGER or SML_TYPE_UNSIGNED) 32 | // and maximal number of bytes (SML_TYPE_NUMBER_8, SML_TYPE_NUMBER_16, 33 | // SML_TYPE_NUMBER_32, SML_TYPE_NUMBER_64) 34 | void *sml_number_parse(sml_buffer *buf, unsigned char type, int max_size); 35 | 36 | void sml_number_write(void *np, unsigned char type, int size, sml_buffer *buf); 37 | 38 | void sml_number_free(void *np); 39 | 40 | #define sml_u8_init(n) (u8 *) sml_number_init(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8) 41 | #define sml_u16_init(n) (u16 *) sml_number_init(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_16) 42 | #define sml_u32_init(n) (u32 *) sml_number_init(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_32) 43 | #define sml_u64_init(n) (u64 *) sml_number_init(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_64) 44 | #define sml_i8_init(n) (i8 *) sml_number_init(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_8) 45 | #define sml_i16_init(n) (i16 *) sml_number_init(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_16) 46 | #define sml_i32_init(n) (i32 *) sml_number_init(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_32) 47 | #define sml_i64_init(n) (i64 *) sml_number_init(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_64) 48 | 49 | #define sml_u8_parse(buf) (u8 *) sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8) 50 | #define sml_u16_parse(buf) (u16 *) sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_16) 51 | #define sml_u32_parse(buf) (u32 *) sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_32) 52 | #define sml_u64_parse(buf) (u64 *) sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_64) 53 | #define sml_i8_parse(buf) (i8 *) sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_8) 54 | #define sml_i16_parse(buf) (i16 *) sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_16) 55 | #define sml_i32_parse(buf) (i32 *) sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_32) 56 | #define sml_i64_parse(buf) (i64 *) sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_64) 57 | 58 | #define sml_u8_write(n, buf) sml_number_write(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8, buf) 59 | #define sml_u16_write(n, buf) sml_number_write(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_16, buf) 60 | #define sml_u32_write(n, buf) sml_number_write(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_32, buf) 61 | #define sml_u64_write(n, buf) sml_number_write(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_64, buf) 62 | #define sml_i8_write(n, buf) sml_number_write(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_8, buf) 63 | #define sml_i16_write(n, buf) sml_number_write(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_16, buf) 64 | #define sml_i32_write(n, buf) sml_number_write(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_32, buf) 65 | #define sml_i64_write(n, buf) sml_number_write(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_64, buf) 66 | 67 | typedef u8 sml_unit; 68 | #define sml_unit_init(n) sml_u8_init(n) 69 | #define sml_unit_parse(buf) sml_u8_parse(buf) 70 | #define sml_unit_write(n, buf) sml_u8_write(n, buf) 71 | #define sml_unit_free(np) sml_number_free(np) 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | 78 | #endif /* _SML_NUMBER_H_ */ 79 | 80 | -------------------------------------------------------------------------------- /sml/include/sml/sml_octet_string.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_OCTET_STRING_H_ 20 | #define _SML_OCTET_STRING_H_ 21 | 22 | #include 23 | #include "sml_shared.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | typedef struct { 30 | unsigned char *str; 31 | int len; 32 | } octet_string; 33 | 34 | octet_string *sml_octet_string_init(unsigned char *str, int length); 35 | octet_string *sml_octet_string_init_from_hex(char *str); 36 | // Parses a octet string, updates the buffer accordingly, memory must be free'd elsewhere. 37 | octet_string *sml_octet_string_parse(sml_buffer *buf); 38 | octet_string *sml_octet_string_generate_uuid(); 39 | void sml_octet_string_write(octet_string *str, sml_buffer *buf); 40 | void sml_octet_string_free(octet_string *str); 41 | int sml_octet_string_cmp(octet_string *s1, octet_string *s2); 42 | int sml_octet_string_cmp_with_hex(octet_string *str, char *hex); 43 | 44 | // sml signature 45 | typedef octet_string sml_signature; 46 | #define sml_signature_parse(buf) sml_octet_string_parse(buf) 47 | #define sml_signature_write(s, buf) sml_octet_string_write(s, buf) 48 | #define sml_signature_free(s) sml_octet_string_free(s) 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | 55 | #endif /* _SML_OCTET_STRING_H_ */ 56 | 57 | -------------------------------------------------------------------------------- /sml/include/sml/sml_open_request.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_OPEN_REQUEST_H_ 20 | #define _SML_OPEN_REQUEST_H_ 21 | 22 | #include "sml_shared.h" 23 | #include "sml_octet_string.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | typedef struct { 30 | octet_string *codepage; // optional 31 | octet_string *client_id; 32 | octet_string *req_file_id; 33 | octet_string *server_id; // optional 34 | octet_string *username; // optional 35 | octet_string *password; // optional 36 | u8 *sml_version; // optional 37 | } sml_open_request; 38 | 39 | sml_open_request *sml_open_request_init(); 40 | sml_open_request *sml_open_request_parse(sml_buffer *buf); 41 | void sml_open_request_write(sml_open_request *msg, sml_buffer *buf); 42 | void sml_open_request_free(sml_open_request *msg); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | 49 | #endif /* _SML_OPEN_REQUEST_H_ */ 50 | 51 | -------------------------------------------------------------------------------- /sml/include/sml/sml_open_response.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #ifndef _SML_OPEN_RESPONSE_H_ 21 | #define _SML_OPEN_RESPONSE_H_ 22 | 23 | #include "sml_shared.h" 24 | #include "sml_octet_string.h" 25 | #include "sml_time.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | typedef struct { 32 | octet_string *codepage; // optional 33 | octet_string *client_id; // optional 34 | octet_string *req_file_id; 35 | octet_string *server_id; 36 | sml_time *ref_time; // optional 37 | u8 *sml_version; // optional 38 | } sml_open_response; 39 | 40 | sml_open_response *sml_open_response_init(); 41 | sml_open_response *sml_open_response_parse(sml_buffer *buf); 42 | void sml_open_response_write(sml_open_response *msg, sml_buffer *buf); 43 | void sml_open_response_free(sml_open_response *msg); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | 50 | #endif /* _SML_OPEN_RESPONSE_H_ */ 51 | 52 | -------------------------------------------------------------------------------- /sml/include/sml/sml_set_proc_parameter_request.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_SET_PROC_PARAMETER_REQUEST_H_ 20 | #define _SML_SET_PROC_PARAMETER_REQUEST_H_ 21 | 22 | #include "sml_shared.h" 23 | #include "sml_octet_string.h" 24 | #include "sml_tree.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | typedef struct { 31 | octet_string *server_id; // optional 32 | octet_string *username; // optional 33 | octet_string *password; // optional 34 | sml_tree_path *parameter_tree_path; 35 | sml_tree *parameter_tree; 36 | } sml_set_proc_parameter_request; 37 | 38 | sml_set_proc_parameter_request *sml_set_proc_parameter_request_init(); 39 | sml_set_proc_parameter_request *sml_set_proc_parameter_request_parse(sml_buffer *buf); 40 | void sml_set_proc_parameter_request_write(sml_set_proc_parameter_request *msg, sml_buffer *buf); 41 | void sml_set_proc_parameter_request_free(sml_set_proc_parameter_request *msg); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | 48 | #endif /* _SML_SET_PROC_PARAMETER_REQUEST_H_ */ 49 | 50 | -------------------------------------------------------------------------------- /sml/include/sml/sml_shared.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_SHARED_H_ 20 | #define _SML_SHARED_H_ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | typedef uint8_t u8; 31 | typedef uint16_t u16; 32 | typedef uint32_t u32; 33 | typedef uint64_t u64; 34 | 35 | typedef int8_t i8; 36 | typedef int16_t i16; 37 | typedef int32_t i32; 38 | typedef int64_t i64; 39 | 40 | #define SML_MESSAGE_END 0x0 41 | 42 | #define SML_TYPE_FIELD 0x70 43 | #define SML_LENGTH_FIELD 0xF 44 | #define SML_ANOTHER_TL 0x80 45 | 46 | #define SML_TYPE_OCTET_STRING 0x0 47 | #define SML_TYPE_BOOLEAN 0x40 48 | #define SML_TYPE_INTEGER 0x50 49 | #define SML_TYPE_UNSIGNED 0x60 50 | #define SML_TYPE_LIST 0x70 51 | 52 | #define SML_OPTIONAL_SKIPPED 0x1 53 | 54 | #define SML_TYPE_NUMBER_8 sizeof(u8) 55 | #define SML_TYPE_NUMBER_16 sizeof(u16) 56 | #define SML_TYPE_NUMBER_32 sizeof(u32) 57 | #define SML_TYPE_NUMBER_64 sizeof(u64) 58 | 59 | // This sml_buffer is used in two different use-cases. 60 | // 61 | // Parsing: the raw data is in the buffer field, 62 | // the buffer_len is the number of raw bytes received, 63 | // the cursor points to the current position during parsing 64 | // 65 | // Writing: At the beginning the buffer field is malloced and zeroed with 66 | // a default length, this default length is stored in buffer_len 67 | // (i.e. the maximum bytes one can write to this buffer) 68 | // cursor points to the position, where on can write during the 69 | // writing process. If a file is completely written to the buffer, 70 | // cursor is the number of bytes written to the buffer. 71 | typedef struct { 72 | unsigned char *buffer; 73 | size_t buffer_len; 74 | int cursor; 75 | int error; 76 | char *error_msg; 77 | } sml_buffer; 78 | 79 | sml_buffer *sml_buffer_init(size_t length); 80 | 81 | void sml_buffer_free(sml_buffer *buf); 82 | 83 | // Returns the length of the following data structure. Sets the cursor position to 84 | // the value field. 85 | int sml_buf_get_next_length(sml_buffer *buf); 86 | 87 | void sml_buf_set_type_and_length(sml_buffer *buf, unsigned int type, unsigned int l); 88 | 89 | // Checks if a error is occured. 90 | int sml_buf_has_errors(sml_buffer *buf); 91 | 92 | // Returns the type field of the current byte. 93 | int sml_buf_get_next_type(sml_buffer *buf); 94 | 95 | // Returns the current byte. 96 | unsigned char sml_buf_get_current_byte(sml_buffer *buf); 97 | 98 | // Returns a pointer to the current buffer position. 99 | unsigned char *sml_buf_get_current_buf(sml_buffer *buf); 100 | 101 | void sml_buf_optional_write(sml_buffer *buf); 102 | 103 | // Sets the number of bytes read (moves the cursor forward) 104 | void sml_buf_update_bytes_read(sml_buffer *buf, int bytes); 105 | 106 | // Checks if the next field is a skipped optional field, updates the buffer accordingly 107 | int sml_buf_optional_is_skipped(sml_buffer *buf); 108 | 109 | // Prints arbitrarily byte string to stdout with printf 110 | void hexdump(unsigned char *buffer, size_t buffer_len); 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | 116 | 117 | #endif /* _SML_SHARED_H_ */ 118 | 119 | -------------------------------------------------------------------------------- /sml/include/sml/sml_status.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_STATUS_H_ 20 | #define _SML_STATUS_H_ 21 | 22 | #include "sml_number.h" 23 | #include "sml_shared.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | typedef struct { 30 | u8 type; 31 | union { 32 | u8 *status8; 33 | u16 *status16; 34 | u32 *status32; 35 | u64 *status64; 36 | } data; 37 | } sml_status; 38 | 39 | sml_status *sml_status_init(); 40 | sml_status *sml_status_parse(sml_buffer *buf); 41 | void sml_status_write(sml_status *status, sml_buffer *buf); 42 | void sml_status_free(sml_status *status); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | 49 | #endif /* _SML_STATUS_H_ */ 50 | 51 | -------------------------------------------------------------------------------- /sml/include/sml/sml_time.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #ifndef _SML_TIME_H_ 21 | #define _SML_TIME_H_ 22 | 23 | #include "sml_shared.h" 24 | #include "sml_number.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #define SML_TIME_SEC_INDEX 0x01 31 | #define SML_TIME_TIMESTAMP 0x02 32 | 33 | typedef struct { 34 | u8 *tag; 35 | union { 36 | u32 *sec_index; 37 | u32 *timestamp; 38 | } 39 | data; 40 | } sml_time; 41 | 42 | sml_time *sml_time_init(); 43 | sml_time *sml_time_parse(sml_buffer *buf); 44 | void sml_time_write(sml_time *time, sml_buffer *buf); 45 | void sml_time_free(sml_time *time); 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | 51 | #endif /* _SML_TIME_H_ */ 52 | 53 | -------------------------------------------------------------------------------- /sml/include/sml/sml_transport.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_TRANSPORT_H_ 20 | #define _SML_TRANSPORT_H_ 21 | 22 | #include 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | // sml_transport_read reads continously bytes from fd and scans 30 | // for the SML transport protocol escape sequences. If a SML file 31 | // is detected it will be copied into the buffer. The total amount of bytes read 32 | // will be returned. If the SML file exceeds the len of the buffer, -1 will be returned 33 | size_t sml_transport_read(int fd, unsigned char *buffer, size_t max_len); 34 | 35 | // sml_transport_listen is an endless loop which reads continously 36 | // via sml_transport_read and calls the sml_transporter_receiver 37 | void sml_transport_listen(int fd, void (*sml_transport_receiver)(unsigned char *buffer, size_t buffer_len)); 38 | 39 | // sml_transport_writes adds the SML transport protocol escape 40 | // sequences and writes the given file to fd. The file must be 41 | // in the parsed format. 42 | // The number of bytes written is returned, 0 if there was an 43 | // error. 44 | // The sml_file must be free'd elsewhere. 45 | int sml_transport_write(int fd, sml_file *file); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | 52 | #endif /* _SML_TRANSPORT_H_ */ 53 | 54 | -------------------------------------------------------------------------------- /sml/include/sml/sml_tree.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_TREE_H_ 20 | #define _SML_TREE_H_ 21 | 22 | #include "sml_shared.h" 23 | #include "sml_octet_string.h" 24 | #include "sml_value.h" 25 | #include "sml_time.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #define SML_PROC_PAR_VALUE_TAG_VALUE 0x01 32 | #define SML_PROC_PAR_VALUE_TAG_PERIOD_ENTRY 0x02 33 | #define SML_PROC_PAR_VALUE_TAG_TUPEL_ENTRY 0x03 34 | #define SML_PROC_PAR_VALUE_TAG_TIME 0x04 35 | 36 | // what a messy tupel ... 37 | typedef struct { 38 | octet_string *server_id; 39 | sml_time *sec_index; 40 | u64 *status; 41 | 42 | sml_unit *unit_pA; 43 | i8 *scaler_pA; 44 | i64 *value_pA; 45 | 46 | sml_unit *unit_R1; 47 | i8 *scaler_R1; 48 | i64 *value_R1; 49 | 50 | sml_unit *unit_R4; 51 | i8 *scaler_R4; 52 | i64 *value_R4; 53 | 54 | octet_string *signature_pA_R1_R4; 55 | 56 | sml_unit *unit_mA; 57 | i8 *scaler_mA; 58 | i64 *value_mA; 59 | 60 | sml_unit *unit_R2; 61 | i8 *scaler_R2; 62 | i64 *value_R2; 63 | 64 | sml_unit *unit_R3; 65 | i8 *scaler_R3; 66 | i64 *value_R3; 67 | 68 | octet_string *signature_mA_R2_R3; 69 | } sml_tupel_entry; 70 | 71 | typedef struct { 72 | octet_string *obj_name; 73 | sml_unit *unit; 74 | i8 *scaler; 75 | sml_value *value; 76 | octet_string *value_signature; 77 | } sml_period_entry; 78 | 79 | typedef struct { 80 | u8 *tag; 81 | union { 82 | sml_value *value; 83 | sml_period_entry *period_entry; 84 | sml_tupel_entry *tupel_entry; 85 | sml_time *time; 86 | } data; 87 | } sml_proc_par_value; 88 | 89 | typedef struct s_tree{ 90 | octet_string *parameter_name; 91 | sml_proc_par_value *parameter_value; // optional 92 | struct s_tree **child_list; // optional 93 | 94 | int child_list_len; 95 | } sml_tree; 96 | 97 | typedef struct { 98 | int path_entries_len; 99 | octet_string **path_entries; 100 | } sml_tree_path; 101 | 102 | // sml_tree; 103 | sml_tree *sml_tree_init(); 104 | sml_tree *sml_tree_parse(sml_buffer *buf); 105 | void sml_tree_add_tree(sml_tree *base_tree, sml_tree *tree); 106 | void sml_tree_write(sml_tree *tree, sml_buffer *buf); 107 | void sml_tree_free(sml_tree *tree); 108 | 109 | // sml_tree_path; 110 | sml_tree_path *sml_tree_path_init(); 111 | sml_tree_path *sml_tree_path_parse(sml_buffer *buf); 112 | void sml_tree_path_add_path_entry(sml_tree_path *tree_path, octet_string *entry); 113 | void sml_tree_path_write(sml_tree_path *tree_path, sml_buffer *buf); 114 | void sml_tree_path_free(sml_tree_path *tree_path); 115 | 116 | // sml_proc_par_value; 117 | sml_proc_par_value *sml_proc_par_value_init(); 118 | sml_proc_par_value *sml_proc_par_value_parse(sml_buffer *buf); 119 | void sml_proc_par_value_write(sml_proc_par_value *value, sml_buffer *buf); 120 | void sml_proc_par_value_free(sml_proc_par_value *value); 121 | 122 | // sml_tupel_entry; 123 | sml_tupel_entry *sml_tupel_entry_init(); 124 | sml_tupel_entry *sml_tupel_entry_parse(sml_buffer *buf); 125 | void sml_tupel_entry_write(sml_tupel_entry *tupel, sml_buffer *buf); 126 | void sml_tupel_entry_free(sml_tupel_entry *tupel); 127 | 128 | // sml_period_entry; 129 | sml_period_entry *sml_period_entry_init(); 130 | sml_period_entry *sml_period_entry_parse(sml_buffer *buf); 131 | void sml_period_entry_write(sml_period_entry *period, sml_buffer *buf); 132 | void sml_period_entry_free(sml_period_entry *period); 133 | 134 | #ifdef __cplusplus 135 | } 136 | #endif 137 | 138 | 139 | #endif /* _SML_TREE_H_ */ 140 | 141 | -------------------------------------------------------------------------------- /sml/include/sml/sml_value.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef _SML_VALUE_H_ 20 | #define _SML_VALUE_H_ 21 | 22 | #include "sml_shared.h" 23 | #include "sml_octet_string.h" 24 | #include "sml_number.h" 25 | #include "sml_boolean.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | typedef struct { 32 | u8 type; 33 | union { 34 | sml_boolean *boolean; 35 | octet_string *bytes; // can has zero length 36 | i8 *int8; 37 | i16 *int16; 38 | i32 *int32; 39 | i64 *int64; 40 | u8 *uint8; 41 | u16 *uint16; 42 | u32 *uint32; 43 | u64 *uint64; 44 | } data; 45 | } sml_value; 46 | 47 | sml_value *sml_value_init(); 48 | sml_value *sml_value_parse(sml_buffer *buf); 49 | void sml_value_write(sml_value *value, sml_buffer *buf); 50 | void sml_value_free(sml_value *value); 51 | 52 | // Cast arbitrary sized sml_value to double 53 | double sml_value_to_double(sml_value *value); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | 60 | #endif /* _SML_VALUE_H_ */ 61 | 62 | -------------------------------------------------------------------------------- /sml/lib/.gitdir: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dailab/libsml/550aa8216295ff76076f35ce2eb00872dfd83f8f/sml/lib/.gitdir -------------------------------------------------------------------------------- /sml/src/sml_attention_response.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | 23 | sml_attention_response *sml_attention_response_init() { 24 | sml_attention_response *msg = (sml_attention_response *) malloc(sizeof(sml_attention_response)); 25 | memset(msg, 0, sizeof(sml_attention_response)); 26 | 27 | return msg; 28 | } 29 | 30 | sml_attention_response *sml_attention_response_parse(sml_buffer *buf){ 31 | sml_attention_response *msg = sml_attention_response_init(); 32 | 33 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 34 | buf->error = 1; 35 | goto error; 36 | } 37 | 38 | if (sml_buf_get_next_length(buf) != 4) { 39 | buf->error = 1; 40 | goto error; 41 | } 42 | 43 | msg->server_id = sml_octet_string_parse(buf); 44 | if (sml_buf_has_errors(buf)) goto error; 45 | 46 | msg->attention_number = sml_octet_string_parse(buf); 47 | if (sml_buf_has_errors(buf)) goto error; 48 | 49 | msg->attention_message = sml_octet_string_parse(buf); 50 | if (sml_buf_has_errors(buf)) goto error; 51 | 52 | msg->attention_details = sml_tree_parse(buf); 53 | if (sml_buf_has_errors(buf)) goto error; 54 | 55 | return msg; 56 | 57 | error: 58 | sml_attention_response_free(msg); 59 | return 0; 60 | } 61 | 62 | void sml_attention_response_write(sml_attention_response *msg, sml_buffer *buf) { 63 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 4); 64 | 65 | sml_octet_string_write(msg->server_id, buf); 66 | sml_octet_string_write(msg->attention_number, buf); 67 | sml_octet_string_write(msg->attention_message, buf); 68 | sml_tree_write(msg->attention_details, buf); 69 | } 70 | 71 | void sml_attention_response_free(sml_attention_response *msg){ 72 | if (msg) { 73 | sml_octet_string_free(msg->server_id); 74 | sml_octet_string_free(msg->attention_number); 75 | sml_octet_string_free(msg->attention_message); 76 | sml_tree_free(msg->attention_details); 77 | 78 | free(msg); 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /sml/src/sml_boolean.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | 23 | sml_boolean *sml_boolean_init(u8 b) { 24 | sml_boolean *boolean = malloc(sizeof(u8)); 25 | *boolean = b; 26 | 27 | return boolean; 28 | } 29 | 30 | sml_boolean *sml_boolean_parse(sml_buffer *buf) { 31 | if (sml_buf_optional_is_skipped(buf)) { 32 | return 0; 33 | } 34 | 35 | if (sml_buf_get_next_type(buf) != SML_TYPE_BOOLEAN) { 36 | buf->error = 1; 37 | return 0; 38 | } 39 | 40 | int l = sml_buf_get_next_length(buf); 41 | if (l != 1) { 42 | buf->error = 1; 43 | return 0; 44 | } 45 | 46 | if (sml_buf_get_current_byte(buf)) { 47 | sml_buf_update_bytes_read(buf, 1); 48 | return sml_boolean_init(SML_BOOLEAN_TRUE); 49 | } 50 | else { 51 | sml_buf_update_bytes_read(buf, 1); 52 | return sml_boolean_init(SML_BOOLEAN_FALSE); 53 | } 54 | } 55 | 56 | void sml_boolean_write(sml_boolean *boolean, sml_buffer *buf) { 57 | if (boolean == 0) { 58 | sml_buf_optional_write(buf); 59 | return; 60 | } 61 | 62 | sml_buf_set_type_and_length(buf, SML_TYPE_BOOLEAN, 1); 63 | if (*boolean == SML_BOOLEAN_FALSE) { 64 | buf->buffer[buf->cursor] = SML_BOOLEAN_FALSE; 65 | } 66 | else { 67 | buf->buffer[buf->cursor] = SML_BOOLEAN_TRUE; 68 | } 69 | buf->cursor++; 70 | } 71 | 72 | void sml_boolean_free(sml_boolean *b) { 73 | if (b) { 74 | free(b); 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /sml/src/sml_close_request.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | 23 | sml_close_request *sml_close_request_init() { 24 | sml_close_request *close_request = (sml_close_request *) malloc(sizeof(sml_close_request)); 25 | memset(close_request, 0, sizeof(sml_close_request)); 26 | 27 | return close_request; 28 | } 29 | 30 | sml_close_request * sml_close_request_parse(sml_buffer *buf) { 31 | sml_close_request *msg = sml_close_request_init(); 32 | 33 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 34 | buf->error = 1; 35 | goto error; 36 | } 37 | 38 | if (sml_buf_get_next_length(buf) != 1) { 39 | buf->error = 1; 40 | goto error; 41 | } 42 | 43 | msg->global_signature = sml_octet_string_parse(buf); 44 | if (sml_buf_has_errors(buf)) goto error; 45 | 46 | return msg; 47 | 48 | error: 49 | sml_close_request_free(msg); 50 | return 0; 51 | } 52 | 53 | void sml_close_request_write(sml_close_request *msg, sml_buffer *buf) { 54 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 1); 55 | sml_octet_string_write(msg->global_signature,buf); 56 | } 57 | 58 | void sml_close_request_free(sml_close_request *msg) { 59 | if (msg) { 60 | sml_octet_string_free(msg->global_signature); 61 | free(msg); 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /sml/src/sml_close_response.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | 23 | sml_close_response *sml_close_response_init() { 24 | sml_close_response *msg = (sml_close_response *) malloc(sizeof(sml_close_response)); 25 | memset(msg, 0, sizeof(sml_close_response)); 26 | 27 | return msg; 28 | } 29 | 30 | sml_close_response *sml_close_response_parse(sml_buffer *buf) { 31 | sml_close_response *msg = sml_close_response_init(); 32 | 33 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 34 | buf->error = 1; 35 | goto error; 36 | } 37 | 38 | if (sml_buf_get_next_length(buf) != 1) { 39 | buf->error = 1; 40 | goto error; 41 | } 42 | 43 | msg->global_signature = sml_octet_string_parse(buf); 44 | if (sml_buf_has_errors(buf)) goto error; 45 | 46 | return msg; 47 | 48 | error: 49 | sml_close_response_free(msg); 50 | return 0; 51 | } 52 | 53 | void sml_close_response_write(sml_close_response *msg, sml_buffer *buf) { 54 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 1); 55 | sml_octet_string_write(msg->global_signature,buf); 56 | } 57 | 58 | void sml_close_response_free(sml_close_response *msg) { 59 | if (msg) { 60 | sml_octet_string_free(msg->global_signature); 61 | 62 | free(msg); 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /sml/src/sml_crc16.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | 22 | #define PPPINITFCS16 0xffff // initial FCS value 23 | 24 | // table taken from DIN EN 62056-46 25 | static u16 fcstab [256] = { 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 26 | 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 27 | 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 0x2102, 0x308b, 0x0210, 28 | 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 29 | 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 30 | 0xea66, 0xd8fd, 0xc974, 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, 0xce4c, 0xdfc5, 31 | 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 32 | 0x263a, 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 0x6306, 0x728f, 0x4014, 0x519d, 33 | 0x2522, 0x34ab, 0x0630, 0x17b9, 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 0x7387, 34 | 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 35 | 0x9af9, 0x8b70, 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 0x0840, 0x19c9, 0x2b52, 36 | 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 37 | 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 38 | 0xf2a7, 0xc03c, 0xd1b5, 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 0xb58b, 0xa402, 39 | 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 40 | 0x4d7c, 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, 0x4a44, 0x5bcd, 0x6956, 0x78df, 41 | 0x0c60, 0x1de9, 0x2f72, 0x3efb, 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 0x5ac5, 42 | 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 43 | 0x8238, 0x93b1, 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 0xf78f, 0xe606, 0xd49d, 44 | 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 45 | }; 46 | 47 | u16 sml_crc16_calculate(unsigned char *cp, int len) { 48 | u16 fcs = PPPINITFCS16; 49 | 50 | while (len--) { 51 | fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff]; 52 | } 53 | 54 | fcs ^= 0xffff; 55 | fcs = ((fcs & 0xff) << 8) | ((fcs & 0xff00) >> 8); 56 | 57 | return fcs; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /sml/src/sml_file.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | // EDL meter must provide at least 250 bytes as a receive buffer 29 | #define SML_FILE_BUFFER_LENGTH 512 30 | 31 | sml_file *sml_file_parse(unsigned char *buffer, size_t buffer_len) { 32 | sml_file *file = (sml_file*) malloc(sizeof(sml_file)); 33 | memset(file, 0, sizeof(sml_file)); 34 | 35 | sml_buffer *buf = sml_buffer_init(buffer_len); 36 | memcpy(buf->buffer, buffer, buffer_len); 37 | file->buf = buf; 38 | 39 | sml_message *msg; 40 | 41 | // parsing all messages 42 | for (; buf->cursor < buf->buffer_len;) { 43 | 44 | if(sml_buf_get_current_byte(buf) == SML_MESSAGE_END) { 45 | // reading trailing zeroed bytes 46 | sml_buf_update_bytes_read(buf, 1); 47 | continue; 48 | } 49 | 50 | msg = sml_message_parse(buf); 51 | 52 | if (sml_buf_has_errors(buf)) { 53 | printf("warning: could not read the whole file\n"); 54 | break; 55 | } 56 | 57 | sml_file_add_message(file, msg); 58 | 59 | } 60 | 61 | return file; 62 | } 63 | 64 | sml_file *sml_file_init() { 65 | sml_file *file = (sml_file*) malloc(sizeof(sml_file)); 66 | memset(file, 0, sizeof(sml_file)); 67 | 68 | sml_buffer *buf = sml_buffer_init(SML_FILE_BUFFER_LENGTH); 69 | file->buf = buf; 70 | 71 | return file; 72 | } 73 | 74 | void sml_file_add_message(sml_file *file, sml_message *message) { 75 | file->messages_len++; 76 | file->messages = (sml_message **) realloc(file->messages, sizeof(sml_message *) * file->messages_len); 77 | file->messages[file->messages_len - 1] = message; 78 | } 79 | 80 | void sml_file_write(sml_file *file) { 81 | int i; 82 | 83 | if (file->messages && file->messages_len > 0) { 84 | for (i = 0; i < file->messages_len; i++) { 85 | sml_message_write(file->messages[i], file->buf); 86 | } 87 | } 88 | } 89 | 90 | void sml_file_free(sml_file *file) { 91 | if (file) { 92 | if (file->messages) { 93 | int i; 94 | for (i = 0; i < file->messages_len; i++) { 95 | sml_message_free(file->messages[i]); 96 | } 97 | free(file->messages); 98 | } 99 | 100 | if (file->buf) { 101 | sml_buffer_free(file->buf); 102 | } 103 | 104 | free(file); 105 | } 106 | } 107 | 108 | void sml_file_print(sml_file *file) { 109 | int i; 110 | 111 | printf("SML file (%d SML messages, %d bytes)\n", file->messages_len, file->buf->cursor); 112 | for (i = 0; i < file->messages_len; i++) { 113 | printf("SML message %4.X\n", *(file->messages[i]->message_body->tag)); 114 | } 115 | } 116 | 117 | -------------------------------------------------------------------------------- /sml/src/sml_get_list_request.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | 23 | sml_get_list_request* sml_get_list_request_init() { 24 | sml_get_list_request *msg = (sml_get_list_request *) malloc(sizeof(sml_get_list_request)); 25 | memset(msg, 0, sizeof(sml_get_list_request)); 26 | 27 | return msg; 28 | } 29 | 30 | void sml_get_list_request_write(sml_get_list_request *msg, sml_buffer *buf) { 31 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5); 32 | 33 | sml_octet_string_write(msg->client_id, buf); 34 | sml_octet_string_write(msg->server_id, buf); 35 | sml_octet_string_write(msg->username, buf); 36 | sml_octet_string_write(msg->password, buf); 37 | sml_octet_string_write(msg->list_name,buf); 38 | } 39 | 40 | 41 | sml_get_list_request *sml_get_list_request_parse(sml_buffer *buf) { 42 | sml_get_list_request *msg = (sml_get_list_request *) malloc(sizeof(sml_get_list_request)); 43 | memset(msg, 0, sizeof(sml_get_list_request)); 44 | 45 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 46 | buf->error = 1; 47 | goto error; 48 | } 49 | 50 | if (sml_buf_get_next_length(buf) != 5) { 51 | buf->error = 1; 52 | goto error; 53 | } 54 | 55 | msg->client_id = sml_octet_string_parse(buf); 56 | if (sml_buf_has_errors(buf)) goto error; 57 | 58 | msg->server_id = sml_octet_string_parse(buf); 59 | if (sml_buf_has_errors(buf)) goto error; 60 | 61 | msg->username = sml_octet_string_parse(buf); 62 | if (sml_buf_has_errors(buf)) goto error; 63 | 64 | msg->password = sml_octet_string_parse(buf); 65 | if (sml_buf_has_errors(buf)) goto error; 66 | 67 | msg->list_name = sml_octet_string_parse(buf); 68 | if (sml_buf_has_errors(buf)) goto error; 69 | 70 | return msg; 71 | 72 | error: 73 | sml_get_list_request_free(msg); 74 | return 0; 75 | } 76 | 77 | 78 | void sml_get_list_request_free(sml_get_list_request *msg) { 79 | if (msg) { 80 | sml_octet_string_free(msg->client_id); 81 | sml_octet_string_free(msg->server_id); 82 | sml_octet_string_free(msg->list_name); 83 | sml_octet_string_free(msg->username); 84 | sml_octet_string_free(msg->password); 85 | free(msg); 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /sml/src/sml_get_list_response.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | 22 | sml_get_list_response *sml_get_list_response_init() { 23 | sml_get_list_response *msg = (sml_get_list_response *) malloc(sizeof(sml_get_list_response)); 24 | memset(msg, 0, sizeof(sml_get_list_response)); 25 | 26 | return msg; 27 | } 28 | 29 | sml_get_list_response *sml_get_list_response_parse(sml_buffer *buf) { 30 | sml_get_list_response *msg = sml_get_list_response_init(); 31 | 32 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 33 | buf->error = 1; 34 | goto error; 35 | } 36 | 37 | if (sml_buf_get_next_length(buf) != 7) { 38 | buf->error = 1; 39 | goto error; 40 | } 41 | 42 | msg->client_id = sml_octet_string_parse(buf); 43 | if (sml_buf_has_errors(buf)) goto error; 44 | 45 | msg->server_id = sml_octet_string_parse(buf); 46 | if (sml_buf_has_errors(buf)) goto error; 47 | 48 | msg->list_name = sml_octet_string_parse(buf); 49 | if (sml_buf_has_errors(buf)) goto error; 50 | 51 | msg->act_sensor_time = sml_time_parse(buf); 52 | if (sml_buf_has_errors(buf)) goto error; 53 | 54 | msg->val_list = sml_list_parse(buf); 55 | if (sml_buf_has_errors(buf)) goto error; 56 | 57 | msg->list_signature = sml_octet_string_parse(buf); 58 | if (sml_buf_has_errors(buf)) goto error; 59 | 60 | msg->act_gateway_time = sml_time_parse(buf); 61 | if (sml_buf_has_errors(buf)) goto error; 62 | 63 | return msg; 64 | 65 | error: 66 | sml_get_list_response_free(msg); 67 | return 0; 68 | } 69 | 70 | void sml_get_list_response_write(sml_get_list_response *msg, sml_buffer *buf) { 71 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 7); 72 | 73 | sml_octet_string_write(msg->client_id, buf); 74 | sml_octet_string_write(msg->server_id, buf); 75 | sml_octet_string_write(msg->list_name, buf); 76 | sml_time_write(msg->act_sensor_time, buf); 77 | sml_list_write(msg->val_list, buf); 78 | sml_octet_string_write(msg->list_signature, buf); 79 | sml_time_write(msg->act_gateway_time, buf); 80 | } 81 | 82 | void sml_get_list_response_free(sml_get_list_response *msg) { 83 | if (msg) { 84 | sml_octet_string_free(msg->client_id); 85 | sml_octet_string_free(msg->server_id); 86 | sml_octet_string_free(msg->list_name); 87 | sml_time_free(msg->act_sensor_time); 88 | sml_list_free(msg->val_list); 89 | sml_octet_string_free(msg->list_signature); 90 | sml_time_free(msg->act_gateway_time); 91 | 92 | free(msg); 93 | } 94 | } 95 | 96 | -------------------------------------------------------------------------------- /sml/src/sml_get_proc_parameter_request.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | sml_get_proc_parameter_request *sml_get_proc_parameter_request_init() { 25 | sml_get_proc_parameter_request *msg = (sml_get_proc_parameter_request *) malloc(sizeof (sml_get_proc_parameter_request)); 26 | memset(msg, 0, sizeof(sml_get_proc_parameter_request)); 27 | 28 | return msg; 29 | } 30 | 31 | sml_get_proc_parameter_request *sml_get_proc_parameter_request_parse(sml_buffer *buf) { 32 | sml_get_proc_parameter_request *msg = sml_get_proc_parameter_request_init(); 33 | 34 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 35 | buf->error = 1; 36 | goto error; 37 | } 38 | 39 | if (sml_buf_get_next_length(buf) != 5) { 40 | buf->error = 1; 41 | goto error; 42 | } 43 | 44 | msg->server_id = sml_octet_string_parse(buf); 45 | if (sml_buf_has_errors(buf)) goto error; 46 | 47 | msg->username = sml_octet_string_parse(buf); 48 | if (sml_buf_has_errors(buf)) goto error; 49 | 50 | msg->password = sml_octet_string_parse(buf); 51 | if (sml_buf_has_errors(buf)) goto error; 52 | 53 | msg->parameter_tree_path = sml_tree_path_parse(buf); 54 | if (sml_buf_has_errors(buf)) goto error; 55 | 56 | msg->attribute = sml_octet_string_parse(buf); 57 | if (sml_buf_has_errors(buf)) goto error; 58 | 59 | return msg; 60 | 61 | error: 62 | sml_get_proc_parameter_request_free(msg); 63 | return 0; 64 | } 65 | 66 | void sml_get_proc_parameter_request_write(sml_get_proc_parameter_request *msg, sml_buffer *buf) { 67 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5); 68 | 69 | sml_octet_string_write(msg->server_id, buf); 70 | sml_octet_string_write(msg->username, buf); 71 | sml_octet_string_write(msg->password, buf); 72 | sml_tree_path_write(msg->parameter_tree_path, buf); 73 | sml_octet_string_write(msg->attribute, buf); 74 | } 75 | 76 | void sml_get_proc_parameter_request_free(sml_get_proc_parameter_request *msg) { 77 | if (msg) { 78 | sml_octet_string_free(msg->server_id); 79 | sml_octet_string_free(msg->username); 80 | sml_octet_string_free(msg->password); 81 | sml_tree_path_free(msg->parameter_tree_path); 82 | sml_octet_string_free(msg->attribute); 83 | 84 | free(msg); 85 | } 86 | } 87 | 88 | -------------------------------------------------------------------------------- /sml/src/sml_get_proc_parameter_response.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include 20 | #include 21 | 22 | sml_get_proc_parameter_response *sml_get_proc_parameter_response_init() { 23 | sml_get_proc_parameter_response *msg = (sml_get_proc_parameter_response *)malloc(sizeof(sml_get_proc_parameter_response)); 24 | memset(msg, 0, sizeof(sml_get_proc_parameter_response)); 25 | 26 | return msg; 27 | } 28 | 29 | sml_get_proc_parameter_response *sml_get_proc_parameter_response_parse(sml_buffer *buf) { 30 | sml_get_proc_parameter_response *msg = sml_get_proc_parameter_response_init(); 31 | 32 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 33 | buf->error = 1; 34 | goto error; 35 | } 36 | 37 | if (sml_buf_get_next_length(buf) != 3) { 38 | buf->error = 1; 39 | goto error; 40 | } 41 | 42 | msg->server_id = sml_octet_string_parse(buf); 43 | if (sml_buf_has_errors(buf)) goto error; 44 | 45 | msg->parameter_tree_path = sml_tree_path_parse(buf); 46 | if (sml_buf_has_errors(buf)) goto error; 47 | 48 | msg->parameter_tree = sml_tree_parse(buf); 49 | if (sml_buf_has_errors(buf)) goto error; 50 | 51 | return msg; 52 | 53 | error: 54 | sml_get_proc_parameter_response_free(msg); 55 | return 0; 56 | } 57 | 58 | void sml_get_proc_parameter_response_write(sml_get_proc_parameter_response *msg, sml_buffer *buf) { 59 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 3); 60 | sml_octet_string_write(msg->server_id, buf); 61 | sml_tree_path_write(msg->parameter_tree_path, buf); 62 | sml_tree_write(msg->parameter_tree, buf); 63 | } 64 | 65 | void sml_get_proc_parameter_response_free(sml_get_proc_parameter_response *msg) { 66 | if (msg) { 67 | sml_octet_string_free(msg->server_id); 68 | sml_tree_path_free(msg->parameter_tree_path); 69 | sml_tree_free(msg->parameter_tree); 70 | 71 | free(msg); 72 | } 73 | } 74 | 75 | -------------------------------------------------------------------------------- /sml/src/sml_get_profile_list_request.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include 20 | 21 | // this file is just there for symmetry 22 | 23 | void sml_get_profile_list_request_noop() {} 24 | 25 | -------------------------------------------------------------------------------- /sml/src/sml_get_profile_list_response.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | 22 | // sml_get_profile_list_response; 23 | 24 | sml_get_profile_list_response *sml_get_profile_list_response_init() { 25 | sml_get_profile_list_response *msg = (sml_get_profile_list_response *) malloc(sizeof(sml_get_profile_list_response)); 26 | memset(msg, 0, sizeof(sml_get_profile_list_response)); 27 | return msg; 28 | } 29 | 30 | sml_get_profile_list_response *sml_get_profile_list_response_parse(sml_buffer *buf) { 31 | sml_get_profile_list_response *msg = sml_get_profile_list_response_init(); 32 | 33 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 34 | buf->error = 1; 35 | goto error; 36 | } 37 | 38 | if (sml_buf_get_next_length(buf) != 9) { 39 | buf->error = 1; 40 | goto error; 41 | } 42 | 43 | msg->server_id = sml_octet_string_parse(buf); 44 | if (sml_buf_has_errors(buf)) goto error; 45 | 46 | msg->act_time = sml_time_parse(buf); 47 | if (sml_buf_has_errors(buf)) goto error; 48 | 49 | msg->reg_period = sml_u32_parse(buf); 50 | if (sml_buf_has_errors(buf)) goto error; 51 | 52 | msg->parameter_tree_path = sml_tree_path_parse(buf); 53 | if (sml_buf_has_errors(buf)) goto error; 54 | 55 | msg->val_time = sml_time_parse(buf); 56 | if (sml_buf_has_errors(buf)) goto error; 57 | 58 | msg->status = sml_u64_parse(buf); 59 | if (sml_buf_has_errors(buf)) goto error; 60 | 61 | msg->period_list = sml_sequence_parse(buf, (void *) &sml_period_entry_parse, (void (*)(void *)) &sml_period_entry_free); 62 | if (sml_buf_has_errors(buf)) goto error; 63 | 64 | msg->rawdata = sml_octet_string_parse(buf); 65 | if (sml_buf_has_errors(buf)) goto error; 66 | 67 | msg->period_signature = sml_signature_parse(buf); 68 | if (sml_buf_has_errors(buf)) goto error; 69 | 70 | return msg; 71 | 72 | error: 73 | buf->error = 1; 74 | sml_get_profile_list_response_free(msg); 75 | return 0; 76 | } 77 | 78 | void sml_get_profile_list_response_write(sml_get_profile_list_response *msg, sml_buffer *buf) { 79 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 9); 80 | 81 | sml_octet_string_write(msg->server_id, buf); 82 | sml_time_write(msg->act_time, buf); 83 | sml_u32_write(msg->reg_period, buf); 84 | sml_tree_path_write(msg->parameter_tree_path, buf); 85 | sml_time_write(msg->val_time, buf); 86 | sml_u64_write(msg->status, buf); 87 | sml_sequence_write(msg->period_list, buf, (void (*)(void *, sml_buffer *)) &sml_period_entry_write); 88 | sml_octet_string_write(msg->rawdata, buf); 89 | sml_signature_write(msg->period_signature, buf); 90 | } 91 | 92 | void sml_get_profile_list_response_free(sml_get_profile_list_response *msg) { 93 | if (msg) { 94 | sml_octet_string_free(msg->server_id); 95 | sml_time_free(msg->act_time); 96 | sml_number_free(msg->reg_period); 97 | sml_tree_path_free(msg->parameter_tree_path); 98 | sml_time_free(msg->val_time); 99 | sml_number_free(msg->status); 100 | sml_sequence_free(msg->period_list); 101 | sml_octet_string_free(msg->rawdata); 102 | sml_signature_free(msg->period_signature); 103 | 104 | free(msg); 105 | } 106 | } 107 | 108 | -------------------------------------------------------------------------------- /sml/src/sml_get_profile_pack_request.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | sml_get_profile_pack_request *sml_get_profile_pack_request_init(){ 27 | sml_get_profile_pack_request *msg = (sml_get_profile_pack_request *) malloc(sizeof(sml_get_profile_pack_request)); 28 | memset(msg, 0, sizeof(sml_get_profile_pack_request)); 29 | 30 | return msg; 31 | } 32 | 33 | void sml_get_profile_pack_request_write(sml_get_profile_pack_request *msg, sml_buffer *buf) { 34 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 9); 35 | 36 | sml_octet_string_write(msg->server_id, buf); 37 | sml_octet_string_write(msg->username, buf); 38 | sml_octet_string_write(msg->password, buf); 39 | sml_boolean_write(msg->with_rawdata, buf); 40 | sml_time_write(msg->begin_time, buf); 41 | sml_time_write(msg->end_time, buf); 42 | sml_tree_path_write(msg->parameter_tree_path, buf); 43 | 44 | if (msg->object_list) { 45 | int len = 1; 46 | sml_obj_req_entry_list *l = msg->object_list; 47 | for (l = msg->object_list; l->next; l = l->next) { 48 | len++; 49 | } 50 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, len); 51 | for (l = msg->object_list; l->next; l = l->next) { 52 | sml_obj_req_entry_write(l->object_list_entry, buf); 53 | } 54 | } 55 | else { 56 | sml_buf_optional_write(buf); 57 | } 58 | 59 | sml_tree_write(msg->das_details, buf); 60 | } 61 | 62 | sml_get_profile_pack_request *sml_get_profile_pack_request_parse(sml_buffer *buf) { 63 | sml_get_profile_pack_request *msg = sml_get_profile_pack_request_init(); 64 | 65 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 66 | buf->error = 1; 67 | goto error; 68 | } 69 | 70 | if (sml_buf_get_next_length(buf) != 9) { 71 | buf->error = 1; 72 | goto error; 73 | } 74 | 75 | msg->server_id = sml_octet_string_parse(buf); 76 | if (sml_buf_has_errors(buf)) goto error; 77 | 78 | msg->username = sml_octet_string_parse(buf); 79 | if (sml_buf_has_errors(buf)) goto error; 80 | 81 | msg->password = sml_octet_string_parse(buf); 82 | if (sml_buf_has_errors(buf)) goto error; 83 | 84 | msg->with_rawdata = sml_boolean_parse(buf); 85 | if (sml_buf_has_errors(buf)) goto error; 86 | 87 | msg->begin_time = sml_time_parse(buf); 88 | if (sml_buf_has_errors(buf)) goto error; 89 | 90 | msg->end_time = sml_time_parse(buf); 91 | if (sml_buf_has_errors(buf)) goto error; 92 | 93 | msg->parameter_tree_path = sml_tree_path_parse(buf); 94 | if (sml_buf_has_errors(buf)) goto error; 95 | 96 | if (!sml_buf_optional_is_skipped(buf)) { 97 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 98 | buf->error = 1; 99 | goto error; 100 | } 101 | int i, len = sml_buf_get_next_length(buf); 102 | sml_obj_req_entry_list *last = 0, *n = 0; 103 | for (i = len; i > 0; i--) { 104 | n = (sml_obj_req_entry_list *) malloc(sizeof(sml_obj_req_entry_list)); 105 | memset(n, 0, sizeof(sml_obj_req_entry_list)); 106 | n->object_list_entry = sml_obj_req_entry_parse(buf); 107 | if (sml_buf_has_errors(buf)) goto error; 108 | 109 | if (msg->object_list == 0) { 110 | msg->object_list = n; 111 | last = msg->object_list; 112 | } 113 | else { 114 | last->next = n; 115 | last = n; 116 | } 117 | } 118 | } 119 | 120 | msg->das_details = sml_tree_parse(buf); 121 | if (sml_buf_has_errors(buf)) goto error; 122 | 123 | return msg; 124 | 125 | error: 126 | sml_get_profile_pack_request_free(msg); 127 | return 0; 128 | } 129 | 130 | void sml_get_profile_pack_request_free(sml_get_profile_pack_request *msg){ 131 | if (msg) { 132 | sml_octet_string_free(msg->server_id); 133 | sml_octet_string_free(msg->username); 134 | sml_octet_string_free(msg->password); 135 | sml_boolean_free(msg->with_rawdata); 136 | sml_time_free(msg->begin_time); 137 | sml_time_free(msg->end_time); 138 | sml_tree_path_free(msg->parameter_tree_path); 139 | 140 | if (msg->object_list) { 141 | sml_obj_req_entry_list *n = 0, *d = msg->object_list; 142 | do { 143 | n = d->next; 144 | sml_obj_req_entry_free(d->object_list_entry); 145 | free(d); 146 | d = n; 147 | } while (d); 148 | } 149 | 150 | sml_tree_free(msg->das_details); 151 | free(msg); 152 | } 153 | } 154 | 155 | -------------------------------------------------------------------------------- /sml/src/sml_get_profile_pack_response.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | 23 | // sml_get_profile_pack_response; 24 | 25 | sml_get_profile_pack_response *sml_get_profile_pack_response_init() { 26 | sml_get_profile_pack_response *msg = (sml_get_profile_pack_response *) malloc(sizeof(sml_get_profile_pack_response)); 27 | memset(msg, 0, sizeof(sml_get_profile_pack_response)); 28 | 29 | return msg; 30 | } 31 | 32 | sml_get_profile_pack_response *sml_get_profile_pack_response_parse(sml_buffer *buf){ 33 | sml_get_profile_pack_response *msg = sml_get_profile_pack_response_init(); 34 | 35 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 36 | buf->error = 1; 37 | goto error; 38 | } 39 | 40 | if (sml_buf_get_next_length(buf) != 8) { 41 | buf->error = 1; 42 | goto error; 43 | } 44 | 45 | msg->server_id = sml_octet_string_parse(buf); 46 | if (sml_buf_has_errors(buf)) goto error; 47 | 48 | msg->act_time = sml_time_parse(buf); 49 | if (sml_buf_has_errors(buf)) goto error; 50 | 51 | msg->reg_period = sml_u32_parse(buf); 52 | if (sml_buf_has_errors(buf)) goto error; 53 | 54 | msg->parameter_tree_path = sml_tree_path_parse(buf); 55 | if (sml_buf_has_errors(buf)) goto error; 56 | 57 | msg->header_list = sml_sequence_parse(buf, (void *) &sml_prof_obj_header_entry_parse, (void (*)(void *)) &sml_prof_obj_header_entry_free); 58 | if (sml_buf_has_errors(buf)) goto error; 59 | 60 | msg->period_list = sml_sequence_parse(buf, (void *) &sml_prof_obj_period_entry_parse, (void (*)(void *)) &sml_prof_obj_period_entry_free); 61 | if (sml_buf_has_errors(buf)) goto error; 62 | 63 | msg->rawdata = sml_octet_string_parse(buf); 64 | if (sml_buf_has_errors(buf)) goto error; 65 | 66 | msg->profile_signature = sml_signature_parse(buf); 67 | if (sml_buf_has_errors(buf)) goto error; 68 | 69 | return msg; 70 | 71 | error: 72 | buf->error = 1; 73 | sml_get_profile_pack_response_free(msg); 74 | return 0; 75 | } 76 | 77 | void sml_get_profile_pack_response_write(sml_get_profile_pack_response *msg, sml_buffer *buf) { 78 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 8); 79 | 80 | sml_octet_string_write(msg->server_id, buf); 81 | sml_time_write(msg->act_time, buf); 82 | sml_u32_write(msg->reg_period, buf); 83 | sml_tree_path_write(msg->parameter_tree_path, buf); 84 | sml_sequence_write(msg->header_list, buf, (void (*)(void *, sml_buffer *)) &sml_prof_obj_header_entry_write); 85 | sml_sequence_write(msg->period_list, buf, (void (*)(void *, sml_buffer *)) &sml_prof_obj_period_entry_write); 86 | sml_octet_string_write(msg->rawdata, buf); 87 | sml_signature_write(msg->profile_signature, buf); 88 | } 89 | 90 | void sml_get_profile_pack_response_free(sml_get_profile_pack_response *msg){ 91 | if (msg) { 92 | sml_octet_string_free(msg->server_id); 93 | sml_time_free(msg->act_time); 94 | sml_number_free(msg->reg_period); 95 | sml_tree_path_free(msg->parameter_tree_path); 96 | sml_sequence_free(msg->header_list); 97 | sml_sequence_free(msg->period_list); 98 | sml_octet_string_free(msg->rawdata); 99 | sml_signature_free(msg->profile_signature); 100 | 101 | free(msg); 102 | } 103 | } 104 | 105 | 106 | // sml_prof_obj_header_entry; 107 | 108 | sml_prof_obj_header_entry *sml_prof_obj_header_entry_init() { 109 | sml_prof_obj_header_entry *entry = (sml_prof_obj_header_entry *) malloc(sizeof(sml_prof_obj_header_entry)); 110 | memset(entry, 0, sizeof(sml_prof_obj_header_entry)); 111 | return entry; 112 | } 113 | 114 | sml_prof_obj_header_entry *sml_prof_obj_header_entry_parse(sml_buffer *buf) { 115 | sml_prof_obj_header_entry *entry = sml_prof_obj_header_entry_init(); 116 | 117 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 118 | buf->error = 1; 119 | goto error; 120 | } 121 | 122 | if (sml_buf_get_next_length(buf) != 3) { 123 | buf->error = 1; 124 | goto error; 125 | } 126 | 127 | entry->obj_name = sml_octet_string_parse(buf); 128 | if (sml_buf_has_errors(buf)) goto error; 129 | entry->unit = sml_unit_parse(buf); 130 | if (sml_buf_has_errors(buf)) goto error; 131 | entry->scaler = sml_i8_parse(buf); 132 | if (sml_buf_has_errors(buf)) goto error; 133 | 134 | return entry; 135 | error: 136 | buf->error = 1; 137 | sml_prof_obj_header_entry_free(entry); 138 | return 0; 139 | } 140 | 141 | void sml_prof_obj_header_entry_write(sml_prof_obj_header_entry *entry, sml_buffer *buf) { 142 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 3); 143 | 144 | sml_octet_string_write(entry->obj_name, buf); 145 | sml_unit_write(entry->unit, buf); 146 | sml_i8_write(entry->scaler, buf); 147 | } 148 | 149 | void sml_prof_obj_header_entry_free(sml_prof_obj_header_entry *entry) { 150 | if (entry) { 151 | sml_octet_string_free(entry->obj_name); 152 | sml_unit_free(entry->unit); 153 | sml_number_free(entry->scaler); 154 | 155 | free(entry); 156 | } 157 | } 158 | 159 | 160 | // sml_prof_obj_period_entry; 161 | 162 | sml_prof_obj_period_entry *sml_prof_obj_period_entry_init() { 163 | sml_prof_obj_period_entry *entry = (sml_prof_obj_period_entry *) malloc(sizeof(sml_prof_obj_period_entry)); 164 | memset(entry, 0, sizeof(sml_prof_obj_period_entry)); 165 | return entry; 166 | } 167 | 168 | sml_prof_obj_period_entry *sml_prof_obj_period_entry_parse(sml_buffer *buf) { 169 | sml_prof_obj_period_entry *entry = sml_prof_obj_period_entry_init(); 170 | 171 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 172 | buf->error = 1; 173 | goto error; 174 | } 175 | 176 | if (sml_buf_get_next_length(buf) != 4) { 177 | buf->error = 1; 178 | goto error; 179 | } 180 | 181 | 182 | entry->val_time = sml_time_parse(buf); 183 | if (sml_buf_has_errors(buf)) goto error; 184 | entry->status = sml_u64_parse(buf); 185 | if (sml_buf_has_errors(buf)) goto error; 186 | entry->value_list = sml_sequence_parse(buf, (void *) &sml_value_entry_parse, (void (*)()) &sml_value_entry_free); 187 | if (sml_buf_has_errors(buf)) goto error; 188 | entry->period_signature = sml_signature_parse(buf); 189 | if (sml_buf_has_errors(buf)) goto error; 190 | 191 | return entry; 192 | 193 | error: 194 | buf->error = 1; 195 | sml_prof_obj_period_entry_free(entry); 196 | return 0; 197 | } 198 | 199 | void sml_prof_obj_period_entry_write(sml_prof_obj_period_entry *entry, sml_buffer *buf) { 200 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 4); 201 | sml_time_write(entry->val_time, buf); 202 | sml_u64_write(entry->status, buf); 203 | sml_sequence_write(entry->value_list, buf, (void (*)(void *, sml_buffer *)) &sml_value_entry_write); 204 | sml_signature_write(entry->period_signature, buf); 205 | } 206 | 207 | void sml_prof_obj_period_entry_free(sml_prof_obj_period_entry *entry) { 208 | if (entry) { 209 | sml_time_free(entry->val_time); 210 | sml_number_free(entry->status); 211 | sml_sequence_free(entry->value_list); 212 | sml_signature_free(entry->period_signature); 213 | 214 | free(entry); 215 | } 216 | } 217 | 218 | 219 | // sml_value_entry; 220 | 221 | sml_value_entry *sml_value_entry_init() { 222 | sml_value_entry *entry = (sml_value_entry *) malloc(sizeof(sml_value_entry)); 223 | memset(entry, 0, sizeof(sml_value_entry)); 224 | 225 | return entry; 226 | } 227 | 228 | sml_value_entry *sml_value_entry_parse(sml_buffer *buf) { 229 | sml_value_entry *entry = sml_value_entry_init(); 230 | 231 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 232 | buf->error = 1; 233 | goto error; 234 | } 235 | 236 | if (sml_buf_get_next_length(buf) != 2) { 237 | buf->error = 1; 238 | goto error; 239 | } 240 | 241 | entry->value = sml_value_parse(buf); 242 | if (sml_buf_has_errors(buf)) goto error; 243 | entry->value_signature = sml_signature_parse(buf); 244 | if (sml_buf_has_errors(buf)) goto error; 245 | 246 | return entry; 247 | 248 | error: 249 | buf->error = 1; 250 | sml_value_entry_free(entry); 251 | return 0; 252 | } 253 | 254 | void sml_value_entry_write(sml_value_entry *entry, sml_buffer *buf) { 255 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2); 256 | sml_value_write(entry->value, buf); 257 | sml_signature_write(entry->value_signature, buf); 258 | } 259 | 260 | void sml_value_entry_free(sml_value_entry *entry) { 261 | if (entry) { 262 | sml_value_free(entry->value); 263 | sml_signature_free(entry->value_signature); 264 | 265 | free(entry); 266 | } 267 | } 268 | 269 | -------------------------------------------------------------------------------- /sml/src/sml_list.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | // sml_sequence; 29 | 30 | sml_sequence *sml_sequence_init(void (*elem_free) (void *elem)) { 31 | sml_sequence *seq = (sml_sequence *) malloc(sizeof(sml_sequence)); 32 | memset(seq, 0, sizeof(sml_sequence)); 33 | seq->elem_free = elem_free; 34 | 35 | return seq; 36 | } 37 | 38 | sml_sequence *sml_sequence_parse(sml_buffer *buf, void *(*elem_parse) (sml_buffer *buf), void (*elem_free) (void *elem)) { 39 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 40 | buf->error = 1; 41 | goto error; 42 | } 43 | 44 | sml_sequence *seq = sml_sequence_init(elem_free); 45 | int i, len = sml_buf_get_next_length(buf); 46 | void *p; 47 | for (i = 0; i < len; i++) { 48 | p = elem_parse(buf); 49 | if (sml_buf_has_errors(buf)) goto error; 50 | sml_sequence_add(seq, p); 51 | } 52 | 53 | return seq; 54 | 55 | error: 56 | buf->error = 1; 57 | sml_sequence_free(seq); 58 | return 0; 59 | } 60 | 61 | void sml_sequence_write(sml_sequence *seq, sml_buffer *buf, void (*elem_write) (void *elem, sml_buffer *buf)) { 62 | if (seq == 0) { 63 | sml_buf_optional_write(buf); 64 | return; 65 | } 66 | 67 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, seq->elems_len); 68 | 69 | int i; 70 | for (i = 0; i < seq->elems_len; i++) { 71 | elem_write((seq->elems)[i], buf); 72 | } 73 | } 74 | 75 | void sml_sequence_free(sml_sequence *seq) { 76 | if (seq) { 77 | int i; 78 | for (i = 0; i < seq->elems_len; i++) { 79 | seq->elem_free((seq->elems)[i]); 80 | } 81 | 82 | if (seq->elems != 0) { 83 | free(seq->elems); 84 | } 85 | 86 | free(seq); 87 | } 88 | } 89 | 90 | void sml_sequence_add(sml_sequence *seq, void *new_entry) { 91 | seq->elems_len++; 92 | seq->elems = (void **) realloc(seq->elems, sizeof(void *) * seq->elems_len); 93 | seq->elems[seq->elems_len - 1] = new_entry; 94 | } 95 | 96 | 97 | // sml_list; 98 | 99 | sml_list *sml_list_init(){ 100 | sml_list *s = (sml_list *)malloc(sizeof(sml_list)); 101 | memset(s, 0, sizeof(sml_list)); 102 | return s; 103 | } 104 | 105 | void sml_list_add(sml_list *list, sml_list *new_entry) { 106 | list->next = new_entry; 107 | } 108 | 109 | sml_list *sml_list_entry_parse(sml_buffer *buf) { 110 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 111 | buf->error = 1; 112 | goto error; 113 | } 114 | 115 | if (sml_buf_get_next_length(buf) != 7) { 116 | buf->error = 1; 117 | goto error; 118 | } 119 | sml_list *l = sml_list_init(); 120 | 121 | l->obj_name = sml_octet_string_parse(buf); 122 | if (sml_buf_has_errors(buf)) goto error; 123 | 124 | l->status = sml_status_parse(buf); 125 | if (sml_buf_has_errors(buf)) goto error; 126 | 127 | l->val_time = sml_time_parse(buf); 128 | if (sml_buf_has_errors(buf)) goto error; 129 | 130 | l->unit = sml_u8_parse(buf); 131 | if (sml_buf_has_errors(buf)) goto error; 132 | 133 | l->scaler = sml_i8_parse(buf); 134 | if (sml_buf_has_errors(buf)) goto error; 135 | 136 | l->value = sml_value_parse(buf); 137 | if (sml_buf_has_errors(buf)) goto error; 138 | 139 | l->value_signature = sml_octet_string_parse(buf); 140 | if (sml_buf_has_errors(buf)) goto error; 141 | 142 | return l; 143 | 144 | // This function doesn't free the allocated memory in error cases, 145 | // this is done in sml_list_parse. 146 | error: 147 | buf->error = 1; 148 | return 0; 149 | } 150 | 151 | sml_list *sml_list_parse(sml_buffer *buf) { 152 | if (sml_buf_optional_is_skipped(buf)) { 153 | return 0; 154 | } 155 | 156 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 157 | buf->error = 1; 158 | return 0; 159 | } 160 | 161 | sml_list *first = 0; 162 | sml_list *last = 0; 163 | int elems; 164 | 165 | elems = sml_buf_get_next_length(buf); 166 | 167 | if (elems > 0) { 168 | first = sml_list_entry_parse(buf); 169 | if (sml_buf_has_errors(buf)) goto error; 170 | last = first; 171 | elems--; 172 | } 173 | 174 | while(elems > 0) { 175 | last->next = sml_list_entry_parse(buf); 176 | if (sml_buf_has_errors(buf)) goto error; 177 | last = last->next; 178 | elems--; 179 | } 180 | 181 | return first; 182 | 183 | error: 184 | buf->error = 1; 185 | sml_list_free(first); 186 | return 0; 187 | } 188 | 189 | 190 | void sml_list_entry_write(sml_list *list, sml_buffer *buf) { 191 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 7); 192 | sml_octet_string_write(list->obj_name, buf); 193 | sml_status_write(list->status, buf); 194 | sml_time_write(list->val_time, buf); 195 | sml_u8_write(list->unit, buf); 196 | sml_i8_write(list->scaler, buf); 197 | sml_value_write(list->value, buf); 198 | sml_octet_string_write(list->value_signature, buf); 199 | } 200 | 201 | void sml_list_write(sml_list *list, sml_buffer *buf){ 202 | if (list == 0) { 203 | sml_buf_optional_write(buf); 204 | return; 205 | } 206 | 207 | sml_list *i = list; 208 | int len = 0; 209 | while(i) { 210 | i = i->next; 211 | len++; 212 | } 213 | 214 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, len); 215 | 216 | i = list; 217 | while(i) { 218 | sml_list_entry_write(i, buf); 219 | i = i->next; 220 | } 221 | } 222 | 223 | void sml_list_entry_free(sml_list *list) { 224 | if (list) { 225 | sml_octet_string_free(list->obj_name); 226 | sml_status_free(list->status); 227 | sml_time_free(list->val_time); 228 | sml_number_free(list->unit); 229 | sml_number_free(list->scaler); 230 | sml_value_free(list->value); 231 | sml_octet_string_free(list->value_signature); 232 | 233 | free(list); 234 | } 235 | } 236 | 237 | void sml_list_free(sml_list *list) { 238 | if (list) { 239 | sml_list *f = list; 240 | sml_list *n = list->next; 241 | 242 | while(f) { 243 | sml_list_entry_free(f); 244 | f = n; 245 | if (f) { 246 | n = f->next; 247 | } 248 | } 249 | } 250 | } 251 | 252 | -------------------------------------------------------------------------------- /sml/src/sml_number.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #define SML_BIG_ENDIAN 1 25 | #define SML_LITTLE_ENDIAN 0 26 | 27 | int sml_number_endian(); 28 | void sml_number_byte_swap(unsigned char *bytes, int bytes_len); 29 | 30 | void *sml_number_init(u64 number, unsigned char type, int size) { 31 | 32 | unsigned char* bytes = (unsigned char*)&number; 33 | 34 | // Swap bytes of big-endian number so that 35 | // memcpy copies the right part 36 | if (sml_number_endian() == SML_BIG_ENDIAN) { 37 | bytes += sizeof(u64) - size; 38 | } 39 | 40 | unsigned char *np = malloc(size); 41 | memset(np, 0, size); 42 | memcpy(np, bytes, size); 43 | return np; 44 | } 45 | 46 | void *sml_number_parse(sml_buffer *buf, unsigned char type, int max_size) { 47 | if (sml_buf_optional_is_skipped(buf)) { 48 | return 0; 49 | } 50 | 51 | int l, i; 52 | unsigned char b; 53 | short negative_int = 0; 54 | 55 | if (sml_buf_get_next_type(buf) != type) { 56 | buf->error = 1; 57 | return 0; 58 | } 59 | 60 | l = sml_buf_get_next_length(buf); 61 | if (l < 0 || l > max_size) { 62 | buf->error = 1; 63 | return 0; 64 | } 65 | 66 | unsigned char *np = malloc(max_size); 67 | memset(np, 0, max_size); 68 | 69 | b = sml_buf_get_current_byte(buf); 70 | if (type == SML_TYPE_INTEGER && (b & 128)) { 71 | negative_int = 1; 72 | } 73 | 74 | int missing_bytes = max_size - l; 75 | memcpy(&(np[missing_bytes]), sml_buf_get_current_buf(buf), l); 76 | 77 | if (negative_int) { 78 | for (i = 0; i < missing_bytes; i++) { 79 | np[i] = 0xFF; 80 | } 81 | } 82 | 83 | if (!(sml_number_endian() == SML_BIG_ENDIAN)) { 84 | sml_number_byte_swap(np, max_size); 85 | } 86 | sml_buf_update_bytes_read(buf, l); 87 | 88 | return np; 89 | } 90 | 91 | void sml_number_write(void *np, unsigned char type, int size, sml_buffer *buf) { 92 | if (np == 0) { 93 | sml_buf_optional_write(buf); 94 | return; 95 | } 96 | 97 | sml_buf_set_type_and_length(buf, type, size); 98 | memcpy(sml_buf_get_current_buf(buf), np, size); 99 | 100 | if (!(sml_number_endian() == SML_BIG_ENDIAN)) { 101 | sml_number_byte_swap(sml_buf_get_current_buf(buf), size); 102 | } 103 | 104 | sml_buf_update_bytes_read(buf, size); 105 | } 106 | 107 | void sml_number_byte_swap(unsigned char *bytes, int bytes_len) { 108 | int i; 109 | unsigned char ob[bytes_len]; 110 | memcpy(&ob, bytes, bytes_len); 111 | 112 | for (i = 0; i < bytes_len; i++) { 113 | bytes[i] = ob[bytes_len - (i + 1)]; 114 | } 115 | } 116 | 117 | int sml_number_endian() { 118 | int i = 1; 119 | char *p = (char *)&i; 120 | 121 | if (p[0] == 1) 122 | return SML_LITTLE_ENDIAN; 123 | else 124 | return SML_BIG_ENDIAN; 125 | } 126 | 127 | void sml_number_free(void *np) { 128 | if (np) { 129 | free(np); 130 | } 131 | } 132 | 133 | -------------------------------------------------------------------------------- /sml/src/sml_octet_string.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #ifndef _NO_UUID_LIB 27 | #include 28 | #else 29 | #include // for rand() 30 | #endif 31 | 32 | uint8_t ctoi(uint8_t c); 33 | uint8_t c2toi(uint8_t c1, uint8_t c2); 34 | uint8_t c2ptoi(char* c); 35 | 36 | octet_string *sml_octet_string_init(unsigned char *str, int length) { 37 | octet_string *s = (octet_string *)malloc(sizeof(octet_string)); 38 | memset(s, 0, sizeof(octet_string)); 39 | if (length > 0) { 40 | s->str = (unsigned char *)malloc(length); 41 | memcpy(s->str, str, length); 42 | s->len = length; 43 | } 44 | 45 | return s; 46 | } 47 | 48 | octet_string *sml_octet_string_init_from_hex(char *str) { 49 | int i, len = strlen(str); 50 | if (len % 2 != 0) { 51 | return 0; 52 | } 53 | unsigned char bytes[len / 2]; 54 | for (i = 0; i < (len / 2); i++) { 55 | bytes[i] = c2ptoi(&(str[i * 2])); 56 | } 57 | return sml_octet_string_init(bytes, len / 2); 58 | } 59 | 60 | void sml_octet_string_free(octet_string *str) { 61 | if (str) { 62 | if (str->str) { 63 | free(str->str); 64 | } 65 | free(str); 66 | } 67 | } 68 | 69 | octet_string *sml_octet_string_parse(sml_buffer *buf) { 70 | if (sml_buf_optional_is_skipped(buf)) { 71 | return 0; 72 | } 73 | 74 | int l; 75 | if (sml_buf_get_next_type(buf) != SML_TYPE_OCTET_STRING) { 76 | buf->error = 1; 77 | return 0; 78 | } 79 | 80 | l = sml_buf_get_next_length(buf); 81 | if (l < 0) { 82 | buf->error = 1; 83 | return 0; 84 | } 85 | 86 | octet_string *str = sml_octet_string_init(sml_buf_get_current_buf(buf), l); 87 | sml_buf_update_bytes_read(buf, l); 88 | return str; 89 | } 90 | 91 | void sml_octet_string_write(octet_string *str, sml_buffer *buf) { 92 | if (str == 0) { 93 | sml_buf_optional_write(buf); 94 | return; 95 | } 96 | 97 | sml_buf_set_type_and_length(buf, SML_TYPE_OCTET_STRING, (unsigned int) str->len); 98 | memcpy(sml_buf_get_current_buf(buf), str->str, str->len); 99 | buf->cursor += str->len; 100 | } 101 | 102 | octet_string *sml_octet_string_generate_uuid() { 103 | #ifndef _NO_UUID_LIB 104 | uuid_t uuid; 105 | uuid_generate(uuid); 106 | #else 107 | char uuid[16]; 108 | 109 | // TODO add support for WIN32 systems 110 | #ifdef __linux__ 111 | int fd = open("/dev/urandom", O_RDONLY); 112 | read(fd, uuid, 16); 113 | #else 114 | int i; 115 | for(i = 0; i < 16; i++) { 116 | uuid[i] = rand() % 0xFF; 117 | } 118 | #endif /* __linux__ */ 119 | uuid[6] = (uuid[6] & 0x0F) | 0x40; // set version 120 | uuid[8] = (uuid[8] & 0x3F) | 0x80; // set reserved bits 121 | #endif /* _NO_UUID_LIB */ 122 | return sml_octet_string_init(uuid, 16); 123 | } 124 | 125 | int sml_octet_string_cmp(octet_string *s1, octet_string *s2) { 126 | if (s1->len != s2->len) { 127 | return -1; 128 | } 129 | return memcmp(s1->str, s2->str, s1->len); 130 | } 131 | 132 | int sml_octet_string_cmp_with_hex(octet_string *str, char *hex) { 133 | octet_string *hstr = sml_octet_string_init_from_hex(hex); 134 | if (str->len != hstr->len) { 135 | sml_octet_string_free(hstr); 136 | return -1; 137 | } 138 | int result = memcmp(str->str, hstr->str, str->len); 139 | sml_octet_string_free(hstr); 140 | return result; 141 | } 142 | 143 | uint8_t ctoi(uint8_t c){ 144 | uint8_t ret = 0; 145 | 146 | if((c >= '0') && (c <= '9')) { 147 | ret = c - '0'; 148 | } 149 | else if((c >= 'a') && (c <= 'f')) { 150 | ret = c - 'a' + 10; 151 | } 152 | else if((c >= 'A') && (c <= 'F')) { 153 | ret = c - 'A' + 10; 154 | } 155 | return ret; 156 | } 157 | 158 | uint8_t c2toi(uint8_t c1, uint8_t c2) { 159 | return ctoi(c1) << 4 | ctoi(c2); 160 | } 161 | 162 | uint8_t c2ptoi(char* c) { 163 | return ctoi((uint8_t)c[0]) << 4 | ctoi((uint8_t)c[1]); 164 | } 165 | 166 | -------------------------------------------------------------------------------- /sml/src/sml_open_request.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | sml_open_request *sml_open_request_init(){ 25 | sml_open_request *open_request = (sml_open_request *) malloc(sizeof(sml_open_request)); 26 | memset(open_request, 0, sizeof(sml_open_request)); 27 | return open_request; 28 | } 29 | 30 | sml_open_request *sml_open_request_parse(sml_buffer *buf) { 31 | sml_open_request *msg = sml_open_request_init(); 32 | 33 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 34 | buf->error = 1; 35 | goto error; 36 | } 37 | 38 | if (sml_buf_get_next_length(buf) != 7) { 39 | buf->error = 1; 40 | goto error; 41 | } 42 | 43 | msg->codepage = sml_octet_string_parse(buf); 44 | if (sml_buf_has_errors(buf)) goto error; 45 | 46 | msg->client_id = sml_octet_string_parse(buf); 47 | if (sml_buf_has_errors(buf)) goto error; 48 | 49 | msg->req_file_id = sml_octet_string_parse(buf); 50 | if (sml_buf_has_errors(buf)) goto error; 51 | 52 | msg->server_id = sml_octet_string_parse(buf); 53 | if (sml_buf_has_errors(buf)) goto error; 54 | 55 | msg->username = sml_octet_string_parse(buf); 56 | if (sml_buf_has_errors(buf)) goto error; 57 | 58 | msg->password = sml_octet_string_parse(buf); 59 | if (sml_buf_has_errors(buf)) goto error; 60 | 61 | msg->sml_version = sml_u8_parse(buf); 62 | if (sml_buf_has_errors(buf)) goto error; 63 | 64 | return msg; 65 | 66 | error: 67 | sml_open_request_free(msg); 68 | return 0; 69 | } 70 | 71 | void sml_open_request_write(sml_open_request *msg, sml_buffer *buf) { 72 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 7); 73 | 74 | sml_octet_string_write(msg->codepage, buf); 75 | sml_octet_string_write(msg->client_id, buf); 76 | sml_octet_string_write(msg->req_file_id, buf); 77 | sml_octet_string_write(msg->server_id, buf); 78 | sml_octet_string_write(msg->username,buf); 79 | sml_octet_string_write(msg->password,buf); 80 | sml_u8_write(msg->sml_version, buf); 81 | } 82 | 83 | void sml_open_request_free(sml_open_request *msg) { 84 | if (msg) { 85 | sml_octet_string_free(msg->codepage); 86 | sml_octet_string_free(msg->client_id); 87 | sml_octet_string_free(msg->req_file_id); 88 | sml_octet_string_free(msg->server_id); 89 | sml_octet_string_free(msg->username); 90 | sml_octet_string_free(msg->password); 91 | sml_number_free(msg->sml_version); 92 | 93 | free(msg); 94 | } 95 | } 96 | 97 | -------------------------------------------------------------------------------- /sml/src/sml_open_response.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | 23 | sml_open_response *sml_open_response_init() { 24 | sml_open_response *msg = (sml_open_response *) malloc(sizeof(sml_open_response)); 25 | memset(msg, 0, sizeof(sml_open_response)); 26 | 27 | return msg; 28 | } 29 | 30 | sml_open_response *sml_open_response_parse(sml_buffer *buf) { 31 | sml_open_response *msg = sml_open_response_init(); 32 | 33 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 34 | buf->error = 1; 35 | goto error; 36 | } 37 | 38 | if (sml_buf_get_next_length(buf) != 6) { 39 | buf->error = 1; 40 | goto error; 41 | } 42 | 43 | msg->codepage = sml_octet_string_parse(buf); 44 | if (sml_buf_has_errors(buf)) goto error; 45 | 46 | msg->client_id = sml_octet_string_parse(buf); 47 | if (sml_buf_has_errors(buf)) goto error; 48 | 49 | msg->req_file_id = sml_octet_string_parse(buf); 50 | if (sml_buf_has_errors(buf)) goto error; 51 | 52 | msg->server_id = sml_octet_string_parse(buf); 53 | if (sml_buf_has_errors(buf)) goto error; 54 | 55 | msg->ref_time = sml_time_parse(buf); 56 | if (sml_buf_has_errors(buf)) goto error; 57 | 58 | msg->sml_version = sml_u8_parse(buf); 59 | if (sml_buf_has_errors(buf)) goto error; 60 | 61 | return msg; 62 | error: 63 | sml_open_response_free(msg); 64 | return 0; 65 | } 66 | 67 | void sml_open_response_write(sml_open_response *msg, sml_buffer *buf) { 68 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 6); 69 | 70 | sml_octet_string_write(msg->codepage, buf); 71 | sml_octet_string_write(msg->client_id, buf); 72 | sml_octet_string_write(msg->req_file_id, buf); 73 | sml_octet_string_write(msg->server_id, buf); 74 | sml_time_write(msg->ref_time, buf); 75 | sml_u8_write(msg->sml_version, buf); 76 | } 77 | 78 | void sml_open_response_free(sml_open_response *msg) { 79 | if (msg) { 80 | sml_octet_string_free(msg->codepage); 81 | sml_octet_string_free(msg->client_id); 82 | sml_octet_string_free(msg->req_file_id); 83 | sml_octet_string_free(msg->server_id); 84 | sml_time_free(msg->ref_time); 85 | sml_number_free(msg->sml_version); 86 | 87 | free(msg); 88 | } 89 | } 90 | 91 | -------------------------------------------------------------------------------- /sml/src/sml_set_proc_parameter_request.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | 22 | sml_set_proc_parameter_request *sml_set_proc_parameter_request_init() { 23 | sml_set_proc_parameter_request *msg = (sml_set_proc_parameter_request *) malloc(sizeof (sml_set_proc_parameter_request)); 24 | memset(msg, 0, sizeof(sml_set_proc_parameter_request)); 25 | 26 | return msg; 27 | } 28 | 29 | sml_set_proc_parameter_request *sml_set_proc_parameter_request_parse(sml_buffer *buf) { 30 | sml_set_proc_parameter_request *msg = sml_set_proc_parameter_request_init(); 31 | 32 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 33 | buf->error = 1; 34 | goto error; 35 | } 36 | 37 | if (sml_buf_get_next_length(buf) != 5) { 38 | buf->error = 1; 39 | goto error; 40 | } 41 | 42 | msg->server_id = sml_octet_string_parse(buf); 43 | if (sml_buf_has_errors(buf)) goto error; 44 | 45 | msg->username = sml_octet_string_parse(buf); 46 | if (sml_buf_has_errors(buf)) goto error; 47 | 48 | msg->password = sml_octet_string_parse(buf); 49 | if (sml_buf_has_errors(buf)) goto error; 50 | 51 | msg->parameter_tree_path = sml_tree_path_parse(buf); 52 | if (sml_buf_has_errors(buf)) goto error; 53 | 54 | msg->parameter_tree = sml_tree_parse(buf); 55 | if (sml_buf_has_errors(buf)) goto error; 56 | 57 | return msg; 58 | 59 | error: 60 | sml_set_proc_parameter_request_free(msg); 61 | return 0; 62 | } 63 | 64 | void sml_set_proc_parameter_request_write(sml_set_proc_parameter_request *msg, sml_buffer *buf) { 65 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5); 66 | sml_octet_string_write(msg->server_id, buf); 67 | sml_octet_string_write(msg->username, buf); 68 | sml_octet_string_write(msg->password, buf); 69 | sml_tree_path_write(msg->parameter_tree_path, buf); 70 | sml_tree_write(msg->parameter_tree, buf); 71 | } 72 | 73 | void sml_set_proc_parameter_request_free(sml_set_proc_parameter_request *msg) { 74 | if (msg) { 75 | sml_octet_string_free(msg->server_id); 76 | sml_octet_string_free(msg->username); 77 | sml_octet_string_free(msg->password); 78 | sml_tree_path_free(msg->parameter_tree_path); 79 | sml_tree_free(msg->parameter_tree); 80 | 81 | free(msg); 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /sml/src/sml_shared.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | int sml_buf_get_next_length(sml_buffer *buf) { 25 | int length = 0; 26 | unsigned char byte = sml_buf_get_current_byte(buf); 27 | int list = ((byte & SML_TYPE_FIELD) == SML_TYPE_LIST) ? 0 : -1; 28 | 29 | for (;buf->cursor < buf->buffer_len;) { 30 | byte = sml_buf_get_current_byte(buf); 31 | length <<= 4; 32 | length |= (byte & SML_LENGTH_FIELD); 33 | 34 | if ((byte & SML_ANOTHER_TL) != SML_ANOTHER_TL) { 35 | break; 36 | } 37 | sml_buf_update_bytes_read(buf, 1); 38 | if(list) { 39 | list += -1; 40 | } 41 | } 42 | sml_buf_update_bytes_read(buf, 1); 43 | 44 | return length + list; 45 | } 46 | 47 | void sml_buf_set_type_and_length(sml_buffer *buf, unsigned int type, unsigned int l) { 48 | // set the type 49 | buf->buffer[buf->cursor] = type; 50 | 51 | if (type != SML_TYPE_LIST) { 52 | l++; 53 | } 54 | 55 | if (l > SML_LENGTH_FIELD) { 56 | 57 | // how much shifts are necessary 58 | int mask_pos = (sizeof(unsigned int) * 2) - 1; 59 | 60 | // the 4 most significant bits of l (1111 0000 0000 ...) 61 | unsigned int mask = 0xF0 << (8 * (sizeof(unsigned int) - 1)); 62 | 63 | // select the next 4 most significant bits with a bit set until there 64 | // is something 65 | while (!(mask & l)) { 66 | mask >>= 4; 67 | mask_pos--; 68 | } 69 | 70 | l += mask_pos; // for every TL-field 71 | 72 | if ((0x0F << (4 * (mask_pos + 1))) & l) { 73 | // for the rare case that the addition of the number of TL-fields 74 | // result in another TL-field. 75 | mask_pos++; 76 | l++; 77 | } 78 | 79 | // copy 4 bits of the number to the buffer 80 | while (mask > SML_LENGTH_FIELD) { 81 | buf->buffer[buf->cursor] |= SML_ANOTHER_TL; 82 | buf->buffer[buf->cursor] |= ((mask & l) >> (4 * mask_pos)); 83 | mask >>= 4; 84 | mask_pos--; 85 | buf->cursor++; 86 | } 87 | } 88 | 89 | buf->buffer[buf->cursor] |= (l & SML_LENGTH_FIELD); 90 | buf->cursor++; 91 | } 92 | 93 | int sml_buf_has_errors(sml_buffer *buf) { 94 | return buf->error != 0; 95 | } 96 | 97 | int sml_buf_get_next_type(sml_buffer *buf) { 98 | return (buf->buffer[buf->cursor] & SML_TYPE_FIELD); 99 | } 100 | 101 | unsigned char sml_buf_get_current_byte(sml_buffer *buf) { 102 | return buf->buffer[buf->cursor]; 103 | } 104 | 105 | unsigned char *sml_buf_get_current_buf(sml_buffer *buf) { 106 | return &(buf->buffer[buf->cursor]); 107 | } 108 | 109 | void sml_buf_update_bytes_read(sml_buffer *buf, int bytes) { 110 | buf->cursor += bytes; 111 | } 112 | 113 | sml_buffer *sml_buffer_init(size_t length) { 114 | sml_buffer *buf = (sml_buffer *) malloc(sizeof(sml_buffer)); 115 | memset(buf, 0, sizeof(sml_buffer)); 116 | buf->buffer = (unsigned char *) malloc(length); 117 | buf->buffer_len = length; 118 | memset(buf->buffer, 0, buf->buffer_len); 119 | 120 | return buf; 121 | } 122 | 123 | void sml_buf_optional_write(sml_buffer *buf) { 124 | buf->buffer[buf->cursor] = SML_OPTIONAL_SKIPPED; 125 | buf->cursor++; 126 | } 127 | 128 | void sml_buffer_free(sml_buffer *buf) { 129 | if (buf) { 130 | if (buf->buffer) 131 | free(buf->buffer); 132 | if (buf->error_msg) 133 | free(buf->error_msg); 134 | free(buf); 135 | } 136 | } 137 | 138 | int sml_buf_optional_is_skipped(sml_buffer *buf) { 139 | if (sml_buf_get_current_byte(buf) == SML_OPTIONAL_SKIPPED) { 140 | sml_buf_update_bytes_read(buf, 1); 141 | 142 | return 1; 143 | } 144 | 145 | return 0; 146 | } 147 | 148 | void hexdump(unsigned char *buffer, size_t buffer_len) { 149 | int i; 150 | for (i = 0; i < buffer_len; i++) { 151 | printf("%02X ", (unsigned char) buffer[i]); 152 | if ((i + 1) % 8 == 0) { 153 | printf("\n"); 154 | } 155 | } 156 | printf("\n"); 157 | } 158 | 159 | -------------------------------------------------------------------------------- /sml/src/sml_status.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | 22 | sml_status *sml_status_init() { 23 | sml_status *status = (sml_status *) malloc(sizeof(sml_status)); 24 | memset(status, 0, sizeof(sml_status)); 25 | 26 | return status; 27 | } 28 | 29 | sml_status *sml_status_parse(sml_buffer *buf) { 30 | if (sml_buf_optional_is_skipped(buf)) { 31 | return 0; 32 | } 33 | 34 | int max = 1; 35 | int type = sml_buf_get_next_type(buf); 36 | unsigned char byte = sml_buf_get_current_byte(buf); 37 | 38 | sml_status *status = sml_status_init(); 39 | status->type = type; 40 | switch (type) { 41 | case SML_TYPE_UNSIGNED: 42 | // get maximal size, if not all bytes are used (example: only 6 bytes for a u64) 43 | while (max < ((byte & SML_LENGTH_FIELD) - 1)) { 44 | max <<= 1; 45 | } 46 | 47 | status->data.status8 = sml_number_parse(buf, type, max); 48 | status->type |= max; 49 | break; 50 | default: 51 | buf->error = 1; 52 | break; 53 | } 54 | if (sml_buf_has_errors(buf)) { 55 | sml_status_free(status); 56 | return 0; 57 | } 58 | 59 | return status; 60 | } 61 | 62 | void sml_status_write(sml_status *status, sml_buffer *buf) { 63 | if (status == 0) { 64 | sml_buf_optional_write(buf); 65 | return; 66 | } 67 | sml_number_write(status->data.status8, (status->type & SML_TYPE_FIELD), 68 | (status->type & SML_LENGTH_FIELD), buf); 69 | } 70 | 71 | void sml_status_free(sml_status *status) { 72 | if (status) { 73 | sml_number_free(status->data.status8); 74 | free(status); 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /sml/src/sml_time.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | sml_time *sml_time_init() { 26 | sml_time *t = (sml_time *) malloc(sizeof(sml_time)); 27 | memset(t, 0, sizeof(sml_time)); 28 | return t; 29 | } 30 | 31 | sml_time *sml_time_parse(sml_buffer *buf) { 32 | if (sml_buf_optional_is_skipped(buf)) { 33 | return 0; 34 | } 35 | 36 | sml_time *tme = sml_time_init(); 37 | 38 | if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { 39 | buf->error = 1; 40 | goto error; 41 | } 42 | 43 | if (sml_buf_get_next_length(buf) != 2) { 44 | buf->error = 1; 45 | goto error; 46 | } 47 | 48 | tme->tag = sml_u8_parse(buf); 49 | if (sml_buf_has_errors(buf)) goto error; 50 | 51 | tme->data.timestamp = sml_u32_parse(buf); 52 | if (sml_buf_has_errors(buf)) goto error; 53 | 54 | return tme; 55 | 56 | error: 57 | sml_time_free(tme); 58 | return 0; 59 | } 60 | 61 | void sml_time_write(sml_time *t, sml_buffer *buf) { 62 | if (t == 0) { 63 | sml_buf_optional_write(buf); 64 | return; 65 | } 66 | 67 | sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2); 68 | sml_u8_write(t->tag, buf); 69 | sml_u32_write(t->data.timestamp, buf); 70 | } 71 | 72 | void sml_time_free(sml_time *tme) { 73 | if (tme) { 74 | sml_number_free(tme->tag); 75 | sml_number_free(tme->data.timestamp); 76 | free(tme); 77 | } 78 | } 79 | 80 | -------------------------------------------------------------------------------- /sml/src/sml_transport.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define MC_SML_BUFFER_LEN 8096 30 | 31 | unsigned char esc_seq[] = {0x1b, 0x1b, 0x1b, 0x1b}; 32 | unsigned char start_seq[] = {0x1b, 0x1b, 0x1b, 0x1b, 0x01, 0x01, 0x01, 0x01}; 33 | unsigned char end_seq[] = {0x1b, 0x1b, 0x1b, 0x1b, 0x1a}; 34 | 35 | 36 | size_t sml_read(int fd, fd_set *set, unsigned char *buffer, size_t len) { 37 | 38 | size_t r, tr = 0; 39 | 40 | while (tr < len) { 41 | select(fd + 1, set, 0, 0, 0); 42 | if (FD_ISSET(fd, set)) { 43 | 44 | r = read(fd, &(buffer[tr]), len - tr); 45 | if (r < 0) continue; 46 | 47 | tr += r; 48 | } 49 | } 50 | return tr; 51 | } 52 | 53 | size_t sml_transport_read(int fd, unsigned char *buffer, size_t max_len) { 54 | 55 | fd_set readfds; 56 | FD_ZERO(&readfds); 57 | FD_SET(fd, &readfds); 58 | 59 | unsigned char buf[max_len]; 60 | memset(buf, 0, max_len); 61 | unsigned int len = 0; 62 | 63 | while (len < 8) { 64 | sml_read(fd, &readfds, &(buf[len]), 1); 65 | 66 | if ((buf[len] == 0x1b && len < 4) || (buf[len] == 0x01 && len >= 4)) { 67 | len++; 68 | } 69 | else { 70 | len = 0; 71 | } 72 | } 73 | 74 | // found start sequence 75 | 76 | while (len < max_len) { 77 | 78 | sml_read(fd, &readfds, &(buf[len]), 4); 79 | 80 | if (memcmp(&buf[len], esc_seq, 4) == 0) { 81 | 82 | // found esc sequence 83 | len += 4; 84 | sml_read(fd, &readfds, &(buf[len]), 4); 85 | 86 | if (buf[len] == 0x1a) { 87 | 88 | // found end sequence 89 | len += 4; 90 | memcpy(buffer, &(buf[0]), len); 91 | return len; 92 | } 93 | else { 94 | // dont read other escaped sequences yet 95 | printf("error: unrecognized sequence\n"); 96 | return 0; 97 | } 98 | } 99 | len += 4; 100 | 101 | } 102 | 103 | return 0; 104 | } 105 | 106 | void sml_transport_listen(int fd, void (*sml_transport_receiver)(unsigned char *buffer, size_t buffer_len)) { 107 | unsigned char buffer[MC_SML_BUFFER_LEN]; 108 | size_t bytes; 109 | 110 | while (1) { 111 | bytes = sml_transport_read(fd, buffer, MC_SML_BUFFER_LEN); 112 | 113 | if (bytes > 0) { 114 | sml_transport_receiver(buffer, bytes); 115 | } 116 | } 117 | } 118 | 119 | int sml_transport_write(int fd, sml_file *file) { 120 | sml_buffer *buf = file->buf; 121 | buf->cursor = 0; 122 | 123 | // add start sequence 124 | memcpy(sml_buf_get_current_buf(buf), start_seq, 8); 125 | buf->cursor += 8; 126 | 127 | // add file 128 | sml_file_write(file); 129 | 130 | // add padding bytes 131 | int padding = (buf->cursor % 4) ? (4 - buf->cursor % 4) : 0; 132 | if (padding) { 133 | // write zeroed bytes 134 | memset(sml_buf_get_current_buf(buf), 0, padding); 135 | buf->cursor += padding; 136 | } 137 | 138 | // begin end sequence 139 | memcpy(sml_buf_get_current_buf(buf), end_seq, 5); 140 | buf->cursor += 5; 141 | 142 | // add padding info 143 | buf->buffer[buf->cursor++] = (unsigned char) padding; 144 | 145 | // add crc checksum 146 | u16 crc = sml_crc16_calculate(buf->buffer, buf->cursor); 147 | buf->buffer[buf->cursor++] = (unsigned char) ((crc & 0xFF00) >> 8); 148 | buf->buffer[buf->cursor++] = (unsigned char) (crc & 0x00FF); 149 | 150 | size_t wr = write(fd, buf->buffer, buf->cursor); 151 | if (wr == buf->cursor) { 152 | return wr; 153 | } 154 | 155 | return 0; 156 | } 157 | 158 | -------------------------------------------------------------------------------- /sml/src/sml_value.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | 20 | #include 21 | #include 22 | 23 | sml_value *sml_value_parse(sml_buffer *buf) { 24 | if (sml_buf_optional_is_skipped(buf)) { 25 | return 0; 26 | } 27 | 28 | int max = 1; 29 | int type = sml_buf_get_next_type(buf); 30 | unsigned char byte = sml_buf_get_current_byte(buf); 31 | 32 | sml_value *value = sml_value_init(); 33 | value->type = type; 34 | 35 | switch (type) { 36 | case SML_TYPE_OCTET_STRING: 37 | value->data.bytes = sml_octet_string_parse(buf); 38 | break; 39 | case SML_TYPE_BOOLEAN: 40 | value->data.boolean = sml_boolean_parse(buf); 41 | break; 42 | case SML_TYPE_UNSIGNED: 43 | case SML_TYPE_INTEGER: 44 | // get maximal size, if not all bytes are used (example: only 6 bytes for a u64) 45 | while (max < ((byte & SML_LENGTH_FIELD) - 1)) { 46 | max <<= 1; 47 | } 48 | 49 | value->data.uint8 = sml_number_parse(buf, type, max); 50 | value->type |= max; 51 | break; 52 | default: 53 | buf->error = 1; 54 | break; 55 | } 56 | if (sml_buf_has_errors(buf)) { 57 | sml_value_free(value); 58 | return 0; 59 | } 60 | 61 | return value; 62 | } 63 | 64 | void sml_value_write(sml_value *value, sml_buffer *buf) { 65 | if (value == 0) { 66 | sml_buf_optional_write(buf); 67 | return; 68 | } 69 | 70 | switch (value->type & SML_TYPE_FIELD) { 71 | case SML_TYPE_OCTET_STRING: 72 | sml_octet_string_write(value->data.bytes, buf); 73 | break; 74 | case SML_TYPE_BOOLEAN: 75 | sml_boolean_write(value->data.boolean, buf); 76 | break; 77 | case SML_TYPE_UNSIGNED: 78 | case SML_TYPE_INTEGER: 79 | sml_number_write(value->data.uint8, (value->type & SML_TYPE_FIELD), 80 | (value->type & SML_LENGTH_FIELD), buf); 81 | break; 82 | } 83 | } 84 | 85 | sml_value *sml_value_init() { 86 | sml_value *value = (sml_value *) malloc(sizeof(sml_value)); 87 | memset(value, 0, sizeof(value)); 88 | 89 | return value; 90 | } 91 | 92 | void sml_value_free(sml_value *value) { 93 | if (value) { 94 | switch (value->type) { 95 | case SML_TYPE_OCTET_STRING: 96 | sml_octet_string_free(value->data.bytes); 97 | break; 98 | case SML_TYPE_BOOLEAN: 99 | sml_boolean_free(value->data.boolean); 100 | break; 101 | default: 102 | sml_number_free(value->data.int8); 103 | break; 104 | } 105 | free(value); 106 | } 107 | } 108 | 109 | double sml_value_to_double(sml_value *value) { 110 | switch (value->type) { 111 | case 0x51: return *value->data.int8; break; 112 | case 0x52: return *value->data.int16; break; 113 | case 0x54: return *value->data.int32; break; 114 | case 0x58: return *value->data.int64; break; 115 | case 0x61: return *value->data.uint8; break; 116 | case 0x62: return *value->data.uint16; break; 117 | case 0x64: return *value->data.uint32; break; 118 | case 0x68: return *value->data.uint64; break; 119 | 120 | default: 121 | printf("error: unknown type in %s\n", __FUNCTION__); 122 | return 0; 123 | } 124 | } 125 | 126 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | UNAME := $(shell uname) 2 | CFLAGS += -I../sml/include/ -Wall 3 | LIBSML = ../sml/lib/libsml.a 4 | 5 | ifeq ($(UNAME), Linux) 6 | LIBS = -luuid 7 | endif 8 | 9 | UNITY = \ 10 | unity/unity.o \ 11 | unity/unity_fixture.o 12 | 13 | OBJS = \ 14 | src/test_helper.o \ 15 | src/sml_octet_string_test.o \ 16 | src/sml_buffer_test.o \ 17 | src/sml_number_test.o \ 18 | src/sml_boolean_test.o \ 19 | src/sml_value_test.o \ 20 | src/sml_status_test.o \ 21 | src/sml_list_test.o \ 22 | src/sml_time_test.o \ 23 | src/sml_tree_test.o \ 24 | src/sml_file_test.o \ 25 | src/sml_open_request_test.o \ 26 | src/sml_get_profile_pack_request_test.o \ 27 | src/sml_message_test.o 28 | 29 | test_run: libsml test 30 | @./test 31 | 32 | test : $(UNITY) $(OBJS) $(LIBSML) 33 | $(CC) $(CFLAGS) $(LIBS) $^ test_main.c -o test 34 | 35 | .PHONY: code 36 | libsml : 37 | @$(MAKE) -C ../sml 38 | 39 | %.o : %.c 40 | $(CC) $(CFLAGS) -c $^ -o $@ 41 | 42 | .PHONY: clean 43 | clean : 44 | @rm -f unity/*.o 45 | @rm -f src/*.o 46 | @rm -f test 47 | 48 | -------------------------------------------------------------------------------- /test/src/sml_boolean_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "../unity/unity_fixture.h" 20 | #include "test_helper.h" 21 | #include 22 | 23 | TEST_GROUP(sml_boolean); 24 | 25 | sml_buffer *buf; 26 | 27 | TEST_SETUP(sml_boolean) { 28 | buf = sml_buffer_init(512); 29 | } 30 | 31 | TEST_TEAR_DOWN(sml_boolean) { 32 | sml_buffer_free(buf); 33 | } 34 | 35 | TEST(sml_boolean, init) { 36 | sml_boolean *b = sml_boolean_init(SML_BOOLEAN_TRUE); 37 | TEST_ASSERT_NOT_NULL(b); 38 | TEST_ASSERT_EQUAL(SML_BOOLEAN_TRUE, *b); 39 | } 40 | 41 | TEST(sml_boolean, parse_true) { 42 | hex2binary("420F", sml_buf_get_current_buf(buf)); 43 | sml_boolean *b = sml_boolean_parse(buf); 44 | TEST_ASSERT_NOT_NULL(b); 45 | TEST_ASSERT_EQUAL(SML_BOOLEAN_TRUE, *b); 46 | } 47 | 48 | TEST(sml_boolean, parse_false) { 49 | hex2binary("4200", sml_buf_get_current_buf(buf)); 50 | sml_boolean *b = sml_boolean_parse(buf); 51 | TEST_ASSERT_NOT_NULL(b); 52 | TEST_ASSERT_EQUAL(SML_BOOLEAN_FALSE, *b); 53 | TEST_ASSERT_EQUAL(2, buf->cursor); 54 | } 55 | 56 | TEST(sml_boolean, parse_optional) { 57 | hex2binary("01", sml_buf_get_current_buf(buf)); 58 | sml_boolean *b = sml_boolean_parse(buf); 59 | TEST_ASSERT_NULL(b); 60 | TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); 61 | } 62 | 63 | TEST(sml_boolean, write_true) { 64 | sml_boolean *b = sml_boolean_init(SML_BOOLEAN_TRUE); 65 | sml_boolean_write(b, buf); 66 | expected_buf(buf, "42FF", 2); 67 | } 68 | 69 | TEST(sml_boolean, write_false) { 70 | sml_boolean *b = sml_boolean_init(SML_BOOLEAN_FALSE); 71 | sml_boolean_write(b, buf); 72 | expected_buf(buf, "4200", 2); 73 | } 74 | 75 | TEST(sml_boolean, write_optional) { 76 | sml_boolean_write(0, buf); 77 | expected_buf(buf, "01", 1); 78 | } 79 | 80 | 81 | TEST_GROUP_RUNNER(sml_boolean) { 82 | RUN_TEST_CASE(sml_boolean, init); 83 | RUN_TEST_CASE(sml_boolean, parse_true); 84 | RUN_TEST_CASE(sml_boolean, parse_false); 85 | RUN_TEST_CASE(sml_boolean, parse_optional); 86 | RUN_TEST_CASE(sml_boolean, write_true); 87 | RUN_TEST_CASE(sml_boolean, write_false); 88 | RUN_TEST_CASE(sml_boolean, write_optional); 89 | } 90 | 91 | -------------------------------------------------------------------------------- /test/src/sml_buffer_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "../unity/unity_fixture.h" 20 | #include 21 | 22 | TEST_GROUP(sml_buffer); 23 | 24 | int buffer_len = 512; 25 | sml_buffer *buf; 26 | 27 | TEST_SETUP(sml_buffer) { 28 | buf = sml_buffer_init(buffer_len); 29 | } 30 | 31 | TEST_TEAR_DOWN(sml_buffer) { 32 | 33 | } 34 | 35 | TEST(sml_buffer, init_defaults) { 36 | 37 | TEST_ASSERT_NOT_NULL(buf); 38 | TEST_ASSERT_NOT_NULL(buf->buffer); 39 | TEST_ASSERT_EQUAL(buffer_len, buf->buffer_len); 40 | TEST_ASSERT_EQUAL(0, buf->cursor); 41 | TEST_ASSERT_EQUAL(0, buf->error); 42 | TEST_ASSERT_NULL(buf->error_msg); 43 | } 44 | 45 | TEST_GROUP_RUNNER(sml_buffer) { 46 | RUN_TEST_CASE(sml_buffer, init_defaults); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /test/src/sml_file_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "../unity/unity_fixture.h" 20 | #include "test_helper.h" 21 | #include 22 | 23 | TEST_GROUP(sml_file); 24 | 25 | sml_buffer *buf; 26 | 27 | TEST_SETUP(sml_file) { 28 | buf = sml_buffer_init(512); 29 | } 30 | 31 | TEST_TEAR_DOWN(sml_file) { 32 | sml_buffer_free(buf); 33 | } 34 | 35 | TEST(sml_file, init) { 36 | sml_file *file = sml_file_init(); 37 | TEST_ASSERT_NOT_NULL(file); 38 | TEST_ASSERT_EQUAL(0, file->messages_len); 39 | TEST_ASSERT_NULL(file->messages); 40 | TEST_ASSERT_NOT_NULL(file->buf); 41 | } 42 | 43 | 44 | TEST_GROUP_RUNNER(sml_file) { 45 | RUN_TEST_CASE(sml_file, init); 46 | } 47 | 48 | -------------------------------------------------------------------------------- /test/src/sml_get_profile_pack_request_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "../unity/unity_fixture.h" 20 | #include "test_helper.h" 21 | #include 22 | 23 | TEST_GROUP(sml_get_profile_pack_request); 24 | 25 | sml_buffer *buf; 26 | 27 | TEST_SETUP(sml_get_profile_pack_request) { 28 | buf = sml_buffer_init(512); 29 | } 30 | 31 | TEST_TEAR_DOWN(sml_get_profile_pack_request) { 32 | sml_buffer_free(buf); 33 | } 34 | 35 | TEST(sml_get_profile_pack_request, init) { 36 | sml_get_profile_pack_request *r = sml_get_profile_pack_request_init(); 37 | TEST_ASSERT_NOT_NULL(r); 38 | } 39 | 40 | TEST(sml_get_profile_pack_request, parse) { 41 | hex2binary("7901010101010101730648616C6C6F0648616C6C6F0648616C6C6F01", sml_buf_get_current_buf(buf)); 42 | sml_get_profile_pack_request *r = sml_get_profile_pack_request_parse(buf); 43 | TEST_ASSERT_NOT_NULL(r); 44 | TEST_ASSERT_NOT_NULL(r->object_list); 45 | TEST_ASSERT_NOT_NULL(r->object_list->next); 46 | TEST_ASSERT_NOT_NULL(r->object_list->next->next); 47 | TEST_ASSERT_NULL(r->object_list->next->next->next); 48 | } 49 | 50 | TEST_GROUP_RUNNER(sml_get_profile_pack_request) { 51 | RUN_TEST_CASE(sml_get_profile_pack_request, init); 52 | RUN_TEST_CASE(sml_get_profile_pack_request, parse); 53 | } 54 | 55 | -------------------------------------------------------------------------------- /test/src/sml_list_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "../unity/unity_fixture.h" 20 | #include "test_helper.h" 21 | #include 22 | 23 | TEST_GROUP(sml_list); 24 | 25 | sml_buffer *buf; 26 | 27 | TEST_SETUP(sml_list) { 28 | buf = sml_buffer_init(512); 29 | } 30 | 31 | TEST_TEAR_DOWN(sml_list) { 32 | sml_buffer_free(buf); 33 | } 34 | 35 | TEST(sml_list, init) { 36 | sml_list *l = sml_list_init(); 37 | TEST_ASSERT_NOT_NULL(l); 38 | TEST_ASSERT_NULL(l->next); 39 | } 40 | 41 | TEST(sml_list, add) { 42 | sml_list *l = sml_list_init(); 43 | sml_list *n = sml_list_init(); 44 | sml_list_add(l, n); 45 | TEST_ASSERT_NOT_NULL(l); 46 | TEST_ASSERT_NOT_NULL(l->next); 47 | TEST_ASSERT_TRUE(n == l->next); 48 | } 49 | 50 | TEST(sml_list, parse_two_entries) { 51 | hex2binary("727702610101010142000177026101010101420001", sml_buf_get_current_buf(buf)); 52 | sml_list *l = sml_list_parse(buf); 53 | 54 | TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); 55 | TEST_ASSERT_NOT_NULL(l); 56 | TEST_ASSERT_NOT_NULL(l->next); 57 | TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(l->obj_name, "61")); 58 | } 59 | 60 | TEST(sml_list, parse_optional) { 61 | hex2binary("01", sml_buf_get_current_buf(buf)); 62 | sml_list *l = sml_list_parse(buf); 63 | TEST_ASSERT_NULL(l); 64 | TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); 65 | } 66 | 67 | TEST(sml_list, write_one_entry) { 68 | sml_list *l = sml_list_init(); 69 | l->obj_name = sml_octet_string_init((unsigned char *)"Hallo", 5); 70 | l->value = sml_value_init(); 71 | l->value->type = SML_TYPE_OCTET_STRING; 72 | l->value->data.bytes = sml_octet_string_init((unsigned char *)"Hallo", 5); 73 | 74 | sml_list_write(l, buf); 75 | expected_buf(buf, "71770648616C6C6F010101010648616C6C6F01", 19); 76 | } 77 | 78 | TEST(sml_list, write_optional) { 79 | sml_list_write(0, buf); 80 | expected_buf(buf, "01", 1); 81 | } 82 | 83 | TEST_GROUP_RUNNER(sml_list) { 84 | RUN_TEST_CASE(sml_list, init); 85 | RUN_TEST_CASE(sml_list, add); 86 | RUN_TEST_CASE(sml_list, parse_two_entries); 87 | RUN_TEST_CASE(sml_list, parse_optional); 88 | RUN_TEST_CASE(sml_list, write_one_entry); 89 | RUN_TEST_CASE(sml_list, write_optional); 90 | } 91 | 92 | 93 | 94 | TEST_GROUP(sml_sequence); 95 | 96 | sml_buffer *buf; 97 | 98 | TEST_SETUP(sml_sequence) { 99 | buf = sml_buffer_init(512); 100 | } 101 | 102 | TEST_TEAR_DOWN(sml_sequence) { 103 | sml_buffer_free(buf); 104 | } 105 | 106 | TEST(sml_sequence, init) { 107 | sml_sequence *seq = sml_sequence_init(&free); 108 | TEST_ASSERT_NOT_NULL(seq); 109 | } 110 | 111 | TEST(sml_sequence, parse_octet_string) { 112 | hex2binary("720648616C6C6F0648616C6C6F", sml_buf_get_current_buf(buf)); 113 | 114 | sml_sequence *seq = sml_sequence_parse(buf, (void *) &sml_octet_string_parse, (void (*)(void *))&sml_octet_string_free); 115 | TEST_ASSERT_NOT_NULL(seq); 116 | TEST_ASSERT_EQUAL(2, seq->elems_len); 117 | } 118 | 119 | TEST(sml_sequence, write_octet_string) { 120 | sml_sequence *seq = sml_sequence_init((void (*)(void *))&sml_octet_string_free); 121 | sml_sequence_add(seq, sml_octet_string_init((unsigned char *)"Hallo", 5)); 122 | sml_sequence_add(seq, sml_octet_string_init((unsigned char *)"Hallo", 5)); 123 | 124 | sml_sequence_write(seq, buf, (void (*)(void *, sml_buffer *))&sml_octet_string_write); 125 | expected_buf(buf, "720648616C6C6F0648616C6C6F", 13); 126 | } 127 | 128 | TEST(sml_sequence, free_octet_string) { 129 | sml_sequence *seq = sml_sequence_init((void (*)(void *))&sml_octet_string_free); 130 | sml_sequence_add(seq, sml_octet_string_init((unsigned char *)"Hallo", 5)); 131 | sml_sequence_free(seq); 132 | } 133 | 134 | TEST_GROUP_RUNNER(sml_sequence) { 135 | RUN_TEST_CASE(sml_sequence, init); 136 | RUN_TEST_CASE(sml_sequence, parse_octet_string); 137 | RUN_TEST_CASE(sml_sequence, write_octet_string); 138 | RUN_TEST_CASE(sml_sequence, free_octet_string); 139 | } 140 | 141 | -------------------------------------------------------------------------------- /test/src/sml_message_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "../unity/unity_fixture.h" 20 | #include "test_helper.h" 21 | #include 22 | 23 | TEST_GROUP(sml_message); 24 | 25 | sml_buffer *buf; 26 | 27 | TEST_SETUP(sml_message) { 28 | buf = sml_buffer_init(512); 29 | } 30 | 31 | TEST_TEAR_DOWN(sml_message) { 32 | sml_buffer_free(buf); 33 | } 34 | 35 | TEST(sml_message, init) { 36 | sml_message *msg = sml_message_init(); 37 | TEST_ASSERT_NOT_NULL(msg); 38 | TEST_ASSERT_NOT_NULL(msg->transaction_id); 39 | } 40 | 41 | TEST(sml_message, init_unique_transaction_id) { 42 | sml_message *msg1 = sml_message_init(); 43 | sml_message *msg2 = sml_message_init(); 44 | TEST_ASSERT_TRUE(sml_octet_string_cmp(msg1->transaction_id, msg2->transaction_id) != 0); 45 | } 46 | 47 | TEST(sml_message, parse) { 48 | hex2binary("7607003800003FB662006200726301017601010700380042153D0B06454D48010271533BCD010163820800", sml_buf_get_current_buf(buf)); 49 | sml_message *msg = sml_message_parse(buf); 50 | TEST_ASSERT_NOT_NULL(msg); 51 | } 52 | 53 | TEST_GROUP_RUNNER(sml_message) { 54 | RUN_TEST_CASE(sml_message, init); 55 | RUN_TEST_CASE(sml_message, init_unique_transaction_id); 56 | RUN_TEST_CASE(sml_message, parse); 57 | } 58 | 59 | -------------------------------------------------------------------------------- /test/src/sml_number_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "../unity/unity_fixture.h" 20 | #include "../unity/unity.h" 21 | #include "test_helper.h" 22 | #include 23 | 24 | TEST_GROUP(sml_number); 25 | 26 | sml_buffer *buf; 27 | 28 | TEST_SETUP(sml_number) { 29 | buf = sml_buffer_init(512); 30 | } 31 | 32 | TEST_TEAR_DOWN(sml_number) { 33 | sml_buffer_free(buf); 34 | } 35 | 36 | TEST(sml_number, init_unsigned8) { 37 | u8 *n = sml_u8_init(1); 38 | TEST_ASSERT_NOT_NULL(n); 39 | TEST_ASSERT_EQUAL(1, *n); 40 | } 41 | 42 | TEST(sml_number, init_integer16) { 43 | i16 *n = sml_i16_init(-1); 44 | TEST_ASSERT_NOT_NULL(n); 45 | TEST_ASSERT_EQUAL(-1, *n); 46 | } 47 | 48 | TEST(sml_number, parse_unsigned8) { 49 | hex2binary("6201", sml_buf_get_current_buf(buf)); 50 | u8 *n = sml_u8_parse(buf); 51 | TEST_ASSERT_EQUAL(1, *n); 52 | TEST_ASSERT_EQUAL(2, buf->cursor); 53 | } 54 | 55 | TEST(sml_number, parse_unsigned16) { 56 | hex2binary("630101", sml_buf_get_current_buf(buf)); 57 | u16 *n = sml_u16_parse(buf); 58 | TEST_ASSERT_EQUAL(257, *n); 59 | } 60 | 61 | TEST(sml_number, parse_unsigned32) { 62 | hex2binary("6500000001", sml_buf_get_current_buf(buf)); 63 | u32 *n = sml_u32_parse(buf); 64 | TEST_ASSERT_EQUAL(1, *n); 65 | } 66 | 67 | TEST(sml_number, parse_unsigned32_fewer_bytes) { 68 | hex2binary("64010001", sml_buf_get_current_buf(buf)); 69 | u32 *n = sml_u32_parse(buf); 70 | TEST_ASSERT_EQUAL(65537, *n); 71 | } 72 | 73 | TEST(sml_number, parse_unsigned32_optional) { 74 | hex2binary("01", sml_buf_get_current_buf(buf)); 75 | u32 *n = sml_u32_parse(buf); 76 | TEST_ASSERT_NULL(n); 77 | TEST_ASSERT_EQUAL(1, buf->cursor); 78 | } 79 | 80 | TEST(sml_number, parse_unsigned64) { 81 | hex2binary("690000000000000001", sml_buf_get_current_buf(buf)); 82 | u64 *n = sml_u64_parse(buf); 83 | TEST_ASSERT_EQUAL(1, *n); 84 | } 85 | 86 | TEST(sml_number, parse_unsigned64_fewer_bytes) { 87 | hex2binary("67000000000001", sml_buf_get_current_buf(buf)); 88 | u64 *n = sml_u64_parse(buf); 89 | TEST_ASSERT_EQUAL(1, *n); 90 | } 91 | 92 | TEST(sml_number, parse_int8) { 93 | hex2binary("52FF", sml_buf_get_current_buf(buf)); 94 | i8 *n = sml_i8_parse(buf); 95 | TEST_ASSERT_EQUAL(-1, *n); 96 | } 97 | 98 | TEST(sml_number, parse_int16) { 99 | hex2binary("53EC78", sml_buf_get_current_buf(buf)); 100 | i16 *n = sml_i16_parse(buf); 101 | TEST_ASSERT_EQUAL(-5000, *n); 102 | } 103 | 104 | TEST(sml_number, parse_int32) { 105 | hex2binary("55FFFFEC78", sml_buf_get_current_buf(buf)); 106 | i32 *n = sml_i32_parse(buf); 107 | TEST_ASSERT_EQUAL(-5000, *n); 108 | } 109 | 110 | TEST(sml_number, parse_int64) { 111 | hex2binary("59FFFFFFFFFFFFFFFF", sml_buf_get_current_buf(buf)); 112 | i64 *n = sml_i64_parse(buf); 113 | TEST_ASSERT_EQUAL(-1, *n); 114 | } 115 | 116 | TEST(sml_number, parse_int64_fewer_bytes) { 117 | hex2binary("58FFFFFFFFFFEC78", sml_buf_get_current_buf(buf)); 118 | i64 *n = sml_i64_parse(buf); 119 | TEST_ASSERT_EQUAL(-5000, *n); 120 | } 121 | 122 | TEST(sml_number, write_unsigned8) { 123 | u8 *n = sml_u8_init(1); 124 | sml_u8_write(n, buf); 125 | expected_buf(buf, "6201", 2); 126 | } 127 | 128 | TEST(sml_number, write_integer32) { 129 | i32 *n = sml_i32_init(-5000); 130 | sml_i32_write(n, buf); 131 | expected_buf(buf, "55FFFFEC78", 5); 132 | } 133 | 134 | TEST(sml_number, write_integer8_optional) { 135 | sml_i8_write(0, buf); 136 | expected_buf(buf, "01", 1); 137 | } 138 | 139 | TEST_GROUP_RUNNER(sml_number) { 140 | RUN_TEST_CASE(sml_number, init_unsigned8); 141 | RUN_TEST_CASE(sml_number, init_integer16); 142 | 143 | RUN_TEST_CASE(sml_number, parse_unsigned8); 144 | RUN_TEST_CASE(sml_number, parse_unsigned16); 145 | RUN_TEST_CASE(sml_number, parse_unsigned32); 146 | RUN_TEST_CASE(sml_number, parse_unsigned64); 147 | RUN_TEST_CASE(sml_number, parse_unsigned32_fewer_bytes); 148 | RUN_TEST_CASE(sml_number, parse_unsigned64_fewer_bytes); 149 | RUN_TEST_CASE(sml_number, parse_unsigned32_optional); 150 | RUN_TEST_CASE(sml_number, parse_int8); 151 | RUN_TEST_CASE(sml_number, parse_int16); 152 | RUN_TEST_CASE(sml_number, parse_int32); 153 | RUN_TEST_CASE(sml_number, parse_int64); 154 | RUN_TEST_CASE(sml_number, parse_int64_fewer_bytes); 155 | 156 | RUN_TEST_CASE(sml_number, write_unsigned8); 157 | RUN_TEST_CASE(sml_number, write_integer32); 158 | RUN_TEST_CASE(sml_number, write_integer8_optional); 159 | } 160 | 161 | -------------------------------------------------------------------------------- /test/src/sml_octet_string_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "../unity/unity_fixture.h" 20 | #include "test_helper.h" 21 | #include 22 | 23 | TEST_GROUP(sml_octet_string); 24 | 25 | sml_buffer *buf; 26 | 27 | TEST_SETUP(sml_octet_string) { 28 | buf = sml_buffer_init(512); 29 | } 30 | 31 | TEST_TEAR_DOWN(sml_octet_string) { 32 | sml_buffer_free(buf); 33 | } 34 | 35 | TEST(sml_octet_string, init) { 36 | octet_string *str = sml_octet_string_init((unsigned char *)"hallo", 5); 37 | TEST_ASSERT_EQUAL(5, str->len); 38 | TEST_ASSERT_EQUAL_MEMORY("hallo", str->str, 5); 39 | } 40 | 41 | TEST(sml_octet_string, parse) { 42 | hex2binary("0648616C6C6F", sml_buf_get_current_buf(buf)); 43 | 44 | octet_string *str = sml_octet_string_parse(buf); 45 | expected_octet_string(str, "Hallo", 5); 46 | } 47 | 48 | TEST(sml_octet_string, parse_multiple_tl_fields) { 49 | hex2binary("8102616161616F6161616161616161616161", sml_buf_get_current_buf(buf)); 50 | 51 | octet_string *str = sml_octet_string_parse(buf); 52 | expected_octet_string(str, "aaaaoaaaaaaaaaaa", 16); 53 | } 54 | 55 | TEST(sml_octet_string, parse_optional) { 56 | hex2binary("01", sml_buf_get_current_buf(buf)); 57 | octet_string *str = sml_octet_string_parse(buf); 58 | 59 | TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); 60 | TEST_ASSERT_NULL(str); 61 | TEST_ASSERT_EQUAL(1, buf->cursor); 62 | } 63 | 64 | TEST(sml_octet_string, write) { 65 | octet_string *str = sml_octet_string_init((unsigned char *)"Hallo", 5); 66 | sml_octet_string_write(str, buf); 67 | expected_buf(buf, "0648616C6C6F", 6); 68 | } 69 | 70 | TEST(sml_octet_string, write_multiple_tl_fields) { 71 | octet_string *str = sml_octet_string_init((unsigned char *)"aaaaoaaaaaaaaaaa", 16); 72 | sml_octet_string_write(str, buf); 73 | expected_buf(buf, "8102616161616F6161616161616161616161", 18); 74 | } 75 | 76 | TEST(sml_octet_string, write_optional) { 77 | sml_octet_string_write(0, buf); 78 | expected_buf(buf, "01", 1); 79 | } 80 | 81 | TEST(sml_octet_string, cmp) { 82 | octet_string *s1 = sml_octet_string_init((unsigned char *)"Hallo", 5); 83 | octet_string *s2 = sml_octet_string_init((unsigned char *)"Hi", 2); 84 | octet_string *s3 = sml_octet_string_init((unsigned char *)"Hallo", 5); 85 | 86 | TEST_ASSERT_TRUE(sml_octet_string_cmp(s1, s2) != 0); 87 | TEST_ASSERT_EQUAL(0, sml_octet_string_cmp(s1, s3)); 88 | } 89 | 90 | TEST(sml_octet_string, cmp_with_hex) { 91 | octet_string *s = sml_octet_string_init((unsigned char *)"Hallo", 5); 92 | TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(s, "48616C6C6F")); 93 | } 94 | 95 | TEST_GROUP_RUNNER(sml_octet_string) { 96 | RUN_TEST_CASE(sml_octet_string, init); 97 | RUN_TEST_CASE(sml_octet_string, parse); 98 | RUN_TEST_CASE(sml_octet_string, parse_multiple_tl_fields); 99 | RUN_TEST_CASE(sml_octet_string, parse_optional); 100 | RUN_TEST_CASE(sml_octet_string, write); 101 | RUN_TEST_CASE(sml_octet_string, write_multiple_tl_fields); 102 | RUN_TEST_CASE(sml_octet_string, write_optional); 103 | RUN_TEST_CASE(sml_octet_string, cmp); 104 | RUN_TEST_CASE(sml_octet_string, cmp_with_hex); 105 | } 106 | 107 | -------------------------------------------------------------------------------- /test/src/sml_open_request_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "../unity/unity_fixture.h" 20 | #include "test_helper.h" 21 | #include 22 | 23 | TEST_GROUP(sml_open_request); 24 | 25 | sml_buffer *buf; 26 | 27 | TEST_SETUP(sml_open_request) { 28 | buf = sml_buffer_init(512); 29 | } 30 | 31 | TEST_TEAR_DOWN(sml_open_request) { 32 | sml_buffer_free(buf); 33 | } 34 | 35 | TEST(sml_open_request, init) { 36 | sml_open_request *m = sml_open_request_init(); 37 | TEST_ASSERT_NOT_NULL(m); 38 | } 39 | 40 | TEST_GROUP_RUNNER(sml_open_request) { 41 | RUN_TEST_CASE(sml_open_request, init); 42 | } 43 | 44 | -------------------------------------------------------------------------------- /test/src/sml_status_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "../unity/unity_fixture.h" 20 | #include "test_helper.h" 21 | #include 22 | 23 | TEST_GROUP(sml_status); 24 | 25 | sml_buffer *buf; 26 | 27 | TEST_SETUP(sml_status) { 28 | buf = sml_buffer_init(512); 29 | } 30 | 31 | TEST_TEAR_DOWN(sml_status) { 32 | sml_buffer_free(buf); 33 | } 34 | 35 | TEST(sml_status, init) { 36 | sml_status *s = sml_status_init(); 37 | TEST_ASSERT_NOT_NULL(s); 38 | } 39 | 40 | TEST(sml_status, parse_status8) { 41 | hex2binary("6201", sml_buf_get_current_buf(buf)); 42 | sml_status *s = sml_status_parse(buf); 43 | 44 | TEST_ASSERT_NOT_NULL(s); 45 | TEST_ASSERT_EQUAL(1, *(s->data.status8)); 46 | TEST_ASSERT_EQUAL((SML_TYPE_UNSIGNED | SML_TYPE_NUMBER_8), s->type); 47 | } 48 | 49 | TEST(sml_status, parse_optional) { 50 | hex2binary("01", sml_buf_get_current_buf(buf)); 51 | sml_status *s = sml_status_parse(buf); 52 | 53 | TEST_ASSERT_NULL(s); 54 | TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); 55 | TEST_ASSERT_EQUAL(1, buf->cursor); 56 | } 57 | 58 | TEST(sml_status, parse_not_unsigned) { 59 | hex2binary("5001", sml_buf_get_current_buf(buf)); 60 | sml_status *s = sml_status_parse(buf); 61 | 62 | TEST_ASSERT_NULL(s); 63 | TEST_ASSERT_TRUE(sml_buf_has_errors(buf)); 64 | } 65 | 66 | TEST(sml_status, write_status32) { 67 | sml_status *s = sml_status_init(); 68 | s->type = SML_TYPE_UNSIGNED | SML_TYPE_NUMBER_32; 69 | s->data.status32 = sml_u32_init(42); 70 | 71 | sml_status_write(s, buf); 72 | expected_buf(buf, "650000002A", 5); 73 | } 74 | 75 | TEST(sml_status, write_optional) { 76 | sml_status_write(0, buf); 77 | expected_buf(buf, "01", 1); 78 | } 79 | 80 | 81 | TEST_GROUP_RUNNER(sml_status) { 82 | RUN_TEST_CASE(sml_status, init); 83 | RUN_TEST_CASE(sml_status, parse_status8); 84 | RUN_TEST_CASE(sml_status, parse_optional); 85 | RUN_TEST_CASE(sml_status, parse_not_unsigned); 86 | RUN_TEST_CASE(sml_status, write_status32); 87 | RUN_TEST_CASE(sml_status, write_optional); 88 | } 89 | 90 | -------------------------------------------------------------------------------- /test/src/sml_time_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "../unity/unity_fixture.h" 20 | #include "test_helper.h" 21 | #include 22 | 23 | TEST_GROUP(sml_time); 24 | 25 | sml_buffer *buf; 26 | 27 | TEST_SETUP(sml_time) { 28 | buf = sml_buffer_init(512); 29 | } 30 | 31 | TEST_TEAR_DOWN(sml_time) { 32 | sml_buffer_free(buf); 33 | } 34 | 35 | TEST(sml_time, init) { 36 | sml_time *t = sml_time_init(); 37 | TEST_ASSERT_NOT_NULL(t); 38 | } 39 | 40 | TEST(sml_time, parse_sec_index) { 41 | hex2binary("72620165000000FF", sml_buf_get_current_buf(buf)); 42 | sml_time *t = sml_time_parse(buf); 43 | 44 | TEST_ASSERT_NOT_NULL(t); 45 | TEST_ASSERT_EQUAL(SML_TIME_SEC_INDEX, *(t->tag)); 46 | TEST_ASSERT_EQUAL(8, buf->cursor); 47 | } 48 | 49 | TEST(sml_time, parse_timestamp) { 50 | hex2binary("72620265000000FF", sml_buf_get_current_buf(buf)); 51 | sml_time *t = sml_time_parse(buf); 52 | 53 | TEST_ASSERT_NOT_NULL(t); 54 | TEST_ASSERT_EQUAL(SML_TIME_TIMESTAMP, *(t->tag)); 55 | TEST_ASSERT_EQUAL(8, buf->cursor); 56 | } 57 | 58 | TEST(sml_time, parse_optional) { 59 | hex2binary("01", sml_buf_get_current_buf(buf)); 60 | sml_time *t = sml_time_parse(buf); 61 | 62 | TEST_ASSERT_NULL(t); 63 | TEST_ASSERT_EQUAL(1, buf->cursor); 64 | } 65 | 66 | TEST(sml_time, write_sec_index) { 67 | sml_time *t = sml_time_init(); 68 | t->data.sec_index = sml_u32_init(255); 69 | t->tag = sml_u8_init(SML_TIME_SEC_INDEX); 70 | 71 | sml_time_write(t, buf); 72 | expected_buf(buf, "72620165000000FF", 8); 73 | } 74 | 75 | TEST(sml_time, write_optional) { 76 | sml_time_write(0, buf); 77 | expected_buf(buf, "01", 1); 78 | } 79 | 80 | TEST_GROUP_RUNNER(sml_time) { 81 | RUN_TEST_CASE(sml_time, init); 82 | RUN_TEST_CASE(sml_time, parse_sec_index); 83 | RUN_TEST_CASE(sml_time, parse_timestamp); 84 | RUN_TEST_CASE(sml_time, parse_optional); 85 | RUN_TEST_CASE(sml_time, write_sec_index); 86 | RUN_TEST_CASE(sml_time, write_optional); 87 | } 88 | 89 | -------------------------------------------------------------------------------- /test/src/sml_tree_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "../unity/unity_fixture.h" 20 | #include "test_helper.h" 21 | #include 22 | #include 23 | 24 | TEST_GROUP(sml_tree); 25 | 26 | sml_buffer *buf; 27 | 28 | TEST_SETUP(sml_tree) { 29 | buf = sml_buffer_init(512); 30 | } 31 | 32 | TEST_TEAR_DOWN(sml_tree) { 33 | sml_buffer_free(buf); 34 | } 35 | 36 | TEST(sml_tree, init) { 37 | sml_tree *t = sml_tree_init(); 38 | TEST_ASSERT_NOT_NULL(t); 39 | } 40 | 41 | TEST(sml_tree, add_tree) { 42 | sml_tree *t = sml_tree_init(); 43 | sml_tree_add_tree(t, sml_tree_init()); 44 | 45 | TEST_ASSERT_NOT_NULL(t->child_list[0]); 46 | TEST_ASSERT_EQUAL(1, t->child_list_len); 47 | } 48 | 49 | TEST(sml_tree, write) { 50 | sml_tree *t = sml_tree_init(); 51 | t->parameter_name = sml_octet_string_init((unsigned char *)"Hallo", 5); 52 | sml_tree_write(t, buf); 53 | expected_buf(buf, "730648616C6C6F0101", 9); 54 | } 55 | 56 | TEST(sml_tree, parse_with_child) { 57 | hex2binary("730648616C6C6F0171730648616C6C6F0101", sml_buf_get_current_buf(buf)); 58 | sml_tree *t = sml_tree_parse(buf); 59 | 60 | TEST_ASSERT_NOT_NULL(t); 61 | TEST_ASSERT_NOT_NULL(t->child_list[0]); 62 | TEST_ASSERT_EQUAL(1, t->child_list_len); 63 | } 64 | 65 | TEST(sml_tree, parse_with_error_child) { 66 | hex2binary("730648616C6C6F0171720648616C6C6F0101", sml_buf_get_current_buf(buf)); 67 | sml_tree *t = sml_tree_parse(buf); 68 | 69 | TEST_ASSERT_NULL(t); 70 | } 71 | 72 | TEST_GROUP_RUNNER(sml_tree) { 73 | RUN_TEST_CASE(sml_tree, init); 74 | RUN_TEST_CASE(sml_tree, add_tree); 75 | RUN_TEST_CASE(sml_tree, write); 76 | RUN_TEST_CASE(sml_tree, parse_with_child); 77 | RUN_TEST_CASE(sml_tree, parse_with_error_child); 78 | } 79 | 80 | 81 | 82 | TEST_GROUP(sml_tree_path); 83 | 84 | TEST_SETUP(sml_tree_path) { 85 | buf = sml_buffer_init(512); 86 | } 87 | 88 | TEST_TEAR_DOWN(sml_tree_path) { 89 | sml_buffer_free(buf); 90 | } 91 | 92 | TEST(sml_tree_path, init) { 93 | sml_tree_path *t = sml_tree_path_init(); 94 | TEST_ASSERT_NOT_NULL(t); 95 | } 96 | 97 | TEST(sml_tree_path, add_entry) { 98 | sml_tree_path *t = sml_tree_path_init(); 99 | TEST_ASSERT_NOT_NULL(t); 100 | TEST_ASSERT_EQUAL(0, t->path_entries_len); 101 | sml_tree_path_add_path_entry(t, sml_octet_string_init((unsigned char *)"tree", 4)); 102 | TEST_ASSERT_EQUAL(1, t->path_entries_len); 103 | } 104 | 105 | TEST(sml_tree_path, parse) { 106 | hex2binary("720648616C6C6F0264", sml_buf_get_current_buf(buf)); 107 | sml_tree_path *t = sml_tree_path_parse(buf); 108 | TEST_ASSERT_NOT_NULL(t); 109 | TEST_ASSERT_EQUAL(2, t->path_entries_len); 110 | TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(t->path_entries[0], "48616C6C6F")); 111 | TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(t->path_entries[1], "64")); 112 | } 113 | 114 | TEST(sml_tree_path, write) { 115 | sml_tree_path *t = sml_tree_path_init(); 116 | sml_tree_path_add_path_entry(t, sml_octet_string_init((unsigned char *)"Hallo", 5)); 117 | sml_tree_path_add_path_entry(t, sml_octet_string_init((unsigned char *)"Hallo", 5)); 118 | sml_tree_path_write(t, buf); 119 | expected_buf(buf, "720648616C6C6F0648616C6C6F", 13); 120 | } 121 | 122 | TEST_GROUP_RUNNER(sml_tree_path) { 123 | RUN_TEST_CASE(sml_tree_path, init); 124 | RUN_TEST_CASE(sml_tree_path, add_entry); 125 | RUN_TEST_CASE(sml_tree_path, parse); 126 | RUN_TEST_CASE(sml_tree_path, write); 127 | } 128 | 129 | 130 | 131 | TEST_GROUP(sml_proc_par_value); 132 | 133 | TEST_SETUP(sml_proc_par_value) { 134 | buf = sml_buffer_init(512); 135 | } 136 | 137 | TEST_TEAR_DOWN(sml_proc_par_value) { 138 | sml_buffer_free(buf); 139 | } 140 | 141 | TEST(sml_proc_par_value, init) { 142 | sml_proc_par_value *t = sml_proc_par_value_init(); 143 | TEST_ASSERT_NOT_NULL(t); 144 | } 145 | 146 | TEST(sml_proc_par_value, parse_time) { 147 | hex2binary("72620472620265000000FF", sml_buf_get_current_buf(buf)); 148 | sml_proc_par_value *t = sml_proc_par_value_parse(buf); 149 | TEST_ASSERT_NOT_NULL(t); 150 | TEST_ASSERT_EQUAL(SML_PROC_PAR_VALUE_TAG_TIME, *(t->tag)); 151 | TEST_ASSERT_EQUAL(11, buf->cursor); 152 | } 153 | 154 | TEST(sml_proc_par_value, write_time) { 155 | sml_proc_par_value *ppv = sml_proc_par_value_init(); 156 | ppv->tag = sml_u8_init(SML_PROC_PAR_VALUE_TAG_TIME); 157 | sml_time *t = sml_time_init(); 158 | t->data.sec_index = sml_u32_init(255); 159 | t->tag = sml_u8_init(SML_TIME_SEC_INDEX); 160 | ppv->data.time = t; 161 | sml_proc_par_value_write(ppv, buf); 162 | expected_buf(buf, "72620472620165000000FF", 11); 163 | } 164 | 165 | TEST_GROUP_RUNNER(sml_proc_par_value) { 166 | RUN_TEST_CASE(sml_proc_par_value, init); 167 | RUN_TEST_CASE(sml_proc_par_value, parse_time); 168 | RUN_TEST_CASE(sml_proc_par_value, write_time); 169 | } 170 | 171 | -------------------------------------------------------------------------------- /test/src/sml_value_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "../unity/unity_fixture.h" 20 | #include "test_helper.h" 21 | #include 22 | 23 | TEST_GROUP(sml_value); 24 | 25 | sml_buffer *buf; 26 | 27 | TEST_SETUP(sml_value) { 28 | buf = sml_buffer_init(512); 29 | } 30 | 31 | TEST_TEAR_DOWN(sml_value) { 32 | sml_buffer_free(buf); 33 | } 34 | 35 | TEST(sml_value, init) { 36 | sml_value *v = sml_value_init(); 37 | TEST_ASSERT_NOT_NULL(v); 38 | } 39 | 40 | TEST(sml_value, parse_octet_string) { 41 | hex2binary("0648616C6C6F", sml_buf_get_current_buf(buf)); 42 | sml_value *v = sml_value_parse(buf); 43 | 44 | TEST_ASSERT_NOT_NULL(v); 45 | TEST_ASSERT_EQUAL(SML_TYPE_OCTET_STRING, v->type); 46 | expected_octet_string(v->data.bytes, "Hallo", 5); 47 | } 48 | 49 | TEST(sml_value, parse_boolean) { 50 | hex2binary("4200", sml_buf_get_current_buf(buf)); 51 | sml_value *v = sml_value_parse(buf); 52 | 53 | TEST_ASSERT_NOT_NULL(v); 54 | TEST_ASSERT_EQUAL(SML_TYPE_BOOLEAN, v->type); 55 | TEST_ASSERT_FALSE(*(v->data.boolean)); 56 | } 57 | 58 | TEST(sml_value, parse_unsigned32) { 59 | hex2binary("6500000001", sml_buf_get_current_buf(buf)); 60 | sml_value *v = sml_value_parse(buf); 61 | 62 | TEST_ASSERT_NOT_NULL(v); 63 | TEST_ASSERT_EQUAL(1, *(v->data.uint32)); 64 | TEST_ASSERT_EQUAL((SML_TYPE_UNSIGNED | SML_TYPE_NUMBER_32), v->type); 65 | TEST_ASSERT_EQUAL(5, buf->cursor); 66 | 67 | } 68 | 69 | TEST(sml_value, parse_integer64_fewer_bytes) { 70 | hex2binary("58FFFFFFFFFFFF0F", sml_buf_get_current_buf(buf)); 71 | sml_value *v = sml_value_parse(buf); 72 | 73 | TEST_ASSERT_EQUAL(-241, *(v->data.int64)); 74 | TEST_ASSERT_EQUAL((SML_TYPE_INTEGER | SML_TYPE_NUMBER_64), v->type); 75 | } 76 | 77 | TEST(sml_value, parse_optional) { 78 | hex2binary("01", sml_buf_get_current_buf(buf)); 79 | sml_value *v = sml_value_parse(buf); 80 | 81 | TEST_ASSERT_NULL(v); 82 | TEST_ASSERT_EQUAL(1, buf->cursor); 83 | } 84 | 85 | TEST(sml_value, write_octet_string) { 86 | sml_value *v = sml_value_init(); 87 | v->type = SML_TYPE_OCTET_STRING; 88 | v->data.bytes = sml_octet_string_init((unsigned char *)"Hallo", 5); 89 | 90 | sml_value_write(v, buf); 91 | expected_buf(buf, "0648616C6C6F", 6); 92 | } 93 | 94 | TEST(sml_value, write_boolean) { 95 | sml_value *v = sml_value_init(); 96 | v->type = SML_TYPE_BOOLEAN; 97 | v->data.boolean = sml_boolean_init(SML_BOOLEAN_FALSE); 98 | 99 | sml_value_write(v, buf); 100 | expected_buf(buf, "4200", 2); 101 | } 102 | 103 | TEST(sml_value, write_unsigned32) { 104 | sml_value *v = sml_value_init(); 105 | v->type = SML_TYPE_UNSIGNED | SML_TYPE_NUMBER_32; 106 | v->data.uint32 = sml_u32_init(42); 107 | 108 | sml_value_write(v, buf); 109 | expected_buf(buf, "650000002A", 5); 110 | } 111 | 112 | TEST(sml_value, write_integer16) { 113 | sml_value *v = sml_value_init(); 114 | v->type = SML_TYPE_INTEGER | SML_TYPE_NUMBER_16; 115 | v->data.int16 = sml_i16_init(-5); 116 | 117 | sml_value_write(v, buf); 118 | expected_buf(buf, "53FFFB", 3); 119 | } 120 | 121 | TEST(sml_value, write_optional) { 122 | sml_value_write(0, buf); 123 | expected_buf(buf, "01", 1); 124 | } 125 | 126 | TEST_GROUP_RUNNER(sml_value) { 127 | RUN_TEST_CASE(sml_value, init); 128 | RUN_TEST_CASE(sml_value, parse_octet_string); 129 | RUN_TEST_CASE(sml_value, parse_boolean); 130 | RUN_TEST_CASE(sml_value, parse_unsigned32); 131 | RUN_TEST_CASE(sml_value, parse_integer64_fewer_bytes); 132 | RUN_TEST_CASE(sml_value, parse_optional); 133 | RUN_TEST_CASE(sml_value, write_octet_string); 134 | RUN_TEST_CASE(sml_value, write_boolean); 135 | RUN_TEST_CASE(sml_value, write_unsigned32); 136 | RUN_TEST_CASE(sml_value, write_integer16); 137 | RUN_TEST_CASE(sml_value, write_optional); 138 | } 139 | 140 | -------------------------------------------------------------------------------- /test/src/test_helper.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "test_helper.h" 20 | #include "../unity/unity_fixture.h" 21 | #include 22 | #include 23 | 24 | uint8_t test_helper_ctoi(uint8_t c){ 25 | uint8_t ret = 0; 26 | 27 | if((c >= '0') && (c <= '9')){ 28 | ret = c - '0'; 29 | } else if((c >= 'a') && (c <= 'f')){ 30 | ret = c - 'a' + 10; 31 | } else if((c >= 'A') && (c <= 'F')){ 32 | ret = c - 'A' + 10; 33 | } 34 | 35 | return ret; 36 | } 37 | 38 | inline uint8_t test_helper_c2toi(uint8_t c1, uint8_t c2){ 39 | return test_helper_ctoi(c1) << 4 | test_helper_ctoi(c2); 40 | } 41 | 42 | inline uint8_t test_helper_c2ptoi(char* c){ 43 | return test_helper_ctoi((uint8_t)c[0]) << 4 | test_helper_ctoi((uint8_t)c[1]); 44 | } 45 | 46 | int hex2binary(char *hex, unsigned char *buf) { 47 | int i; 48 | int len = strlen(hex); 49 | for (i = 0; i < (len /2); i++) { 50 | buf[i] = test_helper_c2ptoi(&(hex[i * 2])); 51 | } 52 | return i; 53 | } 54 | 55 | void expected_buf(sml_buffer *buf, char *hex, int len) { 56 | unsigned char expected_buf[len]; 57 | hex2binary(hex, expected_buf); 58 | TEST_ASSERT_EQUAL_MEMORY(expected_buf, buf->buffer, len); 59 | TEST_ASSERT_EQUAL(len, buf->cursor); 60 | } 61 | 62 | void expected_octet_string(octet_string *str, char *content, int len) { 63 | TEST_ASSERT_NOT_NULL(str); 64 | TEST_ASSERT_EQUAL(len, str->len); 65 | TEST_ASSERT_EQUAL_MEMORY(content, str->str, len); 66 | } 67 | 68 | -------------------------------------------------------------------------------- /test/src/test_helper.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #ifndef TEST_HELPER_H_ 20 | #define TEST_HELPER_H_ 21 | 22 | #include 23 | #include 24 | 25 | int hex2binary(char *hex, unsigned char *buf); 26 | void expected_buf(sml_buffer *buf, char *hex, int len); 27 | void expected_octet_string(octet_string *str, char *content, int len); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /test/test_main.c: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed 2 | // DAI-Labor, TU-Berlin 3 | // 4 | // This file is part of libSML. 5 | // 6 | // libSML is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // libSML is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with libSML. If not, see . 18 | 19 | #include "unity/unity_fixture.h" 20 | 21 | static void runAllTests() { 22 | RUN_TEST_GROUP(sml_octet_string); 23 | RUN_TEST_GROUP(sml_buffer); 24 | RUN_TEST_GROUP(sml_number); 25 | RUN_TEST_GROUP(sml_boolean); 26 | RUN_TEST_GROUP(sml_value); 27 | RUN_TEST_GROUP(sml_status); 28 | RUN_TEST_GROUP(sml_list); 29 | RUN_TEST_GROUP(sml_sequence); 30 | RUN_TEST_GROUP(sml_time); 31 | RUN_TEST_GROUP(sml_tree); 32 | RUN_TEST_GROUP(sml_tree_path); 33 | RUN_TEST_GROUP(sml_proc_par_value); 34 | RUN_TEST_GROUP(sml_open_request); 35 | RUN_TEST_GROUP(sml_get_profile_pack_request); 36 | RUN_TEST_GROUP(sml_message); 37 | RUN_TEST_GROUP(sml_file); 38 | } 39 | 40 | int main(int argc, char * argv[]) { 41 | return UnityMain(argc, argv, runAllTests); 42 | } -------------------------------------------------------------------------------- /test/unity/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007-2010 Mike Karlesky, Mark VanderVoord, Greg Williams 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | The end-user documentation included with the redistribution, if 16 | any, must include the following acknowledgment: "This product 17 | includes software developed for the Unity Project, by Mike Karlesky, 18 | Mark VanderVoord, and Greg Williams and other contributors", in 19 | the same place and form as other third-party acknowledgments. 20 | Alternately, this acknowledgment may appear in the software 21 | itself, in the same form and location as other such third-party 22 | acknowledgments. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 26 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 28 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 29 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 30 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 31 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /test/unity/unity_fixture.c: -------------------------------------------------------------------------------- 1 | //- Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | /* ========================================== 3 | Unity Project - A Test Framework for C 4 | Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | [Released under MIT License. Please refer to license.txt for details] 6 | ========================================== */ 7 | 8 | #include "unity_fixture.h" 9 | #include "unity_internals.h" 10 | #include 11 | 12 | UNITY_FIXTURE_T UnityFixture; 13 | 14 | //If you decide to use the function pointer approach. 15 | int (*outputChar)(int) = putchar; 16 | 17 | int verbose = 0; 18 | 19 | void setUp(void) { /*does nothing*/ } 20 | void tearDown(void) { /*does nothing*/ } 21 | 22 | void announceTestRun(int runNumber) 23 | { 24 | UnityPrint("Unity test run "); 25 | UnityPrintNumber(runNumber+1); 26 | UnityPrint(" of "); 27 | UnityPrintNumber(UnityFixture.RepeatCount); 28 | UNITY_OUTPUT_CHAR('\n'); 29 | } 30 | 31 | int UnityMain(int argc, char* argv[], void (*runAllTests)()) 32 | { 33 | int result = UnityGetCommandLineOptions(argc, argv); 34 | int r; 35 | if (result != 0) 36 | return result; 37 | 38 | for (r = 0; r < UnityFixture.RepeatCount; r++) 39 | { 40 | announceTestRun(r); 41 | UnityBegin(); 42 | runAllTests(); 43 | UNITY_OUTPUT_CHAR('\n'); 44 | UnityEnd(); 45 | } 46 | 47 | return UnityFailureCount(); 48 | } 49 | 50 | static int selected(const char * filter, const char * name) 51 | { 52 | if (filter == 0) 53 | return 1; 54 | return strstr(name, filter) ? 1 : 0; 55 | } 56 | 57 | static int testSelected(const char* test) 58 | { 59 | return selected(UnityFixture.NameFilter, test); 60 | } 61 | 62 | static int groupSelected(const char* group) 63 | { 64 | return selected(UnityFixture.GroupFilter, group); 65 | } 66 | 67 | static void runTestCase() 68 | { 69 | 70 | } 71 | 72 | void UnityTestRunner(unityfunction* setup, 73 | unityfunction* testBody, 74 | unityfunction* teardown, 75 | const char * printableName, 76 | const char * group, 77 | const char * name, 78 | const char * file, int line) 79 | { 80 | if (testSelected(name) && groupSelected(group)) 81 | { 82 | Unity.CurrentTestFailed = 0; 83 | Unity.TestFile = file; 84 | Unity.CurrentTestName = printableName; 85 | Unity.CurrentTestLineNumber = line; 86 | if (!UnityFixture.Verbose) 87 | UNITY_OUTPUT_CHAR('.'); 88 | else 89 | UnityPrint(printableName); 90 | 91 | Unity.NumberOfTests++; 92 | UnityMalloc_StartTest(); 93 | UnityPointer_Init(); 94 | 95 | runTestCase(); 96 | if (TEST_PROTECT()) 97 | { 98 | setup(); 99 | testBody(); 100 | } 101 | if (TEST_PROTECT()) 102 | { 103 | teardown(); 104 | } 105 | if (TEST_PROTECT()) 106 | { 107 | UnityPointer_UndoAllSets(); 108 | if (!Unity.CurrentTestFailed) 109 | UnityMalloc_EndTest(); 110 | UnityConcludeFixtureTest(); 111 | } 112 | else 113 | { 114 | //aborting - jwg - di i need these for the other TEST_PROTECTS? 115 | } 116 | } 117 | } 118 | 119 | 120 | //------------------------------------------------- 121 | //Malloc and free stuff 122 | // 123 | #define MALLOC_DONT_FAIL -1 124 | static int malloc_count; 125 | static int malloc_fail_countdown = MALLOC_DONT_FAIL; 126 | 127 | void UnityMalloc_StartTest() 128 | { 129 | malloc_count = 0; 130 | malloc_fail_countdown = MALLOC_DONT_FAIL; 131 | } 132 | 133 | void UnityMalloc_EndTest() 134 | { 135 | malloc_fail_countdown = MALLOC_DONT_FAIL; 136 | if (malloc_count != 0) 137 | { 138 | TEST_FAIL_MESSAGE("This test leaks!"); 139 | } 140 | } 141 | 142 | void UnityMalloc_MakeMallocFailAfterCount(int countdown) 143 | { 144 | malloc_fail_countdown = countdown; 145 | } 146 | 147 | #ifdef malloc 148 | #undef malloc 149 | #endif 150 | 151 | #ifdef free 152 | #undef free 153 | #endif 154 | 155 | #include 156 | #include 157 | 158 | typedef struct GuardBytes 159 | { 160 | int size; 161 | char guard[sizeof(int)]; 162 | } Guard; 163 | 164 | 165 | static const char * end = "END"; 166 | 167 | void * unity_malloc(size_t size) 168 | { 169 | char* mem; 170 | Guard* guard; 171 | 172 | if (malloc_fail_countdown != MALLOC_DONT_FAIL) 173 | { 174 | if (malloc_fail_countdown == 0) 175 | return 0; 176 | malloc_fail_countdown--; 177 | } 178 | 179 | malloc_count++; 180 | 181 | guard = (Guard*)malloc(size + sizeof(Guard) + 4); 182 | guard->size = size; 183 | mem = (char*)&(guard[1]); 184 | memcpy(&mem[size], end, strlen(end) + 1); 185 | 186 | return (void*)mem; 187 | } 188 | 189 | static int isOverrun(void * mem) 190 | { 191 | Guard* guard = (Guard*)mem; 192 | char* memAsChar = (char*)mem; 193 | guard--; 194 | 195 | return strcmp(&memAsChar[guard->size], end) != 0; 196 | } 197 | 198 | static void release_memory(void * mem) 199 | { 200 | Guard* guard = (Guard*)mem; 201 | guard--; 202 | 203 | malloc_count--; 204 | free(guard); 205 | } 206 | 207 | void unity_free(void * mem) 208 | { 209 | int overrun = isOverrun(mem);//strcmp(&memAsChar[guard->size], end) != 0; 210 | release_memory(mem); 211 | if (overrun) 212 | { 213 | TEST_FAIL_MESSAGE("Buffer overrun detected during free()"); 214 | } 215 | } 216 | 217 | void* unity_calloc(size_t num, size_t size) 218 | { 219 | void* mem = unity_malloc(num * size); 220 | memset(mem, 0, num*size); 221 | return mem; 222 | } 223 | 224 | void* unity_realloc(void * oldMem, size_t size) 225 | { 226 | Guard* guard = (Guard*)oldMem; 227 | // char* memAsChar = (char*)oldMem; 228 | void* newMem; 229 | 230 | if (oldMem == 0) 231 | return unity_malloc(size); 232 | 233 | guard--; 234 | if (isOverrun(oldMem)) 235 | { 236 | release_memory(oldMem); 237 | TEST_FAIL_MESSAGE("Buffer overrun detected during realloc()"); 238 | } 239 | 240 | if (size == 0) 241 | { 242 | release_memory(oldMem); 243 | return 0; 244 | } 245 | 246 | if (guard->size >= size) 247 | return oldMem; 248 | 249 | newMem = unity_malloc(size); 250 | memcpy(newMem, oldMem, size); 251 | unity_free(oldMem); 252 | return newMem; 253 | } 254 | 255 | 256 | //-------------------------------------------------------- 257 | //Automatic pointer restoration functions 258 | typedef struct _PointerPair 259 | { 260 | struct _PointerPair * next; 261 | void ** pointer; 262 | void * old_value; 263 | } PointerPair; 264 | 265 | enum {MAX_POINTERS=50}; 266 | static PointerPair pointer_store[MAX_POINTERS]; 267 | static int pointer_index = 0; 268 | 269 | void UnityPointer_Init() 270 | { 271 | pointer_index = 0; 272 | } 273 | 274 | void UnityPointer_Set(void ** pointer, void * newValue) 275 | { 276 | if (pointer_index >= MAX_POINTERS) 277 | TEST_FAIL_MESSAGE("Too many pointers set"); 278 | 279 | pointer_store[pointer_index].pointer = pointer; 280 | pointer_store[pointer_index].old_value = *pointer; 281 | *pointer = newValue; 282 | pointer_index++; 283 | } 284 | 285 | void UnityPointer_UndoAllSets() 286 | { 287 | while (pointer_index > 0) 288 | { 289 | pointer_index--; 290 | *(pointer_store[pointer_index].pointer) = 291 | pointer_store[pointer_index].old_value; 292 | 293 | } 294 | } 295 | 296 | int UnityFailureCount() 297 | { 298 | return Unity.TestFailures; 299 | } 300 | 301 | int UnityGetCommandLineOptions(int argc, char* argv[]) 302 | { 303 | int i; 304 | UnityFixture.Verbose = 0; 305 | UnityFixture.GroupFilter = 0; 306 | UnityFixture.NameFilter = 0; 307 | UnityFixture.RepeatCount = 1; 308 | 309 | if (argc == 1) 310 | return 0; 311 | 312 | for (i = 1; i < argc; ) 313 | { 314 | if (strcmp(argv[i], "-v") == 0) 315 | { 316 | UnityFixture.Verbose = 1; 317 | i++; 318 | } 319 | else if (strcmp(argv[i], "-g") == 0) 320 | { 321 | i++; 322 | if (i >= argc) 323 | return 1; 324 | UnityFixture.GroupFilter = argv[i]; 325 | i++; 326 | } 327 | else if (strcmp(argv[i], "-n") == 0) 328 | { 329 | i++; 330 | if (i >= argc) 331 | return 1; 332 | UnityFixture.NameFilter = argv[i]; 333 | i++; 334 | } 335 | else if (strcmp(argv[i], "-r") == 0) 336 | { 337 | UnityFixture.RepeatCount = 2; 338 | i++; 339 | if (i < argc) 340 | { 341 | if (*(argv[i]) >= '0' && *(argv[i]) <= '9') 342 | { 343 | UnityFixture.RepeatCount = atoi(argv[i]); 344 | i++; 345 | } 346 | } 347 | } 348 | } 349 | return 0; 350 | } 351 | 352 | void UnityConcludeFixtureTest() 353 | { 354 | if (Unity.CurrentTestIgnored) 355 | { 356 | Unity.TestIgnores++; 357 | } 358 | else if (!Unity.CurrentTestFailed) 359 | { 360 | if (UnityFixture.Verbose) 361 | { 362 | UnityPrint(" PASS"); 363 | UNITY_OUTPUT_CHAR('\n'); 364 | } 365 | } 366 | else if (Unity.CurrentTestFailed) 367 | { 368 | Unity.TestFailures++; 369 | } 370 | 371 | Unity.CurrentTestFailed = 0; 372 | Unity.CurrentTestIgnored = 0; 373 | } 374 | -------------------------------------------------------------------------------- /test/unity/unity_fixture.h: -------------------------------------------------------------------------------- 1 | //- Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | /* ========================================== 3 | Unity Project - A Test Framework for C 4 | Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | [Released under MIT License. Please refer to license.txt for details] 6 | ========================================== */ 7 | 8 | #ifndef UNITY_FIXTURE_H_ 9 | #define UNITY_FIXTURE_H_ 10 | 11 | #include "unity.h" 12 | #include "unity_internals.h" 13 | #include "unity_fixture_malloc_overrides.h" 14 | #include "unity_fixture_internals.h" 15 | 16 | int UnityMain(int argc, char* argv[], void (*runAllTests)()); 17 | 18 | 19 | #define TEST_GROUP(group)\ 20 | int TEST_GROUP_##group = 0 21 | 22 | #define TEST_SETUP(group) void TEST_##group##_SETUP() 23 | 24 | #define TEST_TEAR_DOWN(group) void TEST_##group##_TEAR_DOWN() 25 | 26 | 27 | #define TEST(group, name) \ 28 | void TEST_##group##_##name##_testBody();\ 29 | void TEST_##group##_##name##_run()\ 30 | {\ 31 | UnityTestRunner(TEST_##group##_SETUP,\ 32 | TEST_##group##_##name##_testBody,\ 33 | TEST_##group##_TEAR_DOWN,\ 34 | "TEST(" #group ", " #name ")",\ 35 | #group, #name,\ 36 | __FILE__, __LINE__);\ 37 | }\ 38 | void TEST_##group##_##name##_testBody() 39 | 40 | #define IGNORE_TEST(group, name) \ 41 | void TEST_##group##_##name##_testBody();\ 42 | void TEST_##group##_##name##_run()\ 43 | {\ 44 | }\ 45 | void TEST_##group##_##name##_testBody() 46 | 47 | #define DECLARE_TEST_CASE(group, name) \ 48 | void TEST_##group##_##name##_run() 49 | 50 | #define RUN_TEST_CASE(group, name) \ 51 | DECLARE_TEST_CASE(group, name);\ 52 | TEST_##group##_##name##_run(); 53 | 54 | //This goes at the bottom of each test file or in a separate c file 55 | #define TEST_GROUP_RUNNER(group)\ 56 | void TEST_##group##_GROUP_RUNNER_runAll();\ 57 | void TEST_##group##_GROUP_RUNNER()\ 58 | {\ 59 | TEST_##group##_GROUP_RUNNER_runAll();\ 60 | }\ 61 | void TEST_##group##_GROUP_RUNNER_runAll() 62 | 63 | //Call this from main 64 | #define RUN_TEST_GROUP(group)\ 65 | void TEST_##group##_GROUP_RUNNER();\ 66 | TEST_##group##_GROUP_RUNNER(); 67 | 68 | //CppUTest Compatibility Macros 69 | #define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&ptr, (void*)newPointerValue) 70 | #define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR(expected, actual) 71 | #define TEST_ASSERT_BYTES_EQUAL(expected, actual) TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual)) 72 | #define FAIL(message) TEST_FAIL((message)) 73 | #define CHECK(condition) TEST_ASSERT_TRUE((condition)) 74 | #define LONGS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_INT((expected), (actual)) 75 | #define STRCMP_EQUAL(expected, actual) TEST_ASSERT_EQUAL_STRING((expected), (actual)) 76 | #define DOUBLES_EQUAL(expected, actual, delta) TEST_ASSERT_FLOAT_WITHIN(((expected), (actual), (delta)) 77 | 78 | void UnityMalloc_MakeMallocFailAfterCount(int count); 79 | 80 | #endif /* UNITY_FIXTURE_H_ */ 81 | -------------------------------------------------------------------------------- /test/unity/unity_fixture_internals.h: -------------------------------------------------------------------------------- 1 | //- Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | /* ========================================== 3 | Unity Project - A Test Framework for C 4 | Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | [Released under MIT License. Please refer to license.txt for details] 6 | ========================================== */ 7 | 8 | #ifndef UNITY_FIXTURE_INTERNALS_H_ 9 | #define UNITY_FIXTURE_INTERNALS_H_ 10 | 11 | typedef struct _UNITY_FIXTURE_T 12 | { 13 | int Verbose; 14 | unsigned int RepeatCount; 15 | const char* NameFilter; 16 | const char* GroupFilter; 17 | } UNITY_FIXTURE_T; 18 | 19 | typedef void unityfunction(); 20 | void UnityTestRunner(unityfunction * setup, 21 | unityfunction * body, 22 | unityfunction * teardown, 23 | const char * printableName, 24 | const char * group, 25 | const char * name, 26 | const char * file, int line); 27 | 28 | void UnityMalloc_StartTest(); 29 | void UnityMalloc_EndTest(); 30 | int UnityFailureCount(); 31 | int UnityGetCommandLineOptions(int argc, char* argv[]); 32 | void UnityConcludeFixtureTest(); 33 | 34 | void UnityPointer_Set(void ** ptr, void * newValue); 35 | void UnityPointer_UndoAllSets(); 36 | void UnityPointer_Init(); 37 | 38 | void UnityAssertEqualPointer(const void * expected, 39 | const void * actual, 40 | const char* msg, 41 | const UNITY_LINE_TYPE lineNumber); 42 | 43 | #endif /* UNITY_FIXTURE_INTERNALS_H_ */ 44 | -------------------------------------------------------------------------------- /test/unity/unity_fixture_malloc_overrides.h: -------------------------------------------------------------------------------- 1 | //- Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 | /* ========================================== 3 | Unity Project - A Test Framework for C 4 | Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 | [Released under MIT License. Please refer to license.txt for details] 6 | ========================================== */ 7 | 8 | #ifndef UNITY_FIXTURE_MALLOC_OVERRIDES_H_ 9 | #define UNITY_FIXTURE_MALLOC_OVERRIDES_H_ 10 | 11 | #define malloc unity_malloc 12 | #define calloc unity_calloc 13 | #define realloc unity_realloc 14 | #define free unity_free 15 | 16 | #endif /* UNITY_FIXTURE_MALLOC_OVERRIDES_H_ */ 17 | --------------------------------------------------------------------------------