├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── CONTROLLER_SETUP.md ├── CTRL_FILE_RULES.md ├── Dockerfile ├── LICENSE ├── Makefile.am ├── QUICK_START_GUIDE.md ├── README.md ├── RELEASES.md ├── configure.ac ├── ctrl_coap_example.txt ├── ctrl_mqtt_example.txt ├── ctrl_stomp_example.txt ├── factory_reset_example.txt ├── mqtt_factory_reset_example.txt ├── src ├── core │ ├── bdc_exec.c │ ├── bdc_exec.h │ ├── cli.h │ ├── cli_client.c │ ├── cli_server.c │ ├── coap_client.c │ ├── coap_common.c │ ├── coap_server.c │ ├── common_defs.h │ ├── data_model.c │ ├── data_model.h │ ├── database.c │ ├── database.h │ ├── device.h │ ├── device_bulkdata.c │ ├── device_controller.c │ ├── device_ctrust.c │ ├── device_local_agent.c │ ├── device_mqtt.c │ ├── device_mtp.c │ ├── device_request.c │ ├── device_security.c │ ├── device_selftest_example.c │ ├── device_stomp.c │ ├── device_subscription.c │ ├── device_time.c │ ├── dllist.c │ ├── dllist.h │ ├── dm_access.c │ ├── dm_access.h │ ├── dm_exec.c │ ├── dm_exec.h │ ├── dm_inst_vector.c │ ├── dm_inst_vector.h │ ├── dm_trans.c │ ├── dm_trans.h │ ├── error_resp.c │ ├── expr_vector.c │ ├── expr_vector.h │ ├── group_get_vector.c │ ├── group_get_vector.h │ ├── group_set_vector.c │ ├── group_set_vector.h │ ├── handle_add.c │ ├── handle_delete.c │ ├── handle_get.c │ ├── handle_get_instances.c │ ├── handle_get_supported_dm.c │ ├── handle_get_supported_protocol.c │ ├── handle_notify.c │ ├── handle_operate.c │ ├── handle_set.c │ ├── int_vector.c │ ├── int_vector.h │ ├── iso8601.c │ ├── iso8601.h │ ├── kv_vector.c │ ├── kv_vector.h │ ├── main.c │ ├── mqtt.c │ ├── mqtt.h │ ├── msg_handler.c │ ├── msg_handler.h │ ├── mtp_exec.c │ ├── mtp_exec.h │ ├── nu_ipaddr.c │ ├── nu_ipaddr.h │ ├── nu_macaddr.c │ ├── nu_macaddr.h │ ├── os_utils.c │ ├── os_utils.h │ ├── path_resolver.c │ ├── path_resolver.h │ ├── proto_trace.c │ ├── proto_trace.h │ ├── retry_wait.c │ ├── retry_wait.h │ ├── rfc1123.c │ ├── rfc1123.h │ ├── socket_set.c │ ├── socket_set.h │ ├── stomp.c │ ├── stomp.h │ ├── str_vector.c │ ├── str_vector.h │ ├── subs_retry.c │ ├── subs_retry.h │ ├── subs_vector.c │ ├── subs_vector.h │ ├── sync_timer.c │ ├── sync_timer.h │ ├── text_utils.c │ ├── text_utils.h │ ├── uptime.c │ ├── uptime.h │ ├── uri.c │ ├── uri.h │ ├── usp_api.c │ ├── usp_coap.h │ ├── usp_err.c │ ├── usp_err.h │ ├── usp_log.c │ ├── usp_log.h │ ├── usp_mem.c │ ├── usp_mem.h │ ├── usp_register.c │ ├── version.h │ ├── wsclient.c │ └── wsclient.h ├── include │ ├── compiler.h │ ├── usp_api.h │ ├── usp_err_codes.h │ └── vendor_api.h ├── libjson │ ├── ccan │ │ └── json │ │ │ ├── LICENSE │ │ │ ├── _info │ │ │ ├── json.c │ │ │ ├── json.h │ │ │ └── test │ │ │ ├── common.h │ │ │ ├── run-construction.c │ │ │ ├── run-decode-encode.c │ │ │ ├── run-stringify.c │ │ │ ├── run-validate.c │ │ │ ├── test-strings │ │ │ └── test-strings-reencoded │ ├── licenses │ │ └── BSD-MIT │ └── pedigree.txt ├── protobuf-c │ ├── LICENSE │ ├── pedigree.txt │ ├── protobuf-c.c │ ├── protobuf-c.h │ ├── usp-msg.pb-c.c │ ├── usp-msg.pb-c.h │ ├── usp-record.pb-c.c │ └── usp-record.pb-c.h └── vendor │ ├── ctrl_file_parser.c │ ├── vendor.am │ ├── vendor.c │ ├── vendor_defs.h │ └── vendor_factory_reset_example.c └── tests └── mqtt ├── README.md ├── mosquitto.conf ├── mosquitto_password.txt ├── shared.sh ├── test_dynamic_adding_clients.sh ├── test_keep_alive.sh ├── test_password.sh ├── test_retry.sh ├── test_set_parameters.sh ├── test_ssl.sh ├── test_start_stop.sh └── test_subscriptions.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # autoconf artifacts 2 | Makefile 3 | Makefile.in 4 | */aclocal.m4 5 | autom4te.cache/* 6 | compile 7 | config.guess 8 | config.sub 9 | config.log 10 | config.status 11 | libtool 12 | obuspa 13 | configure 14 | depcomp 15 | include/config.h.in~ 16 | install-sh 17 | ltmain.sh 18 | m4/ 19 | missing 20 | ylwrap 21 | *.Po 22 | *.o 23 | *.m4 24 | .dirstamp 25 | *.swp 26 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # OBUSPA Test Controller 2 | 3 | ## 2022-04-04: Received USP messages now logged 4 | 5 | ### Fixed 6 | - Received USP messages now logged 7 | 8 | 9 | ## 2022-02-07: Added MQTT Support 10 | 11 | ### Added 12 | - MQTT support 13 | 14 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to OB-USP-Agent Test Controller 2 | 3 | **First:** if you're unsure or afraid of _anything_, just ask or submit the issue anyways. You won't be yelled at for giving your best effort. The worst that can happen is that you'll be politely asked to change something. We appreciate any sort of contributions, and don't want a wall of rules to get in the way of that. 4 | 5 | ## Getting Started 6 | ### Some Ways to Contribute 7 | * Report potential bugs. 8 | * Improve our guides and documentation. OB-USP-Agent Test Controller's [QUICK_START_GUIDE](https://github.com/BroadbandForum/obuspa-test-controller/blob/master/QUICK_START_GUIDE.md) is deployed from this repo. 9 | * Respond to questions about usage on the issue tracker or mailing list. 10 | 11 | ### Reporting an Issue: 12 | >Note: Issues on GitHub for OB-USP-Agent Test Controller are intended to be related to bugs and integration questions. 13 | 14 | * Make sure you test against the latest released version. It is possible we already fixed the bug you're experiencing. However, if you are on an older version of OB-USP-Agent Test Controller and feel the issue is critical, do let us know. 15 | 16 | * Check existing issues (both open and closed) to make sure it has not been reported previously. 17 | 18 | * Provide a reproducible test case. If a contributor can't reproduce an issue, then it dramatically lowers the chances it'll get fixed. 19 | 20 | * Aim to respond promptly to any questions made by the OB-USP-Agent Test Controller team on your issue. Stale issues will be closed. 21 | 22 | ## Building OB-USP-Agent Test Controller 23 | 24 | For build instructions, please refer to [QUICK_START_GUIDE](https://github.com/BroadbandForum/obuspa-test-controller/blob/master/QUICK_START_GUIDE.md). 25 | 26 | ## Contributor License Agreement 27 | 28 | Any company or individual interested in participating in the OB-USP-Agent open source project (which includes both the OB-USP-Agent and the OB-USP-Agent test controller) must sign a Contributor License Agreement (more details [here](https://github.com/BroadbandForum/obuspa/wiki/Contributor-License-Agreement-Details)). 29 | 30 | -------------------------------------------------------------------------------- /CTRL_FILE_RULES.md: -------------------------------------------------------------------------------- 1 | # File Message Syntax and Usage 2 | 3 | Examples are given in those files: 4 | - ctrl_stomp_example.txt 5 | - ctrl_coap_example.txt 6 | - ctrl_mqtt_example.txt 7 | 8 | ## General syntax 9 | - The file parser ignores lines when starting with the hash mark (#). 10 | - The file parser also ignores empty lines (e.g. starting with LF or CR control character). 11 | - Each message must fit on a single line. 12 | 13 | ## The first line 14 | The first line declares the USP and MTP parameters used for messages to be sent, so it MUST have the parameters correctly declared. 15 | 16 | ### USP Message ID 17 | The first line MUST have the `msg_id:""` parameter. This value will be used for the first message being sent. Sequential numbers (incremented by 1) will be used for subsequent messages in the same file. 18 | 19 | ### Endpoint ID of the destination 20 | The first line MUST have the `to_id:""` parameter. This value will be used for all messages being sent. That identifier is the `Device.LocalAgent.EndpointID` value of the Agent-to-be-communicated-with. 21 | 22 | ### MTP parameters 23 | The first line MUST also include the parameters for one of the MTP to be used: 24 | 25 | If STOMP, then include: 26 | - `stomp_agent_dest:""` 27 | - `stomp_instance:""` 28 | 29 | If CoAP, then include: 30 | - `coap_host:""` 31 | - `coap_port:""` 32 | - `coap_resource:""` 33 | 34 | If MQTT, then include: 35 | - `mqtt_topic:""` 36 | - `mqtt_instance:""` 37 | 38 | You can use the `obuspa -c show database` command (on this test controller and on the Agent-to-be-communicated-with) to determine the MTP parameter values that need to be included in the first line. 39 | 40 | ## The other lines 41 | The Controller uses a waiting time specified by the hardcoded `WAIT_BETWEEN_MSGS` variable declared in the `src/vendor/ctrl_file_parser.c` file. That waiting time is in seconds and is applied: 42 | - before sending the first message, 43 | - between all sending, and 44 | - after sending the last message. 45 | 46 | The Controller process will end after last message in a file is sent. 47 | 48 | ### Controller messages 49 | Parameters with default values can be omitted. 50 | 51 | Supported parameters, per msg_type, are: 52 | 53 | - `Get`: 54 | - `param_paths` (required, may be repeated) 55 | - `GetSupportedDM`: 56 | - `obj_paths` (required, may be repeated), 57 | - `first_level_only` (default=false), 58 | - `return_commands` (default=false), 59 | - `return_events` (default=false), 60 | - `return_params` (default=false) 61 | - `GetInstances`: 62 | - `obj_paths` (required, may be repeated), 63 | - `first_level_only` (default=false) 64 | - `Set`: 65 | - `allow_partial` (default=false), 66 | - `update_objs` (required, may be repeated, expressed as `obj_path` with one or more param and value parameter pairs, each pair enclosed in "{}"), 67 | - `required` (default=false) 68 | - `Add`: 69 | - `allow_partial` (default=false), 70 | - `create_objs` (required, may be repeated, expressed as `obj_path` with one or more param and value parameter pairs, each pair enclosed in "{}"), 71 | - `required` (default=false) 72 | - `Delete`: 73 | - `obj_paths` (required, may be repeated) 74 | - `Operate`: 75 | - `command` (required), 76 | - `command_key` (required), 77 | - `send_resp` (default=false), 78 | - with zero or more param and value parameter pairs, each pair enclosed in "{}" 79 | - `GetSupportedProtocol`: 80 | - `controller_supported_protocol_versions` (required) 81 | 82 | ## Unsupported feature 83 | - There is no output of received USP messages. 84 | - There is no support for NotifyResp message. 85 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | 3 | ENV MAKE_JOBS=8 4 | ENV OBUSPA_ARGS="-v4" 5 | 6 | # Add mosquitto latest ppa 7 | RUN apt-get update && \ 8 | apt-get install -y software-properties-common && \ 9 | add-apt-repository ppa:mosquitto-dev/mosquitto-ppa 10 | 11 | # Install dependencies 12 | RUN apt-get update &&\ 13 | apt-get -y install \ 14 | libssl-dev \ 15 | libcurl4-openssl-dev\ 16 | libsqlite3-dev \ 17 | libc-ares-dev \ 18 | libz-dev \ 19 | autoconf \ 20 | automake \ 21 | libtool \ 22 | libmosquitto-dev \ 23 | libwebsockets-dev \ 24 | pkg-config \ 25 | make \ 26 | &&\ 27 | apt-get clean 28 | 29 | # Copy in all of the code 30 | # Then compile, as root. 31 | COPY . /obuspa/ 32 | RUN cd /obuspa/ && \ 33 | autoreconf -fi && \ 34 | ./configure && \ 35 | make -j${MAKE_JOBS} && \ 36 | make install 37 | 38 | # Then delete the code 39 | # that's no longer needed 40 | RUN rm -rf /obuspa 41 | 42 | # Run obuspa with args expanded 43 | CMD obuspa ${OBUSPA_ARGS} 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2019-2021, Broadband Forum 2 | Copyright (C) 2016-2021 CommScope, Inc 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 29 | THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OB-USP-Agent Test Controller 2 | 3 | Open Broadband-User Services Platform-Agent Test Controller (OB-USP-Agent Test Controller) is an open source project that takes the OB-USP-Agent code [Broadband Forum OB-USP-Agent GitHub repository](https://github.com/BroadbandForum/obuspa) and adds functionality to allow the sending of Controller messages from a file. 4 | 5 | USP is a remote management and control protocol where management entities are separated between the Agent and the Controller. A USP Agent is responsible for exposing a set of "Service Elements" (essentially, a data model composed of objects and parameters that represent a specific set of functionality) for consumption by a Controller. While USP is capable of being used in many different environments, the home network is expected to be the most common environment, and in this environment a USP Agent would reside in a piece of Customer Premise Equipment (CPE), e.g. broadband home router, Wi-Fi access point, IoT gateway. 6 | Quick Start 7 | 8 | For build instructions, please refer to QUICK_START_GUIDE. 9 | 10 | ## Contributing 11 | 12 | Thank you for your interest in contributing! Please refer to CONTRIBUTING.md for guidance. 13 | 14 | ## Wiki Access 15 | 16 | The OB-USP-Agent test controller is part of Broadband Forum's OB-USP-Agent project. Please see the [OB-USP-Agent Wiki](https://github.com/BroadbandForum/obuspa/wiki) for more details about the OB-USP-Agent project. 17 | 18 | 19 | -------------------------------------------------------------------------------- /RELEASES.md: -------------------------------------------------------------------------------- 1 | # Release History 2 | 3 | ## Release 1.1.0-pre 4 | * Updated to the code base of obuspa pre-release 5.0 (November 23th 2021) 5 | * Added MQTT support 6 | * Clarified documentation about Test Controller usages 7 | 8 | ## Release 1.0.1 9 | * Fixed -f option not working when using -x option 10 | * Clarified contributing guidelines 11 | 12 | ## Release 1.0.0 13 | * Added rudimentary Controller function to the code base of obuspa Release 2.1 14 | 15 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.63]) 5 | 6 | AC_INIT([ob-uspagent],[1.0.0]) 7 | AM_INIT_AUTOMAKE([foreign silent-rules subdir-objects -Wall -Werror -Wno-portability]) 8 | AC_CONFIG_MACRO_DIR([m4]) 9 | AC_USE_SYSTEM_EXTENSIONS 10 | 11 | LT_PREREQ([2.2]) 12 | LT_INIT([shared disable-static]) 13 | 14 | # Checks for programs. 15 | AC_PROG_CC 16 | AM_PROG_CC_C_O 17 | 18 | AC_ARG_ENABLE(stomp, [AS_HELP_STRING([--enable-stomp], [enable STOMP Message support])],,enable_stomp=yes) 19 | AC_ARG_ENABLE(mqtt, [AS_HELP_STRING([--enable-mqtt], [enable MQTT Message support])],,enable_mqtt=yes) 20 | AC_ARG_ENABLE(coap, [AS_HELP_STRING([--enable-coap], [enable COAP Message support])],,enable_coap=yes) 21 | AC_ARG_ENABLE(websockets, [AS_HELP_STRING([--enable-websockets], [enable WebSockets Message support])],,enable_websockets=yes) 22 | 23 | # Checks for libraries. 24 | # This also defines autotools magic variables for use in the .am files 25 | PKG_CHECK_MODULES([openssl], [openssl]) 26 | PKG_CHECK_MODULES([sqlite3], [sqlite3]) 27 | PKG_CHECK_MODULES([libcurl], [libcurl]) 28 | PKG_CHECK_MODULES([zlib], [zlib]) 29 | 30 | AS_IF([test "x$enable_stomp" = xno], [ 31 | AC_DEFINE(DISABLE_STOMP) 32 | ]) 33 | 34 | AS_IF([test "x$enable_coap" = xyes], [ 35 | AC_DEFINE(ENABLE_COAP) 36 | ]) 37 | 38 | AS_IF([test "x$enable_mqtt" = xyes], [ 39 | PKG_CHECK_MODULES([libmosquitto], [libmosquitto]) 40 | AC_DEFINE(ENABLE_MQTT) 41 | ]) 42 | 43 | AS_IF([test "x$enable_websockets" = xyes], [ 44 | PKG_CHECK_MODULES([libwebsockets], [libwebsockets >= 3.2.0]) 45 | AC_DEFINE(ENABLE_WEBSOCKETS) 46 | ]) 47 | 48 | # Check which flavour of strerror_r is available on the target 49 | AC_FUNC_STRERROR_R 50 | 51 | AC_CHECK_HEADERS([malloc.h]) 52 | AC_CHECK_HEADERS([execinfo.h]) 53 | AC_CHECK_FUNCS([mallinfo]) 54 | AC_CHECK_FUNCS([mallinfo2]) 55 | 56 | # Generate Makefiles 57 | AC_CONFIG_FILES([Makefile]) 58 | 59 | # Finally, generate top-level config.status. 60 | AC_OUTPUT 61 | -------------------------------------------------------------------------------- /ctrl_coap_example.txt: -------------------------------------------------------------------------------- 1 | msg_id:"1" to_id:"proto::Agent1" coap_host:"192.168.1.119" coap_port:"5683" coap_resource:"Agent1" 2 | msg_type:"GetSupportedProtocol" controller_supported_protocol_versions:"1.0" 3 | msg_type:GetInstances obj_paths:"Device.LocalAgent.MTP." first_level_only:"false" 4 | msg_type:"Get" param_paths:"Device.LocalAgent.MTP.*." param_paths:"Device.LocalAgent.Controller.*." param_paths:"Device.LocalAgent." param_paths:"Device.LocalAgent.MTP.1." param_paths:"Device.LocalAgent.MTP.*." 5 | msg_type:Add create_objs{obj_path:"Device.LocalAgent.Subscription." allow_partial:"true" {param:"Enable" value:"false"} {param:"ID" value:"test123"} {param:"NotifType" value:"ObjectCreation"} {param:"ReferenceList" value:"Device.LocalAgent.Controller."}} create_objs{obj_path:"Device.LocalAgent.Subscription." {param:"Enable" value:"false" required:"true"} {param:"ID" value:"test456" required:"true"} {param:"NotifType" value:"Event"} {param:"ReferenceList" value:"Device.Boot!"}} 6 | msg_type:"Set" allow_partial:"true" update_objs{obj_path:"Device.DeviceInfo." {param:"FriendlyName" value:"MyDevicesFriendlyName" required:"true"}} update_objs{obj_path:"Device.LocalAgent.Subscription.[ID==\"test123\"]" {param:"Enable" value:"true"}} 7 | msg_type:Delete obj_paths:"Device.LocalAgent.Subscription.[ID==\"test123\"]." 8 | msg_type:Delete obj_paths:"Device.LocalAgent.Subscription.[ID==\"test456\"]." 9 | -------------------------------------------------------------------------------- /ctrl_mqtt_example.txt: -------------------------------------------------------------------------------- 1 | # Example for MQTT exchanges 2 | 3 | # This is the first line 4 | msg_id:"1" to_id:"proto::Agent1" mqtt_topic:"/usp/endpoint/1" mqtt_instance:"1" 5 | 6 | # Those are the messages to be sent 7 | #msg_type:"GetSupportedDM" obj_paths:"Device." first_level_only:"false" return_commands:"true" return_events:"true" return_params:"true" 8 | msg_type:"GetSupportedProtocol" controller_supported_protocol_versions:"1.0" 9 | #msg_type:GetInstances obj_paths:"Device.LocalAgent.MTP." first_level_only:"false" 10 | #msg_type:"Get" param_paths:"Device.LocalAgent.MTP.*." param_paths:"Device.LocalAgent.Controller.*." param_paths:"Device.LocalAgent." param_paths:"Device.LocalAgent.MTP.1." param_paths:"Device.LocalAgent.MTP.*." 11 | msg_type:"Operate" command:"Device.Reboot()" command_key:"boot123" send_resp:"true" 12 | -------------------------------------------------------------------------------- /ctrl_stomp_example.txt: -------------------------------------------------------------------------------- 1 | msg_id:"101" to_id:"proto::Agent1" stomp_agent_dest:"/queue/Agent1" stomp_instance:"1" 2 | msg_type:"GetSupportedDM" obj_paths:"Device." first_level_only:"false" return_commands:"true" return_events:"true" return_params:"true" 3 | msg_type:"GetSupportedProtocol" controller_supported_protocol_versions:"1.0" 4 | msg_type:GetInstances obj_paths:"Device.LocalAgent.MTP." first_level_only:"false" 5 | msg_type:"Get" param_paths:"Device.LocalAgent.MTP.*." param_paths:"Device.LocalAgent.Controller.*." param_paths:"Device.LocalAgent." param_paths:"Device.LocalAgent.MTP.1." param_paths:"Device.LocalAgent.MTP.*." 6 | msg_type:Add create_objs{obj_path:"Device.LocalAgent.Subscription." {param:"Enable" value:"false"} {param:"ID" value:"test123"} {param:"NotifType" value:"ObjectCreation"} {param:"ReferenceList" value:"Device.LocalAgent.Controller."}} create_objs{obj_path:"Device.LocalAgent.Subscription." {param:"Enable" value:"false" required:"true"} {param:"ID" value:"test456"} {param:"NotifType" value:"Event"} {param:"ReferenceList" value:"Device.Boot!"}} 7 | msg_type:"Set" allow_partial:"true" update_objs{obj_path:"Device.DeviceInfo." {param:"FriendlyName" value:"MyDevicesFriendlyName" required:"true"}} update_objs{obj_path:"Device.LocalAgent.Subscription.[ID==\"test123\"]" {param:"Enable" value:"true"}} 8 | msg_type:"Operate" command:"Device.Reboot()" command_key:"boot123" send_resp:"true" 9 | msg_type:Delete obj_paths:"Device.LocalAgent.Subscription.[ID==\"test123\"]." 10 | -------------------------------------------------------------------------------- /factory_reset_example.txt: -------------------------------------------------------------------------------- 1 | ########################################################################################################## 2 | # 3 | # This file contains a factory reset database in text format 4 | # 5 | # If no USP database exists when OB-USP-AGENT starts, then OB-USP-AGENT will create a database containing 6 | # the parameters specified in a text file located by the '-r' option. 7 | # Example: 8 | # obuspa -p -v 4 -r factory_reset_example.txt 9 | # 10 | # Each line of this file contains either a comment (denoted by '#' at the start of the line) 11 | # or a USP data model parameter and its factory reset value. 12 | # The parameter and value are separated by whitespace. 13 | # The value may optionally be enclosed in speech marks "" (this is the only way to specify an empty string) 14 | # 15 | ########################################################################################################## 16 | 17 | # 18 | # The following parameters will definitely need modifying 19 | # 20 | Device.LocalAgent.Controller.1.EndpointID "self::usp-controller.com" 21 | Device.STOMP.Connection.1.Host "usp-controller.com" 22 | Device.STOMP.Connection.1.Username "username" 23 | Device.STOMP.Connection.1.Password "password" 24 | 25 | # 26 | # The following parameters may be modified 27 | # 28 | Device.LocalAgent.MTP.1.Alias "cpe-1" 29 | Device.LocalAgent.MTP.1.Enable "true" 30 | Device.LocalAgent.MTP.1.Protocol "STOMP" 31 | Device.LocalAgent.MTP.1.STOMP.Reference "Device.STOMP.Connection.1" 32 | Device.LocalAgent.MTP.1.STOMP.Destination "/queue/agent-1" 33 | Device.LocalAgent.Controller.1.Alias "cpe-1" 34 | Device.LocalAgent.Controller.1.Enable "true" 35 | Device.LocalAgent.Controller.1.AssignedRole "Device.LocalAgent.ControllerTrust.Role.1" 36 | Device.LocalAgent.Controller.1.PeriodicNotifInterval "86400" 37 | Device.LocalAgent.Controller.1.PeriodicNotifTime "0001-01-01T00:00:00Z" 38 | Device.LocalAgent.Controller.1.USPNotifRetryMinimumWaitInterval "5" 39 | Device.LocalAgent.Controller.1.USPNotifRetryIntervalMultiplier "2000" 40 | Device.LocalAgent.Controller.1.ControllerCode "" 41 | Device.LocalAgent.Controller.1.MTP.1.Alias "cpe-1" 42 | Device.LocalAgent.Controller.1.MTP.1.Enable "true" 43 | Device.LocalAgent.Controller.1.MTP.1.Protocol "STOMP" 44 | Device.LocalAgent.Controller.1.MTP.1.STOMP.Reference "Device.STOMP.Connection.1" 45 | Device.LocalAgent.Controller.1.MTP.1.STOMP.Destination "controller-notify-dest"" 46 | Device.STOMP.Connection.1.Alias "cpe-1" 47 | Device.STOMP.Connection.1.Enable "true" 48 | Device.STOMP.Connection.1.Port "61613" 49 | Device.STOMP.Connection.1.EnableEncryption "false" 50 | Device.STOMP.Connection.1.VirtualHost "/" 51 | Device.STOMP.Connection.1.EnableHeartbeats "true" 52 | Device.STOMP.Connection.1.OutgoingHeartbeat "30000" 53 | Device.STOMP.Connection.1.IncomingHeartbeat "300000" 54 | Device.STOMP.Connection.1.ServerRetryInitialInterval "60" 55 | Device.STOMP.Connection.1.ServerRetryIntervalMultiplier "2000" 56 | Device.STOMP.Connection.1.ServerRetryMaxInterval "30720" 57 | Internal.Reboot.Cause "LocalFactoryReset" 58 | 59 | -------------------------------------------------------------------------------- /mqtt_factory_reset_example.txt: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # This file contains a factory reset database in text format 4 | # 5 | # If no USP database exists when OB-USP-AGENT starts, then OB-USP-AGENT will create a database containing 6 | # the parameters specified in a text file located by the '-r' option. 7 | # Example: 8 | # obuspa -p -v 4 -r factory_reset_example.txt 9 | # 10 | # Each line of this file contains either a comment (denoted by '#' at the start of the line) 11 | # or a USP data model parameter and its factory reset value. 12 | # The parameter and value are separated by whitespace. 13 | # The value may optionally be enclosed in speech marks "" (this is the only way to specify an empty string) 14 | # 15 | ########################################################################################################## 16 | # 17 | # Adding MQTT parameters to test the datamodel interface 18 | # 19 | 20 | Device.LocalAgent.EndpointID "proto::rx_usp_agent_mqtt" 21 | 22 | 23 | ## Adding boot params 24 | Device.LocalAgent.Controller.1.BootParameter.1.Enable true 25 | Device.LocalAgent.Controller.1.BootParameter.1.ParameterName "Device.LocalAgent.EndpointID" 26 | Device.LocalAgent.Subscription.1.Alias cpe-1 27 | Device.LocalAgent.Subscription.1.Enable true 28 | Device.LocalAgent.Subscription.1.ID default-boot-event-ACS 29 | Device.LocalAgent.Subscription.1.Recipient Device.LocalAgent.Controller.1 30 | Device.LocalAgent.Subscription.1.NotifType Event 31 | Device.LocalAgent.Subscription.1.ReferenceList Device.Boot! 32 | Device.LocalAgent.Subscription.1.Persistent true 33 | 34 | Device.LocalAgent.MTP.1.MQTT.ResponseTopicConfigured "/usp/endpoint/#" 35 | Device.LocalAgent.MTP.1.MQTT.Reference "Device.MQTT.Client.1" 36 | Device.MQTT.Client.1.BrokerAddress "mqtt.eclipse.org" 37 | Device.MQTT.Client.1.ProtocolVersion "5.0" 38 | Device.MQTT.Client.1.BrokerPort "1883" 39 | Device.MQTT.Client.1.TransportProtocol "TCP/IP" 40 | Device.MQTT.Client.1.Username "" 41 | Device.MQTT.Client.1.Password "" 42 | Device.MQTT.Client.1.Alias "cpe-1" 43 | Device.MQTT.Client.1.Enable true 44 | Device.MQTT.Client.1.ClientID "" 45 | Device.MQTT.Client.1.KeepAliveTime "60" 46 | 47 | Device.MQTT.Client.1.ConnectRetryTime "5" 48 | Device.MQTT.Client.1.ConnectRetryIntervalMultiplier "2000" 49 | Device.MQTT.Client.1.ConnectRetryMaxInterval "60" 50 | 51 | 52 | Device.LocalAgent.Controller.1.Alias "cpe-1" 53 | Device.LocalAgent.Controller.1.Enable true 54 | Device.LocalAgent.Controller.1.PeriodicNotifInterval "86400" 55 | Device.LocalAgent.Controller.1.PeriodicNotifTime "0001-01-01T00:00:00Z" 56 | Device.LocalAgent.Controller.1.ControllerCode "" 57 | Device.LocalAgent.Controller.1.MTP.1.Alias "cpe-1" 58 | Device.LocalAgent.Controller.1.MTP.1.Enable true 59 | Device.LocalAgent.Controller.1.MTP.1.Protocol "MQTT" 60 | Device.LocalAgent.Controller.1.EndpointID "self::usp-controller" 61 | Device.LocalAgent.Controller.1.MTP.1.MQTT.Reference "Device.MQTT.Client.1" 62 | Device.LocalAgent.Controller.1.MTP.1.MQTT.Topic "/usp/controller" 63 | 64 | 65 | 66 | # 67 | # The following parameters may be modified 68 | # 69 | Device.LocalAgent.MTP.1.Alias "cpe-1" 70 | Device.LocalAgent.MTP.1.Enable true 71 | Device.LocalAgent.MTP.1.Protocol "MQTT" 72 | 73 | Internal.Reboot.Cause "LocalFactoryReset" 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /src/core/bdc_exec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021, Broadband Forum 4 | * Copyright (C) 2016-2021 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file bdc_exec.h 37 | * 38 | * Header file for Main execution loop of bulk data collection thread 39 | * 40 | */ 41 | #ifndef BDC_EXEC_H 42 | #define BDC_EXEC_H 43 | 44 | //------------------------------------------------------------------------------ 45 | // API functions 46 | int BDC_EXEC_Init(void); 47 | int BDC_EXEC_PostReportToSend(int profile_id, char *full_url, char *query_string, char *username, char *password, unsigned char *report, int report_len, unsigned flags); 48 | void *BDC_EXEC_Main(void *args); 49 | void BDC_EXEC_ScheduleExit(void); 50 | 51 | //------------------------------------------------------------------------------ 52 | // Definitions of bits in flags parameter of BDC_EXEC_PostReportToSend() 53 | #define BDC_FLAG_PUT 0x00000001 // If set, HTTP PUT should be used instead of HTTP POST when sending the report to the BDC server 54 | #define BDC_FLAG_GZIP 0x00000002 // If set, the reports contants are Gzipped 55 | #define BDC_FLAG_DATE_HEADER 0x00000004 // If set, the date header should be included in the HTTP post. 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/core/cli.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file cli.h 37 | * 38 | * Common header file for command line interface (CLI) server and client functionality 39 | * 40 | */ 41 | #ifndef CLI_H 42 | #define CLI_H 43 | 44 | #include "socket_set.h" 45 | 46 | #define MAX_CLI_CMD_LEN 1024 // The maximum allowed size of a CLI command. The limit is arbitrary. 47 | #define CLI_SEPARATOR '\xFF' // Used to separate command and args in stream passed from client to server. 48 | // Used instead of a simple space, because args themselves might contain spaces 49 | 50 | 51 | //------------------------------------------------------------------------------------ 52 | // Server API 53 | int CLI_SERVER_Init(void); 54 | void CLI_SERVER_UpdateSocketSet(socket_set_t *set); 55 | void CLI_SERVER_ProcessSocketActivity(socket_set_t *set); 56 | void CLI_SERVER_SendResponse(const char *s); 57 | bool CLI_SERVER_IsCmdRunLocally(char *command); 58 | int CLI_SERVER_ExecuteCliCommand(char *command); 59 | 60 | //------------------------------------------------------------------------------------ 61 | // Client API 62 | int CLI_CLIENT_ExecCommand(int argc, char *argv[], char *db_file); 63 | 64 | //------------------------------------------------------------------------------------ 65 | extern bool dump_to_cli; // If set, dump logging messages are sent back to the CLI client rather than their normal destination 66 | extern bool is_running_cli_local_command; // Set if this executable is running a local CLI command (eg dbset) 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/core/database.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021, Broadband Forum 4 | * Copyright (C) 2016-2021 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file database.h 37 | * 38 | * Header file containing the API to access the USP Database 39 | * 40 | */ 41 | #ifndef DATABASE_H 42 | #define DATABASE_H 43 | #include "data_model.h" 44 | 45 | //------------------------------------------------------------------------------ 46 | // Defines for bits in flag variable used by DATABASE_GetParameterValue() and DATABASE_SetParameterValue() 47 | #define OBFUSCATED_VALUE 0x00000001 48 | 49 | //------------------------------------------------------------------------------ 50 | // String, set by '-r' command line option to specify a text file containing the factory reset database parameters 51 | extern char *factory_reset_text_file; 52 | 53 | //------------------------------------------------------------------------------ 54 | // API 55 | int DATABASE_Init(char *db_file); 56 | int DATABASE_Start(void); 57 | void DATABASE_Destroy(void); 58 | void DATABASE_PerformFactoryReset_ControllerInitiated(void); 59 | int DATABASE_GetParameterValue(char *path, dm_hash_t hash, char *instances, char *buf, int buflen, unsigned flags); 60 | int DATABASE_SetParameterValue(char *path, dm_hash_t hash, char *instances, char *new_value, unsigned flags); 61 | int DATABASE_DeleteParameter(char *path, dm_hash_t hash, char *instances); 62 | int DATABASE_StartTransaction(void); 63 | int DATABASE_CommitTransaction(void); 64 | int DATABASE_AbortTransaction(void); 65 | void DATABASE_Dump(void); 66 | int DATABASE_ReadDataModelInstanceNumbers(bool remove_unknown_params); 67 | db_hash_t DATABASE_GetMigratedHash(db_hash_t hash); 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /src/core/dllist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file dllist.h 37 | * 38 | * Implements a doubly linked list library 39 | * 40 | */ 41 | 42 | #ifndef DLLIST_H 43 | #define DLLIST_H 44 | 45 | //----------------------------------------------------------------------------------------- 46 | // Doubly Linked list types 47 | typedef struct double_link_t_tag 48 | { 49 | struct double_link_t_tag *next; 50 | struct double_link_t_tag *prev; 51 | } double_link_t; 52 | 53 | typedef struct 54 | { 55 | double_link_t *head; 56 | double_link_t *tail; 57 | } double_linked_list_t; 58 | 59 | //----------------------------------------------------------------------------------------- 60 | // Doubly linked list API 61 | void DLLIST_Init(double_linked_list_t *list); 62 | bool DLLIST_IsItemInList(double_linked_list_t *list, double_link_t *item_to_check); 63 | void DLLIST_LinkToHead(double_linked_list_t *list, void *item_to_add); 64 | void DLLIST_LinkToTail(double_linked_list_t *list, void *item_to_add); 65 | void DLLIST_Unlink(double_linked_list_t *list, void *item_to_remove); 66 | void DLLIST_InsertLinkBefore(void *insert_point, double_linked_list_t *list, void *item_to_add); 67 | void DLLIST_MoveLink(double_linked_list_t *dest_list, double_linked_list_t *src_list, void *item_to_move); 68 | 69 | #endif // DLLIST_H 70 | -------------------------------------------------------------------------------- /src/core/dm_access.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021, Broadband Forum 4 | * Copyright (C) 2016-2021 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file dm_access.h 37 | * 38 | * Header file for API to access data model parameters by type 39 | * 40 | */ 41 | #ifndef DM_ACCESS_H 42 | #define DM_ACCESS_H 43 | 44 | #include 45 | #include "str_vector.h" 46 | #include "nu_ipaddr.h" 47 | 48 | //------------------------------------------------------------------------- 49 | // The prefix to use when forming the default value of an Alias parameter 50 | #define DEFAULT_ALIAS_PREFIX "cpe-" 51 | 52 | //------------------------------------------------------------------------- 53 | // API functions 54 | int DM_ACCESS_GetString(char *path, char **p_str); 55 | int DM_ACCESS_GetPassword(char *path, char **p_str); 56 | int DM_ACCESS_GetInteger(char *path, int *value); 57 | int DM_ACCESS_GetUnsigned(char *path, unsigned *value); 58 | int DM_ACCESS_GetBool(char *path, bool *value); 59 | int DM_ACCESS_GetEnum(char *path, void *value, const enum_entry_t *enums, int num_enums); 60 | int DM_ACCESS_GetDateTime(char *path, time_t *value); 61 | int DM_ACCESS_GetStringVector(char *path, str_vector_t *sv); 62 | int DM_ACCESS_GetIpAddr(char *path, nu_ipaddr_t *ip_addr); 63 | 64 | int DM_ACCESS_SetInteger(char *path, int value); 65 | 66 | int DM_ACCESS_ValidateBool(dm_req_t *req, char *value); 67 | int DM_ACCESS_ValidateBase64(dm_req_t *req, char *value); 68 | int DM_ACCESS_ValidatePort(dm_req_t *req, char *value); 69 | int DM_ACCESS_ValidateRange_Unsigned(dm_req_t *req, unsigned min_value, unsigned max_value); 70 | int DM_ACCESS_ValidateRange_Signed(dm_req_t *req, int min_value, int max_value); 71 | int DM_ACCESS_ValidateReference(char *reference, char *table, int *instance); 72 | int DM_ACCESS_ValidateIpAddr(dm_req_t *req, char *value); 73 | 74 | int DM_ACCESS_CompareString(char *lhs, expr_op_t op, char *rhs, bool *result); 75 | int DM_ACCESS_CompareNumber(char *lhs, expr_op_t op, char *rhs, bool *result); 76 | int DM_ACCESS_CompareBool(char *lhs, expr_op_t op, char *rhs, bool *result); 77 | int DM_ACCESS_CompareDateTime(char *lhs, expr_op_t op, char *rhs, bool *result); 78 | int DM_ACCESS_RestartAsyncOperation(dm_req_t *req, int instance, bool *is_restart, int *err_code, char *err_msg, int err_msg_len, kv_vector_t *output_args); 79 | int DM_ACCESS_DontRestartAsyncOperation(dm_req_t *req, int instance, bool *is_restart, int *err_code, char *err_msg, int err_msg_len, kv_vector_t *output_args); 80 | int DM_ACCESS_PopulateAliasParam(dm_req_t *req, char *buf, int len); 81 | 82 | 83 | 84 | #endif 85 | 86 | -------------------------------------------------------------------------------- /src/core/dm_exec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021, Broadband Forum 4 | * Copyright (C) 2016-2021 CommScope, Inc 5 | * Copyright (C) 2020, BT PLC 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 | * THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | /** 37 | * \file dm_exec.h 38 | * 39 | * Header file for Main execution loop of data model thread 40 | * 41 | */ 42 | #ifndef DM_EXEC_H 43 | #define DM_EXEC_H 44 | 45 | #include "device.h" 46 | //------------------------------------------------------------------------------ 47 | // Bitmask indicating which thread exited to DM_EXEC_PostMtpThreadExited() 48 | #define STOMP_EXITED 0x00000001 49 | #define COAP_EXITED 0x00000002 50 | #define MQTT_EXITED 0x00000004 51 | #define BDC_EXITED 0x00000008 52 | #define WSCLIENT_EXITED 0x00000010 53 | 54 | //------------------------------------------------------------------------------ 55 | // API functions 56 | int DM_EXEC_Init(void); 57 | void DM_EXEC_Destroy(void); 58 | void DM_EXEC_PostUspRecord(unsigned char *pbuf, int pbuf_len, ctrust_role_t role, mtp_reply_to_t *mrt); 59 | void DM_EXEC_PostStompHandshakeComplete(int stomp_instance, ctrust_role_t role); 60 | void DM_EXEC_PostMqttHandshakeComplete(int stomp_instance, ctrust_role_t role); 61 | void DM_EXEC_PostMtpThreadExited(unsigned flags); 62 | int DM_EXEC_NotifyBdcTransferResult(int profile_id, bdc_transfer_result_t transfer_result); 63 | void DM_EXEC_HandleScheduledExit(void); 64 | bool DM_EXEC_IsNotificationsEnabled(void); 65 | void *DM_EXEC_Main(void *args); 66 | //------------------------------------------------------------------------------ 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/core/dm_inst_vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2020, Broadband Forum 4 | * Copyright (C) 2016-2020 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file dm_inst_vector.h 37 | * 38 | * Implements a vector of dm_instances structures 39 | * This is basically a list of all object instances instantiated in the data model 40 | * 41 | */ 42 | 43 | #ifndef DM_INST_VECTOR_H 44 | #define DM_INST_VECTOR_H 45 | 46 | //----------------------------------------------------------------------------------------- 47 | // API 48 | void DM_INST_VECTOR_Init(dm_instances_vector_t *div); 49 | void DM_INST_VECTOR_Destroy(dm_instances_vector_t *div); 50 | int DM_INST_VECTOR_Add(dm_instances_t *inst); 51 | void DM_INST_VECTOR_Remove(dm_instances_t *inst); 52 | int DM_INST_VECTOR_IsExist(dm_instances_t *match, bool *exists); 53 | int DM_INST_VECTOR_GetNextInstance(dm_node_t *node, dm_instances_t *inst, int *next_instance); 54 | int DM_INST_VECTOR_GetNumInstances(dm_node_t *node, dm_instances_t *inst, int *num_instances); 55 | int DM_INST_VECTOR_GetInstances(dm_node_t *node, dm_instances_t *inst, int_vector_t *iv); 56 | int DM_INST_VECTOR_GetAllInstancePaths_Unqualified(dm_node_t *node, dm_instances_t *inst, str_vector_t *sv, combined_role_t *combined_role); 57 | int DM_INST_VECTOR_GetAllInstancePaths_Qualified(dm_instances_t *inst, str_vector_t *sv, combined_role_t *combined_role); 58 | void DM_INST_VECTOR_RefreshBaselineInstances(dm_node_t *parent); 59 | void DM_INST_VECTOR_Dump(dm_instances_vector_t *div); 60 | int DM_INST_VECTOR_RefreshInstance(char *path); 61 | int DM_INST_VECTOR_RefreshTopLevelObjectInstances(dm_node_t *node); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/core/dm_trans.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file dm_trans.h 37 | * 38 | * Implements data model transactions 39 | * These transactions wrap the underlying database and also call notifies whwen the transaction has been comitted 40 | * 41 | */ 42 | 43 | #ifndef DM_TRANS_H 44 | #define DM_TRANS_H 45 | 46 | #include "data_model.h" 47 | 48 | //----------------------------------------------------------------------- 49 | // Enumeration for type of operation that the Data model supports 50 | typedef enum 51 | { 52 | kDMOp_Set = 0, 53 | kDMOp_Add, 54 | kDMOp_Del, 55 | 56 | // Next entry is always the last - used to size arrays 57 | kDMOp_Max 58 | } dm_op_t; 59 | 60 | //----------------------------------------------------------------------- 61 | // Queue of parameters or objects whose notify function will be called when the transaction has been committed successfully 62 | typedef struct 63 | { 64 | dm_op_t op; // Operation (add/delete/set) 65 | char *path; // full data model path to parameter or objet to notify 66 | char *value; // value of parameter (only used by kTransType_Set) 67 | dm_node_t *node; // Node in the data model representing the parameter or object 68 | dm_req_instances_t inst; // Instance array containing the instance numbers in the path 69 | dm_val_union_t val_union; // Stores the native value of the parameter (only used by kTransType_Set). If the parameter is a string, then it will point to the 'value' parameter in this structure 70 | } dm_trans_t; 71 | 72 | //----------------------------------------------------------------------- 73 | // Vector storing all operations made during a transaction 74 | typedef struct 75 | { 76 | int num_entries; 77 | dm_trans_t *vector; 78 | } dm_trans_vector_t; 79 | 80 | //----------------------------------------------------------------------------------------- 81 | // API 82 | int DM_TRANS_Start(dm_trans_vector_t *trans); 83 | void DM_TRANS_Add(dm_op_t op, char *path, char *value, dm_val_union_t *val_union, dm_node_t *node, dm_instances_t *inst); 84 | int DM_TRANS_Commit(void); 85 | int DM_TRANS_Abort(void); 86 | bool DM_TRANS_IsWithinTransaction(void); 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src/core/expr_vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file expr_vector.h 37 | * 38 | * Implements a vector of expression components 39 | * 40 | */ 41 | 42 | #ifndef EXPR_VECTOR_H 43 | #define EXPR_VECTOR_H 44 | 45 | #include "kv_vector.h" 46 | #include "usp_api.h" // for expr_op_t 47 | 48 | //----------------------------------------------------------------------------------------- 49 | // Type representing expression component 50 | typedef struct 51 | { 52 | char *param; 53 | expr_op_t op; 54 | char *value; 55 | } expr_comp_t; 56 | 57 | //----------------------------------------------------------------------------------------- 58 | // Expression vector type 59 | typedef struct 60 | { 61 | expr_comp_t *vector; 62 | int num_entries; 63 | } expr_vector_t; 64 | 65 | //----------------------------------------------------------------------------------------- 66 | // Export array used by debug to convert an operator back to a string representation 67 | extern char *expr_op_2_str[kExprOp_Max]; 68 | 69 | //----------------------------------------------------------------------------------------- 70 | // Defines for 'is_cli_parser' argument of EXPR_VECTOR_SplitExpressions() 71 | #define EXPR_FROM_USP false 72 | #define EXPR_FROM_CLI true 73 | 74 | //----------------------------------------------------------------------------------------- 75 | // Expression Vector API 76 | void EXPR_VECTOR_Init(expr_vector_t *ev); 77 | void EXPR_VECTOR_Add(expr_vector_t *ev, char *param, expr_op_t op, char *value); 78 | void EXPR_VECTOR_ToKeyValueVector(expr_vector_t *ev, kv_vector_t *kvv); 79 | void EXPR_VECTOR_Destroy(expr_vector_t *ev); 80 | void EXPR_VECTOR_Dump(expr_vector_t *ev); 81 | int EXPR_VECTOR_SplitExpressions(char *str, expr_vector_t *ev, char *separator, expr_op_t *valid_ops, int num_valid_ops, bool is_cli_parser); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/core/group_get_vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2020, Broadband Forum 4 | * Copyright (C) 2020 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file group_get_vector.h 37 | * 38 | * Header file for functions performing getting of a mixed group of parameters 39 | * 40 | */ 41 | 42 | #ifndef GROUP_GET_VECTOR_H 43 | #define GROUP_GET_VECTOR_H 44 | 45 | #include "str_vector.h" 46 | #include "kv_vector.h" 47 | 48 | //------------------------------------------------------------------------------ 49 | // Structure containing info for parameter to get, and its value or error 50 | typedef struct 51 | { 52 | char *path; 53 | int group_id; 54 | char *value; 55 | int err_code; 56 | char *err_msg; 57 | } group_get_entry_t; 58 | 59 | //------------------------------------------------------------------------------ 60 | // Vector of all parameters to get (for all groups) 61 | typedef struct 62 | { 63 | group_get_entry_t *vector; 64 | int num_entries; 65 | } group_get_vector_t; 66 | 67 | //------------------------------------------------------------------------------ 68 | // API 69 | void GROUP_GET_VECTOR_Init(group_get_vector_t *ggv); 70 | void GROUP_GET_VECTOR_Destroy(group_get_vector_t *ggv); 71 | void GROUP_GET_VECTOR_Add(group_get_vector_t *ggv, char *path, int group_id); 72 | int GROUP_GET_VECTOR_FindParam(group_get_vector_t *ggv, char *path); 73 | void GROUP_GET_VECTOR_AddParams(group_get_vector_t *ggv, str_vector_t *params, int_vector_t *group_ids); 74 | void GROUP_GET_VECTOR_ConvertToKeyValueVector(group_get_vector_t *ggv, kv_vector_t *kvv); 75 | void GROUP_GET_VECTOR_GetValues(group_get_vector_t *ggv); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /src/core/group_set_vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2020, Broadband Forum 4 | * Copyright (C) 2020 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file group_get_vector.h 37 | * 38 | * Header file for functions performing setting of a mixed group of parameters 39 | * 40 | */ 41 | 42 | #ifndef GROUP_SET_VECTOR_H 43 | #define GROUP_SET_VECTOR_H 44 | 45 | #include "str_vector.h" 46 | #include "device.h" // for combined_role_t 47 | 48 | //------------------------------------------------------------------------------ 49 | // Structure containing info for parameter to set, and its value or error 50 | typedef struct 51 | { 52 | char *path; // Full data model path to the parameter 53 | int group_id; // Group which the parameter belongs to. All parameters in the same group can be obtained at the same time. 54 | unsigned type_flags;// Type of the parameter eg DM_STRING. Some low level (eg RDK) APIs require this additional info 55 | char *value; // NOTE: ownership of the value string stays with the USP request message 56 | bool is_required; // Whether the USP message marked the parameter as being required or not 57 | int err_code; // Set if an error occured when trying to set the parameter 58 | char *err_msg; // Set with an error string if an error occured when trying to set the parameter 59 | } group_set_entry_t; 60 | 61 | //------------------------------------------------------------------------------ 62 | // Vector of all parameters to set (for all groups) 63 | typedef struct 64 | { 65 | group_set_entry_t *vector; 66 | int num_entries; 67 | } group_set_vector_t; 68 | 69 | //------------------------------------------------------------------------------ 70 | // API 71 | void GROUP_SET_VECTOR_Init(group_set_vector_t *gsv); 72 | void GROUP_SET_VECTOR_Destroy(group_set_vector_t *gsv); 73 | void GROUP_SET_VECTOR_Add(group_set_vector_t *gsv, char *path, char *value, bool is_required, combined_role_t *combined_role); 74 | int GROUP_SET_VECTOR_GetFailureIndex(group_set_vector_t *gsv, int index, int num_entries); 75 | void GROUP_SET_VECTOR_SetValues(group_set_vector_t *gsv, int index, int num_entries); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /src/core/int_vector.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2020, Broadband Forum 4 | * Copyright (C) 2016-2020 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file int_vector.c 37 | * 38 | * Implements a data structure containing a vector of integers 39 | * 40 | */ 41 | #include 42 | #include 43 | 44 | #include "common_defs.h" 45 | #include "int_vector.h" 46 | 47 | /*********************************************************************//** 48 | ** 49 | ** INT_VECTOR_Init 50 | ** 51 | ** Initialises an integer vector structure 52 | ** 53 | ** \param iv - pointer to structure to initialise 54 | ** 55 | ** \return None 56 | ** 57 | **************************************************************************/ 58 | void INT_VECTOR_Init(int_vector_t *iv) 59 | { 60 | iv->vector = NULL; 61 | iv->num_entries = 0; 62 | } 63 | 64 | /*********************************************************************//** 65 | ** 66 | ** INT_VECTOR_Add 67 | ** 68 | ** Adds the integer into the vector of integers 69 | ** 70 | ** \param iv - pointer to structure to add the integer to 71 | ** \param number - integer to insert 72 | ** 73 | ** \return USP_ERR_OK if successful 74 | ** 75 | **************************************************************************/ 76 | void INT_VECTOR_Add(int_vector_t *iv, int number) 77 | { 78 | // Allocate a chunk of entries in one go, to avoid excessive reallocation 79 | #define CHUNK_SIZE 4 80 | if ((iv->num_entries % CHUNK_SIZE) == 0) 81 | { 82 | iv->vector = USP_REALLOC(iv->vector, (iv->num_entries + CHUNK_SIZE)*sizeof(int)); 83 | } 84 | 85 | iv->vector[ iv->num_entries ] = number; 86 | iv->num_entries++; 87 | } 88 | 89 | /*********************************************************************//** 90 | ** 91 | ** INT_VECTOR_Find 92 | ** 93 | ** Finds the specified integer in the vector of integers 94 | ** 95 | ** \param iv - pointer to structure to search in 96 | ** \param number - integer to match 97 | ** 98 | ** \return Index in vector of matching integer, or INVALID if not found 99 | ** 100 | **************************************************************************/ 101 | int INT_VECTOR_Find(int_vector_t *iv, int number) 102 | { 103 | int i; 104 | 105 | // Iterate over all entries in the vector 106 | for (i=0; i < iv->num_entries; i++) 107 | { 108 | // Exit if a match has been found 109 | if (iv->vector[i] == number) 110 | { 111 | return i; 112 | } 113 | } 114 | 115 | // If the code gets here, then no match has been found 116 | return INVALID; 117 | } 118 | 119 | /*********************************************************************//** 120 | ** 121 | ** INT_VECTOR_Destroy 122 | ** 123 | ** Deinitialises the integer vector 124 | ** 125 | ** \param iv - pointer to structure to re-initialize 126 | ** 127 | ** \return None 128 | ** 129 | **************************************************************************/ 130 | void INT_VECTOR_Destroy(int_vector_t *iv) 131 | { 132 | USP_SAFE_FREE(iv->vector); 133 | iv->num_entries = 0; 134 | } 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /src/core/int_vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2020, Broadband Forum 4 | * Copyright (C) 2016-2020 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file int_vector.h 37 | * 38 | * Implements a vector of integers 39 | * Unlike the other vector data structures, this has been re-implemented using a maximum fixed size array, 40 | * as this vector is only used to collect the instance numbers of an object. 41 | * Using a fixed size array minimizes the number of memory allocations, speeding up the code and minimising the risk of memory leaks 42 | * 43 | */ 44 | 45 | #ifndef INT_VECTOR_H 46 | #define INT_VECTOR_H 47 | 48 | #include "usp_api.h" 49 | 50 | //----------------------------------------------------------------------------------------- 51 | // Int Vector API 52 | void INT_VECTOR_Init(int_vector_t *iv); 53 | void INT_VECTOR_Add(int_vector_t *iv, int number); 54 | int INT_VECTOR_Find(int_vector_t *iv, int number); 55 | void INT_VECTOR_Destroy(int_vector_t *iv); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/core/iso8601.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file iso8601.h 37 | * 38 | * ISO8601 Time Format string utilities 39 | * 40 | */ 41 | 42 | #ifndef _ISO8601_H_ 43 | #define _ISO8601_H_ 44 | 45 | #include 46 | #include 47 | #include 48 | 49 | //------------------------------------------------------------------ 50 | // Definition for Unknown Time value (from TR-106a7 section A.2.3.5) 51 | #define UNKNOWN_TIME_STR "0001-01-01T00:00:00Z" 52 | #define UNKNOWN_TIME ((time_t)(INT_MIN)) // This is a special case, represented in 32 bits, so that the code works with 32 bit Linux kernels 53 | 54 | //------------------------------------------------------------------ 55 | // Functions 56 | char *iso8601_cur_time(char *buf, int len); 57 | char *iso8601_from_unix_time(time_t unix_time, char *buf, int len); 58 | size_t iso8601_strftime(char *buf, size_t buflen, const struct tm *tm); 59 | size_t iso8601_us_strftime(char *buf, size_t bufsiz, const struct timeval *tv); 60 | bool iso8601_is_valid(const char *date); 61 | time_t iso8601_to_unix_time(const char *date); 62 | size_t uptime_strftime(char *buf, size_t buflen, unsigned uptime); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/core/kv_vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021, Broadband Forum 4 | * Copyright (C) 2016-2021 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file kv_vector.h 37 | * 38 | * Implements a vector of key-value pairs 39 | * 40 | */ 41 | 42 | #ifndef KV_VECTOR_H 43 | #define KV_VECTOR_H 44 | 45 | #include 46 | #include // included as a convenience because calls to KV_VECTOR_GetUnsignedWithinRange() often reference UINT_MAX 47 | 48 | #include "usp_api.h" 49 | #include "str_vector.h" 50 | 51 | //----------------------------------------------------------------------------------------- 52 | // Key-value pair Vector API 53 | void KV_VECTOR_Init(kv_vector_t *kvv); 54 | void KV_VECTOR_Add(kv_vector_t *kvv, char *key, char *value); 55 | bool KV_VECTOR_Replace(kv_vector_t *kvv, char *key, char *value); 56 | bool KV_VECTOR_ReplaceWithHint(kv_vector_t *kvv, char *key, char *value, int hint); 57 | void KV_VECTOR_AddUnsigned(kv_vector_t *kvv, char *key, unsigned value); 58 | void KV_VECTOR_AddBool(kv_vector_t *kvv, char *key, bool value); 59 | void KV_VECTOR_AddDateTime(kv_vector_t *kvv, char *key, time_t value); 60 | void KV_VECTOR_AddEnum(kv_vector_t *kvv, char *key, int value, const enum_entry_t *enums, int num_enums); 61 | void KV_VECTOR_AddHexNumber(kv_vector_t *kvv, char *key, unsigned char *buf, int len); 62 | void KV_VECTOR_Destroy(kv_vector_t *kvv); 63 | void KV_VECTOR_Dump(kv_vector_t *kvv); 64 | int KV_VECTOR_FindKey(kv_vector_t *kvv, char *key, int start_index); 65 | int KV_VECTOR_ValidateArguments(kv_vector_t *args, str_vector_t *expected_schema); 66 | 67 | char *KV_VECTOR_Get(kv_vector_t *kvv, char *key, char *default_value, int start_index); 68 | int KV_VECTOR_GetUnsigned(kv_vector_t *kvv, char *key, unsigned default_value, unsigned *value); 69 | int KV_VECTOR_GetUnsignedWithinRange(kv_vector_t *kvv, char *key, unsigned default_value, unsigned min, unsigned max, unsigned *value); 70 | int KV_VECTOR_GetInt(kv_vector_t *kvv, char *key, int default_value, int *value); 71 | int KV_VECTOR_GetIntWithinRange(kv_vector_t *kvv, char *key, int default_value, int min, int max, int *value); 72 | int KV_VECTOR_GetBool(kv_vector_t *kvv, char *key, bool default_value, bool *value); 73 | int KV_VECTOR_GetDateTime(kv_vector_t *kvv, char *key, char *default_value, time_t *value); 74 | int KV_VECTOR_GetHexNumber(kv_vector_t *kvv, char *key, unsigned char *buf, int len, int *bytes_copied); 75 | int KV_VECTOR_GetEnum(kv_vector_t *kvv, char *key, void *value, int default_value, const enum_entry_t *enums, int num_enums); 76 | 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/core/nu_ipaddr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2020, Broadband Forum 4 | * Copyright (C) 2007-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * @file nu_ipaddr.h 37 | * 38 | * Implements a class that wraps IPv4/v6 address functionality 39 | * 40 | */ 41 | 42 | #ifndef NU_IPADDR_H 43 | #define NU_IPADDR_H 1 44 | 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | #define IPV6_NUIPADDR 1 53 | 54 | #if IPV6_NUIPADDR 55 | #define NU_IPADDRSTRLEN INET6_ADDRSTRLEN 56 | typedef struct in6_addr nu_ipaddr_t; 57 | #else /* IPV6_NUIPADDR */ 58 | #define NU_IPADDRSTRLEN INET_ADDRSTRLEN 59 | typedef struct in_addr nu_ipaddr_t; 60 | #endif /* !IPV6_NUIPADDR */ 61 | 62 | #if BYTE_ORDER == BIG_ENDIAN 63 | #define IP4NETADDR_PRINTF_FMT(_addr) \ 64 | (unsigned int)(((_addr) >> 24) & 0xff), \ 65 | (unsigned int)(((_addr) >> 16) & 0xff), \ 66 | (unsigned int)(((_addr) >> 8) & 0xff), \ 67 | (unsigned int)((_addr) & 0xff) 68 | #else 69 | #define IP4NETADDR_PRINTF_FMT(_addr) \ 70 | (unsigned int)((_addr) & 0xff), \ 71 | (unsigned int)(((_addr) >> 8) & 0xff), \ 72 | (unsigned int)(((_addr) >> 16) & 0xff), \ 73 | (unsigned int)(((_addr) >> 24) & 0xff) 74 | #endif 75 | 76 | /* interface for converting nu_ipaddr_t to standard values */ 77 | int nu_ipaddr_get_family(const nu_ipaddr_t *addr, sa_family_t *familyp); 78 | int nu_ipaddr_to_inaddr(const nu_ipaddr_t *addr, struct in_addr *p); 79 | int nu_ipaddr_to_in6addr(const nu_ipaddr_t *addr, struct in6_addr *p); 80 | int nu_ipaddr_to_sockaddr(const nu_ipaddr_t *addr, int port, struct sockaddr_storage *sa, socklen_t *len_p); 81 | 82 | int nu_ipaddr_to_str(const nu_ipaddr_t *addr, char *buf, int buflen); 83 | char *nu_ipaddr_str(const nu_ipaddr_t *addr, char *buf, int buflen); 84 | int nu_ipaddr_from_str(const char *str, nu_ipaddr_t *addr); 85 | int nu_ipaddr_from_sockaddr_storage(const struct sockaddr_storage *p, nu_ipaddr_t *addr, uint16_t *port); 86 | int nu_ipaddr_from_inaddr(const struct in_addr *p, nu_ipaddr_t *addr); 87 | int nu_ipaddr_from_in6addr(const struct in6_addr *p, nu_ipaddr_t *addr); 88 | 89 | int nu_ipaddr_equal(const nu_ipaddr_t *a1, const nu_ipaddr_t *a2, bool *equalp); 90 | int nu_ipaddr_copy(nu_ipaddr_t *dest, const nu_ipaddr_t *src); 91 | int nu_ipaddr_set_zero(nu_ipaddr_t *addr); 92 | bool nu_ipaddr_is_zero(const nu_ipaddr_t *addrp); 93 | 94 | int nu_ipaddr_get_interface_addr_from_dest_addr(nu_ipaddr_t *dest, nu_ipaddr_t *if_addr); 95 | int nu_ipaddr_get_interface_addr_from_sock_fd(int sock_fd, char *buf, int bufsiz); 96 | int nu_ipaddr_get_interface_name_from_src_addr(char *src_addr, char *name, int name_len); 97 | int nu_ipaddr_has_interface_addr_changed(char *dev, char *expected_addr, bool *has_addr); 98 | int nu_ipaddr_get_ip_supported_families(bool *ipv4_supported, bool *ipv6_supported); 99 | bool nu_ipaddr_is_valid_interface(const char *dev); 100 | char *tw_ulib_diags_family_to_protocol_version(int address_family); 101 | 102 | int tw_ulib_diags_lookup_host(const char *host, int acs_family_pref, bool prefer_ipv6, nu_ipaddr_t *acs_ipaddr_to_bind_to, nu_ipaddr_t *dst); 103 | int tw_ulib_get_dev_ipaddr(const char *dev, char *addr, size_t asiz, bool prefer_ipv6); 104 | 105 | #ifdef CONNECT_ONLY_OVER_WAN_INTERFACE 106 | int tw_ulib_dev_get_live_wan_address(char *buf, size_t bufsiz); 107 | #endif 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /src/core/nu_macaddr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2007-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * @file nu_macaddr.c 37 | * 38 | * Network MAC utilty functions. 39 | * 40 | */ 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | #include "common_defs.h" 53 | #include "nu_macaddr.h" 54 | #include "usp_api.h" 55 | #include "text_utils.h" 56 | 57 | //------------------------------------------------------------------------------ 58 | // String, set by '-i' command line option to specify the network interface to be used by USP communications 59 | char *usp_interface = NULL; 60 | 61 | /*********************************************************************//** 62 | ** 63 | ** nu_macaddr_wan_ifname 64 | ** 65 | ** Returns the name of the WAN interface. 66 | ** This should be the interface that's used to connect to 67 | ** remote network services such as CWMP and XMPP. 68 | ** For example this may be 'eth0' 69 | ** 70 | ** \param None 71 | ** 72 | ** \return pointer to string containing name of the WAN interface 73 | ** 74 | **************************************************************************/ 75 | char *nu_macaddr_wan_ifname(void) 76 | { 77 | char *e; 78 | 79 | // Exit if the network interface was specified by the '-i command line option when invoking this executable 80 | if (usp_interface != NULL) 81 | { 82 | return usp_interface; 83 | } 84 | 85 | // Exit if an environment variable is used to override the interface name 86 | // NOTE: This may be used with docker or with embedded systems still using the 'eth0' style naming convention 87 | e = getenv("USP_BOARD_IFNAME"); 88 | if ((e != NULL) && (*e != '\0')) 89 | { 90 | return e; 91 | } 92 | 93 | return DEFAULT_WAN_IFNAME; 94 | } 95 | 96 | /*********************************************************************//** 97 | ** 98 | ** nu_macaddr_wan_macaddr 99 | ** 100 | ** Returns the MAC address of the WAN interface 101 | ** 102 | ** \param buf - pointer to buffer in which to return MAC address (6 bytes raw) 103 | ** 104 | ** \return USP_ERR_OK if successful 105 | ** 106 | **************************************************************************/ 107 | int nu_macaddr_wan_macaddr(unsigned char *buf) 108 | { 109 | int err; 110 | int sock; 111 | struct ifreq ifr; 112 | 113 | // Set default return MAC address 114 | memset(buf, 0, MAC_ADDR_LEN); 115 | 116 | // Set up which interface we want to get the MAC address of 117 | memset(&ifr, 0x00, sizeof(ifr)); 118 | strcpy(ifr.ifr_name, nu_macaddr_wan_ifname()); 119 | 120 | // Attempt to get the MAC address of the interface 121 | sock = socket(PF_INET, SOCK_DGRAM, 0); 122 | if (sock == -1) 123 | { 124 | USP_ERR_SetMessage("%s: socket() failed. Unable to open a UDP socket (errno=%d, %m)", __FUNCTION__, errno); 125 | return USP_ERR_INTERNAL_ERROR; 126 | } 127 | 128 | err = ioctl(sock, SIOCGIFHWADDR, &ifr); 129 | close(sock); 130 | 131 | // Exit if unable to get the MAC address of the interface 132 | if (err == -1) 133 | { 134 | USP_ERR_SetMessage("%s: ioctl() failed. Unable to get MAC address for interface %s (errno=%d, %m)", __FUNCTION__, ifr.ifr_name, errno); 135 | return USP_ERR_INTERNAL_ERROR; 136 | } 137 | 138 | // Copy MAC address into return buffer 139 | memcpy(buf, ifr.ifr_hwaddr.sa_data, MAC_ADDR_LEN); 140 | 141 | return USP_ERR_OK; 142 | } 143 | -------------------------------------------------------------------------------- /src/core/nu_macaddr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2007-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * @file nu_macaddr.h 37 | * 38 | * Implements a class that wraps MAC address functionality 39 | * 40 | */ 41 | 42 | #ifndef NU_MACADDR_H 43 | #define NU_MACADDR_H 1 44 | 45 | #include 46 | 47 | #define MAC_ADDR_LEN (ETHER_ADDR_LEN) // from 48 | 49 | //------------------------------------------------------------------------------------------------------- 50 | // Network interface specified by the '-i' option 51 | extern char *usp_interface; 52 | 53 | //------------------------------------------------------------------------------------------------------- 54 | // API 55 | char *nu_macaddr_wan_ifname(void); 56 | int nu_macaddr_wan_macaddr(unsigned char *buf); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/core/os_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file os_utils.h 37 | * 38 | * Header file for API to wrapper functions around POSIX Operating System functions, such as creating threads 39 | * 40 | */ 41 | #ifndef OS_UTILS_H 42 | #define OS_UTILS_H 43 | 44 | #include 45 | 46 | //------------------------------------------------------------------------- 47 | // Defines for 'print_warning' argument for OS_UTILS_IsDataModelThread() 48 | #define PRINT_WARNING true 49 | #define DONT_PRINT_WARNING false 50 | 51 | //------------------------------------------------------------------------- 52 | // API functions 53 | int OS_UTILS_CreateThread(void *(* start_routine)(void *), void *args); 54 | void OS_UTILS_SetDataModelThread(void); 55 | bool OS_UTILS_IsDataModelThread(const char *caller, bool print_warning); 56 | int OS_UTILS_InitMutex(pthread_mutex_t *mutex); 57 | void OS_UTILS_LockMutex(pthread_mutex_t *mutex); 58 | void OS_UTILS_UnlockMutex(pthread_mutex_t *mutex); 59 | 60 | #endif 61 | 62 | -------------------------------------------------------------------------------- /src/core/path_resolver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021, Broadband Forum 4 | * Copyright (C) 2016-2021 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file path_resolver.h 37 | * 38 | * Header file for API to functions which resolve path exressions into objects and parameters in the data model 39 | * 40 | */ 41 | #ifndef PATH_RESOLVER_H 42 | #define PATH_RESOLVER_H 43 | 44 | #include "str_vector.h" 45 | 46 | // Enumeration determining what we are attempting to resolve with the path expression 47 | // This affects whether the path is valid, along with which object/parameter paths are returned 48 | typedef enum 49 | { 50 | kResolveOp_Get, // Resolves parameters. Forgiving of permissions and errors. 51 | kResolveOp_Set, // Resolves objects 52 | kResolveOp_Add, // Resolves objects that are not fully qualified 53 | kResolveOp_Del, // Resolves fully qualified objects that exist 54 | kResolveOp_Oper, // Resolves operations (for when a request is made to perform an operation) 55 | kResolveOp_Event, // Resolves events 56 | kResolveOp_Instances, // Resolves fully qualified objects that exist 57 | 58 | // The following operations are similar to their conterparts above, other than they check different permission bits 59 | kResolveOp_SubsValChange, // Resolves the ReferenceList of a value change subscription. Forgiving of errors. 60 | kResolveOp_SubsAdd, // Resolves the ReferenceList of an object creation subscription 61 | kResolveOp_SubsDel, // Resolves the ReferenceList of an object deletion subscription 62 | kResolveOp_SubsOper,// Resolves the ReferenceList of an operation complete subscription 63 | kResolveOp_SubsEvent,// Resolves the ReferenceList of an event complete subscription 64 | 65 | // Special resolve operations 66 | kResolveOp_GetBulkData, // Resolves get parameters. Unforgiving of permissions. Only allows partial path and wildcards. 67 | 68 | kResolveOp_Any, // This just checks that the expression is syntactically correct, but does not check resolved paths for validity 69 | } resolve_op_t; 70 | 71 | // Bitmask for the flags argument of PATH_RESOLVER_ResolvePath(). Thse flags control resolving of the path 72 | #define GET_ALL_INSTANCES 0x0001 73 | 74 | // API 75 | int PATH_RESOLVER_ResolveDevicePath(char *path, str_vector_t *sv, int_vector_t *gv, resolve_op_t op, int *separator_split, combined_role_t *combined_role, unsigned flags); 76 | int PATH_RESOLVER_ResolvePath(char *path, str_vector_t *sv, int_vector_t *gv, resolve_op_t op, int *separator_split, combined_role_t *combined_role, unsigned flags); 77 | 78 | 79 | 80 | #endif 81 | 82 | -------------------------------------------------------------------------------- /src/core/proto_trace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file proto_trace.h 37 | * 38 | * Functions for pretty printing a USP message in protobuf debug format 39 | * 40 | */ 41 | #ifndef PROTO_TRACE_H 42 | #define PROTO_TRACE_H 43 | 44 | #include 45 | 46 | //------------------------------------------------------------------------------ 47 | // API Functions 48 | void PROTO_TRACE_ProtobufMessage(ProtobufCMessage *msg); 49 | 50 | 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /src/core/retry_wait.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2018-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file retry_wait.h 37 | * 38 | * Calculates a time to wait between retries according to the standard TR069 algorithm, detailed in:- 39 | * TR-069 Section 3.2.1.1 Session Retry 40 | * TR-157 Section A.2.2.1 41 | * 42 | * This algorithm is used for :- 43 | * STOMP connection retries 44 | * bulk data collection post retries 45 | * subscription notification retries 46 | * 47 | */ 48 | 49 | #ifndef RETRY_WAIT_H 50 | #define RETRY_WAIT_H 1 51 | 52 | unsigned RETRY_WAIT_Calculate(unsigned retry_count, double m, double k); 53 | 54 | //---------------------------------------------------- 55 | // Random number generator seeds used by each thread 56 | extern unsigned dm_thread_random_seed; 57 | extern unsigned mtp_thread_random_seed; 58 | 59 | //---------------------------------------------------- 60 | // API 61 | void RETRY_WAIT_Init(void); 62 | unsigned RETRY_WAIT_Calculate(unsigned retry_count, double m, double k); 63 | time_t RETRY_WAIT_UseRandomBaseIfUnknownTime(time_t base); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/core/rfc1123.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * @file rfc1123.c 37 | * 38 | * RFC1123 Time Format string utilities 39 | * 40 | */ 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "common_defs.h" 47 | #include "rfc1123.h" 48 | 49 | // RFC1123 dates are specified independant of locale, hence we need to use the arrays here, rather than the 50 | // locale-respecting ones built into strftime() 51 | const char *rfc1123_day[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; 52 | const char *rfc1123_month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; 53 | 54 | 55 | /*********************************************************************//** 56 | ** 57 | ** RFC1123_GetCurTime 58 | ** 59 | ** Gets the current UTC time in an RFC1123 string format 60 | ** 61 | ** \param buf - pointer to buffer in which to return the string 62 | ** \param len - length of buffer. Must be at least 23 bytes long. 63 | ** 64 | ** \return pointer to string (i.e. supplied buffer) 65 | ** 66 | **************************************************************************/ 67 | char *RFC1123_GetCurTime(char *buf, int len) 68 | { 69 | time_t t; 70 | 71 | time(&t); 72 | return RFC1123_FromUnixTime(t, buf, len); 73 | } 74 | 75 | /*********************************************************************//** 76 | ** 77 | ** RFC1123_FromUnixTime 78 | ** 79 | ** Given a time_t converts it to an RFC1123 date format string 80 | ** 81 | ** \param unix_time - time in seconds since the epoch (UTC) 82 | ** \param buf - pointer to buffer in which to return the string 83 | ** \param len - length of buffer. Must be at least 30 bytes long. 84 | ** 85 | ** \return pointer to string (i.e. supplied buffer) 86 | ** 87 | **************************************************************************/ 88 | char *RFC1123_FromUnixTime(time_t unix_time, char *buf, int len) 89 | { 90 | struct tm tm; 91 | 92 | gmtime_r(&unix_time, &tm); 93 | 94 | USP_SNPRINTF(buf, len, "%s, %d %s %d %02d:%02d:%02d GMT", 95 | rfc1123_day[tm.tm_wday], 96 | tm.tm_mday, 97 | rfc1123_month[tm.tm_mon], 98 | 1900 + tm.tm_year, 99 | tm.tm_hour, 100 | tm.tm_min, 101 | tm.tm_sec); 102 | return buf; 103 | } 104 | 105 | 106 | -------------------------------------------------------------------------------- /src/core/rfc1123.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * @file rfc1123.h 37 | * 38 | * RFC1123 Time Format string utilities 39 | * 40 | */ 41 | #include 42 | 43 | #ifndef _RFC1123_H_ 44 | #define _RFC1123 45 | 46 | char *RFC1123_GetCurTime(char *buf, int len); 47 | char *RFC1123_FromUnixTime(time_t unix_time, char *buf, int len); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/core/socket_set.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file socket_set.h 37 | * 38 | * Basic abstraction around read and write socket sets, with a timeout 39 | * 40 | */ 41 | #ifndef SOCKET_SET_H 42 | #define SOCKET_SET_H 43 | 44 | #include 45 | 46 | //------------------------------------------------------------------------------ 47 | // Maximum socket timeout that the code uses - 1 hour in milliseconds 48 | #define MAX_SOCKET_TIMEOUT_SECONDS 3600 49 | #define MAX_SOCKET_TIMEOUT (MAX_SOCKET_TIMEOUT_SECONDS*SECONDS) 50 | 51 | //------------------------------------------------------------------------------ 52 | // Socket set structure 53 | typedef struct 54 | { 55 | int numfds; 56 | fd_set readfds; 57 | fd_set writefds; 58 | fd_set execfds; 59 | struct timeval timeout; 60 | } socket_set_t; 61 | 62 | //------------------------------------------------------------------------------ 63 | // API functions 64 | void SOCKET_SET_Clear(socket_set_t *set); 65 | void SOCKET_SET_AddSocketToReceiveFrom(int sock_fd, int timeout, socket_set_t *set); 66 | void SOCKET_SET_AddSocketToSendTo(int sock_fd, int timeout, socket_set_t *set); 67 | void SOCKET_SET_UpdateTimeout(int timeout, socket_set_t *set); 68 | int SOCKET_SET_IsReadyToWrite(int sock, socket_set_t *set); 69 | int SOCKET_SET_IsReadyToRead(int sock, socket_set_t *set); 70 | int SOCKET_SET_Select(socket_set_t *set); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/core/stomp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file stomp.h 37 | * 38 | * Header file for STOMP connection 39 | * 40 | */ 41 | #ifndef STOMP_H 42 | #define STOMP_H 43 | 44 | #include 45 | #include 46 | 47 | #include "dllist.h" 48 | #include "socket_set.h" 49 | #include "mtp_exec.h" 50 | #include "usp-msg.pb-c.h" 51 | 52 | //------------------------------------------------------------------------------ 53 | // Structure containing the parameters controlling STOMP retries 54 | typedef struct 55 | { 56 | unsigned initial_interval; 57 | unsigned interval_multiplier; 58 | unsigned max_interval; 59 | } stomp_retry_params_t; 60 | 61 | //------------------------------------------------------------------------------ 62 | // Data model parameters for each stomp connection 63 | typedef struct 64 | { 65 | int instance; // instance of this connection in the Device.STOMP.Connection.{i} table. Set to INVALID, if this entry is not used. 66 | bool enable; 67 | char *host; 68 | unsigned port; 69 | char *username; 70 | char *password; 71 | bool enable_encryption; 72 | char *virtual_host; 73 | bool enable_heartbeats; 74 | unsigned incoming_heartbeat_period; // in ms. NOTE: the negotiated heartbeat_period is stored in seconds 75 | unsigned outgoing_heartbeat_period; // in ms 76 | stomp_retry_params_t retry; // parameters associated with retrying the connection after a failure 77 | } stomp_conn_params_t; 78 | 79 | //------------------------------------------------------------------------------ 80 | // API 81 | int STOMP_Init(void); 82 | void STOMP_Destroy(void); 83 | int STOMP_Start(void); 84 | void STOMP_UpdateAllSockSet(socket_set_t *set); 85 | bool STOMP_AreAllResponsesSent(void); 86 | void STOMP_ProcessAllSocketActivity(socket_set_t *set); 87 | int STOMP_QueueBinaryMessage(Usp__Header__MsgType usp_msg_type, int instance, char *controller_queue, char *agent_queue, unsigned char *pbuf, int pbuf_len, mtp_content_type_t content_type, char *err_id_header, time_t expiry_time); 88 | int STOMP_EnableConnection(stomp_conn_params_t *sp, char *stomp_queue); 89 | int STOMP_DisableConnection(int instance, bool purge_queued_messages); 90 | void STOMP_ScheduleReconnect(stomp_conn_params_t *sp, char *stomp_queue); 91 | void STOMP_ActivateScheduledActions(void); 92 | void STOMP_ScheduleResubscribe(int instance, char *stomp_queue); 93 | mtp_status_t STOMP_GetMtpStatus(int instance); 94 | char *STOMP_GetConnectionStatus(int instance, time_t *last_change_date); 95 | void STOMP_UpdateRetryParams(int instance, stomp_retry_params_t *retry_params); 96 | void STOMP_GetDestinationFromServer(int instance, char *buf, int len); 97 | 98 | 99 | // Readability definitions for 'purge_queued_messages' argument of STOMP_StopConnection() 100 | #define PURGE_QUEUED_MESSAGES true 101 | #define DONT_PURGE_QUEUED_MESSAGES false 102 | 103 | #endif 104 | 105 | -------------------------------------------------------------------------------- /src/core/str_vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file str_vector.h 37 | * 38 | * Implements a vector of strings 39 | * 40 | */ 41 | 42 | #ifndef STR_VECTOR_H 43 | #define STR_VECTOR_H 44 | 45 | //----------------------------------------------------------------------------------------- 46 | // String vector type 47 | typedef struct 48 | { 49 | char **vector; 50 | int num_entries; 51 | } str_vector_t; 52 | 53 | //----------------------------------------------------------------------------------------- 54 | #include "kv_vector.h" 55 | 56 | //----------------------------------------------------------------------------------------- 57 | // String Vector API 58 | void STR_VECTOR_Init(str_vector_t *sv); 59 | void STR_VECTOR_Clone(str_vector_t *sv, char **src_vector, int src_num_entries); 60 | void STR_VECTOR_Add(str_vector_t *sv, char *str); 61 | void STR_VECTOR_Add_IfNotExist(str_vector_t *sv, char *str); 62 | int STR_VECTOR_Find(str_vector_t *sv, char *str); 63 | void STR_VECTOR_Destroy(str_vector_t *sv); 64 | void STR_VECTOR_Dump(str_vector_t *sv); 65 | void STR_VECTOR_ConvertToKeyValueVector(str_vector_t *sv, kv_vector_t *kvv); 66 | bool STR_VECTOR_Compare(str_vector_t *sv1, str_vector_t *sv2); 67 | void STR_VECTOR_Sort(str_vector_t *sv); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/core/subs_retry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file subs_retry.h 37 | * 38 | * Header file for API to functions which retry sending a NotifyRequest message 39 | * 40 | */ 41 | #ifndef SUBS_RETRY_H 42 | #define SUBS_RETRY_H 43 | 44 | #include "usp-msg.pb-c.h" 45 | 46 | void SUBS_RETRY_Init(void); 47 | void SUBS_RETRY_Stop(void); 48 | void SUBS_RETRY_Add(int instance, char *msg_id, char *subscription_id, char *dest_endpoint, char *differentiator, 49 | unsigned char *pbuf, int pbuf_len, time_t retry_expiry_time); 50 | void SUBS_RETRY_Remove(char *msg_id, char *subscription_id); 51 | void SUBS_RETRY_Delete(int instance); 52 | 53 | 54 | #endif 55 | 56 | -------------------------------------------------------------------------------- /src/core/subs_vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file subs_vector.h 37 | * 38 | * Implements a vector of subscriptions 39 | * 40 | */ 41 | 42 | #ifndef SUBS_VECTOR_H 43 | #define SUBS_VECTOR_H 44 | 45 | #include 46 | 47 | #include "common_defs.h" 48 | #include "str_vector.h" 49 | #include "kv_vector.h" 50 | 51 | //------------------------------------------------------------------------------ 52 | // Enumeration of types of subscriptions 53 | typedef enum 54 | { 55 | kSubNotifyType_Invalid = INVALID, // Used to mark a subscription for garbage collection and also as a return value if we failed to convert the textual representation of this enum 56 | kSubNotifyType_None = 0, // This is the default value for the notification type parameter - indicates none setup yet 57 | kSubNotifyType_ValueChange = 1, 58 | kSubNotifyType_ObjectCreation, 59 | kSubNotifyType_ObjectDeletion, 60 | kSubNotifyType_OperationComplete, 61 | kSubNotifyType_Event, 62 | 63 | kSubNotifyType_Max // This should always be the last value in this enumeration. It is used to statically size arrays based on one entry for each active enumeration 64 | } subs_notify_t; 65 | 66 | //------------------------------------------------------------------------------ 67 | // Element of subscription vector 68 | typedef struct 69 | { 70 | bool enable; // Whether this subscription is enabled or not 71 | int instance; // Instance number of the subscription in the data model (Device.LocalAgent.Subscription.{i}) 72 | int cont_instance; // Instance number of the recipient controller in Device.LocalAgent.Controller.{i} 73 | char *subscription_id; // Device.LocalAgent.Subscription.{i}.ID 74 | bool notification_retry; // Device.LocalAgent.Subscription.{i}.NotifRetry 75 | str_vector_t path_expressions; // Device.LocalAgent.Subscription.{i}.ReferenceList 76 | subs_notify_t notify_type; // Device.LocalAgent.Subscription.{i}.NotifType 77 | time_t expiry_time; // Time at which this subscription should be stopped and removed from the DB 78 | unsigned retry_expiry_period; // Device.LocalAgent.Subscription.{i}.NotifExpiration 79 | kv_vector_t last_values; // List of parameters+values from last time that the subscription was polled (if the subscription is a value change subscription) 80 | str_vector_t resolved_paths; // Used to cache the resolved paths of an object deletion subscription before the object has been deleted from the data model 81 | } subs_t; 82 | 83 | //------------------------------------------------------------------------------ 84 | // Vector of enabled subscriptions 85 | typedef struct 86 | { 87 | int num_entries; 88 | subs_t *vector; 89 | } subs_vector_t; 90 | 91 | //----------------------------------------------------------------------------------------- 92 | // Subscription Vector API 93 | void SUBS_VECTOR_Init(subs_vector_t *sv); 94 | void SUBS_VECTOR_Add(subs_vector_t *sv, subs_t *sub); 95 | void SUBS_VECTOR_Remove(subs_vector_t *sv, subs_t *sub); 96 | void SUBS_VECTOR_Destroy(subs_vector_t *sv); 97 | void SUBS_VECTOR_DestroySubscriber(subs_t *sub); 98 | subs_t *SUBS_VECTOR_GetSubsByInstance(subs_vector_t *suv, int instance); 99 | void SUBS_VECTOR_MarkSubscriptionForDeletion(subs_t *sub); 100 | void SUBS_VECTOR_GarbageCollectSubscriptions(subs_vector_t *suv); 101 | void SUBS_VECTOR_Dump(subs_vector_t *suv); 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /src/core/sync_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file sync_timer.h 37 | * 38 | * Implements a basic periodic timer mechanism 39 | * 40 | */ 41 | 42 | #ifndef SYNC_TIMER_H 43 | #define SYNC_TIMER_H 44 | 45 | #include 46 | 47 | //-------------------------------------------------------------------------------------- 48 | // Callback function for timer 49 | typedef void (*timer_cb_t)(int id); 50 | 51 | //----------------------------------------------------------------------------------------- 52 | // API 53 | void SYNC_TIMER_Init(void); 54 | void SYNC_TIMER_Destroy(void); 55 | int SYNC_TIMER_Add(timer_cb_t timer_cb, int id, time_t callback_time); 56 | int SYNC_TIMER_Reload(timer_cb_t timer_cb, int id, time_t callback_time); 57 | int SYNC_TIMER_Remove(timer_cb_t timer_cb, int id); 58 | int SYNC_TIMER_TimeToNext(void); 59 | void SYNC_TIMER_Execute(void); 60 | void *SYNC_TIMER_PRIV_GetVector(int *allocated_size); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/core/text_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021, Broadband Forum 4 | * Copyright (C) 2016-2021 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file text_utils.h 37 | * 38 | * Header file for API to convert and validate types from strings 39 | * 40 | */ 41 | #ifndef TEXT_UTILS_H 42 | #define TEXT_UTILS_H 43 | 44 | #include "str_vector.h" 45 | #include "nu_ipaddr.h" 46 | #include "data_model.h" // for dm_hash_t 47 | 48 | //------------------------------------------------------------------------- 49 | // Macros associated with performing the FNV1a hashing algorithm 50 | #define OFFSET_BASIS (0x811C9DC5) 51 | #define FNV_PRIME (0x1000193) 52 | #define ADD_TO_HASH(c, hash) hash = hash*FNV_PRIME; hash = hash^(c); 53 | 54 | //------------------------------------------------------------------------- 55 | // Definitions for bits within flags argument of TEXT_UTILS_PercentEncodeString() and TEXT_UTILS_ValueToHexDigit() 56 | #define USE_UPPERCASE_HEX_DIGITS 0x00000000 57 | #define USE_LOWERCASE_HEX_DIGITS 0x00000001 58 | 59 | //------------------------------------------------------------------------- 60 | // API functions 61 | dm_hash_t TEXT_UTILS_CalcHash(char *s); 62 | int TEXT_UTILS_StringToUnsigned(char *str, unsigned *value); 63 | int TEXT_UTILS_StringToInteger(char *str, int *value); 64 | int TEXT_UTILS_StringToUnsignedLongLong(char *str, unsigned long long *value); 65 | int TEXT_UTILS_StringToBool(char *str, bool *value); 66 | char *TEXT_UTILS_BoolToString(bool value); 67 | int TEXT_UTILS_StringToEnum(char *str, const enum_entry_t *enums, int num_enums); 68 | char *TEXT_UTILS_EnumToString(int value, const enum_entry_t *enums, int num_enums); 69 | int TEXT_UTILS_StringToDateTime(char *str, time_t *value); 70 | int TEXT_UTILS_StringToBinary(char *str, unsigned char *buf, int len, int *bytes_written); 71 | int TEXT_UTILS_Base64StringToBinary(char *str, unsigned char *buf, int len, int *bytes_written); 72 | int TEXT_UTILS_StringToIpAddr(char *str, nu_ipaddr_t *ip_addr); 73 | char *TEXT_UTILS_SplitPath(char *path, char *buf, int len); 74 | char *TEXT_UTILS_SplitPathAtSeparator(char *path, char *buf, int len, int separator_split); 75 | void TEXT_UTILS_ListToString(char **items, int num_items, char *buf, int len); 76 | void TEXT_UTILS_SplitString(char *str, str_vector_t *sv, char *separator); 77 | void TEXT_UTILS_StrncpyLen(char *dst, int dst_len, char *src, int src_len); 78 | char *TEXT_UTILS_StrStr(char *haystack, char *needle); 79 | int TEXT_UTILS_NullStringCompare(char *str1, char *str2); 80 | void TEXT_UTILS_PercentEncodeString(char *src, char *dst, int dst_len, char *safe_chars, unsigned flags); 81 | void TEXT_UTILS_PercentDecodeString(char *buf); 82 | void TEXT_UTILS_ReplaceCharInString(char *src, char match_char, char *replacement, char *dst, int dst_len); 83 | char *TEXT_UTILS_TrimBuffer(char *buf); 84 | void TEXT_UTILS_StripChars(char *strip, char *src, char *dest, int dest_len); 85 | int TEXT_UTILS_HexStringToValue(char *s); 86 | int TEXT_UTILS_HexDigitToValue(char c); 87 | char TEXT_UTILS_ValueToHexDigit(int nibble, unsigned flags); 88 | void TEXT_UTILS_PathToSchemaForm(char *path, char *buf, int len); 89 | int TEXT_UTILS_CountConsecutiveDigits(char *p); 90 | char *TEXT_UTILS_StrDupWithTrailingDot(char *path); 91 | int TEXT_UTILS_KeyValueFromString(char *buf, char **key, char **value); 92 | 93 | #endif 94 | 95 | -------------------------------------------------------------------------------- /src/core/uptime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2008-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * @file uptime.c 37 | * 38 | * Container for non POSIX compliant time functions 39 | * 40 | */ 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include "uptime.h" 48 | 49 | /*********************************************************************//** 50 | ** 51 | ** tu_uptime_msecs 52 | ** 53 | ** Returns the number of milli-seconds since the kernel was rebooted 54 | ** 55 | ** \param None 56 | ** 57 | ** \return Number of milli-seconds 58 | ** 59 | **************************************************************************/ 60 | uint32_t 61 | tu_uptime_msecs(void) 62 | { 63 | time_t t; 64 | struct timespec ts; 65 | 66 | clock_gettime(CLOCK_MONOTONIC, &ts); 67 | t = ((time_t)(ts.tv_sec * 1000) + (time_t)(ts.tv_nsec / 1000000)); 68 | return (uint32_t)t; 69 | } 70 | 71 | /*********************************************************************//** 72 | ** 73 | ** tu_uptime_secs 74 | ** 75 | ** Returns the number of seconds since the kernel was rebooted 76 | ** 77 | ** \param None 78 | ** 79 | ** \return Number of seconds 80 | ** 81 | **************************************************************************/ 82 | uint32_t 83 | tu_uptime_secs(void) 84 | { 85 | time_t t; 86 | struct timespec ts; 87 | 88 | clock_gettime(CLOCK_MONOTONIC, &ts); 89 | t = (time_t)ts.tv_sec; 90 | return (uint32_t)t; 91 | } 92 | 93 | -------------------------------------------------------------------------------- /src/core/uptime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2008-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * @file uptime.h 37 | * 38 | * Container for non POSIX compliant time functions 39 | * 40 | */ 41 | 42 | #ifndef UPTIME_H 43 | 44 | #include 45 | #include 46 | 47 | uint32_t tu_uptime_msecs(void); 48 | uint32_t tu_uptime_secs(void); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/core/uri.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2008-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | 36 | /** 37 | * @file uri.c 38 | * 39 | * Uniform Resource Identifier utilities 40 | * 41 | */ 42 | 43 | -------------------------------------------------------------------------------- /src/core/uri.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2001-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * @file uri.h 37 | * 38 | * Uniform Resource Identifier (URI) utility functions 39 | * 40 | * Future specifications and related documentation should 41 | * use the general term "URI" rather than the more restrictive terms 42 | * "URL" and "URN" [RFC3305] 43 | * 44 | * @version $Id: //depot/nmd/exodus/pace/libs/libnetutil/include/libnetutil/uri.h#1 $ 45 | */ 46 | 47 | #ifndef _LIBNETUTIL_URI_H_ 48 | #define _LIBNETUTIL_URI_H_ 1 49 | 50 | #include 51 | 52 | /* RFC4395 defines an IANA-maintained register of URI Schemes. 53 | * 54 | * See http://www.iana.org/assignments/uri-schemes.html 55 | */ 56 | enum nu_uri_e { 57 | URISCHEME_UNKNOWN, 58 | 59 | URISCHEME_HTTP, /* See RFC2616, RFC3986 */ 60 | URISCHEME_HTTPS, /* See RFC2618, RFC3986 */ 61 | URISCHEME_FTP, /* See RFC1738 */ 62 | URISCHEME_SFTP, // SSH FTP 63 | URISCHEME_TELNET, /* See RFC1738, RFC4248 */ 64 | URISCHEME_FILE, /* See RFC1738 */ 65 | URISCHEME_MAILTO, /* See RFC2368 */ 66 | URISCHEME_LDAP, /* See RFC1959, RFC2255, RFC4516 */ 67 | URISCHEME_SIP, /* See RFC3261 */ 68 | URISCHEME_SIPS, /* See RFC3261 */ 69 | URISCHEME_TEL, /* See RFC3966 */ 70 | 71 | /* 2Wire schemes */ 72 | URISCHEME_CIFS, 73 | URISCHEME_TWCSS, 74 | URISCHEME_RPC, 75 | URISCHEME_TWRPC, 76 | URISCHEME_TWRPCS, 77 | }; 78 | 79 | typedef struct nu_uri_s { 80 | enum nu_uri_e u_type; 81 | 82 | const char *u_scheme; 83 | size_t u_schemesz; 84 | 85 | /* Per RFC 1738 Section 3.1. Common Internet Scheme Syntax 86 | * //:@:/ 87 | * 88 | * Per RFC 2396 Section 3. URI Syntactic Components 89 | * : 90 | * This generic URI syntax considers of four main components 91 | * ://? 92 | * 93 | * Per RFC 3986 Section 3. Syntax Components 94 | * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] 95 | * 96 | * hier-part = "//" authority path-abempty 97 | * / path-absolute 98 | * / path-rootless 99 | * / path-empty 100 | * 101 | * From the above RFCs, the following elements are parsed out 102 | * in a generic fashion. 103 | */ 104 | 105 | /* Authority component */ 106 | const char *u_user; 107 | size_t u_usersz; 108 | const char *u_password; 109 | size_t u_passwordsz; 110 | const char *u_host; 111 | size_t u_hostsz; 112 | const char *u_port; 113 | size_t u_portsz; 114 | 115 | /* Path component */ 116 | const char *u_path; /* start of the path */ 117 | size_t u_pathsz; 118 | 119 | /* Query component */ 120 | const char *u_query; 121 | size_t u_querysz; 122 | 123 | /* Fragment component */ 124 | const char *u_fragment; 125 | size_t u_fragmentsz; 126 | } nu_uri_t; 127 | 128 | /* Split the passed in string into its component parts */ 129 | int nu_uri_from_str(nu_uri_t *uri, const char *str); 130 | 131 | /* Reassemble a string from it's split component parts */ 132 | int nu_uri_to_str(nu_uri_t *nu_uri, char *str, int len); 133 | 134 | 135 | #endif /* !_LIBNETUTIL_URI_H_ */ 136 | -------------------------------------------------------------------------------- /src/core/usp_err.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2020, Broadband Forum 4 | * Copyright (C) 2016-2020 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file usp_err.h 37 | * 38 | * Header file for USP error codes and Error buffer 39 | * The error buffer is used to store error message in the function that generated them, 40 | * for use by functions higher up the call chain (eg to put in a USP response message) 41 | * 42 | */ 43 | #ifndef USP_ERR_H 44 | #define USP_ERR_H 45 | 46 | #include "usp_err_codes.h" 47 | #include 48 | 49 | //------------------------------------------------------------------------------------ 50 | // Functions to set and get the error message associated with the error 51 | #define USP_ERR_MAXLEN 512 // Maximum size of buffer used to store log messages (NOTE: This may be multiple lines eg STOMP header) 52 | void USP_ERR_Init(void); 53 | void USP_ERR_SetMessage_Sql(const char *func, int line, const char *sqlfunc, void *db_handle); 54 | void USP_ERR_SetMessage_SqlParam(const char *func, int line, const char *sqlfunc, void *db_handle); 55 | char *USP_ERR_ToString(int err, char *buf, int len); 56 | char *USP_ERR_UspErrToString(int err); 57 | void USP_ERR_SetMessage_Errno(const char *func, int line, const char *failed_func, int err); 58 | void USP_ERR_ClearMessage(void); 59 | void USP_ERR_ReplaceEmptyMessage(char *fmt, ...) __attribute__((format(printf, 1, 2))); 60 | char *USP_ERR_GetMessage(void); 61 | 62 | //------------------------------------------------------------------------------------ 63 | // Helper macros, so that the code does not have to provide (__FUNCTION__, __LINE__) to the underlying function 64 | #define USP_ERR_SQL(handle, sqlfunc) USP_ERR_SetMessage_Sql(__FUNCTION__, __LINE__, sqlfunc, handle) 65 | #define USP_ERR_SQL_PARAM(handle, sqlfunc) USP_ERR_SetMessage_SqlParam(__FUNCTION__, __LINE__, sqlfunc, handle) 66 | #define USP_ERR_ERRNO(failed_func, err) USP_ERR_SetMessage_Errno(__FUNCTION__, __LINE__, failed_func, err) 67 | 68 | //------------------------------------------------------------------------------------ 69 | // Macro to only apply the analyzer_noreturn compiler attribute when using CLang static analyser 70 | // because otherwise GCC complains about it being an unknown attribute 71 | #ifdef __clang_analyzer__ 72 | #define _attribute_analyzer_noreturn __attribute__((analyzer_noreturn)) 73 | #else 74 | #define _attribute_analyzer_noreturn 75 | #endif 76 | 77 | //------------------------------------------------------------------------------------ 78 | // Functions to exit USP Agent because an error has occurred 79 | void USP_ERR_Terminate(char *fmt, ...) __attribute__((format(printf, 1, 2))) _attribute_analyzer_noreturn; 80 | void USP_ERR_Terminate_BadCase(const char *func, int line, int value) _attribute_analyzer_noreturn; 81 | void USP_ERR_Terminate_OnAssert(const char *func, int line, char *statement) _attribute_analyzer_noreturn; 82 | 83 | //------------------------------------------------------------------------------------ 84 | // Helper macros, so that the code does not have to provide (__FUNCTION__, __LINE__) to the underlying function 85 | #define TERMINATE_BAD_CASE(x) USP_ERR_Terminate_BadCase(__FUNCTION__, __LINE__, x) 86 | #define USP_ASSERT(x) if (!(x)) { USP_ERR_Terminate_OnAssert(__FUNCTION__, __LINE__, #x); } 87 | 88 | // static_assert introduce in C11, make sure we can compile on older compilers 89 | #ifdef static_assert 90 | #define USP_COMPILEASSERT(expr, message) static_assert(expr, message) 91 | #else 92 | #define USP_COMPILEASSERT(expr, message) int _static_assert[expr ? 1 : -1] 93 | #endif 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /src/core/usp_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021, Broadband Forum 4 | * Copyright (C) 2016-2021 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file usp_log.h 37 | * 38 | * Header file for USP low leel logging functionality 39 | * 40 | */ 41 | #ifndef USP_LOG_H 42 | #define USP_LOG_H 43 | 44 | //------------------------------------------------------------------------------------ 45 | // Enumeration for type of information being logged 46 | typedef enum 47 | { 48 | kLogLevel_Off = 0, 49 | kLogLevel_Error = 1, 50 | kLogLevel_Warning = 2, 51 | kLogLevel_Info = 3, 52 | kLogLevel_Debug = 4, 53 | 54 | kLogLevel_Max // This should always be the last value in the enum 55 | } log_level_t; 56 | 57 | //------------------------------------------------------------------------------------ 58 | // Enumeration for type of information being logged 59 | typedef enum 60 | { 61 | kLogType_Debug, 62 | kLogType_Dump, 63 | kLogType_Protocol 64 | } log_type_t; 65 | 66 | //------------------------------------------------------------------------------------ 67 | // API 68 | void USP_LOG_Init(void); 69 | int USP_LOG_SetFile(const char *file); 70 | void USP_LOG_Callstack(void); 71 | void USP_LOG_HexBuffer(const char *title, const unsigned char *buf, int len); 72 | void USP_LOG_String(log_type_t log_type, char *str); 73 | void USP_LOG_Printf(log_type_t log_type, const char *fmt, ...) __attribute__((format(printf, 2, 3))); 74 | void USP_LOG_Puts(log_type_t log_type, const char *str); 75 | void USP_LOG_ErrorSSL(const char *func_name, const char *failure_string, int ret, int err); 76 | 77 | //------------------------------------------------------------------------------------ 78 | // Macros used for normal debug logging 79 | extern log_level_t usp_log_level; 80 | extern bool enable_protocol_trace; 81 | extern bool enable_callstack_debug; 82 | 83 | #define USP_LOG_Error(...) if (usp_log_level >= kLogLevel_Error) { USP_LOG_Printf(kLogType_Debug, __VA_ARGS__); if (enable_callstack_debug) { USP_LOG_Callstack(); } } 84 | #define USP_LOG_Warning(...) if (usp_log_level >= kLogLevel_Warning) { USP_LOG_Printf(kLogType_Debug, __VA_ARGS__); } 85 | #define USP_LOG_Info(...) if (usp_log_level >= kLogLevel_Info) { USP_LOG_Printf(kLogType_Debug, __VA_ARGS__); } 86 | #define USP_LOG_Debug(...) if (usp_log_level >= kLogLevel_Debug) { USP_LOG_Printf(kLogType_Debug, __VA_ARGS__); } 87 | 88 | // Macro used to dump out the data model/database etc 89 | #define USP_DUMP(...) USP_LOG_Printf(kLogType_Dump, __VA_ARGS__) 90 | 91 | // Macro used to print out STOMP frames 92 | #define USP_PROTOCOL(...) USP_LOG_Printf(kLogType_Protocol, __VA_ARGS__) 93 | 94 | // Maximum number of characters in a single log statement 95 | #define USP_LOG_MAXLEN (10*1024) 96 | #endif 97 | -------------------------------------------------------------------------------- /src/core/usp_mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021, Broadband Forum 4 | * Copyright (C) 2016-2021 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file usp_mem.h 37 | * 38 | * Header file for functions which wrap memory allocation on USP Agent 39 | * 40 | */ 41 | #ifndef USP_MEM_H 42 | #define USP_MEM_H 43 | 44 | #include "compiler.h" 45 | 46 | //------------------------------------------------------------------------------------ 47 | // Helper macros, so that the code does not have to provide (__FUNCTION__, __LINE__) to the underlying function 48 | #define USP_MALLOC(x) USP_MEM_Malloc(__FUNCTION__, __LINE__, x) 49 | #define USP_FREE(x) USP_MEM_Free(__FUNCTION__, __LINE__, x) 50 | #define USP_SAFE_FREE(x) if (x != NULL) { USP_MEM_Free(__FUNCTION__, __LINE__, x); x = NULL; } 51 | #define USP_REALLOC(x, y) USP_MEM_Realloc(__FUNCTION__, __LINE__, x, y) 52 | #define USP_STRDUP(x) USP_MEM_Strdup(__FUNCTION__, __LINE__, x) 53 | 54 | //------------------------------------------------------------------------------------ 55 | // Functions wrapping memory allocation 56 | int USP_MEM_Init(void); 57 | void USP_MEM_Destroy(void); 58 | void *USP_MEM_Malloc(const char *func, int line, int size) ARGS_NONNULL MALLOC RETURNS_NONNULL; 59 | void USP_MEM_Free(const char *func, int line, void *ptr) ARGS_NONNULL; 60 | void *USP_MEM_Realloc(const char *func, int line, void *ptr, int size) ARGINDEX_NONNULL(1) MALLOC RETURNS_NONNULL; 61 | void *USP_MEM_Strdup(const char *func, int line, void *ptr) ARGINDEX_NONNULL(1) MALLOC; 62 | void USP_MEM_StartCollection(void); 63 | void USP_MEM_StopCollection(void); 64 | void USP_MEM_Print(void); 65 | void USP_MEM_PrintSummary(void); 66 | int USP_MEM_PrintLeakReport(void); 67 | int USP_MEM_PrintAll(void); 68 | void MAIN_Stop(void); 69 | 70 | // Pointer to structure containing the protocol buffer allocator function 71 | extern void *pbuf_allocator; 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/core/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021, Broadband Forum 4 | * Copyright (C) 2016-2021 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file version.h 37 | * 38 | * USP Agent Software version number file 39 | * 40 | */ 41 | 42 | /* Lines below main version may include patch version numbers */ 43 | #define AGENT_SOFTWARE_VERSION "4.1.0" 44 | -------------------------------------------------------------------------------- /src/core/wsclient.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2021, Broadband Forum 4 | * Copyright (C) 2021 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file wsclient.h 37 | * 38 | * Header file for WebSockets connection 39 | * 40 | */ 41 | #ifndef WSCLIENT_H 42 | #define WSCLIENT_H 43 | 44 | #include "common_defs.h" 45 | #include "usp-msg.pb-c.h" 46 | #include "device.h" // for mtp_reply_to_t 47 | 48 | 49 | //------------------------------------------------------------------------------ 50 | // Structure containing WebSocket client configuration parameters 51 | typedef struct 52 | { 53 | char *host; // Host to send USP messages to the controller on 54 | unsigned port; // Port to send USP messages to the controller on 55 | char *path; // Path to send USP messages to the controller on 56 | bool enable_encryption; // Set if the connection should use TLS 57 | unsigned keep_alive_interval; // Number of seconds between transmitting Websock PING frames 58 | unsigned retry_interval; // Interval constant to use when calculating the exponential backoff period, when retrying a connection 59 | unsigned retry_multiplier; // Multiplier constant to use when calculating the exponential backoff period, when retrying a connection 60 | } wsclient_config_t; 61 | 62 | //------------------------------------------------------------------------------ 63 | // API 64 | int WSCLIENT_Init(void); 65 | void WSCLIENT_Destroy(void); 66 | int WSCLIENT_Start(void); 67 | void WSCLIENT_StartClient(int cont_instance, int mtp_instance, char *cont_endpoint_id, wsclient_config_t *config); 68 | void WSCLIENT_StopClient(int cont_instance, int mtp_instance); 69 | void WSCLIENT_ActivateScheduledActions(void); 70 | void WSCLIENT_QueueBinaryMessage(Usp__Header__MsgType usp_msg_type, int cont_instance, int mtp_instance, 71 | unsigned char *pbuf, int pbuf_len, mtp_content_type_t content_type, time_t expiry_time); 72 | unsigned WSCLIENT_GetRetryCount(int cont_instance, int mtp_instance); 73 | void *WSCLIENT_Main(void *args); 74 | 75 | //------------------------------------------------------------------------------ 76 | // Exported global variables 77 | extern bool is_wsclient_mtp_thread_exited; 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /src/include/compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2020, Broadband Forum 4 | * Copyright (C) 2012-2020 Axiros GmbH 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | /** 35 | * \file compiler.h 36 | * 37 | * Header file containing defines for function annotation to aid in statical code analysis 38 | * 39 | */ 40 | 41 | #ifndef COMPILER_H 42 | #define COMPILER_H 43 | 44 | #ifndef __has_builtin 45 | #define __has_builtin(x) 0 46 | #endif 47 | 48 | #ifndef __has_attribute 49 | #define __has_attribute(x) 0 50 | #endif 51 | 52 | 53 | /************************************************ 54 | Compiler specific annotations for code analysis 55 | ************************************************/ 56 | #if defined(__GNUC__) || __has_attribute(nonnull) 57 | #define ARGINDEX_NONNULL(index) __attribute__ ((nonnull(index))) 58 | #define ARGS_NONNULL __attribute__ ((nonnull)) 59 | #else 60 | #define ARGINDEX_NONNULL(index) 61 | #define ARGS_NONNULL 62 | #endif 63 | 64 | #if __has_attribute(returns_nonnull) 65 | #define RETURNS_NONNULL __attribute__ ((returns_nonnull)) 66 | #else 67 | #define RETURNS_NONNULL 68 | #endif 69 | 70 | #if defined(__GNUC__) || __has_attribute(__format__) 71 | #define ARGS_FORMAT_PRINTF(fmt,args) __attribute__((__format__ (__printf__, fmt, args))) 72 | #else 73 | #define ARGS_FORMAT_PRINTF(fmt,args) 74 | #endif 75 | 76 | #if defined(__GNUC__) || __has_attribute(malloc) 77 | #define MALLOC __attribute__ ((malloc)) 78 | #else 79 | #define MALLOC 80 | #endif 81 | 82 | #endif /* COMPILER_H */ 83 | -------------------------------------------------------------------------------- /src/include/vendor_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file vendor_api.h 37 | * 38 | * Header file containing definition of vendor implemented functions 39 | * 40 | */ 41 | #ifndef VENDOR_API_H 42 | #define VENDOR_API_H 43 | 44 | #include "vendor_defs.h" 45 | #include "usp_api.h" 46 | 47 | //--------------------------------------------------------------------- 48 | // Vendor API 49 | int VENDOR_Init(void); 50 | int VENDOR_Start(void); 51 | int VENDOR_Stop(void); 52 | 53 | #ifdef INCLUDE_PROGRAMMATIC_FACTORY_RESET 54 | int VENDOR_GetFactoryResetParams(kv_vector_t *kvv); 55 | #endif 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /src/libjson/ccan/json/LICENSE: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | -------------------------------------------------------------------------------- /src/libjson/ccan/json/_info: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * json - Parse and generate JSON (JavaScript Object Notation) 7 | * 8 | * This is a library for encoding and decoding JSON that strives to be 9 | * easy to learn, use, and incorporate into an application. 10 | * 11 | * JSON (JavaScript Object Notation) facilitates passing data among different 12 | * programming languages, particularly JavaScript. It looks like this: 13 | * 14 | * [ 15 | * { 16 | * "id": 1, 17 | * "firstname": "John", 18 | * "lastname": "Smith", 19 | * "email": "john@example.com", 20 | * "likes_pizza": false 21 | * }, 22 | * { 23 | * "id": 2, 24 | * "firstname": "Linda", 25 | * "lastname": "Jones", 26 | * "email": null, 27 | * "likes_pizza": true 28 | * } 29 | * ] 30 | * 31 | * Example: 32 | * #include 33 | * #include 34 | * #include 35 | * #include 36 | * 37 | * static int find_number(JsonNode *object, const char *name, double *out) 38 | * { 39 | * JsonNode *node = json_find_member(object, name); 40 | * if (node && node->tag == JSON_NUMBER) { 41 | * *out = node->number_; 42 | * return 1; 43 | * } 44 | * return 0; 45 | * } 46 | * 47 | * static void solve_pythagorean(JsonNode *triple) 48 | * { 49 | * double a = 0, b = 0, c = 0; 50 | * int a_given, b_given, c_given; 51 | * 52 | * if (triple->tag != JSON_OBJECT) { 53 | * fprintf(stderr, "Error: Expected a JSON object.\n"); 54 | * exit(EXIT_FAILURE); 55 | * } 56 | * 57 | * a_given = find_number(triple, "a", &a); 58 | * b_given = find_number(triple, "b", &b); 59 | * c_given = find_number(triple, "c", &c); 60 | * 61 | * if (a_given + b_given + c_given != 2) { 62 | * fprintf(stderr, "Error: I need two sides to compute the length of the third.\n"); 63 | * exit(EXIT_FAILURE); 64 | * } 65 | * 66 | * if (a_given && b_given) { 67 | * c = sqrt(a*a + b*b); 68 | * json_append_member(triple, "c", json_mknumber(c)); 69 | * } else if (a_given && c_given) { 70 | * b = sqrt(c*c - a*a); 71 | * json_append_member(triple, "b", json_mknumber(b)); 72 | * } else if (b_given && c_given) { 73 | * a = sqrt(c*c - b*b); 74 | * json_append_member(triple, "a", json_mknumber(a)); 75 | * } 76 | * } 77 | * 78 | * int main(void) 79 | * { 80 | * JsonNode *triples = json_mkarray(); 81 | * 82 | * json_append_element(triples, json_decode("{\"a\": 3, \"b\": 4}")); 83 | * json_append_element(triples, json_decode("{\"a\": 5, \"c\": 13}")); 84 | * json_append_element(triples, json_decode("{\"b\": 24, \"c\": 25}")); 85 | * 86 | * JsonNode *triple; 87 | * json_foreach(triple, triples) 88 | * solve_pythagorean(triple); 89 | * 90 | * char *tmp = json_stringify(triples, "\t"); 91 | * puts(tmp); 92 | * free(tmp); 93 | * 94 | * json_delete(triples); 95 | * return 0; 96 | * } 97 | * 98 | * Author: Joey Adams 99 | * Version: 0.1 100 | * License: MIT 101 | */ 102 | int main(int argc, char *argv[]) 103 | { 104 | /* Expect exactly one argument */ 105 | if (argc != 2) 106 | return 1; 107 | 108 | if (strcmp(argv[1], "depends") == 0) { 109 | /* Nothing */ 110 | return 0; 111 | } 112 | 113 | if (strcmp(argv[1], "libs") == 0) { 114 | printf("m\n"); /* Needed for sqrt() used in example code above. */ 115 | return 0; 116 | } 117 | 118 | return 1; 119 | } 120 | -------------------------------------------------------------------------------- /src/libjson/ccan/json/json.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 Joseph A. Adams (joeyadams3.14159@gmail.com) 3 | All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CCAN_JSON_H 25 | #define CCAN_JSON_H 26 | 27 | #include 28 | #include 29 | 30 | typedef enum { 31 | JSON_NULL, 32 | JSON_BOOL, 33 | JSON_STRING, 34 | JSON_NUMBER, 35 | JSON_ARRAY, 36 | JSON_OBJECT, 37 | } JsonTag; 38 | 39 | typedef struct JsonNode JsonNode; 40 | 41 | struct JsonNode 42 | { 43 | /* only if parent is an object or array (NULL otherwise) */ 44 | JsonNode *parent; 45 | JsonNode *prev, *next; 46 | 47 | /* only if parent is an object (NULL otherwise) */ 48 | char *key; /* Must be valid UTF-8. */ 49 | 50 | JsonTag tag; 51 | union { 52 | /* JSON_BOOL */ 53 | bool bool_; 54 | 55 | /* JSON_STRING */ 56 | char *string_; /* Must be valid UTF-8. */ 57 | 58 | /* JSON_NUMBER */ 59 | double number_; 60 | 61 | /* JSON_ARRAY */ 62 | /* JSON_OBJECT */ 63 | struct { 64 | JsonNode *head, *tail; 65 | } children; 66 | }; 67 | }; 68 | 69 | /*** Encoding, decoding, and validation ***/ 70 | 71 | JsonNode *json_decode (const char *json); 72 | char *json_encode (const JsonNode *node); 73 | char *json_encode_string (const char *str); 74 | char *json_stringify (const JsonNode *node, const char *space); 75 | void json_delete (JsonNode *node); 76 | 77 | bool json_validate (const char *json); 78 | 79 | /*** Lookup and traversal ***/ 80 | 81 | JsonNode *json_find_element (JsonNode *array, int index); 82 | JsonNode *json_find_member (JsonNode *object, const char *key); 83 | 84 | JsonNode *json_first_child (const JsonNode *node); 85 | 86 | #define json_foreach(i, object_or_array) \ 87 | for ((i) = json_first_child(object_or_array); \ 88 | (i) != NULL; \ 89 | (i) = (i)->next) 90 | 91 | /*** Construction and manipulation ***/ 92 | 93 | JsonNode *json_mknull(void); 94 | JsonNode *json_mkbool(bool b); 95 | JsonNode *json_mkstring(const char *s); 96 | JsonNode *json_mknumber(double n); 97 | JsonNode *json_mkarray(void); 98 | JsonNode *json_mkobject(void); 99 | 100 | void json_append_element(JsonNode *array, JsonNode *element); 101 | void json_prepend_element(JsonNode *array, JsonNode *element); 102 | void json_append_member(JsonNode *object, const char *key, JsonNode *value); 103 | void json_prepend_member(JsonNode *object, const char *key, JsonNode *value); 104 | 105 | void json_remove_from_parent(JsonNode *node); 106 | 107 | /*** Debugging ***/ 108 | 109 | /* 110 | * Look for structure and encoding problems in a JsonNode or its descendents. 111 | * 112 | * If a problem is detected, return false, writing a description of the problem 113 | * to errmsg (unless errmsg is NULL). 114 | */ 115 | bool json_check(const JsonNode *node, char errmsg[256]); 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /src/libjson/ccan/json/test/common.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | static char *chomp(char *s) 8 | { 9 | char *e; 10 | 11 | if (s == NULL || *s == 0) 12 | return s; 13 | 14 | e = strchr(s, 0); 15 | if (e[-1] == '\n') 16 | *--e = 0; 17 | return s; 18 | } 19 | -------------------------------------------------------------------------------- /src/libjson/ccan/json/test/run-construction.c: -------------------------------------------------------------------------------- 1 | /* Build a list of numbers with various appends and prepends, verify them by testing against their encoded value, do pointer consistency checks each time, do element lookups, and remove items as well. */ 2 | 3 | #include "common.h" 4 | 5 | #define should_be(var, expected) should_be_(var, #var, expected) 6 | 7 | static void should_be_(const JsonNode *node, const char *name, const char *expected) 8 | { 9 | char errmsg[256]; 10 | char *encoded; 11 | 12 | if (!json_check(node, errmsg)) { 13 | fail("Invariants check failed: %s", errmsg); 14 | return; 15 | } 16 | 17 | encoded = json_encode(node); 18 | 19 | if (strcmp(encoded, expected) == 0) 20 | pass("%s is %s", name, expected); 21 | else 22 | fail("%s should be %s, but is actually %s", name, expected, encoded); 23 | 24 | free(encoded); 25 | } 26 | 27 | static void test_string(void) 28 | { 29 | JsonNode *str; 30 | 31 | str = json_mkstring("Hello\tworld!\n\001"); 32 | should_be(str, "\"Hello\\tworld!\\n\\u0001\""); 33 | json_delete(str); 34 | 35 | str = json_mkstring("\"\\\b\f\n\r\t"); 36 | should_be(str, "\"\\\"\\\\\\b\\f\\n\\r\\t\""); 37 | json_delete(str); 38 | } 39 | 40 | static void test_number(void) 41 | { 42 | JsonNode *num; 43 | 44 | num = json_mknumber(5678901234.0); 45 | should_be(num, "5678901234"); 46 | json_delete(num); 47 | 48 | num = json_mknumber(-5678901234.0); 49 | should_be(num, "-5678901234"); 50 | json_delete(num); 51 | 52 | num = json_mknumber(0.0 / 0.0); 53 | should_be(num, "null"); 54 | json_delete(num); 55 | } 56 | 57 | static void test_array(void) 58 | { 59 | JsonNode *array; 60 | JsonNode *children[5 + 1]; 61 | 62 | array = json_mkarray(); 63 | should_be(array, "[]"); 64 | 65 | children[1] = json_mknumber(1); 66 | children[2] = json_mknumber(2); 67 | children[3] = json_mknumber(3); 68 | children[4] = json_mknumber(4); 69 | children[5] = json_mknumber(5); 70 | 71 | json_append_element(array, children[3]); 72 | should_be(array, "[3]"); 73 | 74 | json_remove_from_parent(children[3]); 75 | should_be(array, "[]"); 76 | 77 | json_prepend_element(array, children[3]); 78 | should_be(array, "[3]"); 79 | 80 | json_prepend_element(array, children[2]); 81 | should_be(array, "[2,3]"); 82 | 83 | json_append_element(array, children[4]); 84 | should_be(array, "[2,3,4]"); 85 | 86 | json_delete(children[3]); 87 | should_be(array, "[2,4]"); 88 | 89 | json_prepend_element(array, children[1]); 90 | should_be(array, "[1,2,4]"); 91 | 92 | json_delete(children[1]); 93 | should_be(array, "[2,4]"); 94 | 95 | json_delete(children[4]); 96 | should_be(array, "[2]"); 97 | 98 | ok1(json_find_element(array, 0) == children[2]); 99 | ok1(json_find_element(array, -1) == NULL); 100 | ok1(json_find_element(array, 1) == NULL); 101 | 102 | json_append_element(array, children[5]); 103 | should_be(array, "[2,5]"); 104 | 105 | ok1(json_find_element(array, 0) == children[2]); 106 | ok1(json_find_element(array, 1) == children[5]); 107 | ok1(json_find_element(array, -1) == NULL); 108 | ok1(json_find_element(array, 2) == NULL); 109 | 110 | json_delete(children[2]); 111 | json_delete(children[5]); 112 | should_be(array, "[]"); 113 | 114 | ok1(json_find_element(array, -1) == NULL); 115 | ok1(json_find_element(array, 0) == NULL); 116 | ok1(json_find_element(array, 1) == NULL); 117 | 118 | json_delete(array); 119 | } 120 | 121 | static void test_object(void) 122 | { 123 | JsonNode *object; 124 | JsonNode *children[5 + 1]; 125 | 126 | object = json_mkobject(); 127 | should_be(object, "{}"); 128 | 129 | children[1] = json_mknumber(1); 130 | children[2] = json_mknumber(2); 131 | children[3] = json_mknumber(3); 132 | 133 | ok1(json_find_member(object, "one") == NULL); 134 | ok1(json_find_member(object, "two") == NULL); 135 | ok1(json_find_member(object, "three") == NULL); 136 | 137 | json_append_member(object, "one", children[1]); 138 | should_be(object, "{\"one\":1}"); 139 | 140 | ok1(json_find_member(object, "one") == children[1]); 141 | ok1(json_find_member(object, "two") == NULL); 142 | ok1(json_find_member(object, "three") == NULL); 143 | 144 | json_prepend_member(object, "two", children[2]); 145 | should_be(object, "{\"two\":2,\"one\":1}"); 146 | 147 | ok1(json_find_member(object, "one") == children[1]); 148 | ok1(json_find_member(object, "two") == children[2]); 149 | ok1(json_find_member(object, "three") == NULL); 150 | 151 | json_append_member(object, "three", children[3]); 152 | should_be(object, "{\"two\":2,\"one\":1,\"three\":3}"); 153 | 154 | ok1(json_find_member(object, "one") == children[1]); 155 | ok1(json_find_member(object, "two") == children[2]); 156 | ok1(json_find_member(object, "three") == children[3]); 157 | 158 | json_delete(object); 159 | } 160 | 161 | int main(void) 162 | { 163 | JsonNode *node; 164 | 165 | (void) chomp; 166 | 167 | plan_tests(49); 168 | 169 | ok1(json_find_element(NULL, 0) == NULL); 170 | ok1(json_find_member(NULL, "") == NULL); 171 | ok1(json_first_child(NULL) == NULL); 172 | 173 | node = json_mknull(); 174 | should_be(node, "null"); 175 | json_delete(node); 176 | 177 | node = json_mkbool(false); 178 | should_be(node, "false"); 179 | json_delete(node); 180 | 181 | node = json_mkbool(true); 182 | should_be(node, "true"); 183 | json_delete(node); 184 | 185 | test_string(); 186 | test_number(); 187 | test_array(); 188 | test_object(); 189 | 190 | return exit_status(); 191 | } 192 | -------------------------------------------------------------------------------- /src/libjson/ccan/json/test/run-decode-encode.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | int main(void) 4 | { 5 | const char *strings_file = "test/test-strings"; 6 | const char *strings_reencoded_file = "test/test-strings-reencoded"; 7 | FILE *f, *f2; 8 | char buffer[1024], buffer2[1024]; 9 | 10 | plan_tests(90); 11 | 12 | f = fopen(strings_file, "rb"); 13 | if (f == NULL) { 14 | diag("Could not open %s: %s", strings_file, strerror(errno)); 15 | return 1; 16 | } 17 | f2 = fopen(strings_reencoded_file, "rb"); 18 | if (f2 == NULL) { 19 | diag("Could not open %s: %s", strings_reencoded_file, strerror(errno)); 20 | return 1; 21 | } 22 | 23 | while (fgets(buffer, sizeof(buffer), f)) { 24 | const char *s = chomp(buffer); 25 | bool valid; 26 | JsonNode *node; 27 | 28 | if (expect_literal(&s, "valid ")) { 29 | valid = true; 30 | } else if (expect_literal(&s, "invalid ")) { 31 | valid = false; 32 | } else { 33 | fail("Invalid line in test-strings: %s", buffer); 34 | continue; 35 | } 36 | 37 | node = json_decode(s); 38 | 39 | if (valid) { 40 | char *reencoded; 41 | char errmsg[256]; 42 | 43 | if (node == NULL) { 44 | fail("%s is valid, but json_decode returned NULL", s); 45 | continue; 46 | } 47 | 48 | if (!json_check(node, errmsg)) { 49 | fail("Corrupt tree produced by json_decode: %s", errmsg); 50 | continue; 51 | } 52 | 53 | reencoded = json_encode(node); 54 | 55 | if (!fgets(buffer2, sizeof(buffer2), f2)) { 56 | fail("test-strings-reencoded is missing this line: %s", reencoded); 57 | continue; 58 | } 59 | chomp(buffer2); 60 | 61 | ok(strcmp(reencoded, buffer2) == 0, "re-encode %s -> %s", s, reencoded); 62 | 63 | free(reencoded); 64 | json_delete(node); 65 | } else if (node != NULL) { 66 | fail("%s is invalid, but json_decode returned non-NULL", s); 67 | continue; 68 | } 69 | } 70 | 71 | if (ferror(f) || fclose(f) != 0 || ferror(f2) || fclose(f2) != 0) { 72 | diag("I/O error reading test data."); 73 | return 1; 74 | } 75 | 76 | return exit_status(); 77 | } 78 | -------------------------------------------------------------------------------- /src/libjson/ccan/json/test/run-stringify.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | static char buf1[256], buf2[256]; 4 | 5 | /* Used for pass and fail messages */ 6 | static char *quote_string(const char *str, char buf[256]) 7 | { 8 | char *out = buf; 9 | 10 | *out++ = '"'; 11 | for (; *str != 0; str++) { 12 | if (out - buf > 256 - 5) { 13 | /* String is too long. End it with `...' */ 14 | out = buf + 256 - 5; 15 | *out++ = '.'; 16 | *out++ = '.'; 17 | *out++ = '.'; 18 | break; 19 | } 20 | switch (*str) { 21 | case '\t': 22 | *out++ = '\\'; 23 | *out++ = 't'; 24 | break; 25 | case '\n': 26 | *out++ = '\\'; 27 | *out++ = 'n'; 28 | break; 29 | case '"': 30 | *out++ = '\\'; 31 | *out++ = '"'; 32 | break; 33 | case '\\': 34 | *out++ = '\\'; 35 | *out++ = '\\'; 36 | break; 37 | default: 38 | *out++ = *str; 39 | break; 40 | } 41 | } 42 | *out++ = '"'; 43 | 44 | *out = 0; 45 | return buf; 46 | } 47 | 48 | static void test_stringify(const char *input, const char *expected) 49 | { 50 | JsonNode *node = NULL; 51 | char *enc = NULL; 52 | char *strn = NULL; 53 | char *str = NULL; 54 | 55 | node = json_decode(input); 56 | if (node == NULL) { 57 | fail("Failed to decode %s", input); 58 | goto end; 59 | } 60 | 61 | enc = json_encode(node); 62 | if (strcmp(enc, input) != 0) { 63 | fail("%s re-encodes to %s. Either encode/decode is broken, or the input string needs to be normalized", input, enc); 64 | goto end; 65 | } 66 | 67 | strn = json_stringify(node, NULL); 68 | if (strcmp(strn, enc) != 0) { 69 | fail("json_stringify with NULL space produced a different string than json_encode"); 70 | goto end; 71 | } 72 | 73 | str = json_stringify(node, "\t"); 74 | if (strcmp(str, expected) != 0) { 75 | fail("Expected %s, but json_stringify produced %s", 76 | quote_string(expected, buf1), quote_string(str, buf2)); 77 | goto end; 78 | } 79 | 80 | pass("stringify %s", input); 81 | 82 | end: 83 | json_delete(node); 84 | free(enc); 85 | free(strn); 86 | free(str); 87 | } 88 | 89 | int main(void) 90 | { 91 | (void) chomp; 92 | 93 | plan_tests(9); 94 | 95 | test_stringify("[]", "[]"); 96 | test_stringify("[1]", "[\n\t1\n]"); 97 | test_stringify("[1,2,3]", "[\n\t1,\n\t2,\n\t3\n]"); 98 | test_stringify("[[]]", "[\n\t[]\n]"); 99 | test_stringify("[[1,2],[3,4]]", "[\n\t[\n\t\t1,\n\t\t2\n\t],\n\t[\n\t\t3,\n\t\t4\n\t]\n]"); 100 | 101 | test_stringify("{}", "{}"); 102 | test_stringify("{\"one\":1}", "{\n\t\"one\": 1\n}"); 103 | test_stringify("{\"one\":1,\"t*\":[2,3,10]}", "{\n\t\"one\": 1,\n\t\"t*\": [\n\t\t2,\n\t\t3,\n\t\t10\n\t]\n}"); 104 | test_stringify("{\"a\":{\"1\":1,\"2\":2},\"b\":{\"3\":[null,false,true,\"\\f\"]}}", 105 | "{\n\t\"a\": {\n\t\t\"1\": 1,\n\t\t\"2\": 2\n\t},\n\t\"b\": {\n\t\t\"3\": [\n\t\t\tnull,\n\t\t\tfalse,\n\t\t\ttrue,\n\t\t\t\"\\f\"\n\t\t]\n\t}\n}"); 106 | 107 | return exit_status(); 108 | } 109 | -------------------------------------------------------------------------------- /src/libjson/ccan/json/test/run-validate.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | int main(void) 4 | { 5 | const char *strings_file = "test/test-strings"; 6 | FILE *f; 7 | char buffer[1024]; 8 | 9 | plan_tests(224); 10 | 11 | f = fopen(strings_file, "rb"); 12 | if (f == NULL) { 13 | diag("Could not open %s: %s", strings_file, strerror(errno)); 14 | return 1; 15 | } 16 | 17 | while (fgets(buffer, sizeof(buffer), f)) { 18 | const char *s = chomp(buffer); 19 | bool valid; 20 | 21 | if (expect_literal(&s, "valid ")) { 22 | valid = true; 23 | } else if (expect_literal(&s, "invalid ")) { 24 | valid = false; 25 | } else { 26 | fail("Invalid line in test-strings: %s", buffer); 27 | continue; 28 | } 29 | 30 | if (strcmp(s, "\"1\\u2\"") == 0) 31 | puts("here"); 32 | 33 | if (json_validate(s) == valid) { 34 | pass("%s %s", valid ? "valid" : "invalid", s); 35 | } else { 36 | fail("%s is %s, but json_validate returned %s", 37 | s, 38 | valid ? "valid" : "invalid", 39 | valid ? "false" : "true"); 40 | } 41 | } 42 | 43 | if (ferror(f) || fclose(f) != 0) { 44 | diag("I/O error reading test strings."); 45 | return 1; 46 | } 47 | 48 | return exit_status(); 49 | } 50 | -------------------------------------------------------------------------------- /src/libjson/ccan/json/test/test-strings: -------------------------------------------------------------------------------- 1 | invalid 2 | invalid 3 | invalid " 4 | invalid [,] 5 | invalid [) 6 | invalid []] 7 | invalid [} 8 | invalid {,} 9 | invalid {] 10 | invalid ["1":2] 11 | invalid [1,2,] 12 | invalid [1:2} 13 | invalid {"1":2,} 14 | invalid {1:2} 15 | invalid {"1":2, "2.5" : [3, 4, {}, {"5": ["6"], [7 ]}]} 16 | invalid {"1":2, "2.5" : [3, 4, {}, {"5": ["6"], [7]}]} 17 | invalid {"1":2, "2.5" : [3, 4, {}, {"5": ["6"], "7" :[8 ]}] 18 | invalid {"1":2, "2.5" : [3, 4, {}, {"5": ["6"], "7" :[8 ]}]] 19 | invalid {"1":2, "3":4 20 | invalid "1\u2" 21 | invalid [,2] 22 | invalid "3 23 | invalid "3" "4" 24 | invalid [3[4] 25 | invalid [3[4]] 26 | invalid [3, [4, [5], 6] 7, 8 9] 27 | invalid [3, [4, [5], 6] 7, 8, 9] 28 | invalid [3, [4, [5], 6], 7, 8 9] 29 | invalid {"hello":true, "bye":false, null} 30 | invalid {"hello":true, "bye":false, null:null} 31 | invalid "hi 32 | invalid "hi""" 33 | invalid {"hi": "bye"] 34 | invalid "\uD800\uD800" 35 | invalid "\uD800\uDBFF" 36 | invalid "\UD834\UDD1E" 37 | invalid "\uDB00" 38 | invalid "\uDB00\uDBFF" 39 | valid "\uFFFE" 40 | valid "\uFFFF" 41 | invalid . 42 | valid "" 43 | valid [] 44 | valid {} 45 | invalid +. 46 | valid 0.5 47 | invalid 0.e1 48 | valid {"1":{}} 49 | valid {"1":2} 50 | valid {"1":2, "2.5" : [3, 4, {}, {"5": ["6"]}]} 51 | valid {"1":2, "2.5" : [3, 4, {}, {"5": ["6"], "7" :[8 ]}]} 52 | valid 1234 53 | valid -1234 54 | valid {"1":2, "3":4} 55 | invalid +1234 56 | invalid ++1234 57 | valid 123.456e142 58 | valid 123.456e-142 59 | valid 123.456e+142 60 | invalid 123.e-142 61 | valid "1\u2000" 62 | valid "1\u20001" 63 | valid 2 64 | invalid .246e-142 65 | invalid .2e-142 66 | valid 3 67 | invalid .3 68 | valid "3" 69 | valid [3] 70 | invalid +3. 71 | valid 3.2e+1 72 | valid [3, [4]] 73 | valid [3, [4, [5]]] 74 | valid [3, [4, [5], 6]] 75 | valid [3, [4, [5], 6], 7] 76 | valid [3, [4, [5], 6], 7, 8] 77 | valid [3, [4, [5], 6], 7, 8, 9] 78 | invalid +3.5 79 | invalid .3e 80 | invalid .3e1 81 | invalid .3e-1 82 | invalid .3e+1 83 | invalid 3.e1 84 | invalid 3.e+1 85 | valid 3e+1 86 | invalid .5 87 | invalid +.5 88 | invalid .5e+1 89 | valid [ 7] 90 | valid [7 ] 91 | valid [7] 92 | invalid .e-14234 93 | valid "hello" 94 | valid ["hello"] 95 | valid ["hello", "bye"] 96 | valid ["hello", "bye\n"] 97 | valid ["hello", "bye\n\r\t"] 98 | valid ["hello", "bye\n\r\t\b"] 99 | valid ["hello", "bye\n\r\t\b",true] 100 | valid ["hello", "bye\n\r\t\b",true , false] 101 | valid ["hello", "bye\n\r\t\b",true , false, null] 102 | invalid ["hello", "bye\n\r\t\v"] 103 | valid {"hello":true} 104 | valid {"hello":true, "bye":false} 105 | valid {"hello":true, "bye":false, "foo":["one","two","three"]} 106 | valid "hi" 107 | valid ["hi"] 108 | valid ["hi", "bye"] 109 | valid {"hi": "bye"} 110 | valid ["hi", "bye", 3] 111 | valid ["hi", "bye[", 3] 112 | valid "\u0007" 113 | valid "\u0008" 114 | valid "\u0009" 115 | valid "\u0010" 116 | valid "\u0020" 117 | valid "\u10000" 118 | valid "\u1234" 119 | valid "\u99999" 120 | valid "\ud800\udc00" 121 | valid "\uD800\uDC00" 122 | valid "\uD834\uDD1E" 123 | valid "\uDBFF\uDFFF" 124 | valid "\uFFFD" 125 | valid "\uFFFF" 126 | invalid hello 127 | valid [32, 1] 128 | invalid [32, 129 | valid "\uD800\uDC00" 130 | valid "\n" 131 | valid "hello" 132 | valid "hello\u0009world" 133 | valid "hello" 134 | valid "hello\n" 135 | valid "hello" 136 | valid 3 137 | invalid 3. 138 | invalid .3 139 | valid 0.3 140 | invalid 0.3e 141 | invalid 0.3e+ 142 | valid 0.3e+5 143 | valid 0.3e-5 144 | valid 0.3e5 145 | valid "hello" 146 | invalid +3 147 | valid -3 148 | invalid -3. 149 | valid -3.1 150 | invalid .5 151 | invalid 5. 152 | invalid 5.e1 153 | valid 0.5 154 | invalid .3e1 155 | invalid .3e+1 156 | invalid .3e-1 157 | invalid .3e-1 .5 158 | invalid .3e-1.5 159 | invalid .3e+1.5 160 | invalid .3e+. 161 | invalid .3e+.5 162 | invalid .3e+1.5 163 | invalid 9.3e+1.5 164 | invalid 9.e+1.5 165 | invalid 9.e+ 166 | invalid 9.e+1 167 | valid "\"" 168 | valid "\"3.5" 169 | valid "\"." 170 | invalid "\".". 171 | valid "\"....." 172 | invalid "\"\"\"\""" 173 | invalid ["\"\"\"\"", .5] 174 | invalid [.5] 175 | valid ["\"\"\"\"", 0.5] 176 | invalid ["\"\"\"\"", .5] 177 | invalid ["\"\"\"\"",.5] 178 | invalid ["\"",.5] 179 | invalid ["\".5",.5] 180 | invalid ["\".5",".5\"".5] 181 | invalid ["\".5",".5\"", .5] 182 | invalid ["\".5",".5\"",.5] 183 | valid ["\".5",".5\"",0.5] 184 | invalid {"key":/*comment*/"value"} 185 | invalid {"key":/*comment"value"} 186 | invalid {"key":"value"}/* 187 | invalid {"key":"value"}/**/ 188 | invalid {"key":"value"}/***/ 189 | invalid {"key":"value"}/**// 190 | invalid {"key":"value"}/**/// 191 | invalid {"key":"value"}/**///---- 192 | invalid {"key":"value"}# 193 | invalid {"key":"value"}#{ 194 | invalid {"key":"value"}#{} 195 | invalid {"key":"value"}#, 196 | invalid {"key":"value"/**/, "k2":"v2"} 197 | valid "\u0027" 198 | invalid "hello\'" 199 | invalid 'hello\'' 200 | invalid 'hello' 201 | invalid 'hell\'o' 202 | invalid '\'hello' 203 | invalid '\'hello\'' 204 | invalid \'hello\' 205 | invalid 'hello\' 206 | invalid ['hello\'] 207 | invalid ['hello\''] 208 | invalid ['hello"'] 209 | invalid ['hello\"'] 210 | invalid ['hello"o'] 211 | invalid ['"'] 212 | invalid '"' 213 | invalid '"hello"' 214 | invalid '"hello' 215 | invalid '"hi"' 216 | valid [ 1 , 2 , 3 ] 217 | invalid nil 218 | invalid fals 219 | invalid falsify 220 | invalid falsetto 221 | invalid truism 222 | invalid {"key" 223 | invalid {"key","key2":value} 224 | invalid "\u0000" 225 | -------------------------------------------------------------------------------- /src/libjson/ccan/json/test/test-strings-reencoded: -------------------------------------------------------------------------------- 1 | "￾" 2 | "￿" 3 | "" 4 | [] 5 | {} 6 | 0.5 7 | {"1":{}} 8 | {"1":2} 9 | {"1":2,"2.5":[3,4,{},{"5":["6"]}]} 10 | {"1":2,"2.5":[3,4,{},{"5":["6"],"7":[8]}]} 11 | 1234 12 | -1234 13 | {"1":2,"3":4} 14 | 1.23456e+144 15 | 1.23456e-140 16 | 1.23456e+144 17 | "1 " 18 | "1 1" 19 | 2 20 | 3 21 | "3" 22 | [3] 23 | 32 24 | [3,[4]] 25 | [3,[4,[5]]] 26 | [3,[4,[5],6]] 27 | [3,[4,[5],6],7] 28 | [3,[4,[5],6],7,8] 29 | [3,[4,[5],6],7,8,9] 30 | 30 31 | [7] 32 | [7] 33 | [7] 34 | "hello" 35 | ["hello"] 36 | ["hello","bye"] 37 | ["hello","bye\n"] 38 | ["hello","bye\n\r\t"] 39 | ["hello","bye\n\r\t\b"] 40 | ["hello","bye\n\r\t\b",true] 41 | ["hello","bye\n\r\t\b",true,false] 42 | ["hello","bye\n\r\t\b",true,false,null] 43 | {"hello":true} 44 | {"hello":true,"bye":false} 45 | {"hello":true,"bye":false,"foo":["one","two","three"]} 46 | "hi" 47 | ["hi"] 48 | ["hi","bye"] 49 | {"hi":"bye"} 50 | ["hi","bye",3] 51 | ["hi","bye[",3] 52 | "\u0007" 53 | "\b" 54 | "\t" 55 | "\u0010" 56 | " " 57 | "က0" 58 | "ሴ" 59 | "香9" 60 | "𐀀" 61 | "𐀀" 62 | "𝄞" 63 | "􏿿" 64 | "�" 65 | "￿" 66 | [32,1] 67 | "𐀀" 68 | "\n" 69 | "hello" 70 | "hello\tworld" 71 | "hello" 72 | "hello\n" 73 | "hello" 74 | 3 75 | 0.3 76 | 30000 77 | 3e-06 78 | 30000 79 | "hello" 80 | -3 81 | -3.1 82 | 0.5 83 | "\"" 84 | "\"3.5" 85 | "\"." 86 | "\"....." 87 | ["\"\"\"\"",0.5] 88 | ["\".5",".5\"",0.5] 89 | "'" 90 | [1,2,3] 91 | -------------------------------------------------------------------------------- /src/libjson/licenses/BSD-MIT: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | -------------------------------------------------------------------------------- /src/libjson/pedigree.txt: -------------------------------------------------------------------------------- 1 | From: http://ccodearchive.net/info/json.html 2 | 3 | -------------------------------------------------------------------------------- /src/protobuf-c/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2016, Dave Benson and the protobuf-c authors. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following disclaimer 13 | in the documentation and/or other materials provided with the 14 | distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | The code generated by the protoc-gen-c code generator and by the 29 | protoc-c compiler is owned by the owner of the input files used when 30 | generating it. This code is not standalone and requires a support 31 | library to be linked with it. This support library is covered by the 32 | above license. 33 | -------------------------------------------------------------------------------- /src/protobuf-c/pedigree.txt: -------------------------------------------------------------------------------- 1 | From: https://github.com/protobuf-c/protobuf-c/releases/download/v1.2.1/protobuf-c-1.2.1.tar.gz 2 | 3 | -------------------------------------------------------------------------------- /src/vendor/vendor.am: -------------------------------------------------------------------------------- 1 | # Source files in vendor 2 | SOURCES += src/vendor/vendor.c \ 3 | src/vendor/vendor_factory_reset_example.c\ 4 | src/vendor/ctrl_file_parser.c 5 | 6 | # Add extra vendor specific CPP or LD flags below 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/vendor/vendor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019, Broadband Forum 4 | * Copyright (C) 2016-2019 CommScope, Inc 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 | * THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | 35 | /** 36 | * \file vendor.c 37 | * 38 | * Implements the interface to all vendor implemented data model nodes 39 | * 40 | */ 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | #include "usp_err_codes.h" 47 | #include "vendor_defs.h" 48 | #include "vendor_api.h" 49 | #include "usp_api.h" 50 | 51 | /*********************************************************************//** 52 | ** 53 | ** VENDOR_Init 54 | ** 55 | ** Initialises this component, and registers all parameters and vendor hooks, which it implements 56 | ** 57 | ** \param None 58 | ** 59 | ** \return USP_ERR_OK if successful 60 | ** 61 | **************************************************************************/ 62 | int VENDOR_Init(void) 63 | { 64 | 65 | return USP_ERR_OK; 66 | } 67 | 68 | 69 | /*********************************************************************//** 70 | ** 71 | ** VENDOR_Start 72 | ** 73 | ** Called after data model has been registered and after instance numbers have been read from the USP database 74 | ** Typically this function is used to seed the data model with instance numbers or 75 | ** initialise internal data structures which require the data model to be running to access parameters 76 | ** 77 | ** \param None 78 | ** 79 | ** \return USP_ERR_OK if successful 80 | ** 81 | **************************************************************************/ 82 | int VENDOR_Start(void) 83 | { 84 | 85 | return USP_ERR_OK; 86 | } 87 | 88 | /*********************************************************************//** 89 | ** 90 | ** VENDOR_Stop 91 | ** 92 | ** Called when stopping USP agent gracefully, to free up memory and shutdown 93 | ** any vendor processes etc 94 | ** 95 | ** \param None 96 | ** 97 | ** \return USP_ERR_OK if successful 98 | ** 99 | **************************************************************************/ 100 | int VENDOR_Stop(void) 101 | { 102 | 103 | return USP_ERR_OK; 104 | } 105 | 106 | -------------------------------------------------------------------------------- /tests/mqtt/README.md: -------------------------------------------------------------------------------- 1 | # MQTT Tests 2 | 3 | This folder contains all of the MQTT functional tests. These have been added to verify that basic functionality is still present. 4 | 5 | # Setup the tests 6 | 7 | As some of these tests require client certificates, and these expire. It is left to the user to generate these properly. 8 | 9 | The server certificates are also left to the user to generate. 10 | 11 | ## Server Certs 12 | 13 | To get the normal certs for the server connections, use the following: 14 | 15 | `openssl s_client -connect mqtt.eclipse.org:8883 -showcerts < /dev/null > cert.pem` 16 | 17 | Then, strip out all information outside of the ----- BEGIN CERTIFICATE ----- and ----- END CERTIFICATE ----- lines. 18 | 19 | You must then append the root CA certificate to the cert.pem. E.g: 20 | 21 | `cat cert.pem /etc/ssl/certs/DST_Root_CA_X3.pem > cert.pem` 22 | 23 | For any further server connections, you must append the any further certs to the same .pem file, generated in the same order as above. 24 | 25 | ## Client Certs and Keys 26 | 27 | To generate a client key/ cert pair, use https://test.mosquitto.org/ssl/ to generate a private key, CSR and download a private certificate. 28 | 29 | The key and cert must then be concatenated together into a file called client.pem (in this directory). 30 | 31 | `cat client.key client.crt > client.pem` 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /tests/mqtt/mosquitto.conf: -------------------------------------------------------------------------------- 1 | per_listener_settings true 2 | allow_anonymous false 3 | password_file /obuspa/tests/mqtt/mosquitto_password.txt 4 | 5 | -------------------------------------------------------------------------------- /tests/mqtt/mosquitto_password.txt: -------------------------------------------------------------------------------- 1 | obuspa:$7$101$/0AQJ0pC/8G+x3JZ$q2OcTO4x38PGX3Q3o4Cp/rftxNwShDlO6aB66i07M7sKpYTbSBTNlf5aAhbIu47ms1wnxcEzJKWpSdRS3Wn3Uw== 2 | -------------------------------------------------------------------------------- /tests/mqtt/test_dynamic_adding_clients.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Dynamically adding and removing MQTT clients 3 | CURRENT_DIR="$(dirname $0)" 4 | source "$CURRENT_DIR"/shared.sh || exit 1 5 | 6 | rm -rf "$LOG_FILE" 7 | rm -rf "$GREP_FILE" 8 | rm -rf "$DB_FILE" 9 | 10 | trap cleanup EXIT 11 | trap cleanup SIGINT 12 | 13 | function verify_status() { 14 | local instance="$1" 15 | local status="$2" 16 | local output="" 17 | 18 | output=$(obuspa_cmd -c get "Device.MQTT.Client.$instance.Status") 19 | if grep -q "$status" <<< $output; then 20 | techo "Status of $instance is $status" 21 | else 22 | fail "Status of $instance is not $status is: ($output)" 23 | fi 24 | } 25 | 26 | stop_obuspa 27 | sleep 1 28 | start_obuspa 29 | techo 30 | techo "TEST 1" 31 | techo "Adding MQTT.Client.1, Client.2" 32 | 33 | add_client 1 34 | verify_client 1 35 | 36 | add_client 2 37 | verify_client 1 2 38 | 39 | del_client 1 40 | verify_no_client 1 41 | verify_client 2 42 | 43 | verify_client 2 44 | del_client 2 45 | verify_no_client 2 46 | 47 | add_client 1 2 3 4 5 48 | verify_client 1 2 3 4 5 49 | 50 | add_local_agent_mtp 1 2 51 | add_local_agent_controller 1 2 52 | add_local_agent_controller_mtp 1 2 53 | 54 | configure_client "1" "mqtt.eclipse.org" "1883" "/usp/endpoint/#" "/usp/controller" 55 | enable_client 1 56 | sleep 1 57 | 58 | # Verify enable works by checking the logs 59 | # NB escaped characters in this grep 60 | grep '\-\-> Running' -- "$GREP_FILE" || fail "Failed to enable client" 61 | cat "$GREP_FILE" >> $LOG_FILE 62 | echo "" > "$GREP_FILE" 63 | 64 | # Verify the status 65 | verify_status 1 "Running" 66 | 67 | disable_client 1 68 | sleep 1 69 | grep '\-\-> Idle' -- $GREP_FILE || fail "Failed to disable client" 70 | cat "$GREP_FILE" >> $LOG_FILE 71 | echo "" > "$GREP_FILE" 72 | 73 | verify_status 1 "Disabled" 74 | 75 | configure_client "2" "doesnt-exist" "1883" "/usp/endpoint/#" "/usp/controller" 76 | enable_client 2 77 | sleep 1 78 | 79 | verify_status 2 "Error_BrokerUnreachable" 80 | 81 | techo "Passed" 82 | 83 | stop_obuspa 84 | grep '0 memory allocations' -- $GREP_FILE || fail "Memory leaks" 85 | 86 | 87 | -------------------------------------------------------------------------------- /tests/mqtt/test_keep_alive.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CURRENT_DIR="$(dirname $0)" 3 | source "$CURRENT_DIR"/shared.sh || exit 1 4 | 5 | rm -rf "$LOG_FILE" 6 | rm -rf "$GREP_FILE" 7 | rm -rf "$DB_FILE" 8 | 9 | trap cleanup EXIT 10 | trap cleanup SIGINT 11 | 12 | stop_obuspa 13 | sleep 1 14 | start_obuspa 15 | techo 16 | techo "TEST 2" 17 | techo "Verifying dynamic keep alive change" 18 | 19 | add_client 1 20 | verify_client 1 21 | 22 | add_local_agent_mtp 1 23 | add_local_agent_controller 1 24 | add_local_agent_controller_mtp 1 25 | 26 | configure_client "1" "mqtt.eclipse.org" "1883" "/usp/endpoint/#" "/usp/controller" 27 | enable_client 1 28 | sleep 5 29 | 30 | # Verify enable works by checking the logs 31 | # NB escaped characters in this grep 32 | grep '\-\-> Running' -- $GREP_FILE || fail "Failed to enable client" 33 | cat $GREP_FILE >> $LOG_FILE 34 | echo "" > $GREP_FILE 35 | 36 | techo "Setup finished." 37 | 38 | # Client now enabled. Now change the keepalive. 39 | obuspa_cmd -c set "Device.MQTT.Client.1.KeepAliveTime" "55" 40 | sleep 5 41 | grep '\-\-> Running' -- $GREP_FILE || fail "Failed to change keep alive" 42 | cat $GREP_FILE >> $LOG_FILE 43 | echo "" > $GREP_FILE 44 | 45 | obuspa_cmd -c set "Device.MQTT.Client.1.KeepAliveTime" "5" 46 | sleep 5 47 | grep '\-\-> Running' -- $GREP_FILE || fail "Failed to change keep alive" 48 | cat $GREP_FILE >> $LOG_FILE 49 | echo "" > $GREP_FILE 50 | 51 | 52 | # Client now enabled. Now change the keepalive. 53 | obuspa_cmd -c set "Device.MQTT.Client.1.KeepAliveTime" "60" 54 | sleep 5 55 | grep '\-\-> Running' -- $GREP_FILE || fail "Failed to change keep alive" 56 | cat $GREP_FILE >> $LOG_FILE 57 | echo "" > $GREP_FILE 58 | 59 | obuspa_cmd -c set "Device.MQTT.Client.1.KeepAliveTime" "10" 60 | sleep 5 61 | grep '\-\-> Running' -- $GREP_FILE || fail "Failed to change keep alive" 62 | cat $GREP_FILE >> $LOG_FILE 63 | echo "" > $GREP_FILE 64 | 65 | -------------------------------------------------------------------------------- /tests/mqtt/test_password.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CURRENT_DIR="$(dirname $0)" 3 | source "$CURRENT_DIR"/shared.sh || exit 1 4 | 5 | rm -rf "$LOG_FILE" 6 | rm -rf "$GREP_FILE" 7 | rm -rf "$DB_FILE" 8 | 9 | trap cleanup EXIT 10 | trap cleanup SIGINT 11 | 12 | stop_obuspa 13 | sleep 1 14 | start_obuspa -m 15 | obuspa_cmd -c dump mdelta 16 | NO_LEAK_STRING=$(obuspa_cmd -c dump mdelta) 17 | techo 18 | techo "TEST START STOP" 19 | 20 | add_client 1 21 | verify_client 1 22 | 23 | add_local_agent_mtp 1 24 | add_local_agent_controller 1 25 | add_local_agent_controller_mtp 1 26 | 27 | configure_client "1" "localhost" "1883" "/usp/endpoint/#" "/usp/controller" 28 | enable_client 1 29 | 30 | techo "Setup finished." 31 | 32 | sleep 10 33 | 34 | obuspa_cmd -c set Device.MQTT.Client.1.Username "obuspa" 35 | sleep 10 36 | 37 | obuspa_cmd -c set Device.MQTT.Client.1.Password "obuspa" 38 | sleep 2 39 | grep '\-\-> Running' -- $GREP_FILE || fail "Failed to enable client with password." 40 | cat $GREP_FILE >> $LOG_FILE 41 | echo "" > $GREP_FILE 42 | 43 | obuspa_cmd -c get Device.MQTT.Client.1.Username 44 | obuspa_cmd -c get Device.MQTT.Client.1.Password | grep obuspa && fail "Password was printed" 45 | 46 | 47 | disable_client 1 48 | obuspa_cmd -c del Device.LocalAgent.MTP.1. 49 | obuspa_cmd -c del Device.LocalAgent.Controller.1. 50 | del_client 1 51 | 52 | stop_obuspa 53 | grep '0 memory allocations' -- $GREP_FILE || fail "Memory leaks" 54 | 55 | -------------------------------------------------------------------------------- /tests/mqtt/test_retry.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CURRENT_DIR="$(dirname $0)" 3 | source "$CURRENT_DIR"/shared.sh || exit 1 4 | 5 | rm -rf "$LOG_FILE" 6 | rm -rf "$GREP_FILE" 7 | rm -rf "$DB_FILE" 8 | 9 | trap cleanup EXIT 10 | trap cleanup SIGINT 11 | 12 | stop_obuspa 13 | sleep 1 14 | start_obuspa -m 15 | obuspa_cmd -c dump mdelta 16 | NO_LEAK_STRING=$(obuspa_cmd -c dump mdelta) 17 | techo 18 | techo "TEST START STOP" 19 | 20 | add_client 1 21 | verify_client 1 22 | 23 | add_local_agent_mtp 1 24 | add_local_agent_controller 1 25 | add_local_agent_controller_mtp 1 26 | 27 | configure_client "1" "mqtt.eclipse.org" "1883" "/usp/endpoint/#" "/usp/controller" 28 | enable_client 1 29 | sleep 1 30 | 31 | # Verify enable works by checking the logs 32 | # NB escaped characters in this grep 33 | grep '\-\-> Running' -- $GREP_FILE || fail "Failed to enable client" 34 | cat $GREP_FILE >> $LOG_FILE 35 | echo "" > $GREP_FILE 36 | 37 | techo "Setup finished." 38 | 39 | obuspa_cmd -c get Device. 40 | 41 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription. 42 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription. 43 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription. 44 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription. 45 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription. 46 | 47 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.1.Topic "topic1" || fail 48 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.2.Topic "topic1" || fail 49 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.3.Topic "topic1" || fail 50 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.4.Topic "topic1" || fail 51 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.5.Topic "topic1" || fail 52 | 53 | obuspa_cmd -c set Device.MQTT.Client.1.BrokerAddress "doesntexist.org.uk.something" 54 | 55 | # Wait for it to retry 56 | sleep 10 57 | 58 | obuspa_cmd -c set Device.MQTT.Client.1.BrokerAddress "mqtt.eclipse.org" 59 | sleep 2 60 | 61 | 62 | disable_client 1 63 | obuspa_cmd -c del Device.LocalAgent.MTP.1. 64 | obuspa_cmd -c del Device.LocalAgent.Controller.1. 65 | del_client 1 66 | 67 | stop_obuspa 68 | grep '0 memory allocations' -- $GREP_FILE || fail "Memory leaks" 69 | 70 | -------------------------------------------------------------------------------- /tests/mqtt/test_set_parameters.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Test setting client paramters in MQTT 3 | CURRENT_DIR="$(dirname $0)" 4 | source "$CURRENT_DIR"/shared.sh || exit 1 5 | 6 | rm -rf "$LOG_FILE" 7 | rm -rf "$GREP_FILE" 8 | rm -rf "$DB_FILE" 9 | 10 | trap cleanup EXIT 11 | trap cleanup SIGINT 12 | 13 | stop_obuspa 14 | sleep 1 15 | start_obuspa 16 | techo 17 | techo "Verifying dynamic parameter change" 18 | 19 | add_client 1 20 | verify_client 1 21 | 22 | add_local_agent_mtp 1 23 | add_local_agent_controller 1 24 | add_local_agent_controller_mtp 1 25 | 26 | configure_client "1" "mqtt.eclipse.org" "1883" "/usp/endpoint/#" "/usp/controller" 27 | enable_client 1 28 | sleep 5 29 | # Verify enable works by checking the logs 30 | # NB escaped characters in this grep 31 | grep '\-\-> Running' -- $GREP_FILE || fail "Failed to enable client" 32 | cat $GREP_FILE >> $LOG_FILE 33 | echo "" > $GREP_FILE 34 | 35 | techo "Setup finished." 36 | techo "Set various connection parameters for a client OBUSPA" 37 | set_parameter_client "CleanSession" "false" 38 | set_parameter_client "CleanSession" "true" 39 | set_parameter_client "CleanStart" "false" 40 | set_parameter_client "CleanStart" "true" 41 | set_parameter_client_reconnect "KeepAliveTime" "75" 42 | set_parameter_client_reconnect "KeepAliveTime" "65" 43 | set_parameter_client_reconnect "KeepAliveTime" "90" 44 | set_parameter_client_reconnect "KeepAliveTime" "10" 45 | set_parameter_client_reconnect "KeepAliveTime" "60" 46 | set_parameter_client_reconnect "Username" "obuspa_user" 47 | set_parameter_client_reconnect "Password" "obuspa_password" 48 | set_parameter_client_reconnect "ProtocolVersion" "3.1.1" 49 | set_parameter_client_reconnect "ProtocolVersion" "3.1" 50 | set_parameter_client_reconnect "ProtocolVersion" "5.0" 51 | set_parameter_client_reconnect "Name" "indigoc1" 52 | set_parameter_client_reconnect "ClientID" "obuspacid" 53 | set_parameter_client_reconnect "TransportProtocol" "WebSocket" 54 | set_parameter_client_reconnect "TransportProtocol" "TCP/IP" 55 | 56 | techo "Passed" 57 | 58 | stop_obuspa 59 | grep '0 memory allocations' -- $GREP_FILE || fail "Memory leaks" 60 | -------------------------------------------------------------------------------- /tests/mqtt/test_ssl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CURRENT_DIR="$(dirname $0)" 3 | source "$CURRENT_DIR"/shared.sh || exit 1 4 | CERTS_ARGS="-t $(dirname $0)/certs.pem -a $(dirname $0)/client.pem" 5 | 6 | rm -rf "$LOG_FILE" 7 | rm -rf "$GREP_FILE" 8 | rm -rf "$DB_FILE" 9 | 10 | trap cleanup EXIT 11 | trap cleanup SIGINT 12 | 13 | stop_obuspa 14 | sleep 1 15 | start_obuspa $CERTS_ARGS 16 | techo 17 | techo "TEST SSL" 18 | 19 | obuspa_cmd -c dump mdelta 20 | NO_LEAK_STRING=$(obuspa_cmd -c dump mdelta) 21 | 22 | add_client 1 2 3 4 5 23 | verify_client 1 2 3 4 5 24 | 25 | add_local_agent_mtp 1 2 3 4 5 || fail 26 | add_local_agent_controller 1 2 3 4 5 || fail 27 | add_local_agent_controller_mtp 1 2 3 4 5 || fail 28 | 29 | configure_client "1" "mqtt.eclipse.org" "8883" "/usp/endpoint/#" "/usp/controller" 30 | obuspa_cmd -c set "Device.MQTT.Client.1.TransportProtocol" "TLS" 31 | 32 | configure_client "2" "test.mosquitto.org" "8883" "/usp/endpoint/#" "/usp/controller" 33 | obuspa_cmd -c set "Device.MQTT.Client.2.TransportProtocol" "TLS" 34 | 35 | configure_client "3" "test.mosquitto.org" "1883" "/usp/endpoint/#" "/usp/controller" 36 | 37 | configure_client "4" "mqtt.eclipse.org" "8883" "/usp/endpoint/#" "/usp/controller" 38 | obuspa_cmd -c set "Device.MQTT.Client.4.TransportProtocol" "TLS" 39 | 40 | configure_client "5" "test.mosquitto.org" "8884" "/usp/endpoint/#" "/usp/controller" 41 | obuspa_cmd -c set "Device.MQTT.Client.5.TransportProtocol" "TLS" 42 | 43 | obuspa_cmd -c get Device.MQTT.Client. 44 | 45 | # Finally, enable the all of the clients 46 | enable_client 1 2 3 4 5 47 | sleep 2 48 | 49 | # Verify we have all 5 up and running, and saw now errors 50 | [[ 5 == $(grep '\-\-> Running' -- "$GREP_FILE" | wc -l) ]] || fail "Not correct running clients" 51 | grep -v -i 'Error' -- "$GREP_FILE" || fail "Found an error." 52 | 53 | # Log and wipe grep file 54 | cat "$GREP_FILE" >> $LOG_FILE 55 | echo "" > "$GREP_FILE" 56 | 57 | 58 | disable_client 1 2 3 4 5 59 | obuspa_cmd -c del Device.LocalAgent.MTP.1. 60 | obuspa_cmd -c del Device.LocalAgent.MTP.2. 61 | obuspa_cmd -c del Device.LocalAgent.MTP.3. 62 | obuspa_cmd -c del Device.LocalAgent.MTP.4. 63 | obuspa_cmd -c del Device.LocalAgent.MTP.5. 64 | obuspa_cmd -c del Device.LocalAgent.Controller.1. 65 | obuspa_cmd -c del Device.LocalAgent.Controller.2. 66 | obuspa_cmd -c del Device.LocalAgent.Controller.3. 67 | obuspa_cmd -c del Device.LocalAgent.Controller.4. 68 | obuspa_cmd -c del Device.LocalAgent.Controller.5. 69 | del_client 1 2 3 4 5 70 | 71 | mdelta_string="$(obuspa_cmd -c dump mdelta)" 72 | 73 | if [[ "$mdelta_string" != "$NO_LEAK_STRING" ]]; then 74 | echo "$mdelta_string" 75 | fail "Memory leak" 76 | fi 77 | 78 | techo "Passed" 79 | stop_obuspa 80 | grep '0 memory allocations' -- $GREP_FILE || fail "Memory leaks" 81 | -------------------------------------------------------------------------------- /tests/mqtt/test_start_stop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CURRENT_DIR="$(dirname $0)" 3 | source "$CURRENT_DIR"/shared.sh || exit 1 4 | 5 | rm -rf "$LOG_FILE" 6 | rm -rf "$GREP_FILE" 7 | rm -rf "$DB_FILE" 8 | 9 | trap cleanup EXIT 10 | trap cleanup SIGINT 11 | 12 | stop_obuspa 13 | sleep 1 14 | start_obuspa 15 | techo "TEST START STOP" 16 | 17 | add_client 1 18 | verify_client 1 19 | 20 | add_local_agent_mtp 1 21 | add_local_agent_controller 1 22 | add_local_agent_controller_mtp 1 23 | 24 | configure_client "1" "mqtt.eclipse.org" "1883" "/usp/endpoint/#" "/usp/controller" 25 | enable_client 1 26 | sleep 1 27 | disable_client 1 28 | enable_client 1 29 | 30 | # Verify enable works by checking the logs 31 | # NB escaped characters in this grep 32 | grep '\-\-> Running' -- $GREP_FILE || fail "Failed to enable client" 33 | cat $GREP_FILE >> $LOG_FILE 34 | echo "" > $GREP_FILE 35 | 36 | techo "Setup finished." 37 | 38 | obuspa_cmd -c get Device. 39 | 40 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription. 41 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription. 42 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription. 43 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription. 44 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription. 45 | 46 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.1.Topic "topic1" || fail 47 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.2.Topic "topic1" || fail 48 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.3.Topic "topic1" || fail 49 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.4.Topic "topic1" || fail 50 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.5.Topic "topic1" || fail 51 | 52 | disable_client 1 53 | obuspa_cmd -c del Device.LocalAgent.MTP.1. 54 | obuspa_cmd -c del Device.LocalAgent.Controller.1. 55 | del_client 1 56 | 57 | stop_obuspa 58 | grep -q "0 memory allocations" -- $GREP_FILE || fail "Memory leaks exist" 59 | 60 | 61 | -------------------------------------------------------------------------------- /tests/mqtt/test_subscriptions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CURRENT_DIR="$(dirname $0)" 3 | source "$CURRENT_DIR"/shared.sh || exit 1 4 | 5 | rm -rf "$LOG_FILE" 6 | rm -rf "$GREP_FILE" 7 | rm -rf "$DB_FILE" 8 | 9 | trap cleanup EXIT 10 | trap cleanup SIGINT 11 | 12 | stop_obuspa 13 | sleep 1 14 | start_obuspa -m 15 | obuspa_cmd -c dump mdelta 16 | NO_LEAK_STRING=$(obuspa_cmd -c dump mdelta) 17 | techo 18 | techo "TEST START STOP" 19 | 20 | add_client 1 21 | verify_client 1 22 | 23 | add_local_agent_mtp 1 24 | add_local_agent_controller 1 25 | add_local_agent_controller_mtp 1 26 | 27 | configure_client "1" "mqtt.eclipse.org" "1883" "/usp/endpoint/#" "/usp/controller" 28 | enable_client 1 29 | sleep 1 30 | 31 | # Verify enable works by checking the logs 32 | # NB escaped characters in this grep 33 | grep '\-\-> Running' -- $GREP_FILE || fail "Failed to enable client" 34 | cat $GREP_FILE >> $LOG_FILE 35 | echo "" > $GREP_FILE 36 | 37 | techo "Setup finished." 38 | 39 | obuspa_cmd -c get Device. 40 | 41 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription 42 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription 43 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription 44 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription 45 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription 46 | obuspa_cmd -c get Device.MQTT.Client.1.Subscription. 47 | obuspa_cmd -c del Device.MQTT.Client.1.Subscription.5 48 | obuspa_cmd -c add Device.MQTT.Client.1.Subscription 49 | 50 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.1.Topic "/usp/topic1" || fail 51 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.2.Topic "/usp/topic2" || fail 52 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.3.Topic "/usp/topic3" || fail 53 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.4.Topic "/usp/topic4" || fail 54 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.6.Topic "/usp/topic5" || fail 55 | 56 | 57 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.3.Enable true 58 | sleep 1 59 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.3.Topic "/usp/newtopic" 60 | sleep 1 61 | grep 'Resubscribing' -- $GREP_FILE || fail "Failed to switch topic" 62 | cat $GREP_FILE >> $LOG_FILE 63 | echo "" > $GREP_FILE 64 | 65 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.3.Enable false 66 | sleep 1 67 | grep 'UNSUBACK' -- $GREP_FILE || fail "Failed to unsubscribe" 68 | cat $GREP_FILE >> $LOG_FILE; echo "" > $GREP_FILE 69 | 70 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.3.Enable true 71 | sleep 1 72 | grep 'd SUBACK' -- $GREP_FILE || fail "Failed to unsubscribe" 73 | cat $GREP_FILE >> $LOG_FILE; echo "" > $GREP_FILE 74 | 75 | 76 | obuspa_cmd -c add Device.MQTT.Client 77 | obuspa_cmd -c add Device.MQTT.Client 78 | obuspa_cmd -c add Device.MQTT.Client 79 | obuspa_cmd -c add Device.MQTT.Client 80 | obuspa_cmd -c del Device.MQTT.Client.3 81 | obuspa_cmd -c add Device.MQTT.Client || fail 82 | 83 | obuspa_cmd -c set Device.MQTT.Client.1.Subscription.3.Enable false 84 | 85 | disable_client 1 86 | obuspa_cmd -c del Device.LocalAgent.MTP.1. 87 | obuspa_cmd -c del Device.LocalAgent.Controller.1. 88 | 89 | stop_obuspa 90 | grep '0 memory allocations' -- $GREP_FILE || fail "Memory leaks seen." 91 | --------------------------------------------------------------------------------