├── .mailmap ├── LICENSE ├── Makefile ├── PROJECT ├── README.md ├── output └── tmp │ └── .place_holder ├── release_compile.sh ├── scripts ├── README.md └── linux │ └── arm_wrt1900acx │ ├── start_linksys.sh │ ├── topology_change.sh │ └── wps ├── src ├── al │ ├── Makefile │ ├── internal_interfaces │ │ ├── al.h │ │ ├── platform_alme_server.h │ │ ├── platform_crypto.h │ │ ├── platform_interfaces.h │ │ └── platform_os.h │ ├── src_independent │ │ ├── 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 │ │ └── extensions │ │ │ └── bbf │ │ │ ├── bbf_recv.c │ │ │ ├── bbf_recv.h │ │ │ ├── bbf_send.c │ │ │ └── bbf_send.h │ └── src_linux │ │ ├── al_entity_main.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_priv.h │ │ ├── platform_interfaces_simulated.c │ │ ├── platform_interfaces_simulated_priv.h │ │ ├── platform_interfaces_wrt1900acx.c │ │ ├── platform_interfaces_wrt1900acx_priv.h │ │ ├── platform_os.c │ │ └── platform_os_priv.h ├── common │ ├── Makefile │ ├── interfaces │ │ ├── packet_tools.h │ │ ├── platform.h │ │ └── utils.h │ ├── src_independent │ │ └── utils.c │ └── src_linux │ │ └── platform.c ├── factory │ ├── Makefile │ ├── interfaces │ │ ├── 1905_alme.h │ │ ├── 1905_cmdus.h │ │ ├── 1905_l2.h │ │ ├── 1905_tlvs.h │ │ ├── extensions │ │ │ └── bbf │ │ │ │ └── bbf_tlvs.h │ │ ├── lldp_payload.h │ │ ├── lldp_tlvs.h │ │ └── media_specific_blobs.h │ ├── src_independent │ │ ├── 1905_alme.c │ │ ├── 1905_cmdus.c │ │ ├── 1905_tlvs.c │ │ ├── extensions │ │ │ └── bbf │ │ │ │ └── bbf_tlvs.c │ │ ├── lldp_payload.c │ │ ├── lldp_tlvs.c │ │ └── media_specific_blobs.c │ └── unit_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 │ │ ├── Makefile │ │ ├── extensions │ │ └── bbf │ │ │ ├── bbf_tlv_forging.c │ │ │ ├── bbf_tlv_parsing.c │ │ │ ├── bbf_tlv_test_vectors.c │ │ │ └── bbf_tlv_test_vectors.h │ │ ├── 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 └── hle │ ├── Makefile │ └── src_linux │ └── hle_entity_main.c └── version.txt /.mailmap: -------------------------------------------------------------------------------- 1 | Daniel Mateu 2 | Santiago Vicent 3 | William Lupton 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, Broadband Forum 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 | -------------------------------------------------------------------------------- /PROJECT: -------------------------------------------------------------------------------- 1 | Broadband Forum IEEE 1905.1/1a stack 2 | -------------------------------------------------------------------------------- /output/tmp/.place_holder: -------------------------------------------------------------------------------- 1 | This empty file exists so that 'git' includes this empty folder. 2 | You can ignore this... just don't remove this file. 3 | -------------------------------------------------------------------------------- /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/al/Makefile: -------------------------------------------------------------------------------- 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 | # When calling this Makefile, the following environment variables must be set: 57 | # 58 | # CC ------------> Path to the compiler 59 | # CCFLAGS -------> Extra flags to use while compiling 60 | # LDGLAGS -------> Extra flags to use while linking 61 | # 62 | # PLATFORM -> Possible values: "linux" 63 | # OUTPUT_FOLDER -> Absolute path to the folder where binaries will be built 64 | # 65 | # COMMON_LIB ----> Absolute path to the "common library" *.a file 66 | # COMMON_INC ----> Absolute path to the folder containing common (to all 67 | # sub-projects) header files 68 | # 69 | # FACTORY_LIB -> Absolute path to the "factory library" *.a file 70 | # FACTORY_INC -> Absolute path to the folder containing the "factory 71 | # library" header files 72 | # 73 | # AL_EXE --------> Absolute path to the final AL entity binary 74 | # 75 | # MKDIR ---------> Tool to create a directory 76 | # 77 | 78 | EXE := $(AL_EXE) 79 | 80 | AL_DIRECTORY := al 81 | 82 | SRC_INDEPENDENT := $(wildcard src_independent/*.c) 83 | SRC_INDEPENDENT += $(wildcard src_independent/extensions/*/*.c) 84 | SRC_PLATFORM := $(wildcard src_$(PLATFORM)/*.c) 85 | 86 | OBJ_INDEPENDENT := $(patsubst %.c,$(OUTPUT_FOLDER)/tmp/$(AL_DIRECTORY)/%.o,$(SRC_INDEPENDENT)) 87 | OBJ_PLATFORM := $(patsubst %.c,$(OUTPUT_FOLDER)/tmp/$(AL_DIRECTORY)/%.o,$(SRC_PLATFORM)) 88 | 89 | INTERNAL_INC_INDEPENDENT := src_independent internal_interfaces 90 | INTERNAL_INC_INDEPENDENT += $(sort $(dir $(wildcard interfaces/extensions/*/))) $(sort $(dir $(wildcard src_independent/extensions/*/))) 91 | INTERNAL_INC_PLATFORM := src_$(PLATFORM) internal_interfaces 92 | 93 | EXTERNAL_INC := $(COMMON_INC) $(FACTORY_INC) 94 | 95 | HDR_INDEPENDENT := $(shell find $(INTERNAL_INC_INDEPENDENT) $(EXTERNAL_INC) -name *.h) 96 | HDR_PLATFORM := $(shell find $(INTERNAL_INC_PLATFORM) $(EXTERNAL_INC) -name *.h) 97 | 98 | 99 | ################################################################################ 100 | # Targets 101 | ################################################################################ 102 | 103 | .PHONY: all 104 | all: $(EXE) 105 | 106 | 107 | $(EXE): $(OBJ_INDEPENDENT) $(OBJ_PLATFORM) $(FACTORY_LIB) $(COMMON_LIB) 108 | $(CC) $^ $(LDFLAGS) -o $@ 109 | 110 | $(OBJ_INDEPENDENT) : $(OUTPUT_FOLDER)/tmp/$(AL_DIRECTORY)/%.o : %.c $(HDR_INDEPENDENT) 111 | $(foreach directory, $(sort $(dir $(wildcard $(SRC_INDEPENDENT)))), $(MKDIR) $(OUTPUT_FOLDER)/tmp/$(AL_DIRECTORY)/$(directory);) 112 | $(CC) $(CCFLAGS) -c $(addprefix -I,$(INTERNAL_INC_INDEPENDENT) $(EXTERNAL_INC)) $< -o $@ 113 | 114 | $(OBJ_PLATFORM) : $(OUTPUT_FOLDER)/tmp/$(AL_DIRECTORY)/%.o : %.c $(HDR_PLATFORM) 115 | $(foreach directory, $(sort $(dir $(wildcard $(SRC_PLATFORM)))), $(MKDIR) $(OUTPUT_FOLDER)/tmp/$(AL_DIRECTORY)/$(directory);) 116 | $(CC) $(CCFLAGS) -c $(addprefix -I,$(INTERNAL_INC_PLATFORM) $(EXTERNAL_INC)) $< -o $@ 117 | 118 | 119 | .PHONY: clean 120 | clean: 121 | rm -rf $(EXE) 122 | rm -rf $(OUTPUT_FOLDER)/tmp/$(AL_DIRECTORY) 123 | -------------------------------------------------------------------------------- /src/al/internal_interfaces/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 | // This function takes the following arguments: 77 | // 78 | // - 'al_mac_address': a six bytes array containing the AL MAC address of the 79 | // local host. 80 | // - 'map_whole_network_flag': If set to '1', the AL entity will map the whole 81 | // network (instead of just its direct neighbors). This takes more memory 82 | // and generates much more packets on the network, however the TR069 83 | // datamodel of this particular node will contain all the information 84 | // defined in the standard. 85 | // I would personally *only* set this flag to '1' in *one* of the network 86 | // nodes. 87 | // - 'registrar_interface' is the name of the local interface (ex: "wlan0") 88 | // that will act as a registrar in the 1905 network. 89 | // Note that *only one registrar* should be present in the 1905 network, 90 | // thus this parameter should: 91 | // a) Be set to NULL in all those ALs that are not registrars. 92 | // b) Be set to the name of a local 802.11 interface (ex: "wlan0") in the 93 | // AL that will act as a registrar. 94 | // 95 | // It returns when: 96 | // 97 | // - Something went terribly wrong (maybe at initiallization time or maybe 98 | // later, while doing its bussiness). It that case it returns an error code 99 | // which is always bigger than '0': 100 | // 101 | // AL_ERROR_OUT_OF_MEMORY: 102 | // A call to "PLATFORM_MALLOC()" failed, meaning there is no more memory 103 | // available in the system. 104 | // 105 | // AL_ERROR_INVALID_ARGUMENTS: 106 | // The provided 'al_mac_address' is not valid. 107 | // 108 | // AL_ERROR_NO_INTERFACES: 109 | // A call to "PLATFORM_GET_LIST_OF_1905_INTERFACES()" returned an empty 110 | // list, meaning there is nothing for the 1905 AL entity to do. 111 | // 112 | // AL_ERROR_INTERFACE_ERROR: 113 | // A call to "PLATFORM_GET_LIST_OF_1905_INTERFACES() returned an error 114 | // or some other interface related problem. 115 | // 116 | // AL_ERROR_OS: 117 | // One of the OS-related PLATFORM_* functions returned an error (these 118 | // are functions use to create queues, start timers, etc...) 119 | // 120 | // AL_ERROR_PROTOCOL_EXTENSION; 121 | // Error registering, at least, one protocol extension. 122 | // 123 | // - The HLE requested the AL service to stop. In this case it will return '0' 124 | // 125 | INT8U start1905AL(INT8U *al_mac_address, INT8U map_whole_network_flag, char *registrar_interface); 126 | 127 | 128 | #endif 129 | 130 | -------------------------------------------------------------------------------- /src/al/internal_interfaces/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 | INT8U PLATFORM_SEND_ALME_REPLY(INT8U alme_client_id, INT8U *alme_message, INT16U alme_message_len); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/al/internal_interfaces/platform_crypto.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_CRYPTO_H_ 59 | #define _PLATFORM_CRYPTO_H_ 60 | 61 | #define SHA256_MAC_LEN 32 62 | #define AES_BLOCK_SIZE 16 63 | 64 | #include "platform.h" 65 | 66 | 67 | // Fill the buffer of length 'len' pointed by 'p' with random bytes. 68 | // 69 | // Return "0" if there was a problem, "1" otherwise 70 | // 71 | INT8U PLATFORM_GET_RANDOM_BYTES(INT8U *p, INT16U len); 72 | 73 | 74 | // Return a Diffie Hellman pair of private and public keys (and its lengths) in 75 | // the output arguments "priv", "priv_len", "pub" and "pub_len". 76 | // 77 | // Both "priv" and "pub" must be deallocated by the caller when they are no 78 | // longer needed (using "PLATFORM_FREE()") 79 | // 80 | // The keys are obtained using the DH group specified in RFC3523 "section 2" 81 | // (ie. the "1536-bit MODP Group" where "g = 2" and "p = 2^1536 - 2^1472 - 1 + 82 | // 2^64 * { [2^1406 pi] + 741804 }") 83 | // 84 | // Return "0" if there was a problem, "1" otherwise 85 | // 86 | INT8U PLATFORM_GENERATE_DH_KEY_PAIR(INT8U **priv, INT16U *priv_len, INT8U **pub, INT16U *pub_len); 87 | 88 | // Return the Diffie Hell shared secret (in output argument "shared_secret" 89 | // which is "shared_secret_len" bytes long) associated to a remote public key 90 | // ("remote_pub", which is "remote_pub_len" bytes long") and a local private 91 | // key ("local_priv", which is "local_priv_len" bytes long). 92 | // 93 | // "shared_secret" must be deallocated by the caller once it is no longer needed 94 | // (using "PLATFORM_FREE()") 95 | // 96 | // Return "0" if there was a problem, "1" otherwise 97 | // 98 | INT8U PLATFORM_COMPUTE_DH_SHARED_SECRET(INT8U **shared_secret, INT16U *shared_secret_len, INT8U *remote_pub, INT16U remote_pub_len, INT8U *local_priv, INT8U local_priv_len); 99 | 100 | // Return the SHA256 digest of the provided input. 101 | // 102 | // The provided input is the result of concatenating 'num_elem' elements 103 | // (addr[0], addr[1], ..., addr[num_elem-1] of size len[0], len[1], ..., 104 | // len[num_elem-1]) 105 | // 106 | // The digest is returned in the 'digest' output argument which must point to 107 | // a preallocated buffer of "SHA256_MAC_LEN" bytes. 108 | // 109 | INT8U PLATFORM_SHA256(INT8U num_elem, INT8U **addr, INT32U *len, INT8U *digest); 110 | 111 | 112 | // Return the HMAC_SHA256 digest of the provided input using the provided 'key' 113 | // (which is 'keylen' bytes long). 114 | // 115 | // The provided input is the result of concatenating 'num_elem' elements 116 | // (addr[0], addr[1], ..., addr[num_elem-1] of size len[0], len[1], ..., 117 | // len[num_elem-1]) 118 | // 119 | // The digest is returned in the 'hmac' output argument which must point to 120 | // a preallocated buffer of "SHA256_MAC_LEN" bytes. 121 | // 122 | INT8U PLATFORM_HMAC_SHA256(INT8U *key, INT32U keylen, INT8U num_elem, INT8U **addr, INT32U *len, INT8U *hmac); 123 | 124 | // Encrypt the provided 'data' (which is a pointer to buffer of size 125 | // n*AES_BLOCK_SIZE) using the AES 128 CBC algorithm with the provided 126 | // "initialization vector" ('iv', which is also a pointer to a buffer of 127 | // AES_BLOCK_SIZE bytes). 128 | // 129 | // The result is written to THE SAME 'data' buffer and has the same length as 130 | // the input (plain) data. 131 | // 132 | // Note that you might have to "pad" the data buffer (so that its length is a 133 | // multiple of AES_BLOCK_SIZE) in most cases. 134 | // 135 | // Return "0" if there was a problem, "1" otherwise 136 | // 137 | INT8U PLATFORM_AES_ENCRYPT(INT8U *key, INT8U *iv, INT8U *data, INT32U data_len); 138 | 139 | // Works exactly like "PLATFORM_AES_ENCRYPT", but now the 'data' buffer 140 | // originally contains encrypted data and after the call it contains 141 | // unencrypted data. 142 | INT8U PLATFORM_AES_DECRYPT(INT8U *key, INT8U *iv, INT8U *data, INT32U data_len); 143 | 144 | #endif 145 | -------------------------------------------------------------------------------- /src/al/src_independent/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 | 64 | // This function does "whatever needs to be done" as a result of receiving a 65 | // CMDU: for example, some CMDU trigger a response, others are used to update 66 | // the topology data base, etc... 67 | // 68 | // This function does *not* deal with "discarding" or "forwarding" the packet 69 | // (that should have already been taken care of before this function is called) 70 | // 71 | // 'c' is the just received CMDU structure. 72 | // 73 | // 'receiving_interface_addr' is the MAC address of the local interface where 74 | // the CMDU packet was received 75 | // 76 | // 'src_addr' is the MAC address contained in the 'src' field of the ethernet 77 | // frame which contained the just received CMDU payload. 78 | // 79 | // 'queue_id' is the ID of the queue where messages to the AL entity should be 80 | // posted in case new actions are derived from the processing of the current 81 | // message. 82 | // 83 | // Return values: 84 | // PROCESS_CMDU_KO: 85 | // There was problem processing the CMDU 86 | // PROCESS_CMDU_OK: 87 | // The CMDU was correctly processed. No further action required. 88 | // PROCESS_CMDU_OK_TRIGGER_AP_SEARCH: 89 | // The CMDU was correctly processed. The caller should now trigger an "AP 90 | // search" process if there is still an unconfigured AP local interface. 91 | // 92 | #define PROCESS_CMDU_KO (0) 93 | #define PROCESS_CMDU_OK (1) 94 | #define PROCESS_CMDU_OK_TRIGGER_AP_SEARCH (2) 95 | INT8U process1905Cmdu(struct CMDU *c, INT8U *receiving_interface_addr, INT8U *src_addr, INT8U queue_id); 96 | 97 | // Call this function when receiving an LLPD "bridge discovery" message so that 98 | // the topology database is properly updated. 99 | // 100 | INT8U processLlpdPayload(struct PAYLOAD *payload, INT8U *receiving_interface_addr); 101 | 102 | // Call this function when receiving an ALME REQUEST message. It will take 103 | // action depending on the actual contents of this message (ie. "shut down an 104 | // interface", "add a new bridge configuration", etc...) 105 | // 106 | INT8U process1905Alme(INT8U *alme_tlv, INT8U alme_client_id); 107 | 108 | #endif 109 | 110 | 111 | -------------------------------------------------------------------------------- /src/al/src_independent/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 | INT16U getNextMid(void) 67 | { 68 | static INT16U mid = 0; 69 | static INT8U 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((INT8U*)&mid, sizeof(INT16U)); 82 | } 83 | else 84 | { 85 | mid++; 86 | } 87 | 88 | return mid; 89 | } 90 | 91 | -------------------------------------------------------------------------------- /src/al/src_independent/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 | INT16U getNextMid(void); 65 | 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /src/al/src_independent/al_wsc.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_WSC_H_ 59 | #define _AL_WSC_H_ 60 | 61 | #include "platform.h" 62 | 63 | // One type of 1905 CMDUs embeds "M1" and "M2" messages from the "Wi-Fi simple 64 | // configuration standard". 65 | // 66 | // Because building these "M1" and "M2" messages in completely independent from 67 | // the 1905 standard, I have created this simple interface to isolate the 68 | // process as much as possible. 69 | // 70 | // It works like this: 71 | // 72 | // * ENROLLEE: 73 | // 74 | // 1. When a 1905 node has an unconfigured interface, it needs to send an 75 | // "M1" message. It does this by calling "wscBuildM1()", which takes the 76 | // name of the unconfigured interface and returns a data buffer that can 77 | // be directly embedded inside the WSC TLV/CMDU. 78 | // It also returns a "key" structure that will later be need to process 79 | // the response. 80 | // 81 | // 2. When the response ("M2") is received, the enrollee calls 82 | // "wscProcessM2()", which configures the interface and frees the "M1" 83 | // and "key" buffers previously allocated in "wscBuildM1()" 84 | // 85 | // * REGISTRAR: 86 | // 87 | // 1. When a 1905 node recieves an "M1" message, it calls "wscBuildM2()", 88 | // which takes the contents of the "M1" message and returns a data buffer 89 | // that can be directly embedded inside the WSC response TLV/CMDU. 90 | // 91 | // 2. After sending the TLV/CMDU, the "M2" buffer must be freed with a call 92 | // to "wscFreeM2()" 93 | // 94 | // Note that, in the enrolle, "M1" is automatically freed by "wscProcessM2()", 95 | // while, in the registrar, "M2" needs to be freed with "wscFreeM2()". 96 | // 97 | // When receiving a WSC TLV, because its contents are opaque to the 1905 node, 98 | // function "wscGetType()" can be used do distinguish between "M1" and "M2". 99 | // 100 | // With all of this said, this is how you would use this API in the 1905 code: 101 | // 102 | // - When receiving a AP search response (ie. when we want to configure an 103 | // unconfigured AP interface and a registrar has been found): 104 | // 105 | // INT8U *m1; 106 | // INT16U m1_size; 107 | // void *key; 108 | // 109 | // wscBuildM1("wlan0", &m1, &m1_size, &key); 110 | // 111 | // 112 | // 113 | // 114 | // - When receiving a WSC CMDU: 115 | // 116 | // if (WSC_TYPE_M1 == wscGetType(m, m_size)) 117 | // { 118 | // // Registrar 119 | // 120 | // INT8U *m2; 121 | // INT16U m2_size; 122 | // 123 | // wscBuildM2(m, m_size, &m2, &m2_size); 124 | // 125 | // wscFreeM2(m2, m2_size); 126 | // } 127 | // else 128 | // { 129 | // // Enrollee 130 | // 131 | // 132 | // wscProcessM2(key, m1, m1_size, m, m_size); 133 | // } 134 | // 135 | // Note that the references to "M1" and "key" must be "saved" for later use, 136 | // once the response is received. 137 | // For convenience, "wscProcessM2()" also accepts "NULL" as the 'M1' 138 | // arguments meaning "the last built M and its key" 139 | // However, if you use this shortcut, make sure you never call "wscBuildM1()" 140 | // more than once in a row (without calling "wscProcessM2()" in between), or 141 | // else the first "M1" will be lost forever. 142 | // 143 | // By the way, all the next functions return "0" if there a problem an "1" 144 | // otherwise (except for "wscGetType()", which returns the message type) 145 | 146 | INT8U wscBuildM1(char *interface_name, INT8U **m1, INT16U *m1_size, void **key); 147 | INT8U wscProcessM2(void *key, INT8U *m1, INT16U m1_size, INT8U *m2, INT16U m2_size); 148 | 149 | 150 | INT8U wscBuildM2(INT8U *m1, INT16U m1_size, INT8U **m2, INT16U *m2_size); 151 | INT8U wscFreeM2(INT8U *m, INT16U m_size); 152 | 153 | 154 | #define WSC_TYPE_M1 (0x00) 155 | #define WSC_TYPE_M2 (0x01) 156 | #define WSC_TYPE_UNKNOWN (0xFF) 157 | 158 | INT8U wscGetType(INT8U *m, INT16U m_size); 159 | 160 | 161 | #endif 162 | -------------------------------------------------------------------------------- /src/al/src_independent/extensions/bbf/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 | INT8U CBKprocess1905BBFExtensions(struct CMDU *memory_structure); 78 | 79 | #endif 80 | 81 | 82 | -------------------------------------------------------------------------------- /src/al/src_independent/extensions/bbf/bbf_send.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_SEND_H_ 59 | #define _BBF_SEND_H_ 60 | 61 | #include "1905_cmdus.h" 62 | 63 | 64 | //////////////////////////////////////////////////////////////////////////////// 65 | // CMDU extension callbacks 66 | //////////////////////////////////////////////////////////////////////////////// 67 | 68 | // This function inserts BBF TLVs (if appropriate) to the input CMDU. 69 | // 70 | // According to the standard, any CMDU is subject to be extended with extra 71 | // Vendor Specific TLVs, so each inserted BBF TLV will be embedded inside a 72 | // Vendor Specific TLV. 73 | // 74 | // BBF TLVs inserted (zero or more) depend on the CMDU type. They are always 75 | // inserted at the end of the current TLV list of the CMDU. 76 | // This function makes use of the generic API: 77 | // embedExtensionInVendorSpecificTLV() and insertVendorSpecificTLV() to insert 78 | // the BBF TLVs in the CMDU. 79 | // 80 | // 'memory_structure' is a pointer to the CMDU structure 81 | // 82 | // Return '0' if there was a problem, '1' otherwise 83 | // 84 | INT8U CBKSend1905BBFExtensions(struct CMDU *memory_structure); 85 | 86 | //////////////////////////////////////////////////////////////////////////////// 87 | // Datamodel extension callbacks 88 | //////////////////////////////////////////////////////////////////////////////// 89 | 90 | // This function obtains local non-standard info 91 | // 92 | // Local non-standard info is encoded in one of the defined BBF TLVs, which in 93 | // turn, is embedded in a standard Vendor Specific TLV. 94 | // This process will result in an array of Vendor Specific TLVs (one per BBF 95 | // TLV) 96 | // 97 | // This TLV list will be used to update the datamodel 'extensions' section by 98 | // the 'CBKUpdateBBFExtendedInfo()' callback. 99 | // 100 | // 'extensions' is a pointer to the local extensions 101 | // 102 | // 'nr' is the number of local extensions 103 | // 104 | void CBKObtainBBFExtendedLocalInfo(struct vendorSpecificTLV ***extensions, INT8U *nr); 105 | 106 | // This function updates the datamodel extensions section with non-standard info 107 | // 108 | // The datamodel structure keeps an extension TLV list per device. This TLV 109 | // list may be a set of TLVs from different registered actors (i.e. BBF, DPM, 110 | // ...), so each registered actor must update its own TLVs in the common 111 | // datamodel. 112 | // 113 | // 'extensions' is a pointer to the extensions section belonging to the device 114 | // with 'al_mac_address' AL mac address. 115 | // 116 | // 'nr' is the number of TLV extensions 117 | // 118 | // 'al_mac_address' is the AL mac address of the requested device. 119 | // 120 | void CBKUpdateBBFExtendedInfo(struct vendorSpecificTLV **extensions, INT8U nr, INT8U *al_mac_address); 121 | 122 | // This function extendes the ALME 'dnd' report 123 | // 124 | // This callback is called once per device. At this point, the standard 125 | // datamodel info is already added to the ALME 'dnd' report. This function may 126 | // add extra non-standard info obtained from the extensions TLV list 127 | // (previously updated via CBKUpdateBBFExtendedInfo()) 128 | // 129 | // The extensions TLV list may be a mix of TLVs from different registered 130 | // actors. This function preprocesses the whole list, takes care only of its 131 | // own TLVs, reorganizes data and presents the info in a user friendly manner 132 | // (i.e. non-1905 metrics (tx and rx) are classified by device) 133 | // 134 | // 'memory_structure' is a pointer to an array of TLV extensions. Each 135 | // registered function must represent its own extensions and ignore the rest. 136 | // 137 | // 'structure_nr' is the number of TLV extensions 138 | // 139 | // 'callback' is a function that will be executed on each element with the 140 | // following arguments: 141 | // * A pointer to the "write()" function that will be used to dump text. 142 | // This is always the "write_function()" pointer provided as third argument 143 | // to the "visit_1905_TLV_structure()" function. 144 | // * The size of the element to print (1, 2, 4, n bytes) 145 | // * A prefix string. 146 | // This is always the "prefix" value provided as fourth argument to the 147 | // "visit_1905_TLV_structure()" function 148 | // * The name of the element (ex: "mac_address") 149 | // * A 'fmt' string which must be used to print the contents of the element 150 | // * A pointer to the element itself 151 | // 152 | // 'write' is a function that will be used when the callback is executed 153 | // 154 | // 'prefix' is a string argument that will be used when the callback is 155 | // executed (it usually contains "context" information that the callback 156 | // function prints before anything else to make it easy to follow the structure 157 | // traversing order) 158 | // 159 | // These last three arguments will be passed to the 'visit_bbf_TLV_structure()' 160 | // function, which is defined in the 'bbf_tlvs.h' file and it's responsible for 161 | // converting the datamodel structure data into user friendly text. 162 | // 163 | void CBKDumpBBFExtendedInfo(INT8U **memory_structure, 164 | INT8U structure_nr, 165 | void (*callback)(void (*write_function)(const char *fmt, ...), const char *prefix, INT8U size, const char *name, const char *fmt, void *p), 166 | void (*write_function)(const char *fmt, ...), 167 | const char *prefix); 168 | 169 | #endif 170 | 171 | -------------------------------------------------------------------------------- /src/al/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 "platform.h" 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 | INT8U 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/al/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/al/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 | INT8U registerInterfaceStub(char *interface_type, INT8U 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/al/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/al/src_linux/platform_interfaces_wrt1900acx_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_WRT1900ACX_PRIV_H_ 59 | #define _PLATFORM_INTERFACES_WRT1900ACX_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 | INT8U linksys_wrt1900acx_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 | INT8U linksys_wrt1900acx_apply_80211_configuration(char *interface_name, INT8U *ssid, INT8U *network_key); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/al/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 "platform.h" 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 | INT8U sendMessageToAlQueue(INT8U queue_id, INT8U *message, INT16U message_len); 68 | 69 | #endif 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/common/Makefile: -------------------------------------------------------------------------------- 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 | # When calling this Makefile, the following environment variables must be set: 57 | # 58 | # CC ------------> Path to the compiler 59 | # CCFLAGS -------> Extra flags to use while compiling 60 | # 61 | # PLATFORM -> Possible values: "linux" 62 | # OUTPUT_FOLDER -> Absolute path to the folder where binaries will be built 63 | # 64 | # COMMON_LIB ----> Absolute path to the "common library" *.a file 65 | # 66 | # MKDIR ---------> Tool to create a directory 67 | # 68 | 69 | LIB := $(COMMON_LIB) 70 | 71 | COMMON_DIRECTORY := common 72 | 73 | SRC_INDEPENDENT := $(wildcard src_independent/*.c) 74 | SRC_PLATFORM := $(wildcard src_$(PLATFORM)/*.c) 75 | 76 | OBJ_INDEPENDENT := $(patsubst %.c,$(OUTPUT_FOLDER)/tmp/$(COMMON_DIRECTORY)/%.o,$(SRC_INDEPENDENT)) 77 | OBJ_PLATFORM := $(patsubst %.c,$(OUTPUT_FOLDER)/tmp/$(COMMON_DIRECTORY)/%.o,$(SRC_PLATFORM)) 78 | 79 | INTERNAL_INC_INDEPENDENT := src_independent interfaces 80 | INTERNAL_INC_PLATFORM := src_$(PLATFORM) interfaces 81 | 82 | EXTERNAL_INC := 83 | 84 | HDR_INDEPENDENT := $(shell find $(INTERNAL_INC_INDEPENDENT) $(EXTERNAL_INC) -name *.h) 85 | HDR_PLATFORM := $(shell find $(INTERNAL_INC_PLATFORM) $(EXTERNAL_INC) -name *.h) 86 | 87 | 88 | ################################################################################ 89 | # Targets 90 | ################################################################################ 91 | 92 | .PHONY: all 93 | all: $(LIB) 94 | 95 | 96 | $(LIB) : $(OBJ_INDEPENDENT) $(OBJ_PLATFORM) 97 | $(AR) -rc $@ $^ 98 | 99 | 100 | $(OBJ_INDEPENDENT) : $(OUTPUT_FOLDER)/tmp/$(COMMON_DIRECTORY)/%.o : %.c $(HDR_INDEPENDENT) 101 | $(foreach directory, $(sort $(dir $(wildcard $(SRC_INDEPENDENT)))), $(MKDIR) $(OUTPUT_FOLDER)/tmp/$(COMMON_DIRECTORY)/$(directory);) 102 | $(CC) $(CCFLAGS) -c $(addprefix -I,$(INTERNAL_INC_INDEPENDENT) $(EXTERNAL_INC)) $< -o $@ 103 | 104 | $(OBJ_PLATFORM) : $(OUTPUT_FOLDER)/tmp/$(COMMON_DIRECTORY)/%.o : %.c $(HDR_PLATFORM) 105 | $(foreach directory, $(sort $(dir $(wildcard $(SRC_PLATFORM)))), $(MKDIR) $(OUTPUT_FOLDER)/tmp/$(COMMON_DIRECTORY)/$(directory);) 106 | $(CC) $(CCFLAGS) -c $(addprefix -I,$(INTERNAL_INC_PLATFORM) $(EXTERNAL_INC)) $< -o $@ 107 | 108 | 109 | .PHONY: clean 110 | clean: 111 | rm -rf $(LIB) 112 | rm -rf $(OUTPUT_FOLDER)/tmp/$(COMMON_DIRECTORY) 113 | 114 | -------------------------------------------------------------------------------- /src/common/interfaces/packet_tools.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 _PACKET_TOOLS_H_ 59 | #define _PACKET_TOOLS_H_ 60 | 61 | #include "platform.h" 62 | 63 | 64 | // Auxiliary functions to: 65 | // 66 | // A) Extract 1, 2 or 4 bytes from a stream received from the network. 67 | // 68 | // B) Insert 1, 2 or 4 bytes into a stream which is going to be sent into 69 | // the network. 70 | // 71 | // These functions do three things: 72 | // 73 | // 1. Avoid unaligned memory accesses (which might cause slowdowns or even 74 | // exceptions on some architectures) 75 | // 76 | // 2. Convert from network order to host order (and the other way) 77 | // 78 | // 3. Advance the packet pointer as many bytes as those which have just 79 | // been extracted/inserted. 80 | 81 | // Extract/insert 1 byte 82 | // 83 | static inline void _E1B(INT8U **packet_ppointer, INT8U *memory_pointer) 84 | { 85 | *memory_pointer = **packet_ppointer; 86 | (*packet_ppointer) += 1; 87 | } 88 | static inline void _I1B(INT8U *memory_pointer, INT8U **packet_ppointer) 89 | { 90 | **packet_ppointer = *memory_pointer; 91 | (*packet_ppointer) += 1; 92 | } 93 | 94 | // Extract/insert 2 bytes 95 | // 96 | static inline void _E2B(INT8U **packet_ppointer, INT16U *memory_pointer) 97 | { 98 | #if _HOST_IS_BIG_ENDIAN_ == 1 99 | *(((INT8U *)memory_pointer)+0) = **packet_ppointer; (*packet_ppointer)++; 100 | *(((INT8U *)memory_pointer)+1) = **packet_ppointer; (*packet_ppointer)++; 101 | #elif _HOST_IS_LITTLE_ENDIAN_ == 1 102 | *(((INT8U *)memory_pointer)+1) = **packet_ppointer; (*packet_ppointer)++; 103 | *(((INT8U *)memory_pointer)+0) = **packet_ppointer; (*packet_ppointer)++; 104 | #else 105 | #error You must specify your architecture endianess 106 | #endif 107 | } 108 | static inline void _I2B(INT16U *memory_pointer, INT8U **packet_ppointer) 109 | { 110 | #if _HOST_IS_BIG_ENDIAN_ == 1 111 | **packet_ppointer = *(((INT8U *)memory_pointer)+0); (*packet_ppointer)++; 112 | **packet_ppointer = *(((INT8U *)memory_pointer)+1); (*packet_ppointer)++; 113 | #elif _HOST_IS_LITTLE_ENDIAN_ == 1 114 | **packet_ppointer = *(((INT8U *)memory_pointer)+1); (*packet_ppointer)++; 115 | **packet_ppointer = *(((INT8U *)memory_pointer)+0); (*packet_ppointer)++; 116 | #else 117 | #error You must specify your architecture endianess 118 | #endif 119 | } 120 | 121 | // Extract/insert 4 bytes 122 | // 123 | static inline void _E4B(INT8U **packet_ppointer, INT32U *memory_pointer) 124 | { 125 | #if _HOST_IS_BIG_ENDIAN_ == 1 126 | *(((INT8U *)memory_pointer)+0) = **packet_ppointer; (*packet_ppointer)++; 127 | *(((INT8U *)memory_pointer)+1) = **packet_ppointer; (*packet_ppointer)++; 128 | *(((INT8U *)memory_pointer)+2) = **packet_ppointer; (*packet_ppointer)++; 129 | *(((INT8U *)memory_pointer)+3) = **packet_ppointer; (*packet_ppointer)++; 130 | #elif _HOST_IS_LITTLE_ENDIAN_ == 1 131 | *(((INT8U *)memory_pointer)+3) = **packet_ppointer; (*packet_ppointer)++; 132 | *(((INT8U *)memory_pointer)+2) = **packet_ppointer; (*packet_ppointer)++; 133 | *(((INT8U *)memory_pointer)+1) = **packet_ppointer; (*packet_ppointer)++; 134 | *(((INT8U *)memory_pointer)+0) = **packet_ppointer; (*packet_ppointer)++; 135 | #else 136 | #error You must specify your architecture endianess 137 | #endif 138 | } 139 | static inline void _I4B(INT32U *memory_pointer, INT8U **packet_ppointer) 140 | { 141 | #if _HOST_IS_BIG_ENDIAN_ == 1 142 | **packet_ppointer = *(((INT8U *)memory_pointer)+0); (*packet_ppointer)++; 143 | **packet_ppointer = *(((INT8U *)memory_pointer)+1); (*packet_ppointer)++; 144 | **packet_ppointer = *(((INT8U *)memory_pointer)+2); (*packet_ppointer)++; 145 | **packet_ppointer = *(((INT8U *)memory_pointer)+3); (*packet_ppointer)++; 146 | #elif _HOST_IS_LITTLE_ENDIAN_ == 1 147 | **packet_ppointer = *(((INT8U *)memory_pointer)+3); (*packet_ppointer)++; 148 | **packet_ppointer = *(((INT8U *)memory_pointer)+2); (*packet_ppointer)++; 149 | **packet_ppointer = *(((INT8U *)memory_pointer)+1); (*packet_ppointer)++; 150 | **packet_ppointer = *(((INT8U *)memory_pointer)+0); (*packet_ppointer)++; 151 | #else 152 | #error You must specify your architecture endianess 153 | #endif 154 | } 155 | 156 | // Extract/insert N bytes (ignore endianess) 157 | // 158 | static inline void _EnB(INT8U **packet_ppointer, void *memory_pointer, INT32U n) 159 | { 160 | PLATFORM_MEMCPY(memory_pointer, *packet_ppointer, n); 161 | (*packet_ppointer) += n; 162 | } 163 | static inline void _InB(void *memory_pointer, INT8U **packet_ppointer, INT32U n) 164 | { 165 | PLATFORM_MEMCPY(*packet_ppointer, memory_pointer, n); 166 | (*packet_ppointer) += n; 167 | } 168 | 169 | #endif 170 | -------------------------------------------------------------------------------- /src/common/interfaces/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 _UTILS_H_ 59 | #define _UTILS_H_ 60 | 61 | // This is an auxiliary function which is used when calling the "visit_*()" 62 | // family of functions so that the contents of the memory structures can be 63 | // printed on screen for debugging/logging purposes. 64 | // 65 | // The documentation for any of the "visit_*()" function explains what this 66 | // functions should do and look like. 67 | // 68 | void print_callback (void (*write_function)(const char *fmt, ...), const char *prefix, INT8U size, const char *name, const char *fmt, void *p); 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/common/src_independent/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 "utils.h" 60 | 61 | //////////////////////////////////////////////////////////////////////////////// 62 | // Public API 63 | //////////////////////////////////////////////////////////////////////////////// 64 | // 65 | void print_callback(void (*write_function)(const char *fmt, ...), const char *prefix, INT8U size, const char *name, const char *fmt, void *p) 66 | { 67 | 68 | if (0 == PLATFORM_MEMCMP(fmt, "%s", 3)) 69 | { 70 | // Strings are printed with triple quotes surrounding them 71 | // 72 | write_function("%s%s: \"\"\"%s\"\"\"\n", prefix, name, p); 73 | return; 74 | } 75 | else if (0 == PLATFORM_MEMCMP(fmt, "%ipv4", 6)) 76 | { 77 | // This is needed because "size == 4" on IPv4 addresses, but we don't 78 | // want them to be treated as 4 bytes integers, so we change the 79 | // "fmt" to "%d" and do *not* returns (so that the IPv4 ends up being 80 | // printed as a sequence of bytes. 81 | // 82 | fmt = "%d"; 83 | } 84 | else 85 | { 86 | #define FMT_LINE_SIZE 20 87 | char fmt_line[FMT_LINE_SIZE]; 88 | 89 | fmt_line[0] = 0x0; 90 | 91 | PLATFORM_SNPRINTF(fmt_line, FMT_LINE_SIZE-1, "%%s%%s: %s\n", fmt); 92 | fmt_line[FMT_LINE_SIZE-1] = 0x0; 93 | 94 | if (1 == size) 95 | { 96 | write_function(fmt_line, prefix, name, *(INT8U *)p); 97 | 98 | return; 99 | } 100 | else if (2 == size) 101 | { 102 | write_function(fmt_line, prefix, name, *(INT16U *)p); 103 | 104 | return; 105 | } 106 | else if (4 == size) 107 | { 108 | write_function(fmt_line, prefix, name, *(INT32U *)p); 109 | 110 | return; 111 | } 112 | } 113 | 114 | // If we get here, it's either an IPv4 address or a sequence of bytes 115 | // 116 | { 117 | #define AUX1_SIZE 200 // Store a whole output line 118 | #define AUX2_SIZE 20 // Store a fmt conversion 119 | 120 | INT16U i, j; 121 | 122 | char aux1[AUX1_SIZE]; 123 | char aux2[AUX2_SIZE]; 124 | 125 | INT16U space_left = AUX1_SIZE-1; 126 | 127 | aux1[0] = 0x00; 128 | PLATFORM_STRNCAT(aux1, "%s%s: ", AUX1_SIZE); 129 | 130 | for (i=0; i space_left) 155 | { 156 | // No more space left 157 | // 158 | aux1[AUX1_SIZE-6] = '.'; 159 | aux1[AUX1_SIZE-5] = '.'; 160 | aux1[AUX1_SIZE-4] = '.'; 161 | aux1[AUX1_SIZE-3] = '.'; 162 | aux1[AUX1_SIZE-2] = '.'; 163 | aux1[AUX1_SIZE-1] = 0x00; 164 | break; 165 | } 166 | 167 | // Append string to "aux1" 168 | // 169 | PLATFORM_STRNCAT(aux1, aux2, j); 170 | PLATFORM_STRNCAT(aux1, ", ", 2); 171 | space_left -= (j+2); 172 | } 173 | 174 | PLATFORM_STRNCAT(aux1, "\n", 2); 175 | write_function(aux1, prefix, name); 176 | } 177 | 178 | return; 179 | } 180 | 181 | 182 | -------------------------------------------------------------------------------- /src/factory/Makefile: -------------------------------------------------------------------------------- 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 | # When calling this Makefile, the following environment variables must be set: 57 | # 58 | # CC ------------> Path to the compiler 59 | # CCFLAGS -------> Extra flags to use while compiling 60 | # 61 | # OUTPUT_FOLDER -> Absolute path to the folder where binaries will be built 62 | # 63 | # COMMON_INC ----> Absolute path to the folder containing common (to all 64 | # sub-projects) header files 65 | # 66 | # FACTORY_LIB ---> Absolute path to the "factory library" *.a file 67 | # 68 | # MKDIR ---------> Tool to create a directory 69 | # 70 | 71 | FACTORY_DIRECTORY := factory 72 | 73 | LIB := $(FACTORY_LIB) 74 | SRC := $(wildcard src_independent/*.c) 75 | SRC += $(wildcard src_independent/extensions/*/*.c) 76 | OBJ := $(patsubst %.c,$(OUTPUT_FOLDER)/tmp/$(FACTORY_DIRECTORY)/%.o,$(SRC)) 77 | 78 | INTERNAL_INC := src_independent interfaces 79 | INTERNAL_INC += $(sort $(dir $(wildcard interfaces/extensions/*/))) 80 | EXTERNAL_INC := $(COMMON_INC) 81 | 82 | HDR := $(shell find $(INTERNAL_INC) $(EXTERNAL_INC) -name *.h) 83 | 84 | 85 | ################################################################################ 86 | # Targets 87 | ################################################################################ 88 | 89 | .PHONY: all 90 | all: $(LIB) 91 | 92 | 93 | $(LIB) : $(OBJ) 94 | $(AR) -rc $@ $^ 95 | 96 | 97 | $(OBJ) : $(OUTPUT_FOLDER)/tmp/$(FACTORY_DIRECTORY)/%.o : %.c $(HDR) 98 | $(foreach directory, $(sort $(dir $(wildcard $(SRC)))), $(MKDIR) $(OUTPUT_FOLDER)/tmp/$(FACTORY_DIRECTORY)/$(directory);) 99 | $(CC) $(CCFLAGS) -c $(addprefix -I,$(INTERNAL_INC) $(EXTERNAL_INC)) $< -o $@ 100 | 101 | 102 | .PHONY: unit_tests 103 | unit_tests: 104 | $(MAKE) -C unit_tests all 105 | 106 | 107 | .PHONY: clean 108 | clean: 109 | rm -rf $(LIB) 110 | rm -rf $(OUTPUT_FOLDER)/tmp/$(FACTORY_DIRECTORY) 111 | $(MAKE) -C unit_tests clean 112 | 113 | -------------------------------------------------------------------------------- /src/factory/interfaces/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 (0x893a) 64 | #define ETHERTYPE_LLDP (0x88cc) 65 | 66 | 67 | // 1905 multicast address ("01:80:C2:00:00:13") 68 | // 69 | #define MCAST_1905_B0 (0x01) 70 | #define MCAST_1905_B1 (0x80) 71 | #define MCAST_1905_B2 (0xC2) 72 | #define MCAST_1905_B3 (0x00) 73 | #define MCAST_1905_B4 (0x00) 74 | #define MCAST_1905_B5 (0x13) 75 | #define MCAST_1905 {MCAST_1905_B0, MCAST_1905_B1, MCAST_1905_B2, MCAST_1905_B3, MCAST_1905_B4, MCAST_1905_B5} 76 | 77 | 78 | // LLDP nearest bridge multicast address ("01:80:C2:00:00:0E") 79 | // 80 | #define MCAST_LLDP_B0 (0x01) 81 | #define MCAST_LLDP_B1 (0x80) 82 | #define MCAST_LLDP_B2 (0xC2) 83 | #define MCAST_LLDP_B3 (0x00) 84 | #define MCAST_LLDP_B4 (0x00) 85 | #define MCAST_LLDP_B5 (0x0E) 86 | #define MCAST_LLDP {MCAST_LLDP_B0, MCAST_LLDP_B1, MCAST_LLDP_B2, MCAST_LLDP_B3, MCAST_LLDP_B4, MCAST_LLDP_B5} 87 | 88 | #endif 89 | 90 | -------------------------------------------------------------------------------- /src/factory/interfaces/media_specific_blobs.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 _MEDIA_SPECIFIC_BLOBS_H_ 59 | #define _MEDIA_SPECIFIC_BLOBS_H_ 60 | 61 | 62 | //////////////////////////////////////////////////////////////////////////////// 63 | // Structure type used for generic interfaces 64 | //////////////////////////////////////////////////////////////////////////////// 65 | 66 | // The 1905 standard originally only recognized a limited set of interface 67 | // types (IEEE802.11, IEEE802.3, IEEE1901, MOCA, ...) and for each of these 68 | // types some parameters were defined (for example, the "bssid" and other 69 | // things for IEEE802.11 interfaces, the "networ). 70 | // 71 | // Later, the standard was expanded to accept arbitrary parameters from all 72 | // types of interfaces. This is done by using the next structure. 73 | // 74 | struct genericInterfaceType 75 | { 76 | INT8U oui[3]; // Three bytes containing either the 77 | // "Organizationally Unique Identifier" 78 | // ("http://standards.ieee.org/develop/regauth/oui") 79 | // or the "Company ID" 80 | // ("http://standards.ieee.org/develop/regauth/cid") 81 | // responsible for this particular interface type. 82 | 83 | char *generic_phy_description_xml_url; 84 | // NULL terminated string pointing to the URL of 85 | // the "Generic Phy XML Description Document" that 86 | // describes the properties of this interface type. 87 | // This document must conform to the "Generic Phy 88 | // XML schema" 89 | // ("http://standards.ieee.org/downloads/1905/GenericPhyInfoV1.xsd") 90 | 91 | INT8U variant_index; // The "Generic Phy XML Description Document" might 92 | // might contain more than one "class" of 93 | // interfaces for each OUI. This variable is used 94 | // to identify which class/variant is the one that 95 | // applies to this particular interface type. 96 | 97 | char *variant_name; // NULL terminated string containing the "friendly 98 | // name" this variant receives in the "Generic Phy 99 | // XML Description Document". 100 | // Must not be longer than 32 bytes (including the 101 | // final NULL character). 102 | // NOTE: The OUI and variant_index are 103 | // enough to identify a variant inside a 104 | // "Generic Phy XML Description Document", 105 | // however we required this field too for 106 | // convinience. 107 | 108 | union _mediaSpecific 109 | { 110 | struct _ituGhn 111 | { 112 | // This is the structure to fill when: 113 | // 114 | // - 'generic_phy_description_xml_url' is set to 115 | // "http://handle.itu.int/11.1002/3000/1706" 116 | // 117 | // - 'oui' is set to 00:19:A7 118 | // 119 | // - ...and the 'variant_index' is set to either 1, 2, 3 or 4 120 | 121 | INT8U dni[2]; // Domain name identifier (see clause 122 | // 8.6.8.2.1 of "ITU-T G.9961") 123 | } ituGhn; 124 | 125 | struct _unsupported 126 | { 127 | // This is the structure to fill in all other cases. If you don't 128 | // want to provide media specific data, just set 'bytes_nr' to '0', 129 | // otherwise use this array to send arbitrary data to upper layers 130 | // 131 | INT16U bytes_nr; 132 | INT8U *bytes; 133 | 134 | } unsupported; 135 | 136 | } media_specific; 137 | 138 | }; 139 | 140 | 141 | 142 | //////////////////////////////////////////////////////////////////////////////// 143 | // Main API functions 144 | //////////////////////////////////////////////////////////////////////////////// 145 | 146 | // This function receives a pointer to a "genericInterfaceType" structure and 147 | // then allocates and returns a buffer holding the array of bytes that should 148 | // be inserted in the 1905 "media_specific" fields present in several TLVs 149 | // ("generic phy device information TLV", "push button generic phy event 150 | // notification TLV" and "power off interface TLV"). 151 | // 152 | // This function "translates" the "genericInterfaceType" structure fields 153 | // specific for each supported interface type into a stream of bytes according 154 | // to the corresponding standard that applies to each particular type of 155 | // interface. 156 | // 157 | // The returned pointer can later be free with "free_media_specific_blob()" 158 | // 159 | // 'len' is an output argument that holds the length of the returned buffer. 160 | // 161 | INT8U *forge_media_specific_blob(struct genericInterfaceType *m, INT16U *len); 162 | 163 | // 'forge_media_specific_blob()' returns a regular buffer which can be freed 164 | // using this macro defined to be PLATFORM_FREE 165 | // 166 | #define free_media_specific_blob PLATFORM_FREE 167 | 168 | #endif 169 | -------------------------------------------------------------------------------- /src/factory/src_independent/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 "platform.h" 59 | 60 | #include "media_specific_blobs.h" 61 | 62 | 63 | //////////////////////////////////////////////////////////////////////////////// 64 | // Actual API functions 65 | //////////////////////////////////////////////////////////////////////////////// 66 | 67 | INT8U *forge_media_specific_blob(struct genericInterfaceType *m, INT16U *len) 68 | { 69 | #define ITU_T_GHN_XML "http://handle.itu.int/11.1002/3000/1706" 70 | 71 | INT8U *ret; 72 | 73 | ret = NULL; 74 | 75 | if (NULL == m->generic_phy_description_xml_url) 76 | { 77 | return NULL; 78 | } 79 | 80 | if (0 == PLATFORM_MEMCMP(m->generic_phy_description_xml_url, ITU_T_GHN_XML, PLATFORM_STRLEN(ITU_T_GHN_XML)+1)) 81 | { 82 | // This XML file defines the *same* media specific data format for all 83 | // interfaces that meet the following requirements: 84 | // 85 | // - OUI = 00:19:A7 86 | // - Variant = 0, 1, 2, 3 or 4 (it also defines 10 and 11, but we will 87 | // ignore these) 88 | 89 | if ( 90 | m->oui[0] != 0x00 || 91 | m->oui[1] != 0x19 || 92 | m->oui[2] != 0xa7 93 | ) 94 | { 95 | // Unknown OUI 96 | } 97 | else if ( 98 | m->variant_index != 0 && 99 | m->variant_index != 1 && 100 | m->variant_index != 2 && 101 | m->variant_index != 3 && 102 | m->variant_index != 4 103 | ) 104 | { 105 | // Unknown variant 106 | } 107 | else 108 | { 109 | // The 1905 media specific field is made up of FIVE bytes: 110 | // 111 | // 0x01, 0x00, 0x02, dni[0], dni[1] 112 | // 113 | // (see ITU-T G.9979 Tables 8.2 and 8.3) 114 | // 115 | *len = 5; 116 | ret = (INT8U *)PLATFORM_MALLOC(*len); 117 | ret[0] = 0x01; 118 | ret[1] = 0x00; 119 | ret[2] = 0x02; 120 | ret[3] = m->media_specific.ituGhn.dni[0]; 121 | ret[4] = m->media_specific.ituGhn.dni[1]; 122 | } 123 | } 124 | 125 | if (NULL == ret) 126 | { 127 | // If we get to this point and "ret" is still "NULL", that means that the 128 | // "XML"/"OUI"/"variant_index" combination has not been recognized, and thus 129 | // we will simply return the contents of the "unsupported" structure. 130 | // 131 | *len = m->media_specific.unsupported.bytes_nr; 132 | ret = (INT8U *)PLATFORM_MALLOC(*len); 133 | 134 | PLATFORM_MEMCPY(ret, m->media_specific.unsupported.bytes, *len); 135 | } 136 | 137 | return ret; 138 | } 139 | 140 | -------------------------------------------------------------------------------- /src/factory/unit_tests/1905_cmdu_parsing.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 "parse_1905_CMDU_from_packets()" function by providing 60 | // some test input streams and checking the generated output structure. 61 | // 62 | 63 | #include "platform.h" 64 | #include "utils.h" 65 | 66 | #include "1905_tlvs.h" 67 | #include "1905_cmdus.h" 68 | #include "1905_cmdu_test_vectors.h" 69 | 70 | INT8U _check(const char *test_description, INT8U **input, struct CMDU *expected_output) 71 | { 72 | INT8U result; 73 | struct CMDU *real_output; 74 | 75 | real_output = parse_1905_CMDU_from_packets(input); 76 | 77 | if (0 == compare_1905_CMDU_structures(real_output, expected_output)) 78 | { 79 | result = 0; 80 | PLATFORM_PRINTF("%-100s: OK\n", test_description); 81 | } 82 | else 83 | { 84 | result = 1; 85 | PLATFORM_PRINTF("%-100s: KO !!!\n", test_description); 86 | PLATFORM_PRINTF(" Expected output:\n"); 87 | visit_1905_CMDU_structure(expected_output, print_callback, PLATFORM_PRINTF, ""); 88 | PLATFORM_PRINTF(" Real output :\n"); 89 | visit_1905_CMDU_structure(real_output, print_callback, PLATFORM_PRINTF, ""); 90 | } 91 | 92 | return result; 93 | } 94 | 95 | 96 | int main(void) 97 | { 98 | INT8U result = 0; 99 | 100 | #define x1905CMDUPARSE001 "x1905CMDUPARSE001 - Parse link metric query CMDU (x1905_cmdu_streams_001)" 101 | result += _check(x1905CMDUPARSE001, x1905_cmdu_streams_001, &x1905_cmdu_structure_001); 102 | 103 | #define x1905CMDUPARSE002 "x1905CMDUPARSE002 - Parse link metric query CMDU (x1905_cmdu_streams_002)" 104 | result += _check(x1905CMDUPARSE002, x1905_cmdu_streams_002, &x1905_cmdu_structure_002); 105 | 106 | #define x1905CMDUPARSE003 "x1905CMDUPARSE003 - Parse link metric query CMDU (x1905_cmdu_streams_004)" 107 | result += _check(x1905CMDUPARSE003, x1905_cmdu_streams_004, &x1905_cmdu_structure_004); 108 | 109 | #define x1905CMDUPARSE004 "x1905CMDUPARSE004 - Parse topology query CMDU (x1905_cmdu_streams_005)" 110 | result += _check(x1905CMDUPARSE004, x1905_cmdu_streams_005, &x1905_cmdu_structure_005); 111 | 112 | // Return the number of test cases that failed 113 | // 114 | return result; 115 | } 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /src/factory/unit_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 INT8U *x1905_cmdu_streams_001[]; 66 | extern INT16U x1905_cmdu_streams_len_001[]; 67 | 68 | extern struct CMDU x1905_cmdu_structure_002; 69 | extern INT8U *x1905_cmdu_streams_002[]; 70 | extern INT16U x1905_cmdu_streams_len_002[]; 71 | 72 | extern struct CMDU x1905_cmdu_structure_003; 73 | extern INT8U *x1905_cmdu_streams_003[]; 74 | extern INT16U x1905_cmdu_streams_len_003[]; 75 | 76 | extern struct CMDU x1905_cmdu_structure_004; 77 | extern INT8U *x1905_cmdu_streams_004[]; 78 | extern INT16U x1905_cmdu_streams_len_004[]; 79 | 80 | extern struct CMDU x1905_cmdu_structure_005; 81 | extern INT8U *x1905_cmdu_streams_005[]; 82 | extern INT16U x1905_cmdu_streams_len_005[]; 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /src/factory/unit_tests/Makefile: -------------------------------------------------------------------------------- 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 | # When calling this Makefile, the following environment variables must be set: 57 | # 58 | # CC ------------> Path to the compiler 59 | # CCFLAGS -------> Extra flags to use while compiling 60 | # 61 | # OUTPUT_FOLDER -> Absolute path to the folder where binaries will be built 62 | # 63 | # COMMON_LIB ----> Absolute path to the "common library" *.a file 64 | # COMMON_INC ----> Absolute path to the folder containing common (to all 65 | # sub-projects) header files 66 | 67 | # FACTORY_LIB -> Absolute path to the "factory library" *.a file 68 | # FACTORY_INC -> Absolute path to the folder containing the "factory 69 | # library" header files 70 | # 71 | # MKDIR ---------> Tool to create a directory 72 | # 73 | UNIT_TESTS_DIRECTORY := factory/unit_tests 74 | 75 | UNITS := 1905_tlv_forging 76 | UNITS += 1905_tlv_parsing 77 | UNITS += 1905_cmdu_forging 78 | UNITS += 1905_cmdu_parsing 79 | UNITS += 1905_alme_forging 80 | UNITS += 1905_alme_parsing 81 | UNITS += lldp_tlv_parsing 82 | UNITS += lldp_payload_forging 83 | UNITS += lldp_payload_parsing 84 | 85 | UNITS += extensions/bbf/bbf_tlv_forging 86 | UNITS += extensions/bbf/bbf_tlv_parsing 87 | 88 | EXE := $(addprefix $(OUTPUT_FOLDER)/UNITTEST_, $(UNITS)) 89 | SRC := $(addsuffix .c, $(UNITS)) 90 | OBJ := $(addprefix $(OUTPUT_FOLDER)/tmp/$(UNIT_TESTS_DIRECTORY)/, $(addsuffix .o, $(UNITS))) 91 | 92 | 93 | INTERNAL_INC := . $(sort $(dir $(wildcard extensions/*/))) 94 | EXTERNAL_INC := $(COMMON_INC) $(FACTORY_INC) 95 | 96 | HDR := $(shell find $(INTERNAL_INC) $(EXTERNAL_INC) -name "*.h") 97 | 98 | SHARED_SRC := $(wildcard *test_vectors.c) 99 | SHARED_SRC += $(wildcard extensions/*/*test_vectors.c) 100 | SHARED_OBJ := $(addprefix $(OUTPUT_FOLDER)/tmp/$(UNIT_TESTS_DIRECTORY)/,$(patsubst %.c,%.o,$(SHARED_SRC))) 101 | SHARED_HDR := $(patsubst %.c,%.h,$(SHARED_SRC)) 102 | 103 | #LDFLAGS += -fdata-sections -ffunction-sections -Wl,--gc-sections 104 | 105 | TESTS := $(addprefix UNITTEST_,$(basename $(UNITS))) 106 | 107 | ################################################################################ 108 | # Targets 109 | ################################################################################ 110 | 111 | .PHONY: all 112 | all: $(TESTS) 113 | 114 | 115 | .PHONY: $(TESTS) 116 | $(TESTS) : UNITTEST_% : $(OUTPUT_FOLDER)/UNITTEST_% 117 | $< 118 | 119 | 120 | $(EXE) : $(OUTPUT_FOLDER)/UNITTEST_% : $(OUTPUT_FOLDER)/tmp/$(UNIT_TESTS_DIRECTORY)/%.o $(SHARED_OBJ) $(COMMON_LIB) $(FACTORY_LIB) 121 | $(foreach directory, $(UNITS), $(MKDIR) $(OUTPUT_FOLDER)/UNITTEST_$(shell dirname $(directory);)) 122 | $(CC) $(LDFLAGS) $^ -o $@ 123 | 124 | $(OBJ) : $(OUTPUT_FOLDER)/tmp/$(UNIT_TESTS_DIRECTORY)/%.o : %.c 125 | $(foreach directory, $(sort $(dir $(wildcard $(SRC)))), $(MKDIR) $(OUTPUT_FOLDER)/tmp/$(UNIT_TESTS_DIRECTORY)/$(directory);) 126 | $(CC) $(CCFLAGS) -c $(addprefix -I,$(INTERNAL_INC) $(EXTERNAL_INC)) $< -o $@; 127 | 128 | 129 | $(SHARED_OBJ) : $(OUTPUT_FOLDER)/tmp/$(UNIT_TESTS_DIRECTORY)/%.o : %.c $(SHARED_HDR) 130 | $(foreach directory, $(sort $(dir $(wildcard $(SHARED_SRC)))), $(MKDIR) $(OUTPUT_FOLDER)/tmp/$(UNIT_TESTS_DIRECTORY)/$(directory);) 131 | $(CC) $(CCFLAGS) -c $(addprefix -I,$(INTERNAL_INC) $(EXTERNAL_INC)) $< -o $@; 132 | 133 | 134 | .PHONY: clean 135 | clean: 136 | rm -f $(EXE) 137 | rm -rf $(OUTPUT_FOLDER)/UNITTEST_* 138 | rm -rf $(OUTPUT_FOLDER)/tmp/UNITTEST_* 139 | rm -rf $(OUTPUT_FOLDER)/tmp/$(UNIT_TESTS_DIRECTORY) 140 | -------------------------------------------------------------------------------- /src/factory/unit_tests/extensions/bbf/bbf_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_non_1905_TLV_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 "bbf_tlvs.h" 66 | #include "bbf_tlv_test_vectors.h" 67 | 68 | INT8U _check(const char *test_description, INT8U mode, INT8U *input, INT8U *expected_output, INT16U expected_output_len) 69 | { 70 | INT8U result; 71 | INT8U *real_output; 72 | INT16U real_output_len; 73 | 74 | // Build the packet 75 | real_output = forge_bbf_TLV_from_structure((INT8U *)input, &real_output_len); 76 | 77 | if (NULL == real_output) 78 | { 79 | PLATFORM_PRINTF("%-100s: KO !!!\n", test_description); 80 | PLATFORM_PRINTF(" forge_non_1905_TLV_from_structure() returned a NULL pointer\n"); 81 | 82 | return 1; 83 | } 84 | 85 | // Compare packets 86 | if (mode == CHECK_TRUE) 87 | { 88 | // Compare the packets 89 | if ((expected_output_len == real_output_len) && (0 == PLATFORM_MEMCMP(expected_output, real_output, real_output_len))) 90 | { 91 | result = 0; 92 | PLATFORM_PRINTF("%-100s: OK\n", test_description); 93 | } 94 | else 95 | { 96 | INT16U i; 97 | 98 | result = 1; 99 | PLATFORM_PRINTF("%-100s: KO !!!\n", test_description); 100 | 101 | // CheckTrue error needs more debug info 102 | // 103 | PLATFORM_PRINTF(" Expected output: "); 104 | 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 | (INT8U *)(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 | (INT8U *)(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 | (INT8U *)(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 | INT8U 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 | INT16U lldp_payload_stream_len_001 = 24; 142 | 143 | 144 | -------------------------------------------------------------------------------- /src/factory/unit_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 INT8U lldp_payload_stream_001[]; 66 | extern INT16U lldp_payload_stream_len_001; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/factory/unit_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 | INT8U _check(const char *test_description, INT8U *input, INT8U *expected_output, INT16U expected_output_len) 68 | { 69 | INT8U result; 70 | INT8U *real_output; 71 | INT16U real_output_len; 72 | 73 | real_output = forge_lldp_TLV_from_structure((INT8U *)input, &real_output_len); 74 | 75 | if (NULL == real_output) 76 | { 77 | PLATFORM_PRINTF("%-100s: KO !!!\n", test_description); 78 | PLATFORM_PRINTF(" forge_lldp_TLV_from_structure() returned a NULL pointer\n"); 79 | 80 | return 1; 81 | } 82 | 83 | if ((expected_output_len == real_output_len) && (0 == PLATFORM_MEMCMP(expected_output, real_output, real_output_len))) 84 | { 85 | result = 0; 86 | PLATFORM_PRINTF("%-100s: OK\n", test_description); 87 | } 88 | else 89 | { 90 | INT16U i; 91 | 92 | result = 1; 93 | PLATFORM_PRINTF("%-100s: KO !!!\n", test_description); 94 | PLATFORM_PRINTF(" Expected output: "); 95 | for (i=0; i packet" can only be used to test the 76 | // "forge_lldp_TLV_from_structure()" function. 77 | // 78 | // - Test vectors marked with "TLV <-- packet" can only be used to test the 79 | // "parse_lldp_TLV_from_packet()" function. 80 | // 81 | // - All the other test vectors are marked with "TLC <--> 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_TLV_from_structure(tlv_xxx, &stream_len); 91 | // 92 | // B) tlv = parse_lldp_TLV_from_packet(stream_xxx); 93 | // 94 | 95 | 96 | //////////////////////////////////////////////////////////////////////////////// 97 | //// Test vector 001 (TLV <--> packet) 98 | //////////////////////////////////////////////////////////////////////////////// 99 | 100 | struct endOfLldppduTLV lldp_tlv_structure_001 = 101 | { 102 | .tlv_type = TLV_TYPE_END_OF_LLDPPDU, 103 | }; 104 | 105 | INT8U lldp_tlv_stream_001[] = 106 | { 107 | 0x00, 0x00, 108 | }; 109 | 110 | INT16U lldp_tlv_stream_len_001 = 2; 111 | 112 | 113 | //////////////////////////////////////////////////////////////////////////////// 114 | //// Test vector 002 (TLV <--> packet) 115 | //////////////////////////////////////////////////////////////////////////////// 116 | 117 | struct chassisIdTLV lldp_tlv_structure_002 = 118 | { 119 | .tlv_type = TLV_TYPE_CHASSIS_ID, 120 | .chassis_id_subtype = CHASSIS_ID_TLV_SUBTYPE_MAC_ADDRESS, 121 | .chassis_id = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, 122 | }; 123 | 124 | INT8U lldp_tlv_stream_002[] = 125 | { 126 | 0x02, 0x07, 127 | 0x04, 128 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 129 | }; 130 | 131 | INT16U lldp_tlv_stream_len_002 = 9; 132 | 133 | 134 | //////////////////////////////////////////////////////////////////////////////// 135 | //// Test vector 003 (TLV <--> packet) 136 | //////////////////////////////////////////////////////////////////////////////// 137 | 138 | struct portIdTLV lldp_tlv_structure_003 = 139 | { 140 | .tlv_type = TLV_TYPE_PORT_ID, 141 | .port_id_subtype = PORT_ID_TLV_SUBTYPE_MAC_ADDRESS, 142 | .port_id = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, 143 | }; 144 | 145 | INT8U lldp_tlv_stream_003[] = 146 | { 147 | 0x04, 0x07, 148 | 0x03, 149 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 150 | }; 151 | 152 | INT16U lldp_tlv_stream_len_003 = 9; 153 | 154 | 155 | //////////////////////////////////////////////////////////////////////////////// 156 | //// Test vector 004 (TLV <--> packet) 157 | //////////////////////////////////////////////////////////////////////////////// 158 | 159 | struct timeToLiveTypeTLV lldp_tlv_structure_004 = 160 | { 161 | .tlv_type = TLV_TYPE_TIME_TO_LIVE, 162 | .ttl = TIME_TO_LIVE_TLV_1905_DEFAULT_VALUE, 163 | }; 164 | 165 | INT8U lldp_tlv_stream_004[] = 166 | { 167 | 0x06, 0x02, 168 | 0x00, 0xb4, 169 | }; 170 | 171 | INT16U lldp_tlv_stream_len_004 = 4; 172 | -------------------------------------------------------------------------------- /src/factory/unit_tests/lldp_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 _LLDP_TLV_TEST_VECTORS_H_ 59 | #define _LLDP_TLV_TEST_VECTORS_H_ 60 | 61 | #include "1905_tlvs.h" 62 | 63 | extern struct endOfLldppduTLV lldp_tlv_structure_001; 64 | extern INT8U lldp_tlv_stream_001[]; 65 | extern INT16U lldp_tlv_stream_len_001; 66 | 67 | extern struct chassisIdTLV lldp_tlv_structure_002; 68 | extern INT8U lldp_tlv_stream_002[]; 69 | extern INT16U lldp_tlv_stream_len_002; 70 | 71 | extern struct portIdTLV lldp_tlv_structure_003; 72 | extern INT8U lldp_tlv_stream_003[]; 73 | extern INT16U lldp_tlv_stream_len_003; 74 | 75 | extern struct timeToLiveTypeTLV lldp_tlv_structure_004; 76 | extern INT8U lldp_tlv_stream_004[]; 77 | extern INT16U lldp_tlv_stream_len_004; 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /src/hle/Makefile: -------------------------------------------------------------------------------- 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 | # When calling this Makefile, the following environment variables must be set: 57 | # 58 | # CC ------------> Path to the compiler 59 | # CCFLAGS -------> Extra flags to use while compiling 60 | # LDGLAGS -------> Extra flags to use while linking 61 | # 62 | # PLATFORM -> Possible values: "linux" 63 | # OUTPUT_FOLDER -> Absolute path to the folder where binaries will be built 64 | # 65 | # COMMON_LIB ----> Absolute path to the "common library" *.a file 66 | # COMMON_INC ----> Absolute path to the folder containing common (to all 67 | # sub-projects) header files 68 | # 69 | # FACTORY_LIB -> Absolute path to the "factory library" *.a file 70 | # FACTORY_INC -> Absolute path to the folder containing the "factory 71 | # library" header files 72 | # 73 | # AL_EXE --------> Absolute path to the final AL entity binary 74 | # 75 | # MKDIR ---------> Tool to create a directory 76 | # 77 | 78 | HLE_DIRECTORY := hle 79 | 80 | EXE := $(HLE_EXE) 81 | SRC := $(wildcard src_$(PLATFORM)/*.c) 82 | OBJ := $(patsubst %.c,$(OUTPUT_FOLDER)/tmp/$(HLE_DIRECTORY)/%.o,$(SRC)) 83 | 84 | INTERNAL_INC := src_$(PLATFORM) 85 | EXTERNAL_INC := $(COMMON_INC) $(FACTORY_INC) 86 | 87 | HDR := $(shell find $(INTERNAL_INC) $(FACTORY_INC) -name *.h) 88 | 89 | 90 | ################################################################################ 91 | # Targets 92 | ################################################################################ 93 | 94 | .PHONY: all 95 | all: $(EXE) 96 | 97 | 98 | $(EXE): $(OBJ) $(COMMON_LIB) $(FACTORY_LIB) 99 | $(CC) $^ $(LDFLAGS) -o $@ 100 | 101 | 102 | $(OBJ) : $(OUTPUT_FOLDER)/tmp/$(HLE_DIRECTORY)/%.o : %.c $(HDR) 103 | $(foreach directory, $(sort $(dir $(wildcard $(SRC)))), $(MKDIR) $(OUTPUT_FOLDER)/tmp/$(HLE_DIRECTORY)/$(directory);) 104 | $(CC) $(CCFLAGS) -c $(addprefix -I,$(INTERNAL_INC) $(EXTERNAL_INC)) $< -o $@ 105 | 106 | 107 | .PHONY: clean 108 | clean: 109 | rm -rf $(EXE) 110 | rm -rf $(OUTPUT_FOLDER)/tmp/$(HLE_DIRECTORY) 111 | 112 | -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | i118 2 | --------------------------------------------------------------------------------