├── .gitignore ├── .mailmap ├── .travis.yml ├── CMakeLists.txt ├── CONTRIBUTING.md ├── Doxyfile ├── LICENSE ├── README.md ├── include ├── 1905_alme.h ├── 1905_cmdus.h ├── 1905_l2.h ├── 1905_tlvs.h ├── bbf_tlvs.h ├── datamodel.h ├── dlist.h ├── hlist.h ├── lldp_payload.h ├── lldp_tlvs.h ├── media_specific_blobs.h ├── platform.h ├── platform_linux.h ├── ptrarray.h ├── tlv.h └── utils.h ├── prplMesh.pc.in ├── prplMeshConfig.cmake.in ├── scripts ├── README.md └── linux │ └── arm_wrt1900acx │ ├── start_linksys.sh │ ├── topology_change.sh │ └── wps ├── src ├── 1905_alme.c ├── 1905_cmdus.c ├── 1905_tlvs.c ├── CMakeLists.txt ├── al.h ├── al_datamodel.c ├── al_datamodel.h ├── al_entity.c ├── al_extension.c ├── al_extension.h ├── al_extension_register.c ├── al_recv.c ├── al_recv.h ├── al_send.c ├── al_send.h ├── al_utils.c ├── al_utils.h ├── al_wsc.c ├── al_wsc.h ├── bbf_recv.c ├── bbf_recv.h ├── bbf_send.c ├── bbf_send.h ├── bbf_tlvs.c ├── datamodel.c ├── hlist.c ├── linux │ ├── al_entity │ │ ├── al_entity_main.c │ │ └── al_entity_openwrt.c │ ├── hl_entity │ │ └── hl_entity_main.c │ ├── ieee80211.h │ ├── netlink_collect.c │ ├── netlink_funcs.h │ ├── netlink_socks.c │ ├── netlink_utils.c │ ├── nl80211.h │ ├── platform.c │ ├── platform_alme_server.c │ ├── platform_alme_server_priv.h │ ├── platform_crypto.c │ ├── platform_interfaces.c │ ├── platform_interfaces_ghnspirit.c │ ├── platform_interfaces_ghnspirit_priv.h │ ├── platform_interfaces_openwrt.c │ ├── platform_interfaces_openwrt_priv.h │ ├── platform_interfaces_priv.h │ ├── platform_interfaces_simulated.c │ ├── platform_interfaces_simulated_priv.h │ ├── platform_os.c │ ├── platform_os_priv.h │ ├── platform_uci.c │ └── platform_uci.h ├── lldp_payload.c ├── lldp_tlvs.c ├── mac_address.c ├── media_specific_blobs.c ├── packet_tools.h ├── platform_alme_server.h ├── platform_crypto.h ├── platform_interfaces.h ├── platform_os.h ├── tlv.c └── utils.c └── tests ├── 1905_alme_forging.c ├── 1905_alme_parsing.c ├── 1905_alme_test_vectors.c ├── 1905_alme_test_vectors.h ├── 1905_cmdu_forging.c ├── 1905_cmdu_parsing.c ├── 1905_cmdu_test_vectors.c ├── 1905_cmdu_test_vectors.h ├── 1905_tlv_forging.c ├── 1905_tlv_parsing.c ├── 1905_tlv_test_vectors.c ├── 1905_tlv_test_vectors.h ├── CMakeLists.txt ├── aletest.c ├── aletest.h ├── aletest0.sim ├── aletest1.sim ├── aletest2.sim ├── aletest3.sim ├── ap_onboarding_controller.c ├── bbf_tlv_forging.c ├── bbf_tlv_parsing.c ├── bbf_tlv_test_vectors.c ├── bbf_tlv_test_vectors.h ├── dlist_test.c ├── hlist_test.c ├── lldp_payload_forging.c ├── lldp_payload_parsing.c ├── lldp_payload_test_vectors.c ├── lldp_payload_test_vectors.h ├── lldp_tlv_forging.c ├── lldp_tlv_parsing.c ├── lldp_tlv_test_vectors.c ├── lldp_tlv_test_vectors.h ├── ptrarray_test.c ├── start_interfaces └── topology_discovery.c /.gitignore: -------------------------------------------------------------------------------- 1 | /html/ 2 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Daniel Mateu 2 | Santiago Vicent 3 | William Lupton 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # prplMesh Wi-Fi Multi-AP 2 | # 3 | # Copyright (c) 2018, prpl Foundation 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are 7 | # met: 8 | # 9 | # 1. Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # 12 | # 2. Redistributions in binary form must reproduce the above copyright 13 | # notice, this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | # 16 | # Subject to the terms and conditions of this license, each copyright 17 | # holder and contributor hereby grants to those receiving rights under 18 | # this license a perpetual, worldwide, non-exclusive, no-charge, 19 | # royalty-free, irrevocable (except for failure to satisfy the 20 | # conditions of this license) patent license to make, have made, use, 21 | # offer to sell, sell, import, and otherwise transfer this software, 22 | # where such license applies only to those patent claims, already 23 | # acquired or hereafter acquired, licensable by such copyright holder or 24 | # contributor that are necessarily infringed by: 25 | # 26 | # (a) their Contribution(s) (the licensed copyrights of copyright holders 27 | # and non-copyrightable additions of contributors, in source or binary 28 | # form) alone; or 29 | # 30 | # (b) combination of their Contribution(s) with the work of authorship to 31 | # which such Contribution(s) was added by such copyright holder or 32 | # contributor, if, at the time the Contribution is added, such addition 33 | # causes such combination to be necessarily infringed. The patent 34 | # license shall not apply to any other combinations which include the 35 | # Contribution. 36 | # 37 | # Except as expressly stated above, no rights or licenses from any 38 | # copyright holder or contributor is granted under this license, whether 39 | # expressly, by implication, estoppel or otherwise. 40 | # 41 | # DISCLAIMER 42 | # 43 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 44 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 45 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 46 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 47 | # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 48 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 49 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 50 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 51 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 52 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 53 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 54 | # DAMAGE. 55 | 56 | language: c 57 | 58 | addons: 59 | apt: 60 | packages: 61 | - libssl-dev 62 | - libnl-genl-3-dev 63 | - doxygen 64 | - graphviz 65 | 66 | sudo: required 67 | 68 | script: 69 | - doxygen 70 | - cmake . && make && make test 71 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, prpl Foundation 2 | # 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions are 5 | # met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # 14 | # Subject to the terms and conditions of this license, each copyright 15 | # holder and contributor hereby grants to those receiving rights under 16 | # this license a perpetual, worldwide, non-exclusive, no-charge, 17 | # royalty-free, irrevocable (except for failure to satisfy the 18 | # conditions of this license) patent license to make, have made, use, 19 | # offer to sell, sell, import, and otherwise transfer this software, 20 | # where such license applies only to those patent claims, already 21 | # acquired or hereafter acquired, licensable by such copyright holder or 22 | # contributor that are necessarily infringed by: 23 | # 24 | # (a) their Contribution(s) (the licensed copyrights of copyright holders 25 | # and non-copyrightable additions of contributors, in source or binary 26 | # form) alone; or 27 | # 28 | # (b) combination of their Contribution(s) with the work of authorship to 29 | # which such Contribution(s) was added by such copyright holder or 30 | # contributor, if, at the time the Contribution is added, such addition 31 | # causes such combination to be necessarily infringed. The patent 32 | # license shall not apply to any other combinations which include the 33 | # Contribution. 34 | # 35 | # Except as expressly stated above, no rights or licenses from any 36 | # copyright holder or contributor is granted under this license, whether 37 | # expressly, by implication, estoppel or otherwise. 38 | # 39 | # DISCLAIMER 40 | # 41 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 42 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 43 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 44 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 45 | # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 46 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 47 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 48 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 49 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 50 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 51 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 52 | # DAMAGE. 53 | 54 | cmake_minimum_required(VERSION 3.4) 55 | project(prplMesh LANGUAGES C VERSION 0.9) 56 | 57 | set(libname "prplMesh" CACHE STRING 58 | "Name of the generated library. Includes are installed in a subdirectory of the same name.\ 59 | This allows to install it as e.g. 'lib1905.a' if only 1905 functionality is needed.") 60 | set(INCLUDE_INSTALL_DIR include/ CACHE PATH 61 | "Installation directory for includes (relative to CMAKE_INSTALL_PREFIX)") 62 | set(LIB_INSTALL_DIR lib/ CACHE PATH 63 | "Installation directory for the library (relative to CMAKE_INSTALL_PREFIX)") 64 | set(CMAKE_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake CACHE PATH 65 | "Installation directory for CMake files (relative to CMAKE_INSTALL_PREFIX)") 66 | set(OPENWRT FALSE CACHE BOOL 67 | "Enable OpenWrt integration") 68 | 69 | set(CMAKE_BUILD_TYPE Debug) 70 | 71 | set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS _BUILD_NUMBER_=\"${prplMesh_VERSION}\") 72 | 73 | include(TestBigEndian) 74 | TEST_BIG_ENDIAN(BIGENDIAN) 75 | if(BIGENDIAN) 76 | set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS _HOST_IS_BIG_ENDIAN_=1) 77 | else() 78 | set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS _HOST_IS_LITTLE_ENDIAN_=1) 79 | endif(BIGENDIAN) 80 | 81 | # @todo make these configurable 82 | set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS 83 | MAX_NETWORK_SEGMENT_SIZE=1500 84 | SEND_EMPTY_TLVS 85 | FIX_BROKEN_TLVS 86 | SPEED_UP_DISCOVERY 87 | REGISTER_EXTENSION_BBF 88 | ) 89 | 90 | if (OPENWRT) 91 | set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS OPENWRT) 92 | endif (OPENWRT) 93 | 94 | include_directories(include) 95 | 96 | add_subdirectory(src) 97 | 98 | if (${CMAKE_SYSTEM_NAME} MATCHES Linux) 99 | enable_testing() 100 | add_subdirectory(tests) 101 | endif (${CMAKE_SYSTEM_NAME} MATCHES Linux) 102 | 103 | 104 | # Installation 105 | 106 | include(CMakePackageConfigHelpers) 107 | 108 | install(DIRECTORY include/ DESTINATION ${INCLUDE_INSTALL_DIR}/${libname} COMPONENT Devel FILES_MATCHING PATTERN "*.h") 109 | 110 | configure_package_config_file(prplMeshConfig.cmake.in 111 | ${CMAKE_CURRENT_BINARY_DIR}/${libname}Config.cmake 112 | INSTALL_DESTINATION ${CMAKE_INSTALL_DIR} 113 | NO_CHECK_REQUIRED_COMPONENTS_MACRO 114 | PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR) 115 | write_basic_package_version_file( 116 | "${CMAKE_CURRENT_BINARY_DIR}/${libname}ConfigVersion.cmake" 117 | VERSION ${prplMesh_VERSION} 118 | COMPATIBILITY AnyNewerVersion) 119 | configure_file(prplMesh.pc.in 120 | ${CMAKE_CURRENT_BINARY_DIR}/${libname}.pc 121 | @ONLY) 122 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${libname}Config.cmake 123 | ${CMAKE_CURRENT_BINARY_DIR}/${libname}ConfigVersion.cmake 124 | ${CMAKE_CURRENT_BINARY_DIR}/${libname}.pc 125 | DESTINATION ${CMAKE_INSTALL_DIR} 126 | COMPONENT Devel) 127 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | This repository is still heavily developed. You can follow the development by watching the repository. If you want to get involved, please send a mail to 4 | Arnout Vandecappelle <arnout.vandecappelle@essensium.com>. 5 | 6 | ## Reporting bugs 7 | 8 | Use [github issues](https://github.com/prplfoundation/prplMesh/issues) to report problems. 9 | 10 | ## Contributing code 11 | 12 | Before you can contribute code, you must sign off the Developer Certificate of Origin below. You can do this by adding your name 13 | and e-mail address below it and sending a pull request with that change. 14 | 15 | Contributions are handled through [github pull requests](https://guides.github.com/activities/hello-world/#pr). 16 | 17 | Please try to follow these rules: 18 | * The commit messages should have a short but useful subject line. 19 | * The commit message should explain why a change is made, what is done, and which other options were considered but not used. 20 | 21 | ## Developer Certificate of Origin 22 | 23 | This is the [Developer's Certificate of Origin 1.1](https://developercertificate.org/) 24 | 25 | By making a contribution to this project, I certify that: 26 | 27 | (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or 28 | 29 | (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or 30 | 31 | (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. 32 | 33 | (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. 34 | 35 | Arnout Vandecappelle 36 | Daniel Golle 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, Broadband Forum 2 | Copyright (c) 2018-2019, prpl Foundation 3 | Copyright (c) 2018-2019, the prplMesh contributors 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | Subject to the terms and conditions of this license, each copyright 17 | holder and contributor hereby grants to those receiving rights under 18 | this license a perpetual, worldwide, non-exclusive, no-charge, 19 | royalty-free, irrevocable (except for failure to satisfy the 20 | conditions of this license) patent license to make, have made, use, 21 | offer to sell, sell, import, and otherwise transfer this software, 22 | where such license applies only to those patent claims, already 23 | acquired or hereafter acquired, licensable by such copyright holder or 24 | contributor that are necessarily infringed by: 25 | 26 | (a) their Contribution(s) (the licensed copyrights of copyright holders 27 | and non-copyrightable additions of contributors, in source or binary 28 | form) alone; or 29 | 30 | (b) combination of their Contribution(s) with the work of authorship to 31 | which such Contribution(s) was added by such copyright holder or 32 | contributor, if, at the time the Contribution is added, such addition 33 | causes such combination to be necessarily infringed. The patent 34 | license shall not apply to any other combinations which include the 35 | Contribution. 36 | 37 | Except as expressly stated above, no rights or licenses from any 38 | copyright holder or contributor is granted under this license, whether 39 | expressly, by implication, estoppel or otherwise. 40 | 41 | DISCLAIMER 42 | 43 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 44 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 45 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 46 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 47 | HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 48 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 49 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 50 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 51 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 52 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 53 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 54 | DAMAGE. 55 | -------------------------------------------------------------------------------- /include/1905_l2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _1905_L2_H_ 59 | #define _1905_L2_H_ 60 | 61 | // Ethernet types por 1905 and LLDP packets 62 | // 63 | #define ETHERTYPE_1905 (0x893aU) 64 | #define ETHERTYPE_LLDP (0x88ccU) 65 | 66 | 67 | // 1905 multicast address ("01:80:C2:00:00:13") 68 | // 69 | #define MCAST_1905 "\x01\x80\xC2\x00\x00\x13" 70 | 71 | 72 | // LLDP nearest bridge multicast address ("01:80:C2:00:00:0E") 73 | // 74 | #define MCAST_LLDP "\x01\x80\xC2\x00\x00\x0E" 75 | 76 | #endif 77 | 78 | -------------------------------------------------------------------------------- /include/platform_linux.h: -------------------------------------------------------------------------------- 1 | /* 2 | * prplMesh Wi-Fi Multi-AP 3 | * 4 | * Copyright (c) 2018, prpl Foundation 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef PLATFORM_LINUX_H 59 | #define PLATFORM_LINUX_H 60 | 61 | /** @file 62 | * 63 | * Platform-specific functions and data structures that are only available on Linux platforms. 64 | * 65 | * Only linux-specific source files (i.e., files in the src_linux directory) may include this header. 66 | */ 67 | 68 | /** @brief Get the interface index by name. 69 | * 70 | * @param[in] interface_name The name of the interface on which to listen. 71 | * @return The interface index on success, or -1 on error (errno will be set). 72 | * 73 | * The interface index can be used to set options on the interface and to bind a socket to the interface. 74 | */ 75 | int getIfIndex(const char *interface_name); 76 | 77 | /** @brief Open a socket suitable for raw ethernet packets. 78 | * 79 | * @param[in] ifindex The interface index on which to listen (as returned by getIfIndex()). 80 | * @param[in] eth_type The protocol number (in host byte order) 81 | * @return The socket file descriptor on success, or -1 on error (errno will be set). 82 | * 83 | * The socket is created as SOCK_RAW, so the ethernet header must be added to / removed from the payload. 84 | * 85 | * The created socket will be bound to the given interface and protocol. 86 | * 87 | * Close the socket with close() when done. 88 | * 89 | * No messages are printed in case of error, but errno will be set upon return. 90 | * 91 | * @todo factor with the AL server itself. 92 | */ 93 | int openPacketSocket(int ifindex, uint16_t eth_type); 94 | 95 | 96 | 97 | #endif // PLATFORM_LINUX_H 98 | -------------------------------------------------------------------------------- /prplMesh.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@DEST_DIR@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/@LIB_INSTALL_DIR@ 4 | includedir=${prefix}/@INCLUDE_INSTALL_DIR@ 5 | 6 | Name: @libname@ 7 | Description: IEEE 1905.1 and Wi-Fi Multi-AP stack 8 | Version: @prplMesh_VERSION@ 9 | 10 | Libs: -L${libdir} @PRIVATE_LIBS@ 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /prplMeshConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, prpl Foundation 2 | # 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions are 5 | # met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # 14 | # Subject to the terms and conditions of this license, each copyright 15 | # holder and contributor hereby grants to those receiving rights under 16 | # this license a perpetual, worldwide, non-exclusive, no-charge, 17 | # royalty-free, irrevocable (except for failure to satisfy the 18 | # conditions of this license) patent license to make, have made, use, 19 | # offer to sell, sell, import, and otherwise transfer this software, 20 | # where such license applies only to those patent claims, already 21 | # acquired or hereafter acquired, licensable by such copyright holder or 22 | # contributor that are necessarily infringed by: 23 | # 24 | # (a) their Contribution(s) (the licensed copyrights of copyright holders 25 | # and non-copyrightable additions of contributors, in source or binary 26 | # form) alone; or 27 | # 28 | # (b) combination of their Contribution(s) with the work of authorship to 29 | # which such Contribution(s) was added by such copyright holder or 30 | # contributor, if, at the time the Contribution is added, such addition 31 | # causes such combination to be necessarily infringed. The patent 32 | # license shall not apply to any other combinations which include the 33 | # Contribution. 34 | # 35 | # Except as expressly stated above, no rights or licenses from any 36 | # copyright holder or contributor is granted under this license, whether 37 | # expressly, by implication, estoppel or otherwise. 38 | # 39 | # DISCLAIMER 40 | # 41 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 42 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 43 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 44 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 45 | # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 46 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 47 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 48 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 49 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 50 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 51 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 52 | # DAMAGE. 53 | 54 | set(@libname@_VERSION @prplMesh_VERSION@) 55 | 56 | @PACKAGE_INIT@ 57 | 58 | set_and_check(@libname@_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") 59 | set_and_check(@libname@_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") 60 | -------------------------------------------------------------------------------- /scripts/README.md: -------------------------------------------------------------------------------- 1 | # What is this folder? 2 | 3 | In this folder you will find auxiliary scripts to start/manage/stop/... the 4 | IEEE1905 binaries in different 'targets'. 5 | 6 | The folder structure is organized like this: 7 | 8 | ``` 9 | . 10 | |- 'platform' and 'flavour' take the same 11 | | |- values they receive in file 'Makefile' 12 | | |- on the project root folder. 13 | | ... 14 | | `- Examples of 'platform' values: 'linux', ... 15 | ... 16 | `- Examples of 'flavour' values: 'x86_generic', 17 | |- 'arm_wrt1900acx', 'x86_windows_mingw', ... 18 | |- 19 | ... 20 | `- 21 | ``` 22 | 23 | ...where each leaf directory contains self-documented scripts that in some cases 24 | you will be able to use directly while in others you will first need to modify 25 | them for your particular setup/use case. 26 | 27 | > Note that not all supported platforms/flavours necessarily have an associated 28 | > folder (maybe because no scripts have been developed yet or maybe because 29 | > they are not needed at all). 30 | 31 | For example, the 'linux/arm_wrt1900acx' folder contains scripts to start the AL 32 | binary and manage its 'external triggers' using the OpenWRT's configuration 33 | system available in that target. 34 | 35 | -------------------------------------------------------------------------------- /scripts/linux/arm_wrt1900acx/start_linksys.sh: -------------------------------------------------------------------------------- 1 | # Broadband Forum IEEE 1905.1/1a stack 2 | # 3 | # Copyright (c) 2017, Broadband Forum 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are 7 | # met: 8 | # 9 | # 1. Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # 12 | # 2. Redistributions in binary form must reproduce the above copyright 13 | # notice, this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | # 16 | # Subject to the terms and conditions of this license, each copyright 17 | # holder and contributor hereby grants to those receiving rights under 18 | # this license a perpetual, worldwide, non-exclusive, no-charge, 19 | # royalty-free, irrevocable (except for failure to satisfy the 20 | # conditions of this license) patent license to make, have made, use, 21 | # offer to sell, sell, import, and otherwise transfer this software, 22 | # where such license applies only to those patent claims, already 23 | # acquired or hereafter acquired, licensable by such copyright holder or 24 | # contributor that are necessarily infringed by: 25 | # 26 | # (a) their Contribution(s) (the licensed copyrights of copyright holders 27 | # and non-copyrightable additions of contributors, in source or binary 28 | # form) alone; or 29 | # 30 | # (b) combination of their Contribution(s) with the work of authorship to 31 | # which such Contribution(s) was added by such copyright holder or 32 | # contributor, if, at the time the Contribution is added, such addition 33 | # causes such combination to be necessarily infringed. The patent 34 | # license shall not apply to any other combinations which include the 35 | # Contribution. 36 | # 37 | # Except as expressly stated above, no rights or licenses from any 38 | # copyright holder or contributor is granted under this license, whether 39 | # expressly, by implication, estoppel or otherwise. 40 | # 41 | # DISCLAIMER 42 | # 43 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 44 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 45 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 46 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 47 | # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 48 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 49 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 50 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 51 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 52 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 53 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 54 | # DAMAGE. 55 | 56 | ############################################################################## 57 | # 58 | # Description: This script is an example of how to start the 1905 stack in a 59 | # Linksys 1900 AC device 60 | # 61 | # The following binaries/scripts must be in the same directory : 62 | # - start_linksys.sh 63 | # - topology_change.sh 64 | # - al_entity 65 | # - configlayer 66 | # 67 | # This script will : 68 | # - configure the WIFI radio 1 with default configuration 69 | # - configure the ebtables to drop 1905 multicast MACs 70 | # - start the topology_change.sh script to monitor topology 71 | # changes and inform 1905 stack 72 | # - start the 1905 stack with the default configuration 73 | # 74 | # This script must be run with the following command : 75 | # - ./start_linksys.sh 76 | # 77 | # 78 | ############################################################################### 79 | 80 | AL_MAC=00:50:43:22:22:22 81 | GHN_INTERFACE_MAC=00139D00114C 82 | GHN_INTERFACE=eth0 83 | DEFAULT_DOMAIN_NAME=Demo1905_2 84 | DEFAULT_WIFI_SSID=Marvell1905_2 85 | 86 | PATH=$PATH:. 87 | 88 | #Leave secure mode 89 | ./configlayer -i $GHN_INTERFACE -m $GHN_INTERFACE_MAC -o SETLEGACY -p PAIRING.GENERAL.LEAVE_SECURE_DOMAIN=yes -w paterna 90 | 91 | #Default WIFI configuration 92 | uci set wireless.@wifi-iface[1].ssid=$DEFAULT_WIFI_SSID 93 | uci set wireless.@wifi-iface[1].encryption='psk2' 94 | uci set wireless.@wifi-iface[1].key='12345678' 95 | wifi 96 | sleep 5 97 | 98 | #Default GHN configuration 99 | ./configlayer -i $GHN_INTERFACE -m $GHN_INTERFACE_MAC -o SETLEGACY -p NODE.GENERAL.DOMAIN_NAME=$DEFAULT_DOMAIN_NAME -w paterna 100 | 101 | #Avoid duplicate 1905 multicast messages because of bridge 102 | ebtables -A FORWARD -d 01:80:c2:00:00:13 -j DROP 103 | 104 | #Kill previous topology_change process if exsit 105 | process_id=`ps | grep topology_change | grep exe | awk '{print $1}'` 106 | if [ $? -eq "0" ]; then 107 | kill -9 $process_id 108 | fi 109 | 110 | #Monitor topology changes 111 | ./topology_change.sh $GHN_INTERFACE_MAC > /dev/null & 112 | 113 | #Start 1905 entity 114 | echo ./al_entity -m $AL_MAC -i eth0:ghnspirit:$GHN_INTERFACE_MAC:paterna,eth1,wlan1 -v 115 | ./al_entity -m $AL_MAC -i eth0:ghnspirit:$GHN_INTERFACE_MAC:paterna,eth1,wlan1 -v 116 | 117 | -------------------------------------------------------------------------------- /scripts/linux/arm_wrt1900acx/topology_change.sh: -------------------------------------------------------------------------------- 1 | # Broadband Forum IEEE 1905.1/1a stack 2 | # 3 | # Copyright (c) 2017, Broadband Forum 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are 7 | # met: 8 | # 9 | # 1. Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # 12 | # 2. Redistributions in binary form must reproduce the above copyright 13 | # notice, this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | # 16 | # Subject to the terms and conditions of this license, each copyright 17 | # holder and contributor hereby grants to those receiving rights under 18 | # this license a perpetual, worldwide, non-exclusive, no-charge, 19 | # royalty-free, irrevocable (except for failure to satisfy the 20 | # conditions of this license) patent license to make, have made, use, 21 | # offer to sell, sell, import, and otherwise transfer this software, 22 | # where such license applies only to those patent claims, already 23 | # acquired or hereafter acquired, licensable by such copyright holder or 24 | # contributor that are necessarily infringed by: 25 | # 26 | # (a) their Contribution(s) (the licensed copyrights of copyright holders 27 | # and non-copyrightable additions of contributors, in source or binary 28 | # form) alone; or 29 | # 30 | # (b) combination of their Contribution(s) with the work of authorship to 31 | # which such Contribution(s) was added by such copyright holder or 32 | # contributor, if, at the time the Contribution is added, such addition 33 | # causes such combination to be necessarily infringed. The patent 34 | # license shall not apply to any other combinations which include the 35 | # Contribution. 36 | # 37 | # Except as expressly stated above, no rights or licenses from any 38 | # copyright holder or contributor is granted under this license, whether 39 | # expressly, by implication, estoppel or otherwise. 40 | # 41 | # DISCLAIMER 42 | # 43 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 44 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 45 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 46 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 47 | # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 48 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 49 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 50 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 51 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 52 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 53 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 54 | # DAMAGE. 55 | 56 | ############################################################################## 57 | # 58 | # Description: This script is in charge of monitoring network topology changes 59 | # and inform the 1905 stack that a new device has been connected 60 | # or a device has been disconnected. 61 | # 62 | # This script is automatically started by the 'start_linksys.sh' 63 | # script. 64 | # 65 | # In this example, the script only monitors GHN and WIFI 66 | # interfaces. If something occurs in these two interfaces, 67 | # a "touch" will be done to the /tmp/topology_change file to 68 | # inform the 1905 stack that the topology must be refreshed. 69 | # 70 | ############################################################################### 71 | 72 | GHN_INTERFACE_MAC=$1 73 | GHN_INTERFACE=eth0 74 | WIFI_INTERFACE=wlan1 75 | 76 | wifi_device_list_old="" 77 | ghn_device_list_old="" 78 | while true; 79 | do 80 | echo "Refreshing device list...." 81 | wifi_device_list=`iw dev $WIFI_INTERFACE station dump | grep Station | cut -f2 -d' '` 82 | ghn_device_list=`./configlayer -i $GHN_INTERFACE -m $GHN_INTERFACE_MAC -o GETLEGACY -p DIDMNG.GENERAL.MACS -w paterna` 83 | if [ "$wifi_device_list" != "$wifi_device_list_old" ] || [ "$ghn_device_list" != "$ghn_device_list_old" ] 84 | then 85 | echo "Topology has changed" 86 | touch /tmp/topology_change 87 | echo "Old list :" 88 | echo $wifi_device_list_old 89 | echo $ghn_device_list_old 90 | echo "New list :" 91 | echo $wifi_device_list 92 | echo $ghn_device_list 93 | wifi_device_list_old=$wifi_device_list 94 | ghn_device_list_old=$ghn_device_list 95 | fi 96 | sleep 5 97 | done 98 | 99 | -------------------------------------------------------------------------------- /scripts/linux/arm_wrt1900acx/wps: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Broadband Forum IEEE 1905.1/1a stack 3 | # 4 | # Copyright (c) 2017, Broadband Forum 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # 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 | # Subject to the terms and conditions of this license, each copyright 18 | # holder and contributor hereby grants to those receiving rights under 19 | # this license a perpetual, worldwide, non-exclusive, no-charge, 20 | # royalty-free, irrevocable (except for failure to satisfy the 21 | # conditions of this license) patent license to make, have made, use, 22 | # offer to sell, sell, import, and otherwise transfer this software, 23 | # where such license applies only to those patent claims, already 24 | # acquired or hereafter acquired, licensable by such copyright holder or 25 | # contributor that are necessarily infringed by: 26 | # 27 | # (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | # and non-copyrightable additions of contributors, in source or binary 29 | # form) alone; or 30 | # 31 | # (b) combination of their Contribution(s) with the work of authorship to 32 | # which such Contribution(s) was added by such copyright holder or 33 | # contributor, if, at the time the Contribution is added, such addition 34 | # causes such combination to be necessarily infringed. The patent 35 | # license shall not apply to any other combinations which include the 36 | # Contribution. 37 | # 38 | # Except as expressly stated above, no rights or licenses from any 39 | # copyright holder or contributor is granted under this license, whether 40 | # expressly, by implication, estoppel or otherwise. 41 | # 42 | # DISCLAIMER 43 | # 44 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | # DAMAGE. 56 | 57 | ############################################################################## 58 | # 59 | # Description: This script is in charge of modifying the default behavior of 60 | # the WPS hardware button in a Linksys 1900 AC device, running 61 | # OpenWRT. 62 | # 63 | # This script must be copied in the /etc/rc.button directory. 64 | # 65 | # The WPS button will be reconfigured to execute two actions: 66 | # 67 | # 1) If the button is pressed less than 1 second, it will 68 | # toggle the WIFI 'radio 1' to ON or OFF, depending of its 69 | # previous state. 70 | # This is useful to switch ON or OFF the WIFI without 71 | # entering in the Web configuration page. 72 | # 73 | # 2) If the button is pressed more than 3 seconds, it will 74 | # start the 1905 Push Button procedure. 75 | # Depending on the configuration, this procedure will secure 76 | # all device interfaces, and clone the WIFI configuration 77 | # from another device. 78 | # For more information about the Push Button procedure, 79 | # please read the README file provided with the 1905 stack 80 | # implementation. 81 | # 82 | ############################################################################### 83 | 84 | [ "${ACTION}" = "released" ] || exit 0 85 | 86 | . /lib/functions.sh 87 | 88 | logger "$BUTTON pressed for $SEEN seconds..." 89 | 90 | if [ "$SEEN" -lt 1 ] 91 | then 92 | device="radio1" 93 | case $(uci get wireless.$device.txpower) in 94 | 10) 95 | #wifi down $device 96 | #uci set wireless.$device.disabled=1 97 | uci set wireless.$device.txpower=0 98 | wifi 99 | logger "Wifi $device disabled" 100 | ;; 101 | 0) 102 | # uci set wireless.$device.disabled=0 103 | # wifi up $device 104 | uci set wireless.$device.txpower=10 105 | wifi 106 | logger "Wifi $device enabled" 107 | ;; 108 | esac 109 | elif [ "$SEEN" -gt 3 ] 110 | then 111 | touch /tmp/virtual_push_button 112 | logger "Starting 1905 PUSH BUTTON procedure" 113 | fi 114 | 115 | return 0 116 | 117 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, prpl Foundation 2 | # 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions are 5 | # met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # 14 | # Subject to the terms and conditions of this license, each copyright 15 | # holder and contributor hereby grants to those receiving rights under 16 | # this license a perpetual, worldwide, non-exclusive, no-charge, 17 | # royalty-free, irrevocable (except for failure to satisfy the 18 | # conditions of this license) patent license to make, have made, use, 19 | # offer to sell, sell, import, and otherwise transfer this software, 20 | # where such license applies only to those patent claims, already 21 | # acquired or hereafter acquired, licensable by such copyright holder or 22 | # contributor that are necessarily infringed by: 23 | # 24 | # (a) their Contribution(s) (the licensed copyrights of copyright holders 25 | # and non-copyrightable additions of contributors, in source or binary 26 | # form) alone; or 27 | # 28 | # (b) combination of their Contribution(s) with the work of authorship to 29 | # which such Contribution(s) was added by such copyright holder or 30 | # contributor, if, at the time the Contribution is added, such addition 31 | # causes such combination to be necessarily infringed. The patent 32 | # license shall not apply to any other combinations which include the 33 | # Contribution. 34 | # 35 | # Except as expressly stated above, no rights or licenses from any 36 | # copyright holder or contributor is granted under this license, whether 37 | # expressly, by implication, estoppel or otherwise. 38 | # 39 | # DISCLAIMER 40 | # 41 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 42 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 43 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 44 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 45 | # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 46 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 47 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 48 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 49 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 50 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 51 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 52 | # DAMAGE. 53 | 54 | add_library(${libname} STATIC 55 | 1905_alme.c 56 | 1905_cmdus.c 57 | 1905_tlvs.c 58 | al_datamodel.c 59 | al_entity.c 60 | al_extension.c 61 | al_extension_register.c 62 | al_recv.c 63 | al_send.c 64 | al_utils.c 65 | al_wsc.c 66 | bbf_recv.c 67 | bbf_send.c 68 | bbf_tlvs.c 69 | datamodel.c 70 | hlist.c 71 | lldp_payload.c 72 | lldp_tlvs.c 73 | mac_address.c 74 | media_specific_blobs.c 75 | tlv.c 76 | utils.c) 77 | 78 | install(TARGETS ${libname} DESTINATION lib COMPONENT Devel) 79 | 80 | if (${CMAKE_SYSTEM_NAME} MATCHES Linux) 81 | 82 | find_package(OpenSSL REQUIRED) 83 | find_package(Threads REQUIRED) 84 | 85 | find_package(PkgConfig) 86 | pkg_check_modules(NL3 libnl-3.0 libnl-genl-3.0 REQUIRED) 87 | 88 | find_library(LIBRT rt) 89 | 90 | target_include_directories(${libname} PRIVATE ${OPENSSL_INCLUDE_DIR} ${NL3_INCLUDE_DIRS}) 91 | set_property(TARGET ${libname} APPEND PROPERTY COMPILE_OPTIONS ${NL3_CFLAGS_OTHER}) 92 | 93 | target_sources(${libname} PRIVATE 94 | linux/netlink_collect.c 95 | linux/netlink_socks.c 96 | linux/netlink_utils.c 97 | linux/platform.c 98 | linux/platform_alme_server.c 99 | linux/platform_crypto.c 100 | linux/platform_interfaces.c 101 | # @todo make these configurable 102 | linux/platform_interfaces_ghnspirit.c 103 | linux/platform_interfaces_simulated.c 104 | linux/platform_os.c) 105 | 106 | target_link_libraries(${libname} OpenSSL::Crypto Threads::Threads ${NL3_LIBRARIES}) 107 | if (LIBRT) 108 | target_link_libraries(${libname} rt) 109 | endif (LIBRT) 110 | 111 | if (OPENWRT) 112 | find_library(UBOX ubox) 113 | if (NOT UBOX) 114 | message(SEND_ERROR "OpenWRT integration requires ubox") 115 | endif (NOT UBOX) 116 | find_library(UBUS ubus) 117 | if (NOT UBUS) 118 | message(SEND_ERROR "OpenWRT integration requires ubus") 119 | endif (NOT UBUS) 120 | target_sources(${libname} PRIVATE 121 | linux/platform_uci.c 122 | linux/platform_interfaces_openwrt.c) 123 | target_link_libraries(${libname} ${UBUS} ${UBOX}) 124 | endif (OPENWRT) 125 | 126 | add_executable(al_entity linux/al_entity/al_entity_main.c) 127 | target_link_libraries(al_entity ${libname}) 128 | install(TARGETS al_entity DESTINATION bin) 129 | 130 | if (OPENWRT) 131 | add_executable(prplmesh linux/al_entity/al_entity_openwrt.c) 132 | target_link_libraries(prplmesh ${libname}) 133 | install(TARGETS prplmesh DESTINATION bin) 134 | endif (OPENWRT) 135 | 136 | 137 | add_executable(hl_entity linux/hl_entity/hl_entity_main.c) 138 | target_link_libraries(hl_entity ${libname} OpenSSL::Crypto Threads::Threads) 139 | install(TARGETS hl_entity DESTINATION bin) 140 | 141 | endif (${CMAKE_SYSTEM_NAME} MATCHES Linux) 142 | 143 | -------------------------------------------------------------------------------- /src/al.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _AL_H_ 59 | #define _AL_H_ 60 | 61 | #define AL_ERROR_OUT_OF_MEMORY (1) 62 | #define AL_ERROR_INVALID_ARGUMENTS (2) 63 | #define AL_ERROR_NO_INTERFACES (3) 64 | #define AL_ERROR_INTERFACE_ERROR (4) 65 | #define AL_ERROR_OS (5) 66 | #define AL_ERROR_PROTOCOL_EXTENSION (6) 67 | 68 | // This is the function that runs the 1905 Abstraction Layer (AL) state machine. 69 | // 70 | // In order to start the AL services this is what you have to do from your 71 | // platform specific code: 72 | // 73 | // 1. Create a thread 74 | // 2. Make that thread execute this function 75 | // 76 | // Before calling this function, the platform and al_datamodel must have been initialized. 77 | // 78 | // It returns when: 79 | // 80 | // - Something went terribly wrong (maybe at initiallization time or maybe 81 | // later, while doing its bussiness). It that case it returns an error code 82 | // which is always bigger than '0': 83 | // 84 | // AL_ERROR_OUT_OF_MEMORY: 85 | // A call to "memalloc()" failed, meaning there is no more memory 86 | // available in the system. 87 | // 88 | // AL_ERROR_INVALID_ARGUMENTS: 89 | // The provided 'al_mac_address' is not valid. 90 | // 91 | // AL_ERROR_NO_INTERFACES: 92 | // A call to "PLATFORM_GET_LIST_OF_1905_INTERFACES()" returned an empty 93 | // list, meaning there is nothing for the 1905 AL entity to do. 94 | // 95 | // AL_ERROR_INTERFACE_ERROR: 96 | // A call to "PLATFORM_GET_LIST_OF_1905_INTERFACES() returned an error 97 | // or some other interface related problem. 98 | // 99 | // AL_ERROR_OS: 100 | // One of the OS-related PLATFORM_* functions returned an error (these 101 | // are functions use to create queues, start timers, etc...) 102 | // 103 | // AL_ERROR_PROTOCOL_EXTENSION; 104 | // Error registering, at least, one protocol extension. 105 | // 106 | // - The HLE requested the AL service to stop. In this case it will return '0' 107 | // 108 | uint8_t start1905AL(void); 109 | 110 | 111 | #endif 112 | 113 | -------------------------------------------------------------------------------- /src/al_recv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _AL_RECV_H_ 59 | #define _AL_RECV_H_ 60 | 61 | #include "1905_cmdus.h" 62 | #include "lldp_payload.h" 63 | #include "datamodel.h" 64 | 65 | // This function does "whatever needs to be done" as a result of receiving a 66 | // CMDU: for example, some CMDU trigger a response, others are used to update 67 | // the topology data base, etc... 68 | // 69 | // This function does *not* deal with "discarding" or "forwarding" the packet 70 | // (that should have already been taken care of before this function is called) 71 | // 72 | // 'c' is the just received CMDU structure. 73 | // 74 | // 'receiving_interface_addr' is the MAC address of the local interface where 75 | // the CMDU packet was received 76 | // 77 | // 'src_addr' is the MAC address contained in the 'src' field of the ethernet 78 | // frame which contained the just received CMDU payload. 79 | // 80 | // 'queue_id' is the ID of the queue where messages to the AL entity should be 81 | // posted in case new actions are derived from the processing of the current 82 | // message. 83 | // 84 | // Return values: 85 | // PROCESS_CMDU_KO: 86 | // There was problem processing the CMDU 87 | // PROCESS_CMDU_OK: 88 | // The CMDU was correctly processed. No further action required. 89 | // PROCESS_CMDU_OK_TRIGGER_AP_SEARCH: 90 | // The CMDU was correctly processed. The caller should now trigger an "AP 91 | // search" process if there is still an unconfigured AP local interface. 92 | // 93 | #define PROCESS_CMDU_KO (0) 94 | #define PROCESS_CMDU_OK (1) 95 | #define PROCESS_CMDU_OK_TRIGGER_AP_SEARCH (2) 96 | uint8_t process1905Cmdu(struct CMDU *c, struct interface *receiving_interface, uint8_t *src_addr, uint8_t queue_id); 97 | 98 | // Call this function when receiving an LLPD "bridge discovery" message so that 99 | // the topology database is properly updated. 100 | // 101 | uint8_t processLlpdPayload(struct PAYLOAD *payload, struct interface *receiving_interface); 102 | 103 | // Call this function when receiving an ALME REQUEST message. It will take 104 | // action depending on the actual contents of this message (ie. "shut down an 105 | // interface", "add a new bridge configuration", etc...) 106 | // 107 | uint8_t process1905Alme(uint8_t *alme_tlv, uint8_t alme_client_id); 108 | 109 | #endif 110 | 111 | 112 | -------------------------------------------------------------------------------- /src/al_utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #include "platform.h" 59 | #include "platform_crypto.h" 60 | 61 | 62 | //////////////////////////////////////////////////////////////////////////////// 63 | // Public functions (exported only to files in this same folder) 64 | //////////////////////////////////////////////////////////////////////////////// 65 | 66 | uint16_t getNextMid(void) 67 | { 68 | static uint16_t mid = 0; 69 | static uint8_t first_time = 1; 70 | 71 | if (1 == first_time) 72 | { 73 | // Start with a random MID. The standard is not clear about this, but 74 | // I think a random number is better than simply choosing zero, to 75 | // avoid start up problems (ex: one node boots and after a short time 76 | // it is reset and starts making use of the same MIDs all over again, 77 | // which will probably be ignored by other nodes, thinking they have 78 | // already processed these messages in the past) 79 | // 80 | first_time = 0; 81 | PLATFORM_GET_RANDOM_BYTES((uint8_t*)&mid, sizeof(uint16_t)); 82 | } 83 | else 84 | { 85 | mid++; 86 | } 87 | 88 | return mid; 89 | } 90 | 91 | -------------------------------------------------------------------------------- /src/al_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _AL_UTILS_H_ 59 | #define _AL_UTILS_H_ 60 | 61 | // "MIDs" are "message IDs" used inside 1905 protocol messages. They must be 62 | // monotonically increased as explained in "Section 7.8" 63 | // 64 | uint16_t getNextMid(void); 65 | 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /src/bbf_recv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _BBF_RECV_H_ 59 | #define _BBF_RECV_H_ 60 | 61 | #include "1905_cmdus.h" 62 | 63 | 64 | // Process BBF TLVs included in the incoming CMDU structure 65 | // 66 | // This function allows to parse the new TLVs defined in the BBF community. 67 | // According to the standard, any CMDU is subject to be extended with extra 68 | // Vendor Specific TLVs, so each inserted BBF TLV will be embedded inside a 69 | // Vendor Specific TLV. 70 | // This implementation will only process defined BBF TLVs embedded inside a 71 | // Vendor Specific TLV whose OUI is the BBF one (0x00256d) 72 | // 73 | // 'memory_structure' is the CMDU structure 74 | // 75 | // Return '0' if there was a problem, '1' otherwise 76 | // 77 | uint8_t CBKprocess1905BBFExtensions(struct CMDU *memory_structure); 78 | 79 | #endif 80 | 81 | 82 | -------------------------------------------------------------------------------- /src/hlist.c: -------------------------------------------------------------------------------- 1 | /* 2 | * prplMesh Wi-Fi Multi-AP 3 | * 4 | * Copyright (c) 2018, prpl Foundation 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #include 59 | #include /* memalloc() */ 60 | #include /* memset() */ 61 | 62 | struct hlist_item *hlist_alloc(size_t size, dlist_head *parent) 63 | { 64 | hlist_item *ret = memalloc(size); 65 | memset(ret, 0, size); 66 | dlist_head_init(&ret->l); 67 | dlist_head_init(&ret->children[0]); 68 | dlist_head_init(&ret->children[1]); 69 | if (parent) 70 | { 71 | dlist_add_tail(parent, ret); 72 | } 73 | return ret; 74 | } 75 | 76 | void hlist_delete(dlist_head *list) 77 | { 78 | dlist_head *next = list->next; 79 | 80 | /* Since we will free all items in the list, it is not needed to remove them from the list. However, the normal 81 | * hlist_for_each macro would use the next pointer after the item has been freed. Therefore, we use an open-coded 82 | * iteration here. */ 83 | while (next != list) 84 | { 85 | hlist_item *item = container_of(next, hlist_item, l); 86 | next = next->next; 87 | dlist_head_init(&item->l); 88 | hlist_delete_item(item); 89 | } 90 | /* We still have to make sure the list is empty, in case it is reused later. */ 91 | dlist_head_init(list); 92 | } 93 | 94 | void hlist_delete_item(hlist_item *item) 95 | { 96 | assert(dlist_empty(&item->l)); 97 | hlist_delete(&item->children[0]); 98 | hlist_delete(&item->children[1]); 99 | free(item); 100 | } 101 | -------------------------------------------------------------------------------- /src/linux/ieee80211.h: -------------------------------------------------------------------------------- 1 | #ifndef __IEEE80211 2 | #define __IEEE80211 3 | /* 4 | * Copyright (c) 2007, 2008 Johannes Berg 5 | * Copyright (c) 2007 Andy Lutomirski 6 | * Copyright (c) 2007 Mike Kershaw 7 | * Copyright (c) 2008-2009 Luis R. Rodriguez 8 | * 9 | * Permission to use, copy, modify, and/or distribute this software for any 10 | * purpose with or without fee is hereby granted, provided that the above 11 | * copyright notice and this permission notice appear in all copies. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | */ 21 | 22 | /* 802.11n HT capability AMPDU settings (for ampdu_params_info) */ 23 | #define IEEE80211_HT_AMPDU_PARM_FACTOR 0x03 24 | #define IEEE80211_HT_AMPDU_PARM_DENSITY 0x1C 25 | 26 | #define IEEE80211_HT_CAP_SUP_WIDTH_20_40 0x0002 27 | #define IEEE80211_HT_CAP_SGI_40 0x0040 28 | #define IEEE80211_HT_CAP_MAX_AMSDU 0x0800 29 | 30 | #define IEEE80211_HT_MCS_MASK_LEN 10 31 | 32 | /** 33 | * struct ieee80211_mcs_info - MCS information 34 | * @param rx_mask: RX mask 35 | * @param rx_highest: highest supported RX rate. If set represents 36 | * the highest supported RX data rate in units of 1 Mbps. 37 | * If this field is 0 this value should not be used to 38 | * consider the highest RX data rate supported. 39 | * @param tx_params: TX parameters 40 | */ 41 | struct ieee80211_mcs_info { 42 | __u8 rx_mask[IEEE80211_HT_MCS_MASK_LEN]; 43 | __u16 rx_highest; 44 | __u8 tx_params; 45 | __u8 reserved[3]; 46 | } __attribute__ ((packed)); 47 | 48 | 49 | /** 50 | * struct ieee80211_ht_cap - HT capabilities 51 | * 52 | * This structure is the "HT capabilities element" as 53 | * described in 802.11n D5.0 7.3.2.57 54 | */ 55 | struct ieee80211_ht_cap { 56 | __u16 cap_info; 57 | __u8 ampdu_params_info; 58 | 59 | /* 16 bytes MCS information */ 60 | struct ieee80211_mcs_info mcs; 61 | 62 | __u16 extended_ht_cap_info; 63 | __u32 tx_BF_cap_info; 64 | __u8 antenna_selection_info; 65 | } __attribute__ ((packed)); 66 | 67 | struct ieee80211_vht_mcs_info { 68 | __u16 rx_vht_mcs; 69 | __u16 rx_highest; 70 | __u16 tx_vht_mcs; 71 | __u16 tx_highest; 72 | } __attribute__ ((packed)); 73 | 74 | struct ieee80211_vht_cap { 75 | __u32 cap_info; 76 | struct ieee80211_vht_mcs_info mcs; 77 | } __attribute__ ((packed)); 78 | 79 | #endif /* __IEEE80211 */ 80 | -------------------------------------------------------------------------------- /src/linux/netlink_funcs.h: -------------------------------------------------------------------------------- 1 | #ifndef _NETLINK_FUNCS_H 2 | #define _NETLINK_FUNCS_H 3 | /* 4 | * prplMesh Wi-Fi Multi-AP 5 | * 6 | * Copyright (c) 2018, prpl Foundation 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are 10 | * met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * Subject to the terms and conditions of this license, each copyright 20 | * holder and contributor hereby grants to those receiving rights under 21 | * this license a perpetual, worldwide, non-exclusive, no-charge, 22 | * royalty-free, irrevocable (except for failure to satisfy the 23 | * conditions of this license) patent license to make, have made, use, 24 | * offer to sell, sell, import, and otherwise transfer this software, 25 | * where such license applies only to those patent claims, already 26 | * acquired or hereafter acquired, licensable by such copyright holder or 27 | * contributor that are necessarily infringed by: 28 | * 29 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 30 | * and non-copyrightable additions of contributors, in source or binary 31 | * form) alone; or 32 | * 33 | * (b) combination of their Contribution(s) with the work of authorship to 34 | * which such Contribution(s) was added by such copyright holder or 35 | * contributor, if, at the time the Contribution is added, such addition 36 | * causes such combination to be necessarily infringed. The patent 37 | * license shall not apply to any other combinations which include the 38 | * Contribution. 39 | * 40 | * Except as expressly stated above, no rights or licenses from any 41 | * copyright holder or contributor is granted under this license, whether 42 | * expressly, by implication, estoppel or otherwise. 43 | * 44 | * DISCLAIMER 45 | * 46 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 47 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 48 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 49 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 50 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 51 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 52 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 53 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 54 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 55 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 56 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 57 | * DAMAGE. 58 | */ 59 | 60 | #include 61 | #include // struct nl_sock 62 | #include // nl_msg 63 | 64 | #include "datamodel.h" // struct alDevice / mac_address 65 | #include "nl80211.h" // nl80211_commands 66 | 67 | #define BIT(x) (1ULL<<(x)) 68 | 69 | /** @file 70 | * 71 | * This file defines all the prototypes needed by the netlink functions 72 | */ 73 | 74 | struct nl80211_state { 75 | struct nl_sock *nl_sock; /**< Netlink socket */ 76 | int nl80211_id; /**< Generic netlink family identifer */ 77 | }; 78 | 79 | /** @brief Collect some infos from sysfs (mac, index, ...) 80 | * 81 | * @param basedir Directory to look for phy's attributes (ex. /sys/class/net/wlan0/phy80211) 82 | * @param name Output name of the radio interface (phy{0..9}) 83 | * @param mac Output mac address (uid) of the radio 84 | * @param index Output index of the PHY device 85 | * 86 | * @return >0:success, 0:not found, <0:error 87 | */ 88 | extern int phy_lookup(const char *basedir, char *name, mac_address mac, int *index); 89 | 90 | /** @brief Add all the local radios found with their collected datas into global ::local_device 91 | * @return >=0:Number of radios processed/found, <0:error 92 | */ 93 | extern int netlink_collect_local_infos(void); 94 | 95 | /** @brief Open the netlink socket and prepare for commands 96 | * 97 | * @param out_nlstate Output structure 98 | * 99 | * @return 0=success, <0=error 100 | */ 101 | extern int netlink_open(struct nl80211_state *out_nlstate); 102 | 103 | /** @brief Prepare a new Netlink message to be sent 104 | * 105 | * @param nlsock Netlink socket to use 106 | * @param cmd Netlink Command to initiate (See nl80211.h) 107 | * @param flags Optional command flags 108 | * 109 | * @return 0=success, <0=error 110 | */ 111 | extern struct nl_msg* netlink_prepare(const struct nl80211_state *nlsock, 112 | enum nl80211_commands cmd, int flags); 113 | 114 | /** @brief Execute a netlink command 115 | * 116 | * The @a cb callback is called when a valid data is received. Otherwise, 117 | * internal handlers assume the error handling. 118 | * 119 | * @param nlstate Netlink state & socket infos 120 | * @param nlmsg Netlink message to process 121 | * @param cb Callback to process the valid datas returned by the nlmsg 122 | * @param cbdatas Callback's datas passed as second parameter to @a cb 123 | * 124 | * @return 0:success, <0:error 125 | */ 126 | extern int netlink_do(struct nl80211_state *nlstate, struct nl_msg *nlmsg, 127 | int (*cb)(struct nl_msg *, void *), void *cbdatas); 128 | 129 | /** @brief Close the netlink socket and free allocations 130 | * 131 | * @param nlstate Netlink socket state structure 132 | */ 133 | extern void netlink_close(struct nl80211_state *nlstate); 134 | 135 | /** @brief Get the frequency of the corresponding channel 136 | * 137 | * @param chan Channel ID 138 | * @param band Band this channel is from 139 | * 140 | * @return Frequency (x100) 141 | */ 142 | extern int ieee80211_channel_to_frequency(int chan, enum nl80211_band band); 143 | 144 | /** @brief Get the channel corresponding to this frequency 145 | * 146 | * @param freq Frequency 147 | * 148 | * @return Channel id 149 | */ 150 | extern int ieee80211_frequency_to_channel(int freq); 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /src/linux/platform_alme_server_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _PLATFORM_ALME_SERVER_PRIV_H_ 59 | #define _PLATFORM_ALME_SERVER_PRIV_H_ 60 | 61 | #include 62 | 63 | // When the AL calls "PLATFORM_REGISTER_QUEUE_EVENT()" with 'event_type' set to 64 | // "PLATFORM_QUEUE_EVENT_NEW_ALME_MESSAGE", a thread that runs the following 65 | // function must be started. 66 | // 67 | // This will take care of receiving (in a platform-specific way) ALME messages 68 | // and then forward them to the queue whose ID is contained in the "struct 69 | // _almeServerThreadData" structure that is passed in the "void *p" argument. 70 | // 71 | struct almeServerThreadData 72 | { 73 | uint8_t queue_id; 74 | }; 75 | 76 | void *almeServerThread(void *p); 77 | 78 | 79 | // This function is used to set the port number where the ALME server will 80 | // listen to, waiting for ALME requests. 81 | // It must be called *before* starting the 'almeServerThread()' thread. 82 | // 83 | void almeServerPortSet(int port_number); 84 | 85 | #endif 86 | 87 | -------------------------------------------------------------------------------- /src/linux/platform_interfaces_ghnspirit_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _PLATFORM_INTERFACES_GHNSPIRIT_H_ 59 | #define _PLATFORM_INTERFACES_GHNSPIRIT_H_ 60 | 61 | #include "../platform_interfaces.h" // struct interfaceInfo 62 | 63 | 64 | // Call this function at the very beginning of your program so that interfaces 65 | // of type "ghnspirit" can be processed with the corresponding callbacks in the 66 | // future. 67 | // 68 | void registerGhnSpiritInterfaceType(void); 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/linux/platform_interfaces_openwrt_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _PLATFORM_INTERFACES_OPENWRT_PRIV_H_ 59 | #define _PLATFORM_INTERFACES_OPENWRT_PRIV_H_ 60 | 61 | 62 | // Fill the "interfaceInfo" structure (associated to the provided 63 | // "interface_name") by obtaining information from the OpenWRT UCI subsystem. 64 | // 65 | // 66 | uint8_t openwrt_get_interface_info(char *interface_name, struct interfaceInfo *m); 67 | 68 | // Modify the current Wifi configuration according to the values passed as 69 | // parameters. Modifications take effect immediately. 70 | // 71 | uint8_t openwrt_apply_80211_configuration(char *interface_name, uint8_t *ssid, uint8_t *network_key); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/linux/platform_interfaces_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _PLATFORM_INTERFACES_PRIV_H_ 59 | #define _PLATFORM_INTERFACES_PRIV_H_ 60 | 61 | // This function must be called at the very beginning of your program to 62 | // register new types of "special" interfaces. 63 | // 64 | // Special interfaces are those that, in the command line, contain one or more 65 | // ":". Examples: 66 | // 67 | // eth0:ghnspirit:00ab443a600f:bluemoon 68 | // eth1:simulated:eth1_params.txt 69 | // 70 | // 'interface_type' is the first token after the first ":" ("ghnspirit" or 71 | // "simulated" in the examples above). 72 | // It can be anything you want (as long as you are willing to provide handlers 73 | // for each context to that particular type) 74 | // 75 | // 'sub_type' is one of the available contexts ("STUB_TYPE_*"). 76 | // 77 | // 'f' is a pointer to a function with a specific prototype depending on the 78 | // context: 79 | // 80 | // - STUB_TYPE_GET_INFO --> void (*f)(char *interface_name, char *extended_params, struct interfaceInfo *m) 81 | // - STUB_TYPE_GET_METRICS --> void (*f)(char *interface_name, char *extended_params, struct linkMetrics *m) 82 | // - STUB_TYPE_PUSH_BUTTON_START --> void (*f)(char *interface_name, char *extended_params) 83 | // 84 | // Once registered, the 'f' function will be called from the associated context 85 | // and this is its expected behaviour: 86 | // 87 | // - STUB_TYPE_GET_INFO: 88 | // It receives the 'interface_name' (ex: "eth0") and the "extended_params" 89 | // (everything after the first ":", ex: "ghnspirit:00ab443a600f:bluemoon") 90 | // as arguments, and with that information 'f' is expected to fill the 91 | // 'm' structure with the appropiate information. 92 | // 93 | // - STUB_TYPE_GET_METRICS: 94 | // Same as "STUB_TYPE_GET_INFO", but this time the structure has to be 95 | // filled with metrics information of the link connecting the local 96 | // interface and 'm->neighbor_interface_address'. 97 | // 'm->local_interface_address' and 'm->neighbor_interface_address' are 98 | // the only two fields already filled when the handler is called. All the 99 | // others must be filled by the handler. 100 | // 101 | // - STUB_TYPE_PUSH_BUTTON_START: 102 | // 'f' is expected to start the "push button configuration process" on 103 | // the given local interface. 104 | // 105 | // Note that for each "interface_type" you must call this function STUB_TYPE_MAX 106 | // times (one for each stub type) with (obviously) different handlers (one for 107 | // each context) 108 | // 109 | // This function returns '1' if there was a problem, '0' otherwise. 110 | // 111 | #define STUB_TYPE_GET_INFO (0) 112 | #define STUB_TYPE_GET_METRICS (1) 113 | #define STUB_TYPE_PUSH_BUTTON_START (2) 114 | #define STUB_TYPE_MAX (2) 115 | uint8_t registerInterfaceStub(char *interface_type, uint8_t stub_type, void *f); 116 | 117 | // This function is used to initialize the "interfaces list database" from the 118 | // arguments obtained from the command line. 119 | // 120 | // In other words: when the initialization function obtains the list of 121 | // interfaces the user is interested in making visible to the 1905 AL entity, 122 | // it should call this function (once per interface) *before* starting the AL 123 | // entity. 124 | // 125 | // Note that 'long_interface_name' must include the "whole" interface name as 126 | // given in the command line. Examples: 127 | // 128 | // Regular interface: "eth0" 129 | // Special interface: "eth0:simualted:eth1_params.txt" 130 | // 131 | // For "special interfaces" to work, you need to call "registerInterfaceStub()" 132 | // before calling this function. 133 | // 134 | void addInterface(char *long_interface_name); 135 | 136 | #endif 137 | 138 | -------------------------------------------------------------------------------- /src/linux/platform_interfaces_simulated_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _PLATFORM_INTERFACES_SIMULATED_H_ 59 | #define _PLATFORM_INTERFACES_SIMULATED_H_ 60 | 61 | 62 | // Call this function at the very beginning of your program so that interfaces 63 | // of type "simulated" can be processed with the corresponding callbacks in the 64 | // future. 65 | // 66 | void registerSimulatedInterfaceType(void); 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/linux/platform_os_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _PLATFORM_OS_PRIV_H_ 59 | #define _PLATFORM_OS_PRIV_H_ 60 | 61 | #include 62 | 63 | // Send a message to the AL queue whose id is 'queue_id' 64 | // 65 | // Return "0" if there was a problem, "1" otherwise 66 | // 67 | uint8_t sendMessageToAlQueue(uint8_t queue_id, uint8_t *message, uint16_t message_len); 68 | 69 | #endif 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/linux/platform_uci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * prplMesh Wi-Fi Multi-AP 3 | * 4 | * Copyright (c) 2018, prpl Foundation 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | /** @file 59 | * @brief Driver interface for UCI 60 | * 61 | * This file provides driver functionality using UCI. It uses UCI calls to create access points. 62 | */ 63 | 64 | #ifndef PLATFORM_UCI_H 65 | #define PLATFORM_UCI_H 66 | 67 | /** @brief Register the UCI callbacks for all radios. 68 | * 69 | * This function must be called after the radios have already been discovered (e.g. with nl80211). 70 | * 71 | * @todo Add a non-UCI dummy implementation. 72 | */ 73 | void uci_register_handlers(void); 74 | 75 | #endif // PLATFORM_UCI_H 76 | -------------------------------------------------------------------------------- /src/mac_address.c: -------------------------------------------------------------------------------- 1 | /* 2 | * prplMesh Wi-Fi Multi-AP 3 | * 4 | * Copyright (c) 2018, prpl Foundation 5 | * Copyright (c) 2017, Broadband Forum 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * 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 | * Subject to the terms and conditions of this license, each copyright 19 | * holder and contributor hereby grants to those receiving rights under 20 | * this license a perpetual, worldwide, non-exclusive, no-charge, 21 | * royalty-free, irrevocable (except for failure to satisfy the 22 | * conditions of this license) patent license to make, have made, use, 23 | * offer to sell, sell, import, and otherwise transfer this software, 24 | * where such license applies only to those patent claims, already 25 | * acquired or hereafter acquired, licensable by such copyright holder or 26 | * contributor that are necessarily infringed by: 27 | * 28 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 29 | * and non-copyrightable additions of contributors, in source or binary 30 | * form) alone; or 31 | * 32 | * (b) combination of their Contribution(s) with the work of authorship to 33 | * which such Contribution(s) was added by such copyright holder or 34 | * contributor, if, at the time the Contribution is added, such addition 35 | * causes such combination to be necessarily infringed. The patent 36 | * license shall not apply to any other combinations which include the 37 | * Contribution. 38 | * 39 | * Except as expressly stated above, no rights or licenses from any 40 | * copyright holder or contributor is granted under this license, whether 41 | * expressly, by implication, estoppel or otherwise. 42 | * 43 | * DISCLAIMER 44 | * 45 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 46 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 47 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 48 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 49 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 50 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 51 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 52 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 53 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 54 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 55 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 56 | * DAMAGE. 57 | */ 58 | 59 | #include 60 | #include 61 | #include 62 | 63 | #include "hlist.h" 64 | 65 | void asciiToMac(const char *str, mac_address addr) 66 | { 67 | int i = 0; 68 | 69 | if ( ! str ) { 70 | memset(addr, 0, sizeof(mac_address)); 71 | return; 72 | } 73 | 74 | while ( 0x00 != *str && i < 6 ) { 75 | uint8_t byte = 0; 76 | while ( 0x00 != *str && ':' != *str ) { 77 | char low; 78 | byte <<= 4; 79 | low = tolower(*str); 80 | 81 | if ( low >= 'a' ) byte |= low - 'a' + 10; 82 | else byte |= low - '0'; 83 | 84 | str++; 85 | } 86 | addr[i] = byte; 87 | i++; 88 | if ( ! *str ) 89 | break; 90 | str++; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/media_specific_blobs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #include 59 | 60 | #include "media_specific_blobs.h" 61 | 62 | #include // memcmp(), memcpy(), ... 63 | 64 | 65 | //////////////////////////////////////////////////////////////////////////////// 66 | // Actual API functions 67 | //////////////////////////////////////////////////////////////////////////////// 68 | 69 | uint8_t *forge_media_specific_blob(struct genericInterfaceType *m, uint16_t *len) 70 | { 71 | #define ITU_T_GHN_XML "http://handle.itu.int/11.1002/3000/1706" 72 | 73 | uint8_t *ret; 74 | 75 | ret = NULL; 76 | 77 | if (NULL == m->generic_phy_description_xml_url) 78 | { 79 | return NULL; 80 | } 81 | 82 | if (0 == memcmp(m->generic_phy_description_xml_url, ITU_T_GHN_XML, strlen(ITU_T_GHN_XML)+1)) 83 | { 84 | // This XML file defines the *same* media specific data format for all 85 | // interfaces that meet the following requirements: 86 | // 87 | // - OUI = 00:19:A7 88 | // - Variant = 0, 1, 2, 3 or 4 (it also defines 10 and 11, but we will 89 | // ignore these) 90 | 91 | if ( 92 | m->oui[0] != 0x00 || 93 | m->oui[1] != 0x19 || 94 | m->oui[2] != 0xa7 95 | ) 96 | { 97 | // Unknown OUI 98 | } 99 | else if ( 100 | m->variant_index != 0 && 101 | m->variant_index != 1 && 102 | m->variant_index != 2 && 103 | m->variant_index != 3 && 104 | m->variant_index != 4 105 | ) 106 | { 107 | // Unknown variant 108 | } 109 | else 110 | { 111 | // The 1905 media specific field is made up of FIVE bytes: 112 | // 113 | // 0x01, 0x00, 0x02, dni[0], dni[1] 114 | // 115 | // (see ITU-T G.9979 Tables 8.2 and 8.3) 116 | // 117 | *len = 5; 118 | ret = (uint8_t *)memalloc(*len); 119 | ret[0] = 0x01; 120 | ret[1] = 0x00; 121 | ret[2] = 0x02; 122 | ret[3] = m->media_specific.ituGhn.dni[0]; 123 | ret[4] = m->media_specific.ituGhn.dni[1]; 124 | } 125 | } 126 | 127 | if (NULL == ret) 128 | { 129 | // If we get to this point and "ret" is still "NULL", that means that the 130 | // "XML"/"OUI"/"variant_index" combination has not been recognized, and thus 131 | // we will simply return the contents of the "unsupported" structure. 132 | // 133 | *len = m->media_specific.unsupported.bytes_nr; 134 | ret = (uint8_t *)memalloc(*len); 135 | 136 | memcpy(ret, m->media_specific.unsupported.bytes, *len); 137 | } 138 | 139 | return ret; 140 | } 141 | 142 | -------------------------------------------------------------------------------- /src/platform_alme_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _PLATFORM_ALME_SERVER_H_ 59 | #define _PLATFORM_ALME_SERVER_H_ 60 | 61 | //////////////////////////////////////////////////////////////////////////////// 62 | // ALME message server related functions 63 | //////////////////////////////////////////////////////////////////////////////// 64 | 65 | // This function is called everytime a new ALME RESPONSE/CONFIRMATION meesage 66 | // is generated by the AL entity. 67 | // 68 | // A RESPONSE/CONFIRMATION that is produced as a result of a previous REQUEST, 69 | // contains the same 'alme_client_id' as the one the REQUEST originally inserted 70 | // in the messages queue (as explained in the "PLATFORM_REGISTER_QUEUE_EVENT()" 71 | // documentation). 72 | // 73 | // 'alme_message' is a pointer to the ALME payload and is 'alme_message_len' 74 | // bytes long 75 | // 76 | // Return '0' if there was some problem processing the RESPONSE/CONFIRMATION, 77 | // "1" otherwise. 78 | // 79 | uint8_t PLATFORM_SEND_ALME_REPLY(uint8_t alme_client_id, uint8_t *alme_message, uint16_t alme_message_len); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /tests/1905_cmdu_test_vectors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _1905_CMDU_TEST_VECTORS_H_ 59 | #define _1905_CMDU_TEST_VECTORS_H_ 60 | 61 | #include "1905_cmdus.h" 62 | #include "1905_tlvs.h" 63 | 64 | extern struct CMDU x1905_cmdu_structure_001; 65 | extern uint8_t *x1905_cmdu_streams_001[]; 66 | extern uint16_t x1905_cmdu_streams_len_001[]; 67 | 68 | extern struct CMDU x1905_cmdu_structure_002; 69 | extern uint8_t *x1905_cmdu_streams_002[]; 70 | extern uint16_t x1905_cmdu_streams_len_002[]; 71 | 72 | extern struct CMDU x1905_cmdu_structure_003; 73 | extern uint8_t *x1905_cmdu_streams_003[]; 74 | extern uint16_t x1905_cmdu_streams_len_003[]; 75 | 76 | extern struct CMDU x1905_cmdu_structure_004; 77 | extern uint8_t *x1905_cmdu_streams_004[]; 78 | extern uint16_t x1905_cmdu_streams_len_004[]; 79 | 80 | extern struct CMDU x1905_cmdu_structure_005; 81 | extern uint8_t *x1905_cmdu_streams_005[]; 82 | extern uint16_t x1905_cmdu_streams_len_005[]; 83 | 84 | /** @defgroup tv_cmdu_header CMDU header parsing test vectors 85 | */ 86 | 87 | /** @defgroup tv_cmdu_header_001 CMDU header with last fragment indicator 88 | * 89 | * @ingroup tv_cmdu_header 90 | * @{ 91 | */ 92 | extern struct CMDU_header x1905_cmdu_header_001; 93 | extern uint8_t x1905_cmdu_packet_001[]; 94 | extern size_t x1905_cmdu_packet_len_001; 95 | /** @} */ 96 | 97 | /** @defgroup tv_cmdu_header_002 CMDU header without last fragment indicator 98 | * 99 | * @ingroup tv_cmdu_header 100 | * @{ 101 | */ 102 | extern struct CMDU_header x1905_cmdu_header_002; 103 | extern uint8_t x1905_cmdu_packet_002[]; 104 | extern size_t x1905_cmdu_packet_len_002; 105 | /** @} */ 106 | 107 | /** @defgroup tv_cmdu_header_003 CMDU header with wrong ether type 108 | * 109 | * @ingroup tv_cmdu_header 110 | * @{ 111 | */ 112 | extern uint8_t x1905_cmdu_packet_003[]; 113 | extern size_t x1905_cmdu_packet_len_003; 114 | /** @} */ 115 | 116 | /** @defgroup tv_cmdu_header_004 CMDU header is too short 117 | * 118 | * @ingroup tv_cmdu_header 119 | * @{ 120 | */ 121 | extern uint8_t x1905_cmdu_packet_004[]; 122 | extern size_t x1905_cmdu_packet_len_004; 123 | /** @} */ 124 | 125 | void init_1905_cmdu_test_vectors(void); 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /tests/1905_tlv_parsing.c: -------------------------------------------------------------------------------- 1 | /* 2 | * prplMesh Wi-Fi Multi-AP 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * Copyright (c) 2018, prpl Foundation 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * 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 | * Subject to the terms and conditions of this license, each copyright 19 | * holder and contributor hereby grants to those receiving rights under 20 | * this license a perpetual, worldwide, non-exclusive, no-charge, 21 | * royalty-free, irrevocable (except for failure to satisfy the 22 | * conditions of this license) patent license to make, have made, use, 23 | * offer to sell, sell, import, and otherwise transfer this software, 24 | * where such license applies only to those patent claims, already 25 | * acquired or hereafter acquired, licensable by such copyright holder or 26 | * contributor that are necessarily infringed by: 27 | * 28 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 29 | * and non-copyrightable additions of contributors, in source or binary 30 | * form) alone; or 31 | * 32 | * (b) combination of their Contribution(s) with the work of authorship to 33 | * which such Contribution(s) was added by such copyright holder or 34 | * contributor, if, at the time the Contribution is added, such addition 35 | * causes such combination to be necessarily infringed. The patent 36 | * license shall not apply to any other combinations which include the 37 | * Contribution. 38 | * 39 | * Except as expressly stated above, no rights or licenses from any 40 | * copyright holder or contributor is granted under this license, whether 41 | * expressly, by implication, estoppel or otherwise. 42 | * 43 | * DISCLAIMER 44 | * 45 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 46 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 47 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 48 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 49 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 50 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 51 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 52 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 53 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 54 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 55 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 56 | * DAMAGE. 57 | */ 58 | 59 | // 60 | // This file tests the "parse_1905_TLV_from_packet()" function by providing 61 | // some test input streams and checking the generated output structure. 62 | // 63 | 64 | #include "platform.h" 65 | #include "utils.h" 66 | 67 | #include "1905_tlvs.h" 68 | #include "1905_tlv_test_vectors.h" 69 | 70 | static uint8_t _check(const char *test_description, const uint8_t *input, struct tlv *expected_output) 71 | { 72 | uint8_t result; 73 | struct tlv *real_output; 74 | 75 | real_output = parse_1905_TLV_from_packet(input); 76 | 77 | if (real_output == NULL) 78 | { 79 | result = 1; 80 | PLATFORM_PRINTF("Parse %-100s: KO !!!\n", test_description); 81 | PLATFORM_PRINTF(" Parse failure\n"); 82 | } 83 | else if (0 == compare_1905_TLV_structures(real_output, expected_output)) 84 | { 85 | result = 0; 86 | PLATFORM_PRINTF("Parse %-100s: OK\n", test_description); 87 | } 88 | else 89 | { 90 | result = 1; 91 | PLATFORM_PRINTF("Parse %-100s: KO !!!\n", test_description); 92 | PLATFORM_PRINTF(" Expected output:\n"); 93 | visit_1905_TLV_structure(expected_output, print_callback, PLATFORM_PRINTF, ""); 94 | PLATFORM_PRINTF(" Real output :\n"); 95 | visit_1905_TLV_structure(real_output, print_callback, PLATFORM_PRINTF, ""); 96 | } 97 | free_1905_TLV_structure(real_output); 98 | 99 | return result; 100 | } 101 | 102 | int main(void) 103 | { 104 | int result = 0; 105 | struct x1905_tlv_test_vector *t; 106 | dlist_head test_vectors; 107 | 108 | dlist_head_init(&test_vectors); 109 | get_1905_tlv_test_vectors(&test_vectors); 110 | 111 | hlist_for_each(t, test_vectors, struct x1905_tlv_test_vector, h) 112 | { 113 | if (t->parse) 114 | result += _check(t->description, t->stream, container_of(t->h.children[0].next, struct tlv, s.h.l)); 115 | } 116 | // @todo currently the test vectors still point to statically allocated TLVs 117 | // hlist_delete(&test_vectors); 118 | 119 | // Return the number of test cases that failed 120 | // 121 | return result; 122 | } 123 | -------------------------------------------------------------------------------- /tests/1905_tlv_test_vectors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * prplMesh Wi-Fi Multi-AP 3 | * 4 | * Copyright (c) 2018, prpl Foundation 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _1905_TLV_TEST_VECTORS_H_ 59 | #define _1905_TLV_TEST_VECTORS_H_ 60 | 61 | #include 62 | #include 63 | 64 | struct x1905_tlv_test_vector { 65 | hlist_item h; 66 | const uint8_t *stream; 67 | uint16_t stream_len; 68 | const char *description; 69 | bool parse; 70 | bool forge; 71 | }; 72 | 73 | void get_1905_tlv_test_vectors(dlist_head *test_vectors); 74 | 75 | #endif 76 | 77 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, prpl Foundation 2 | # 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions are 5 | # met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # 14 | # Subject to the terms and conditions of this license, each copyright 15 | # holder and contributor hereby grants to those receiving rights under 16 | # this license a perpetual, worldwide, non-exclusive, no-charge, 17 | # royalty-free, irrevocable (except for failure to satisfy the 18 | # conditions of this license) patent license to make, have made, use, 19 | # offer to sell, sell, import, and otherwise transfer this software, 20 | # where such license applies only to those patent claims, already 21 | # acquired or hereafter acquired, licensable by such copyright holder or 22 | # contributor that are necessarily infringed by: 23 | # 24 | # (a) their Contribution(s) (the licensed copyrights of copyright holders 25 | # and non-copyrightable additions of contributors, in source or binary 26 | # form) alone; or 27 | # 28 | # (b) combination of their Contribution(s) with the work of authorship to 29 | # which such Contribution(s) was added by such copyright holder or 30 | # contributor, if, at the time the Contribution is added, such addition 31 | # causes such combination to be necessarily infringed. The patent 32 | # license shall not apply to any other combinations which include the 33 | # Contribution. 34 | # 35 | # Except as expressly stated above, no rights or licenses from any 36 | # copyright holder or contributor is granted under this license, whether 37 | # expressly, by implication, estoppel or otherwise. 38 | # 39 | # DISCLAIMER 40 | # 41 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 42 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 43 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 44 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 45 | # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 46 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 47 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 48 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 49 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 50 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 51 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 52 | # DAMAGE. 53 | 54 | # Note that this directory is only included under Linux, so no need to 55 | # check for it. 56 | 57 | macro(unittest) 58 | get_filename_component(testname ${ARGV0} NAME_WE) 59 | add_executable(UNITTEST_${testname} ${ARGV}) 60 | target_link_libraries(UNITTEST_${testname} prplMesh) 61 | add_test(NAME ${testname} COMMAND UNITTEST_${testname}) 62 | endmacro(unittest) 63 | 64 | unittest(hlist_test.c) 65 | unittest(dlist_test.c) 66 | unittest(ptrarray_test.c) 67 | 68 | foreach(factory_unit_test 1905_alme 1905_cmdu 1905_tlv lldp_payload lldp_tlv bbf_tlv) 69 | unittest( 70 | ${factory_unit_test}_parsing.c 71 | ${factory_unit_test}_test_vectors.c) 72 | unittest( 73 | ${factory_unit_test}_forging.c 74 | ${factory_unit_test}_test_vectors.c) 75 | endforeach(factory_unit_test) 76 | 77 | macro(aletest testname) 78 | add_executable(ALETEST_${testname} ${testname}.c aletest.c) 79 | target_link_libraries(ALETEST_${testname} prplMesh) 80 | add_test(NAME ${testname} 81 | COMMAND ./start_interfaces $ $ 82 | WORKING_DIRECTORY ${prplMesh_SOURCE_DIR}/tests) 83 | endmacro(aletest) 84 | 85 | aletest(ap_onboarding_controller) 86 | aletest(topology_discovery) 87 | 88 | -------------------------------------------------------------------------------- /tests/aletest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * prplMesh Wi-Fi Multi-AP 3 | * 4 | * Copyright (c) 2018, prpl Foundation 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _ALETEST_H_ 59 | #define _ALETEST_H_ 60 | 61 | #include /* PLATFORM_PRINTF_* */ 62 | #include <1905_cmdus.h> 63 | 64 | #include 65 | #include 66 | #include /* size_t */ 67 | 68 | #define ADDR_AL "\x02\xee\xff\x33\x44\x00" 69 | #define ADDR_MAC0 "\x00\xee\xff\x33\x44\x00" 70 | #define ADDR_MAC1 "\x00\xee\xff\x33\x44\x10" 71 | #define ADDR_MAC2 "\x00\xee\xff\x33\x44\x20" 72 | #define ADDR_MAC3 "\x00\xee\xff\x33\x44\x30" 73 | 74 | #define ADDR_AL_PEER0 "\x02\xaa\xbb\x33\x44\x00" 75 | #define ADDR_AL_PEER1 "\x02\xaa\xbb\x33\x44\x10" 76 | #define ADDR_AL_PEER2 "\x02\xaa\xbb\x33\x44\x20" 77 | #define ADDR_AL_PEER3 "\x02\xaa\xbb\x33\x44\x30" 78 | #define ADDR_MAC_PEER0 "\x00\xee\xff\x33\x44\x01" 79 | #define ADDR_MAC_PEER1 "\x00\xee\xff\x33\x44\x11" 80 | #define ADDR_MAC_PEER2 "\x00\xee\xff\x33\x44\x21" 81 | #define ADDR_MAC_PEER3 "\x00\xee\xff\x33\x44\x31" 82 | 83 | /** Print the contents of @a buf, wrapping at 80 characters, indent every line with @a indent + 1 space */ 84 | void dump_bytes(const uint8_t *buf, size_t buf_len, const char *indent); 85 | 86 | struct CMDU *expect_cmdu(int s, unsigned timeout_ms, const char *testname, uint16_t expected_cmdu_type, 87 | mac_address expected_src_addr, mac_address expected_src_al_addr, mac_address expected_dst_address); 88 | 89 | int expect_cmdu_match(int s, unsigned timeout_ms, const char *testname, const struct CMDU *expected_cmdu, 90 | mac_address expected_src_addr, mac_address expected_src_al_addr, mac_address expected_dst_address); 91 | 92 | /** Send a CMDU. If it fails, print an error and return a value >= 1, else return 0. */ 93 | int send_cmdu(int s, mac_address dst_addr, mac_address src_addr, const struct CMDU *cmdu); 94 | 95 | #endif 96 | 97 | -------------------------------------------------------------------------------- /tests/aletest0.sim: -------------------------------------------------------------------------------- 1 | # prplMesh Wi-Fi Multi-AP 2 | # 3 | # Copyright (c) 2018, prpl Foundation 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are 7 | # met: 8 | # 9 | # 1. Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # 12 | # 2. Redistributions in binary form must reproduce the above copyright 13 | # notice, this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | # 16 | # Subject to the terms and conditions of this license, each copyright 17 | # holder and contributor hereby grants to those receiving rights under 18 | # this license a perpetual, worldwide, non-exclusive, no-charge, 19 | # royalty-free, irrevocable (except for failure to satisfy the 20 | # conditions of this license) patent license to make, have made, use, 21 | # offer to sell, sell, import, and otherwise transfer this software, 22 | # where such license applies only to those patent claims, already 23 | # acquired or hereafter acquired, licensable by such copyright holder or 24 | # contributor that are necessarily infringed by: 25 | # 26 | # (a) their Contribution(s) (the licensed copyrights of copyright holders 27 | # and non-copyrightable additions of contributors, in source or binary 28 | # form) alone; or 29 | # 30 | # (b) combination of their Contribution(s) with the work of authorship to 31 | # which such Contribution(s) was added by such copyright holder or 32 | # contributor, if, at the time the Contribution is added, such addition 33 | # causes such combination to be necessarily infringed. The patent 34 | # license shall not apply to any other combinations which include the 35 | # Contribution. 36 | # 37 | # Except as expressly stated above, no rights or licenses from any 38 | # copyright holder or contributor is granted under this license, whether 39 | # expressly, by implication, estoppel or otherwise. 40 | # 41 | # DISCLAIMER 42 | # 43 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 44 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 45 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 46 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 47 | # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 48 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 49 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 50 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 51 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 52 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 53 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 54 | # DAMAGE. 55 | 56 | mac_address = 00:ee:ff:33:44:00 57 | manufacturer_name = Marvell 58 | model_name = WIFI PHY x200 59 | model_number = 12345 60 | serial_number = 100000000000 61 | device_name = Marvell WIFI phy x200 62 | uuid = 100000000000 63 | interface_type = INTERFACE_TYPE_IEEE_802_11G_2_4_GHZ 64 | ieee80211.bssid = 00:16:03:01:85:1f 65 | ieee80211.ssid = My WIFI network 66 | ieee80211.role = IEEE80211_ROLE_AP 67 | ieee80211.ap_channel_band = 10 68 | ieee80211.ap_channel_center_frequency_index_1 = 20 69 | ieee80211.ap_channel_center_frequency_index_2 = 30 70 | ieee80211.authentication_mode = IEEE80211_AUTH_MODE_WPAPSK 71 | ieee80211.encryption_mode = IEEE80211_ENCRYPTION_MODE_AES 72 | ieee80211.network_key = Test network 73 | is_secured = 1 74 | push_button_on_going = 0 75 | push_button_new_mac_address = 00:00:00:00:00:00 76 | power_state = INTERFACE_POWER_STATE_ON 77 | -------------------------------------------------------------------------------- /tests/aletest1.sim: -------------------------------------------------------------------------------- 1 | # prplMesh Wi-Fi Multi-AP 2 | # 3 | # Copyright (c) 2018, prpl Foundation 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are 7 | # met: 8 | # 9 | # 1. Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # 12 | # 2. Redistributions in binary form must reproduce the above copyright 13 | # notice, this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | # 16 | # Subject to the terms and conditions of this license, each copyright 17 | # holder and contributor hereby grants to those receiving rights under 18 | # this license a perpetual, worldwide, non-exclusive, no-charge, 19 | # royalty-free, irrevocable (except for failure to satisfy the 20 | # conditions of this license) patent license to make, have made, use, 21 | # offer to sell, sell, import, and otherwise transfer this software, 22 | # where such license applies only to those patent claims, already 23 | # acquired or hereafter acquired, licensable by such copyright holder or 24 | # contributor that are necessarily infringed by: 25 | # 26 | # (a) their Contribution(s) (the licensed copyrights of copyright holders 27 | # and non-copyrightable additions of contributors, in source or binary 28 | # form) alone; or 29 | # 30 | # (b) combination of their Contribution(s) with the work of authorship to 31 | # which such Contribution(s) was added by such copyright holder or 32 | # contributor, if, at the time the Contribution is added, such addition 33 | # causes such combination to be necessarily infringed. The patent 34 | # license shall not apply to any other combinations which include the 35 | # Contribution. 36 | # 37 | # Except as expressly stated above, no rights or licenses from any 38 | # copyright holder or contributor is granted under this license, whether 39 | # expressly, by implication, estoppel or otherwise. 40 | # 41 | # DISCLAIMER 42 | # 43 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 44 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 45 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 46 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 47 | # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 48 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 49 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 50 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 51 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 52 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 53 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 54 | # DAMAGE. 55 | 56 | mac_address = 00:ee:ff:33:44:10 57 | manufacturer_name = Marvell 58 | model_name = ETH PHY x200 59 | model_number = 99999 60 | serial_number = 100000000001 61 | device_name = Marvell eth phy x200 62 | uuid = 0000000000810001 63 | interface_type = INTERFACE_TYPE_IEEE_802_3U_FAST_ETHERNET 64 | is_secured = 1 65 | push_button_on_going = 2 66 | push_button_new_mac_address = 00:00:00:00:00:00 67 | power_state = INTERFACE_POWER_STATE_ON 68 | -------------------------------------------------------------------------------- /tests/aletest2.sim: -------------------------------------------------------------------------------- 1 | # prplMesh Wi-Fi Multi-AP 2 | # 3 | # Copyright (c) 2018, prpl Foundation 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are 7 | # met: 8 | # 9 | # 1. Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # 12 | # 2. Redistributions in binary form must reproduce the above copyright 13 | # notice, this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | # 16 | # Subject to the terms and conditions of this license, each copyright 17 | # holder and contributor hereby grants to those receiving rights under 18 | # this license a perpetual, worldwide, non-exclusive, no-charge, 19 | # royalty-free, irrevocable (except for failure to satisfy the 20 | # conditions of this license) patent license to make, have made, use, 21 | # offer to sell, sell, import, and otherwise transfer this software, 22 | # where such license applies only to those patent claims, already 23 | # acquired or hereafter acquired, licensable by such copyright holder or 24 | # contributor that are necessarily infringed by: 25 | # 26 | # (a) their Contribution(s) (the licensed copyrights of copyright holders 27 | # and non-copyrightable additions of contributors, in source or binary 28 | # form) alone; or 29 | # 30 | # (b) combination of their Contribution(s) with the work of authorship to 31 | # which such Contribution(s) was added by such copyright holder or 32 | # contributor, if, at the time the Contribution is added, such addition 33 | # causes such combination to be necessarily infringed. The patent 34 | # license shall not apply to any other combinations which include the 35 | # Contribution. 36 | # 37 | # Except as expressly stated above, no rights or licenses from any 38 | # copyright holder or contributor is granted under this license, whether 39 | # expressly, by implication, estoppel or otherwise. 40 | # 41 | # DISCLAIMER 42 | # 43 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 44 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 45 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 46 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 47 | # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 48 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 49 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 50 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 51 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 52 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 53 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 54 | # DAMAGE. 55 | 56 | mac_address = 00:ee:ff:33:44:20 57 | manufacturer_name = Marvell 58 | model_name = WIFI PHY x200 59 | model_number = 12345 60 | serial_number = 100000000000 61 | device_name = Marvell WIFI phy x200 62 | uuid = 100000000000 63 | interface_type = INTERFACE_TYPE_IEEE_802_11G_2_4_GHZ 64 | ieee80211.bssid = 00:16:03:01:85:1e 65 | ieee80211.ssid = My 2nd WIFI network 66 | ieee80211.role = IEEE80211_ROLE_AP 67 | ieee80211.ap_channel_band = 10 68 | ieee80211.ap_channel_center_frequency_index_1 = 20 69 | ieee80211.ap_channel_center_frequency_index_2 = 30 70 | ieee80211.authentication_mode = IEEE80211_AUTH_MODE_WPAPSK 71 | ieee80211.encryption_mode = IEEE80211_ENCRYPTION_MODE_AES 72 | ieee80211.network_key = Test network 73 | is_secured = 1 74 | push_button_on_going = 0 75 | push_button_new_mac_address = 00:00:00:00:00:00 76 | power_state = INTERFACE_POWER_STATE_ON 77 | -------------------------------------------------------------------------------- /tests/aletest3.sim: -------------------------------------------------------------------------------- 1 | # prplMesh Wi-Fi Multi-AP 2 | # 3 | # Copyright (c) 2018, prpl Foundation 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are 7 | # met: 8 | # 9 | # 1. Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # 12 | # 2. Redistributions in binary form must reproduce the above copyright 13 | # notice, this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | # 16 | # Subject to the terms and conditions of this license, each copyright 17 | # holder and contributor hereby grants to those receiving rights under 18 | # this license a perpetual, worldwide, non-exclusive, no-charge, 19 | # royalty-free, irrevocable (except for failure to satisfy the 20 | # conditions of this license) patent license to make, have made, use, 21 | # offer to sell, sell, import, and otherwise transfer this software, 22 | # where such license applies only to those patent claims, already 23 | # acquired or hereafter acquired, licensable by such copyright holder or 24 | # contributor that are necessarily infringed by: 25 | # 26 | # (a) their Contribution(s) (the licensed copyrights of copyright holders 27 | # and non-copyrightable additions of contributors, in source or binary 28 | # form) alone; or 29 | # 30 | # (b) combination of their Contribution(s) with the work of authorship to 31 | # which such Contribution(s) was added by such copyright holder or 32 | # contributor, if, at the time the Contribution is added, such addition 33 | # causes such combination to be necessarily infringed. The patent 34 | # license shall not apply to any other combinations which include the 35 | # Contribution. 36 | # 37 | # Except as expressly stated above, no rights or licenses from any 38 | # copyright holder or contributor is granted under this license, whether 39 | # expressly, by implication, estoppel or otherwise. 40 | # 41 | # DISCLAIMER 42 | # 43 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 44 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 45 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 46 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 47 | # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 48 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 49 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 50 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 51 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 52 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 53 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 54 | # DAMAGE. 55 | 56 | mac_address = 00:ee:ff:33:44:30 57 | manufacturer_name = Marvell 58 | model_name = ETH PHY x200 59 | model_number = 99999 60 | serial_number = 100000000001 61 | device_name = Marvell eth phy x200 62 | uuid = 0000000000810001 63 | interface_type = INTERFACE_TYPE_IEEE_802_3U_FAST_ETHERNET 64 | is_secured = 1 65 | push_button_on_going = 2 66 | push_button_new_mac_address = 00:00:00:00:00:00 67 | power_state = INTERFACE_POWER_STATE_ON 68 | -------------------------------------------------------------------------------- /tests/bbf_tlv_test_vectors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _BBF_TLV_TEST_VECTORS_H_ 59 | #define _BBF_TLV_TEST_VECTORS_H_ 60 | 61 | #include "bbf_tlvs.h" 62 | 63 | #define CHECK_TRUE 0 // Check a successful parse/forge operation 64 | #define CHECK_FALSE 1 // Check a wrong parse operation (malformed frame) 65 | 66 | extern struct linkMetricQueryTLV bbf_tlv_structure_001; 67 | extern uint8_t bbf_tlv_stream_001[]; 68 | extern uint16_t bbf_tlv_stream_len_001; 69 | 70 | extern struct linkMetricQueryTLV bbf_tlv_structure_002; 71 | extern uint8_t bbf_tlv_stream_002[]; 72 | extern uint8_t bbf_tlv_stream_002b[]; 73 | extern uint16_t bbf_tlv_stream_len_002; 74 | 75 | extern struct linkMetricQueryTLV bbf_tlv_structure_003; 76 | extern uint8_t bbf_tlv_stream_003[]; 77 | extern uint16_t bbf_tlv_stream_len_003; 78 | 79 | extern struct linkMetricQueryTLV bbf_tlv_structure_004; 80 | extern uint8_t bbf_tlv_stream_004[]; 81 | extern uint8_t bbf_tlv_stream_004b[]; 82 | extern uint16_t bbf_tlv_stream_len_004; 83 | 84 | extern struct linkMetricQueryTLV bbf_tlv_structure_005; 85 | extern uint8_t bbf_tlv_stream_005[]; 86 | extern uint16_t bbf_tlv_stream_len_005; 87 | 88 | extern struct linkMetricQueryTLV bbf_tlv_structure_006; 89 | extern uint8_t bbf_tlv_stream_006[]; 90 | extern uint8_t bbf_tlv_stream_006b[]; 91 | extern uint16_t bbf_tlv_stream_len_006; 92 | 93 | extern struct linkMetricQueryTLV bbf_tlv_structure_007; 94 | extern uint8_t bbf_tlv_stream_007[]; 95 | extern uint16_t bbf_tlv_stream_len_007; 96 | 97 | #endif 98 | 99 | -------------------------------------------------------------------------------- /tests/dlist_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * prplMesh Wi-Fi Multi-AP 3 | * 4 | * Copyright (c) 2018, prpl Foundation 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #include 59 | #include "platform.h" 60 | #include 61 | #include 62 | 63 | struct dtest { 64 | dlist_item l; 65 | unsigned data; 66 | }; 67 | 68 | static int check_count(dlist_head *list, size_t expected_count) 69 | { 70 | size_t real_count = dlist_count(list); 71 | if (real_count != expected_count) 72 | { 73 | PLATFORM_PRINTF_DEBUG_WARNING("dlist_count result %u but expected %u\n", (unsigned)real_count, (unsigned)expected_count); 74 | return 1; 75 | } 76 | else 77 | { 78 | return 0; 79 | } 80 | } 81 | 82 | static int check_values(dlist_head *list, const unsigned values[]) 83 | { 84 | struct dtest *t; 85 | unsigned i = 0; 86 | dlist_for_each(t, *list, l) 87 | { 88 | if (values[i] == 0) 89 | { 90 | PLATFORM_PRINTF_DEBUG_WARNING("dlist includes unexpected element %u\n", t->data); 91 | return 1; 92 | } 93 | if (values[i] != t->data) 94 | { 95 | PLATFORM_PRINTF_DEBUG_WARNING("dlist includes unexpected element %u != %u\n", t->data, values[i]); 96 | return 1; 97 | } 98 | i++; 99 | } 100 | return 0; 101 | } 102 | 103 | int main() 104 | { 105 | int ret = 0; 106 | dlist_head list1; 107 | DEFINE_DLIST_HEAD(list2); 108 | struct dtest t1; 109 | struct dtest t2; 110 | struct dtest t3; 111 | 112 | dlist_head_init(&list1); 113 | ret += check_count(&list1, 0); 114 | ret += check_count(&list2, 0); 115 | 116 | if (!dlist_empty(&list1)) 117 | { 118 | PLATFORM_PRINTF_DEBUG_WARNING("dlist_empty() on empty list returns false\n"); 119 | ret++; 120 | } 121 | 122 | t1.data = 1; 123 | t2.data = 2; 124 | t3.data = 3; 125 | 126 | dlist_add_head(&list1, &t1.l); 127 | ret += check_count(&list1, 1); 128 | ret += check_values(&list1, (unsigned[]){1, 0}); 129 | dlist_add_head(&list1, &t2.l); 130 | ret += check_count(&list1, 2); 131 | ret += check_values(&list1, (unsigned[]){2, 1, 0}); 132 | dlist_add_tail(&list1, &t3.l); 133 | ret += check_count(&list1, 3); 134 | ret += check_values(&list1, (unsigned[]){2, 1, 3, 0}); 135 | 136 | dlist_remove(&t1.l); 137 | ret += check_count(&list1, 2); 138 | ret += check_values(&list1, (unsigned[]){2, 3, 0}); 139 | 140 | if (dlist_empty(&list1)) 141 | { 142 | PLATFORM_PRINTF_DEBUG_WARNING("dlist_empty() on non-empty list returns true\n"); 143 | ret++; 144 | } 145 | 146 | dlist_add_head(&list2, &t1.l); 147 | ret += check_count(&list2, 1); 148 | ret += check_values(&list2, (unsigned[]){1, 0}); 149 | /* list1 hasn't changed */ 150 | ret += check_count(&list1, 2); 151 | ret += check_values(&list1, (unsigned[]){2, 3, 0}); 152 | 153 | return ret; 154 | } 155 | -------------------------------------------------------------------------------- /tests/hlist_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * prplMesh Wi-Fi Multi-AP 3 | * 4 | * Copyright (c) 2018, prpl Foundation 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #include 59 | #include "platform.h" 60 | #include 61 | #include 62 | 63 | struct htest1 { 64 | hlist_item h; 65 | unsigned data; 66 | }; 67 | 68 | struct htest2 { 69 | hlist_item h; 70 | char data; 71 | char data2[15]; /* The rest of data, used to test the various print formats. */ 72 | }; 73 | 74 | static int check_count(dlist_head *list, size_t expected_count) 75 | { 76 | size_t real_count = dlist_count(list); 77 | if (real_count != expected_count) 78 | { 79 | PLATFORM_PRINTF_DEBUG_WARNING("dlist_count result %u but expected %u\n", (unsigned)real_count, (unsigned)expected_count); 80 | return 1; 81 | } 82 | else 83 | { 84 | return 0; 85 | } 86 | } 87 | 88 | int main() 89 | { 90 | int ret = 0; 91 | dlist_head list; 92 | struct htest1 *ht1; 93 | 94 | dlist_head_init(&list); 95 | ret += check_count(&list, 0); 96 | ht1 = HLIST_ALLOC(struct htest1, h, &list); 97 | ht1->data = 242; 98 | HLIST_ALLOC(struct htest2, h, &ht1->h.children[0])->data = 42; 99 | HLIST_ALLOC(struct htest2, h, &ht1->h.children[0])->data = 43; 100 | 101 | ret += check_count(&list, 1); 102 | ret += check_count(&ht1->h.children[0], 2); 103 | 104 | dlist_remove(&ht1->h); 105 | ret += check_count(&list, 0); 106 | hlist_delete_item(&ht1->h); 107 | /* This also deletes the two htest2 children, but there's no way to check that. */ 108 | 109 | /* Deleting an empty list works. */ 110 | hlist_delete(&list); 111 | ret += check_count(&list, 0); 112 | 113 | return ret; 114 | } 115 | -------------------------------------------------------------------------------- /tests/lldp_payload_forging.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | // 59 | // This file tests the "forge_lldp_PAYLOAD_from_structure()" function by 60 | // providing some test input structures and checking the generated output 61 | // stream. 62 | // 63 | 64 | #include "platform.h" 65 | #include "lldp_payload.h" 66 | #include "lldp_tlvs.h" 67 | #include "lldp_payload_test_vectors.h" 68 | 69 | #include // memcmp(), memcpy(), ... 70 | 71 | uint8_t _check(const char *test_description, struct PAYLOAD *input, uint8_t *expected_output, uint16_t expected_output_len) 72 | { 73 | uint8_t result; 74 | uint8_t *real_output; 75 | uint16_t real_output_len; 76 | 77 | real_output = forge_lldp_PAYLOAD_from_structure(input, &real_output_len); 78 | 79 | if (NULL == real_output) 80 | { 81 | PLATFORM_PRINTF("%-100s: KO !!!\n", test_description); 82 | PLATFORM_PRINTF(" forge_lldp_PAYLOAD_from_structure() returned a NULL pointer\n"); 83 | 84 | return 1; 85 | } 86 | 87 | if ((expected_output_len == real_output_len) && (0 == memcmp(expected_output, real_output, real_output_len))) 88 | { 89 | result = 0; 90 | PLATFORM_PRINTF("%-100s: OK\n", test_description); 91 | } 92 | else 93 | { 94 | uint16_t i; 95 | 96 | result = 1; 97 | PLATFORM_PRINTF("%-100s: KO !!!\n", test_description); 98 | PLATFORM_PRINTF(" Expected output: "); 99 | for (i=0; i packet" can only be used to test the 76 | // "forge_lldp_PAYLOAD_from_structure()" function. 77 | // 78 | // - Test vectors marked with "PAYLOD <-- packet" can only be used to test the 79 | // "parse_lldp_PAYLOAD_from_packets()" function. 80 | // 81 | // - All the other test vectors are marked with "PAYLOAD <--> packet", meaning 82 | // they can be used to test both functions. 83 | // 84 | // The reason this is happening is that, according to the standard, sometimes 85 | // bits are ignored/changed/forced-to-a-value when forging a packet. Thus, not 86 | // all test vectors are "inversible" (ie. forge(parse(stream)) != x) 87 | // 88 | // This is how you use these test vectors: 89 | // 90 | // A) stream = forge_lldp_PAYLOAD_from_structure(payload_xxx, &stream_len); 91 | // 92 | // B) tlv = parse_lldp_PAYLOAD_from_packets(stream_xxx); 93 | // 94 | 95 | 96 | //////////////////////////////////////////////////////////////////////////////// 97 | //// Test vector 001 (PAYLOAD <--> packet) 98 | //////////////////////////////////////////////////////////////////////////////// 99 | 100 | struct PAYLOAD lldp_payload_structure_001 = 101 | { 102 | .list_of_TLVs = 103 | { 104 | (struct tlv *)(struct chassisIdTLV[]){ 105 | { 106 | .tlv.type = TLV_TYPE_CHASSIS_ID, 107 | .chassis_id_subtype = CHASSIS_ID_TLV_SUBTYPE_MAC_ADDRESS, 108 | .chassis_id = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, 109 | }, 110 | }, 111 | (struct tlv *)(struct portIdTLV[]){ 112 | { 113 | .tlv.type = TLV_TYPE_PORT_ID, 114 | .port_id_subtype = PORT_ID_TLV_SUBTYPE_MAC_ADDRESS, 115 | .port_id = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}, 116 | }, 117 | }, 118 | (struct tlv *)(struct timeToLiveTypeTLV[]){ 119 | { 120 | .tlv.type = TLV_TYPE_TIME_TO_LIVE, 121 | .ttl = TIME_TO_LIVE_TLV_1905_DEFAULT_VALUE, 122 | }, 123 | }, 124 | NULL, 125 | }, 126 | }; 127 | 128 | uint8_t lldp_payload_stream_001[] = 129 | { 130 | 0x02, 0x07, 131 | 0x04, 132 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 133 | 0x04, 0x07, 134 | 0x03, 135 | 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 136 | 0x06, 0x02, 137 | 0x00, 0xb4, 138 | 0x00, 0x00, 139 | }; 140 | 141 | uint16_t lldp_payload_stream_len_001 = 24; 142 | 143 | 144 | -------------------------------------------------------------------------------- /tests/lldp_payload_test_vectors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | #ifndef _LLDP_PAYLOAD_TEST_VECTORS_H_ 59 | #define _LLDP_PAYLOAD_TEST_VECTORS_H_ 60 | 61 | #include "lldp_payload.h" 62 | #include "lldp_tlvs.h" 63 | 64 | extern struct PAYLOAD lldp_payload_structure_001; 65 | extern uint8_t lldp_payload_stream_001[]; 66 | extern uint16_t lldp_payload_stream_len_001; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /tests/lldp_tlv_forging.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Broadband Forum IEEE 1905.1/1a stack 3 | * 4 | * Copyright (c) 2017, Broadband Forum 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * 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 | * Subject to the terms and conditions of this license, each copyright 18 | * holder and contributor hereby grants to those receiving rights under 19 | * this license a perpetual, worldwide, non-exclusive, no-charge, 20 | * royalty-free, irrevocable (except for failure to satisfy the 21 | * conditions of this license) patent license to make, have made, use, 22 | * offer to sell, sell, import, and otherwise transfer this software, 23 | * where such license applies only to those patent claims, already 24 | * acquired or hereafter acquired, licensable by such copyright holder or 25 | * contributor that are necessarily infringed by: 26 | * 27 | * (a) their Contribution(s) (the licensed copyrights of copyright holders 28 | * and non-copyrightable additions of contributors, in source or binary 29 | * form) alone; or 30 | * 31 | * (b) combination of their Contribution(s) with the work of authorship to 32 | * which such Contribution(s) was added by such copyright holder or 33 | * contributor, if, at the time the Contribution is added, such addition 34 | * causes such combination to be necessarily infringed. The patent 35 | * license shall not apply to any other combinations which include the 36 | * Contribution. 37 | * 38 | * Except as expressly stated above, no rights or licenses from any 39 | * copyright holder or contributor is granted under this license, whether 40 | * expressly, by implication, estoppel or otherwise. 41 | * 42 | * DISCLAIMER 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 45 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 50 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 51 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 53 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 54 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 55 | * DAMAGE. 56 | */ 57 | 58 | // 59 | // This file tests the "forge_lldp_TLV_from_structure()" function by providing 60 | // some test input structures and checking the generated output stream. 61 | // 62 | 63 | #include "platform.h" 64 | #include "lldp_tlvs.h" 65 | #include "lldp_tlv_test_vectors.h" 66 | 67 | #include // memcmp(), memcpy(), ... 68 | 69 | uint8_t _check(const char *test_description, struct tlv *input, uint8_t *expected_output, uint16_t expected_output_len) 70 | { 71 | uint8_t result; 72 | uint8_t *real_output; 73 | uint16_t real_output_len; 74 | 75 | real_output = forge_lldp_TLV_from_structure(input, &real_output_len); 76 | 77 | if (NULL == real_output) 78 | { 79 | PLATFORM_PRINTF("%-100s: KO !!!\n", test_description); 80 | PLATFORM_PRINTF(" forge_lldp_TLV_from_structure() returned a NULL pointer\n"); 81 | 82 | return 1; 83 | } 84 | 85 | if ((expected_output_len == real_output_len) && (0 == memcmp(expected_output, real_output, real_output_len))) 86 | { 87 | result = 0; 88 | PLATFORM_PRINTF("%-100s: OK\n", test_description); 89 | } 90 | else 91 | { 92 | uint16_t i; 93 | 94 | result = 1; 95 | PLATFORM_PRINTF("%-100s: KO !!!\n", test_description); 96 | PLATFORM_PRINTF(" Expected output: "); 97 | for (i=0; i 59 | #include "platform.h" 60 | #include 61 | #include 62 | 63 | static PTRARRAY(unsigned) ptrarray; 64 | 65 | static int check_count(unsigned expected_count) 66 | { 67 | if (ptrarray.length != expected_count) 68 | { 69 | PLATFORM_PRINTF_DEBUG_WARNING("ptrarray length %u but expected %u\n", ptrarray.length, expected_count); 70 | return 1; 71 | } 72 | else 73 | { 74 | return 0; 75 | } 76 | } 77 | 78 | static int check_values(const unsigned values[]) 79 | { 80 | unsigned i; 81 | for (i = 0; i < ptrarray.length; i++) 82 | { 83 | if (values[i] == 0) 84 | { 85 | PLATFORM_PRINTF_DEBUG_WARNING("ptrarray includes unexpected element %u\n", ptrarray.data[i]); 86 | return 1; 87 | } 88 | if (values[i] != ptrarray.data[i]) 89 | { 90 | PLATFORM_PRINTF_DEBUG_WARNING("dlist includes unexpected element %u != %u\n", ptrarray.data[i], values[i]); 91 | return 1; 92 | } 93 | } 94 | return 0; 95 | } 96 | 97 | int main() 98 | { 99 | int ret = 0; 100 | 101 | ret += check_count(0); 102 | 103 | PTRARRAY_ADD(ptrarray, 1); 104 | ret += check_count(1); 105 | ret += check_values((unsigned[]){1, 0}); 106 | PTRARRAY_ADD(ptrarray, 2); 107 | ret += check_count(2); 108 | ret += check_values((unsigned[]){1, 2, 0}); 109 | PTRARRAY_ADD(ptrarray, 3); 110 | ret += check_count(3); 111 | ret += check_values((unsigned[]){1, 2, 3, 0}); 112 | 113 | if (PTRARRAY_FIND(ptrarray, 2) != 1) 114 | { 115 | PLATFORM_PRINTF_DEBUG_WARNING("Element '2' not found in ptrarray"); 116 | ret++; 117 | } 118 | if (PTRARRAY_FIND(ptrarray, 0) < 3) 119 | { 120 | PLATFORM_PRINTF_DEBUG_WARNING("Element '4' found in ptrarray"); 121 | ret++; 122 | } 123 | 124 | PTRARRAY_REMOVE(ptrarray, 0); 125 | ret += check_count(2); 126 | ret += check_values((unsigned[]){2, 3, 0}); 127 | 128 | PTRARRAY_REMOVE_ELEMENT(ptrarray, 1); 129 | /* Element 1 not in list => nothing changed */ 130 | ret += check_count(2); 131 | ret += check_values((unsigned[]){2, 3, 0}); 132 | 133 | PTRARRAY_REMOVE_ELEMENT(ptrarray, 3); 134 | ret += check_count(1); 135 | ret += check_values((unsigned[]){2, 0}); 136 | 137 | /* Same element can be added multiple times. */ 138 | PTRARRAY_ADD(ptrarray, 2); 139 | ret += check_count(2); 140 | ret += check_values((unsigned[]){2, 2, 0}); 141 | 142 | PTRARRAY_CLEAR(ptrarray); 143 | ret += check_count(0); 144 | PTRARRAY_ADD(ptrarray, 1); 145 | ret += check_count(1); 146 | ret += check_values((unsigned[]){1, 0}); 147 | 148 | PTRARRAY_CLEAR(ptrarray); 149 | 150 | return ret; 151 | } 152 | -------------------------------------------------------------------------------- /tests/start_interfaces: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # prplMesh Wi-Fi Multi-AP 4 | # 5 | # Copyright (c) 2018, prpl Foundation 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions are 9 | # 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 | # Subject to the terms and conditions of this license, each copyright 19 | # holder and contributor hereby grants to those receiving rights under 20 | # this license a perpetual, worldwide, non-exclusive, no-charge, 21 | # royalty-free, irrevocable (except for failure to satisfy the 22 | # conditions of this license) patent license to make, have made, use, 23 | # offer to sell, sell, import, and otherwise transfer this software, 24 | # where such license applies only to those patent claims, already 25 | # acquired or hereafter acquired, licensable by such copyright holder or 26 | # contributor that are necessarily infringed by: 27 | # 28 | # (a) their Contribution(s) (the licensed copyrights of copyright holders 29 | # and non-copyrightable additions of contributors, in source or binary 30 | # form) alone; or 31 | # 32 | # (b) combination of their Contribution(s) with the work of authorship to 33 | # which such Contribution(s) was added by such copyright holder or 34 | # contributor, if, at the time the Contribution is added, such addition 35 | # causes such combination to be necessarily infringed. The patent 36 | # license shall not apply to any other combinations which include the 37 | # Contribution. 38 | # 39 | # Except as expressly stated above, no rights or licenses from any 40 | # copyright holder or contributor is granted under this license, whether 41 | # expressly, by implication, estoppel or otherwise. 42 | # 43 | # DISCLAIMER 44 | # 45 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 46 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 47 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 48 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 49 | # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 50 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 51 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 52 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 53 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 54 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 55 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 56 | # DAMAGE. 57 | 58 | # Make sure we are root 59 | test $(id -u) = 0 || exec sudo "$0" "$@" 60 | 61 | al_entity_exec="$1"; shift 62 | test -x "${al_entity_exec}" || { 63 | echo "$0: $al_entity_exec not executable" 1>&2 64 | exit 1 65 | } 66 | 67 | stop_interfaces() { 68 | # If there is a background job, kill it 69 | kill -9 %1 2>/dev/null || true 70 | wait %1 2>/dev/null # Suppress "Terminated" output 71 | for num in 0 1 2 3; do 72 | ip link delete aletest$num 73 | done 74 | } 75 | 76 | trap stop_interfaces EXIT 77 | 78 | interfaces="" 79 | for num in 0 1 2 3; do 80 | ip link add aletest$num type veth peer name aletestpeer$num 81 | ip link set dev aletest$num up address 00:ee:ff:33:44:${num}0 82 | ip link set dev aletestpeer$num up address 00:ee:ff:33:44:${num}1 83 | interfaces="${interfaces}${interfaces:+,}aletest${num}:simulated:aletest${num}.sim" 84 | done 85 | 86 | # Generate 8MB core files 87 | ulimit -c 8000 88 | 89 | "$al_entity_exec" -m 02:ee:ff:33:44:00 -i "$interfaces" -r aletest2 -v -v & 90 | 91 | "$@" || exit $? 92 | 93 | # Test that background job is still running. 94 | jobs %1 >/dev/null 2>&1 || exit 1 95 | 96 | --------------------------------------------------------------------------------