Issue 2 move folders and use deep path include file names to prevent collisions (#4)
* moving folders and files and adjust server demo build * Fix Makefile for apps/server on Linux * fix unit test source file folders * fix datetime convert UTC functions. Add Code::Blocks project for datetime testing * added some ignore extensions * disable parallel make option * fix build for abort, dcc, and epics apps * fix build for dcc, epics, error, and getevent apps. * Fixed building of all apps * fix the ipv4 to ipv6 router app build * Change indent style from Google to Webkit * make pretty to re-format style * removed common Makefile since we already had one and two was too many * remove scripts from root folder that are no longer maintained or used * remove mercurial EOL and ignore files for git repo * remove .vscodeconfig files from repo * tweak clang-format style * clang-format src and apps with tweaked style * added clang-tidy to fix readability if braces in src * result of make tidy for src and apps * fix clang-tidy mangling * Added code::blocks project for BACnet server simulation * added code::blocks linux project for WhoIs app * update text files for EOL * fix EOL in some files * fixed make win32 apps for older gcc * Removed Borland C++ Makefile in apps. Unable to maintain support for Borland C++ compiler. * created codeblocks project for apps/epics for Windows * fixing ports/xplained to work with new data structure. * fix ports/xplained example for Atmel Studio compile * fix ports/stm32f10x example for gcc Makefile compile * fix ports/stm32f10x example for IAR EWARM compile * fix ports/xplained timer callback * fix ports/bdk_atxx_mspt build with subdirs * fix ports/bdk_atxx_mspt build with subdirs * updated git ignore for IAR build artifacts * updated gitignore for non-tracked files and folders * fixed bdk-atxx4-mstp port for Rowley Crossworks project file * fixed bdk-atxx4-mstp port for GCC AVR Makefile * fixed atmega168 port for IAR AVR and GCC AVR Makefile * fixed at91sam7s port for IAR ARM and GCC ARM Makefile * removed unmaintainable DOS, RTOS32, and atmega8 ports. Updated rx62n (untested). * changed arm7 to uip port
This commit is contained in:
@@ -33,10 +33,10 @@
|
||||
####COPYRIGHTEND####*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "bacdef.h"
|
||||
#include "npdu.h"
|
||||
#include "arcnet.h"
|
||||
#include "net.h"
|
||||
#include "bacnet/bacdef.h"
|
||||
#include "bacnet/npdu.h"
|
||||
#include "bacnet/datalink/arcnet.h"
|
||||
#include "bacport.h"
|
||||
|
||||
/** @file linux/arcnet.c Provides Linux-specific functions for Arcnet. */
|
||||
|
||||
|
||||
+281
-281
@@ -1,281 +1,281 @@
|
||||
-- bacnet_BIPV6.lua
|
||||
--
|
||||
-- Dissector for BACnet/IPv6 [135-2016 Annex X]
|
||||
--
|
||||
-- Copyright 2011, Siemens Building Technolgies
|
||||
-- Maintainer Philippe Goetz <philippe.goetz@siemens.com>
|
||||
-- Updated by Steve Karg <skarg@users.sourceforge.net>
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or
|
||||
-- modify it under the terms of the GNU General Public License
|
||||
-- as published by the Free Software Foundation; either version 2
|
||||
-- of the License, or (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
-- Add the following to the end of init.lua in the Wireshark install directory:
|
||||
-- dofile("bacnet_ipv6.lua")
|
||||
|
||||
|
||||
-- [in] tree,pf,buffer,offset,len
|
||||
-- [out] offset, value, ti, bf
|
||||
function uint_dissector(tree,pf,buffer,offset,len)
|
||||
if (offset + len) <= buffer:len() then
|
||||
local bf = buffer(offset,len)
|
||||
local ti = nil
|
||||
if tree ~= nil then
|
||||
ti = tree:add(pf,bf)
|
||||
end
|
||||
return offset + len, bf:uint(), ti, bf
|
||||
end
|
||||
local ti = tree:add(pf,buffer(offset))
|
||||
ti:add_expert_info(PI_MALFORMED, PI_ERROR, "Data shortage")
|
||||
error("Data shortage")
|
||||
end
|
||||
|
||||
function bytes_dissector(tree,pf,buffer,offset,len)
|
||||
if (offset + len) <= buffer:len() then
|
||||
local bf = buffer(offset,len)
|
||||
local ti = nil
|
||||
if tree ~= nil then
|
||||
ti = tree:add(pf,bf)
|
||||
end
|
||||
return offset + len, bf:bytes(), ti, bf
|
||||
end
|
||||
local ti = tree:add(pf,buffer(offset))
|
||||
ti:add_expert_info(PI_MALFORMED, PI_ERROR, "Data shortage")
|
||||
error("Data shortage")
|
||||
end
|
||||
|
||||
p_BACnetBIPV6 = Proto("lua_BACnetBIPV6", "B/IPv6 BACnet Virtual Link Control");
|
||||
p_BACnet_Port = Proto("BACnet-Port", "BACnet UDP Port Handoff")
|
||||
p_dissector_bacnet = Dissector.get("bacnet")
|
||||
p_dissector_bipv4 = Dissector.get("bvlc")
|
||||
|
||||
do
|
||||
p_BACnetBIPV6.init = function()
|
||||
debug("p_BACnetBIPV6.init")
|
||||
end
|
||||
|
||||
local t_BACnetBIPV6_Types = {
|
||||
[0x82]="B/IPv6 (Annex X)"
|
||||
}
|
||||
local t_BACnetBIPV6_Functions = {
|
||||
-- Annex X, PPR3 Draft 22
|
||||
[0x00]="BVLC-Result",
|
||||
[0x01]="Original-Unicast-NPDU",
|
||||
[0x02]="Original-Broadcast-NPDU",
|
||||
[0x03]="Address-Resolution",
|
||||
[0x04]="Forwarded-Address-Resolution",
|
||||
[0x05]="Address-Resolution-Ack",
|
||||
[0x06]="Virtual-Address-Resolution",
|
||||
[0x07]="Virtual-Address-Resolution-Ack",
|
||||
[0x08]="Forwarded-NPDU",
|
||||
[0x09]="Register-Foreign-Device",
|
||||
[0x0A]="Delete-Foreign-Device",
|
||||
[0x0B]="Secure-BVLL",
|
||||
[0x0C]="Distribute-Broadcast-To-Network"
|
||||
}
|
||||
|
||||
local pf_BIPV6Data = ProtoField.bytes ("BIPV6.data", "B/IPV6 Data")
|
||||
|
||||
p_BACnetBIPV6.fields = {
|
||||
pf_BIPV6Data
|
||||
}
|
||||
|
||||
local t_BACnetBIPV6_dissectors = {}
|
||||
|
||||
-- local dt_BIPV6_npdu = DissectorTable.new("lua_BACnetBIPV6.npdu","BIPV6 NPDU",ftypes.UINT8,base.HEX)
|
||||
-- BIPV6 header fields
|
||||
local pf_BIPV6 = {}
|
||||
pf_BIPV6.Type = ProtoField.uint8 ("BIPV6.type","Type",base.HEX,t_BACnetBIPV6_Types)
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.Type)
|
||||
pf_BIPV6.Function = ProtoField.uint8 ("BIPV6.function","Function",base.HEX,t_BACnetBIPV6_Functions,0,"BIPV6 Function")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.Function)
|
||||
pf_BIPV6.Length = ProtoField.uint16("BIPV6.length","BIPV6-Length",base.DEC,nil,0,"Length of BIPV6")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.Length)
|
||||
pf_BIPV6.ResultCode = ProtoField.uint16("BIPV6.resultCode","Result-Code",base.DEC,nil,0,"Result Code")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.ResultCode)
|
||||
pf_BIPV6.SourceVirtualAddress = ProtoField.uint24 ("BIPV6.sourceVirtualAddress","Source-Virtual-Address")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.SourceVirtualAddress)
|
||||
pf_BIPV6.DestinationVirtualAddress = ProtoField.uint24 ("BIPV6.destinationVirtualAddress","Destination-Virtual-Address")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.DestinationVirtualAddress)
|
||||
pf_BIPV6.OriginalSourceEffectiveAddress = ProtoField.bytes ("BIPV6.originalSourceEffectiveAddress","Original-Source-B/IPv6-Address")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.OriginalSourceEffectiveAddress)
|
||||
pf_BIPV6.OriginalSourceEffectiveAddress_ip = ProtoField.ipv6 ("BIPV6.originalSourceEffectiveAddress.ip","Original-Source-B/IPv6-Address (ip)")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.OriginalSourceEffectiveAddress_ip)
|
||||
pf_BIPV6.OriginalSourceEffectiveAddress_port = ProtoField.uint16 ("BIPV6.originalSourceEffectiveAddress.port","Original-Source-B/IPv6-Address (port)")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.OriginalSourceEffectiveAddress_port)
|
||||
pf_BIPV6.OriginalSourceVirtualAddress = ProtoField.uint24 ("BIPV6.originalSourceVirtualAddress","Original-Source-Virtual-Address")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.OriginalSourceVirtualAddress)
|
||||
pf_BIPV6.DestinationEffectiveAddress = ProtoField.bytes ("BIPV6.destinationEffectiveAddress","Original-Source-B/IPv6-Address")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.DestinationEffectiveAddress)
|
||||
pf_BIPV6.DestinationEffectiveAddress_ip = ProtoField.ipv6 ("BIPV6.destinationEffectiveAddress.ip","Original-Source-B/IPv6-Address (ip)")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.DestinationEffectiveAddress_ip)
|
||||
pf_BIPV6.DestinationEffectiveAddress_port = ProtoField.uint16 ("BIPV6.destinationEffectiveAddress.port","Original-Source-B/IPv6-Address (port)")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.DestinationEffectiveAddress_port)
|
||||
pf_BIPV6.TimeToLive = ProtoField.uint16 ("BIPV6.timeToLive","Time-To-Live")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.TimeToLive)
|
||||
|
||||
function p_BACnetBIPV6.dissector(buffer,pkt,tree)
|
||||
|
||||
pkt.cols["protocol"] = "B/IPv6"
|
||||
pkt.cols["info"] = "BACnet Building Automation and Control Network"
|
||||
local offset = 0
|
||||
local v_BIPV6 = {}
|
||||
local ti_BIPV6 = {}
|
||||
ti_BIPV6.ti = tree:add(p_BACnetBIPV6,buffer(0))
|
||||
offset, v_BIPV6.Type, ti_BIPV6.Type = uint_dissector(ti_BIPV6.ti, pf_BIPV6.Type, buffer, offset, 1)
|
||||
--if v_BIPV6.Type == 0x81 then
|
||||
-- p_dissector_bipv4:call(buffer, pkt, tree)
|
||||
-- elseif v_BIPV6 ~= 0x82 then
|
||||
-- ti_BIPV6.Type:add_expert_info(PI_MALFORMED, PI_WARN, "Unknown BVLC Type")
|
||||
-- return
|
||||
--end
|
||||
if v_BIPV6.Type ~= 0x82 then
|
||||
ti_BIPV6.Type:add_expert_info(PI_MALFORMED, PI_WARN, "Unknown BVLC Type")
|
||||
return
|
||||
end
|
||||
offset, v_BIPV6.Function, ti_BIPV6.Function = uint_dissector(ti_BIPV6.ti, pf_BIPV6.Function, buffer, offset, 1)
|
||||
offset, v_BIPV6.Length, ti_BIPV6.Length = uint_dissector(ti_BIPV6.ti, pf_BIPV6.Length, buffer, offset, 2)
|
||||
local BIPV6Dissector = t_BACnetBIPV6_dissectors[v_BIPV6.Function]
|
||||
local npduData = nil
|
||||
if BIPV6Dissector ~= nil then
|
||||
pkt.cols["info"] = t_BACnetBIPV6_Functions[v_BIPV6.Function]
|
||||
offset, npduData = BIPV6Dissector(buffer,pkt,ti_BIPV6.ti,offset,v_BIPV6,tree)
|
||||
end
|
||||
if npduData ~= nil then
|
||||
if p_BACnetNPDU ~= nil then
|
||||
ti_BIPV6.ti:set_len(offset)
|
||||
p_BACnetNPDU.dissector:call(npduData:tvb(), pkt, tree)
|
||||
offset = offset + npduData:len()
|
||||
else
|
||||
p_dissector_bacnet:call(npduData:tvb(), pkt, tree)
|
||||
end
|
||||
end
|
||||
-- CLB don't show the raw data
|
||||
-- if offset ~= buffer:len() then
|
||||
-- ti_BIPV6.ti:add(pf_BIPV6Data,buffer(offset))
|
||||
-- end
|
||||
ti_BIPV6 = nil
|
||||
collectgarbage("collect")
|
||||
end
|
||||
|
||||
-- [0x00] BVLC-Result
|
||||
t_BACnetBIPV6_dissectors[0x00] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.ResultCode,buffer,offset,2)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x01] Original-Unicast-NPDU
|
||||
t_BACnetBIPV6_dissectors[0x01] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.DestinationVirtualAddress,buffer,offset,3)
|
||||
return offset, buffer(offset)
|
||||
end
|
||||
|
||||
-- [0x02] Original-Broadcast-NPDU
|
||||
t_BACnetBIPV6_dissectors[0x02] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
return offset, buffer(offset)
|
||||
end
|
||||
|
||||
-- [0x03] Address-Resolution
|
||||
t_BACnetBIPV6_dissectors[0x03] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.DestinationVirtualAddress,buffer,offset,3)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x04] Forwarded-Address-Resolution
|
||||
t_BACnetBIPV6_dissectors[0x04] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.OriginalSourceVirtualAddress,buffer,offset,3)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.DestinationVirtualAddress,buffer,offset,3)
|
||||
local subtree = tree:add(pf_BIPV6.OriginalSourceEffectiveAddress,buffer(offset,18))
|
||||
offset = bytes_dissector(subtree,pf_BIPV6.OriginalSourceEffectiveAddress_ip,buffer,offset,16)
|
||||
offset = uint_dissector(subtree,pf_BIPV6.OriginalSourceEffectiveAddress_port,buffer,offset,2)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x05] Address-Resolution-Ack
|
||||
t_BACnetBIPV6_dissectors[0x05] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.DestinationVirtualAddress,buffer,offset,3)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x06] Virtual-Address-Resolution
|
||||
t_BACnetBIPV6_dissectors[0x06] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x07] Virtual-Address-Resolution-Ack
|
||||
t_BACnetBIPV6_dissectors[0x07] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x08] Forwarded-NPDU
|
||||
t_BACnetBIPV6_dissectors[0x08] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.OriginalSourceVirtualAddress,buffer,offset,3)
|
||||
local subtree = tree:add(pf_BIPV6.OriginalSourceEffectiveAddress,buffer(offset,18))
|
||||
offset = bytes_dissector(subtree,pf_BIPV6.OriginalSourceEffectiveAddress_ip,buffer,offset,16)
|
||||
offset = uint_dissector(subtree,pf_BIPV6.OriginalSourceEffectiveAddress_port,buffer,offset,2)
|
||||
return offset, buffer(offset)
|
||||
end
|
||||
|
||||
-- [0x09] Register-Foreign-Device
|
||||
t_BACnetBIPV6_dissectors[0x09] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
offset = uint_dissector(tree,pf_BIPV6.TimeToLive,buffer,offset,2)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x0A] Delete-Foreign-Device
|
||||
t_BACnetBIPV6_dissectors[0x0A] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
-- FDT Entry decoding
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x0B] Secure-BVLL
|
||||
t_BACnetBIPV6_dissectors[0x0B] = function(buffer,pkt,tree,offset,npdu)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x0C] Distribute-Broadcast-To-Network
|
||||
t_BACnetBIPV6_dissectors[0x0C] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.OriginalSourceVirtualAddress,buffer,offset,3)
|
||||
local subtree = tree:add(pf_BIPV6.OriginalSourceEffectiveAddress,buffer(offset,18))
|
||||
offset = bytes_dissector(subtree,pf_BIPV6.OriginalSourceEffectiveAddress_ip,buffer,offset,16)
|
||||
offset = uint_dissector(subtree,pf_BIPV6.OriginalSourceEffectiveAddress_port,buffer,offset,2)
|
||||
return offset, buffer(offset)
|
||||
end
|
||||
|
||||
function p_BACnet_Port.dissector(tvb, pinfo, tree)
|
||||
local BIP_Type = tvb(0,1):uint()
|
||||
if BIP_Type == 0x81 then
|
||||
p_dissector_bipv4:call(tvb, pinfo, tree)
|
||||
elseif BIP_Type == 0x82 then
|
||||
p_BACnetBIPV6.dissector(tvb, pinfo, tree)
|
||||
end
|
||||
end
|
||||
|
||||
-- load the udp.port table
|
||||
local dt_udp_port = DissectorTable.get("udp.port")
|
||||
-- p_dissector_bvlc = dt_udp_port:get_dissector(47808)
|
||||
-- dt_udp_port:remove(47808, p_dissector_bvlc)
|
||||
-- dt_udp_port:add(47808, p_BACnetBIPV6)
|
||||
dt_udp_port:add(47808, p_BACnet_Port)
|
||||
|
||||
end
|
||||
-- bacnet_BIPV6.lua
|
||||
--
|
||||
-- Dissector for BACnet/IPv6 [135-2016 Annex X]
|
||||
--
|
||||
-- Copyright 2011, Siemens Building Technolgies
|
||||
-- Maintainer Philippe Goetz <philippe.goetz@siemens.com>
|
||||
-- Updated by Steve Karg <skarg@users.sourceforge.net>
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or
|
||||
-- modify it under the terms of the GNU General Public License
|
||||
-- as published by the Free Software Foundation; either version 2
|
||||
-- of the License, or (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
-- Add the following to the end of init.lua in the Wireshark install directory:
|
||||
-- dofile("bacnet_ipv6.lua")
|
||||
|
||||
|
||||
-- [in] tree,pf,buffer,offset,len
|
||||
-- [out] offset, value, ti, bf
|
||||
function uint_dissector(tree,pf,buffer,offset,len)
|
||||
if (offset + len) <= buffer:len() then
|
||||
local bf = buffer(offset,len)
|
||||
local ti = nil
|
||||
if tree ~= nil then
|
||||
ti = tree:add(pf,bf)
|
||||
end
|
||||
return offset + len, bf:uint(), ti, bf
|
||||
end
|
||||
local ti = tree:add(pf,buffer(offset))
|
||||
ti:add_expert_info(PI_MALFORMED, PI_ERROR, "Data shortage")
|
||||
error("Data shortage")
|
||||
end
|
||||
|
||||
function bytes_dissector(tree,pf,buffer,offset,len)
|
||||
if (offset + len) <= buffer:len() then
|
||||
local bf = buffer(offset,len)
|
||||
local ti = nil
|
||||
if tree ~= nil then
|
||||
ti = tree:add(pf,bf)
|
||||
end
|
||||
return offset + len, bf:bytes(), ti, bf
|
||||
end
|
||||
local ti = tree:add(pf,buffer(offset))
|
||||
ti:add_expert_info(PI_MALFORMED, PI_ERROR, "Data shortage")
|
||||
error("Data shortage")
|
||||
end
|
||||
|
||||
p_BACnetBIPV6 = Proto("lua_BACnetBIPV6", "B/IPv6 BACnet Virtual Link Control");
|
||||
p_BACnet_Port = Proto("BACnet-Port", "BACnet UDP Port Handoff")
|
||||
p_dissector_bacnet = Dissector.get("bacnet")
|
||||
p_dissector_bipv4 = Dissector.get("bvlc")
|
||||
|
||||
do
|
||||
p_BACnetBIPV6.init = function()
|
||||
debug("p_BACnetBIPV6.init")
|
||||
end
|
||||
|
||||
local t_BACnetBIPV6_Types = {
|
||||
[0x82]="B/IPv6 (Annex X)"
|
||||
}
|
||||
local t_BACnetBIPV6_Functions = {
|
||||
-- Annex X, PPR3 Draft 22
|
||||
[0x00]="BVLC-Result",
|
||||
[0x01]="Original-Unicast-NPDU",
|
||||
[0x02]="Original-Broadcast-NPDU",
|
||||
[0x03]="Address-Resolution",
|
||||
[0x04]="Forwarded-Address-Resolution",
|
||||
[0x05]="Address-Resolution-Ack",
|
||||
[0x06]="Virtual-Address-Resolution",
|
||||
[0x07]="Virtual-Address-Resolution-Ack",
|
||||
[0x08]="Forwarded-NPDU",
|
||||
[0x09]="Register-Foreign-Device",
|
||||
[0x0A]="Delete-Foreign-Device",
|
||||
[0x0B]="Secure-BVLL",
|
||||
[0x0C]="Distribute-Broadcast-To-Network"
|
||||
}
|
||||
|
||||
local pf_BIPV6Data = ProtoField.bytes ("BIPV6.data", "B/IPV6 Data")
|
||||
|
||||
p_BACnetBIPV6.fields = {
|
||||
pf_BIPV6Data
|
||||
}
|
||||
|
||||
local t_BACnetBIPV6_dissectors = {}
|
||||
|
||||
-- local dt_BIPV6_npdu = DissectorTable.new("lua_BACnetBIPV6.npdu","BIPV6 NPDU",ftypes.UINT8,base.HEX)
|
||||
-- BIPV6 header fields
|
||||
local pf_BIPV6 = {}
|
||||
pf_BIPV6.Type = ProtoField.uint8 ("BIPV6.type","Type",base.HEX,t_BACnetBIPV6_Types)
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.Type)
|
||||
pf_BIPV6.Function = ProtoField.uint8 ("BIPV6.function","Function",base.HEX,t_BACnetBIPV6_Functions,0,"BIPV6 Function")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.Function)
|
||||
pf_BIPV6.Length = ProtoField.uint16("BIPV6.length","BIPV6-Length",base.DEC,nil,0,"Length of BIPV6")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.Length)
|
||||
pf_BIPV6.ResultCode = ProtoField.uint16("BIPV6.resultCode","Result-Code",base.DEC,nil,0,"Result Code")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.ResultCode)
|
||||
pf_BIPV6.SourceVirtualAddress = ProtoField.uint24 ("BIPV6.sourceVirtualAddress","Source-Virtual-Address")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.SourceVirtualAddress)
|
||||
pf_BIPV6.DestinationVirtualAddress = ProtoField.uint24 ("BIPV6.destinationVirtualAddress","Destination-Virtual-Address")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.DestinationVirtualAddress)
|
||||
pf_BIPV6.OriginalSourceEffectiveAddress = ProtoField.bytes ("BIPV6.originalSourceEffectiveAddress","Original-Source-B/IPv6-Address")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.OriginalSourceEffectiveAddress)
|
||||
pf_BIPV6.OriginalSourceEffectiveAddress_ip = ProtoField.ipv6 ("BIPV6.originalSourceEffectiveAddress.ip","Original-Source-B/IPv6-Address (ip)")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.OriginalSourceEffectiveAddress_ip)
|
||||
pf_BIPV6.OriginalSourceEffectiveAddress_port = ProtoField.uint16 ("BIPV6.originalSourceEffectiveAddress.port","Original-Source-B/IPv6-Address (port)")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.OriginalSourceEffectiveAddress_port)
|
||||
pf_BIPV6.OriginalSourceVirtualAddress = ProtoField.uint24 ("BIPV6.originalSourceVirtualAddress","Original-Source-Virtual-Address")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.OriginalSourceVirtualAddress)
|
||||
pf_BIPV6.DestinationEffectiveAddress = ProtoField.bytes ("BIPV6.destinationEffectiveAddress","Original-Source-B/IPv6-Address")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.DestinationEffectiveAddress)
|
||||
pf_BIPV6.DestinationEffectiveAddress_ip = ProtoField.ipv6 ("BIPV6.destinationEffectiveAddress.ip","Original-Source-B/IPv6-Address (ip)")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.DestinationEffectiveAddress_ip)
|
||||
pf_BIPV6.DestinationEffectiveAddress_port = ProtoField.uint16 ("BIPV6.destinationEffectiveAddress.port","Original-Source-B/IPv6-Address (port)")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.DestinationEffectiveAddress_port)
|
||||
pf_BIPV6.TimeToLive = ProtoField.uint16 ("BIPV6.timeToLive","Time-To-Live")
|
||||
table.insert(p_BACnetBIPV6.fields,pf_BIPV6.TimeToLive)
|
||||
|
||||
function p_BACnetBIPV6.dissector(buffer,pkt,tree)
|
||||
|
||||
pkt.cols["protocol"] = "B/IPv6"
|
||||
pkt.cols["info"] = "BACnet Building Automation and Control Network"
|
||||
local offset = 0
|
||||
local v_BIPV6 = {}
|
||||
local ti_BIPV6 = {}
|
||||
ti_BIPV6.ti = tree:add(p_BACnetBIPV6,buffer(0))
|
||||
offset, v_BIPV6.Type, ti_BIPV6.Type = uint_dissector(ti_BIPV6.ti, pf_BIPV6.Type, buffer, offset, 1)
|
||||
--if v_BIPV6.Type == 0x81 then
|
||||
-- p_dissector_bipv4:call(buffer, pkt, tree)
|
||||
-- elseif v_BIPV6 ~= 0x82 then
|
||||
-- ti_BIPV6.Type:add_expert_info(PI_MALFORMED, PI_WARN, "Unknown BVLC Type")
|
||||
-- return
|
||||
--end
|
||||
if v_BIPV6.Type ~= 0x82 then
|
||||
ti_BIPV6.Type:add_expert_info(PI_MALFORMED, PI_WARN, "Unknown BVLC Type")
|
||||
return
|
||||
end
|
||||
offset, v_BIPV6.Function, ti_BIPV6.Function = uint_dissector(ti_BIPV6.ti, pf_BIPV6.Function, buffer, offset, 1)
|
||||
offset, v_BIPV6.Length, ti_BIPV6.Length = uint_dissector(ti_BIPV6.ti, pf_BIPV6.Length, buffer, offset, 2)
|
||||
local BIPV6Dissector = t_BACnetBIPV6_dissectors[v_BIPV6.Function]
|
||||
local npduData = nil
|
||||
if BIPV6Dissector ~= nil then
|
||||
pkt.cols["info"] = t_BACnetBIPV6_Functions[v_BIPV6.Function]
|
||||
offset, npduData = BIPV6Dissector(buffer,pkt,ti_BIPV6.ti,offset,v_BIPV6,tree)
|
||||
end
|
||||
if npduData ~= nil then
|
||||
if p_BACnetNPDU ~= nil then
|
||||
ti_BIPV6.ti:set_len(offset)
|
||||
p_BACnetNPDU.dissector:call(npduData:tvb(), pkt, tree)
|
||||
offset = offset + npduData:len()
|
||||
else
|
||||
p_dissector_bacnet:call(npduData:tvb(), pkt, tree)
|
||||
end
|
||||
end
|
||||
-- CLB don't show the raw data
|
||||
-- if offset ~= buffer:len() then
|
||||
-- ti_BIPV6.ti:add(pf_BIPV6Data,buffer(offset))
|
||||
-- end
|
||||
ti_BIPV6 = nil
|
||||
collectgarbage("collect")
|
||||
end
|
||||
|
||||
-- [0x00] BVLC-Result
|
||||
t_BACnetBIPV6_dissectors[0x00] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.ResultCode,buffer,offset,2)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x01] Original-Unicast-NPDU
|
||||
t_BACnetBIPV6_dissectors[0x01] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.DestinationVirtualAddress,buffer,offset,3)
|
||||
return offset, buffer(offset)
|
||||
end
|
||||
|
||||
-- [0x02] Original-Broadcast-NPDU
|
||||
t_BACnetBIPV6_dissectors[0x02] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
return offset, buffer(offset)
|
||||
end
|
||||
|
||||
-- [0x03] Address-Resolution
|
||||
t_BACnetBIPV6_dissectors[0x03] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.DestinationVirtualAddress,buffer,offset,3)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x04] Forwarded-Address-Resolution
|
||||
t_BACnetBIPV6_dissectors[0x04] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.OriginalSourceVirtualAddress,buffer,offset,3)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.DestinationVirtualAddress,buffer,offset,3)
|
||||
local subtree = tree:add(pf_BIPV6.OriginalSourceEffectiveAddress,buffer(offset,18))
|
||||
offset = bytes_dissector(subtree,pf_BIPV6.OriginalSourceEffectiveAddress_ip,buffer,offset,16)
|
||||
offset = uint_dissector(subtree,pf_BIPV6.OriginalSourceEffectiveAddress_port,buffer,offset,2)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x05] Address-Resolution-Ack
|
||||
t_BACnetBIPV6_dissectors[0x05] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.DestinationVirtualAddress,buffer,offset,3)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x06] Virtual-Address-Resolution
|
||||
t_BACnetBIPV6_dissectors[0x06] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x07] Virtual-Address-Resolution-Ack
|
||||
t_BACnetBIPV6_dissectors[0x07] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x08] Forwarded-NPDU
|
||||
t_BACnetBIPV6_dissectors[0x08] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.OriginalSourceVirtualAddress,buffer,offset,3)
|
||||
local subtree = tree:add(pf_BIPV6.OriginalSourceEffectiveAddress,buffer(offset,18))
|
||||
offset = bytes_dissector(subtree,pf_BIPV6.OriginalSourceEffectiveAddress_ip,buffer,offset,16)
|
||||
offset = uint_dissector(subtree,pf_BIPV6.OriginalSourceEffectiveAddress_port,buffer,offset,2)
|
||||
return offset, buffer(offset)
|
||||
end
|
||||
|
||||
-- [0x09] Register-Foreign-Device
|
||||
t_BACnetBIPV6_dissectors[0x09] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
offset = uint_dissector(tree,pf_BIPV6.TimeToLive,buffer,offset,2)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x0A] Delete-Foreign-Device
|
||||
t_BACnetBIPV6_dissectors[0x0A] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.SourceVirtualAddress,buffer,offset,3)
|
||||
-- FDT Entry decoding
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x0B] Secure-BVLL
|
||||
t_BACnetBIPV6_dissectors[0x0B] = function(buffer,pkt,tree,offset,npdu)
|
||||
return offset
|
||||
end
|
||||
|
||||
-- [0x0C] Distribute-Broadcast-To-Network
|
||||
t_BACnetBIPV6_dissectors[0x0C] = function(buffer,pkt,tree,offset,npdu)
|
||||
offset = bytes_dissector(tree,pf_BIPV6.OriginalSourceVirtualAddress,buffer,offset,3)
|
||||
local subtree = tree:add(pf_BIPV6.OriginalSourceEffectiveAddress,buffer(offset,18))
|
||||
offset = bytes_dissector(subtree,pf_BIPV6.OriginalSourceEffectiveAddress_ip,buffer,offset,16)
|
||||
offset = uint_dissector(subtree,pf_BIPV6.OriginalSourceEffectiveAddress_port,buffer,offset,2)
|
||||
return offset, buffer(offset)
|
||||
end
|
||||
|
||||
function p_BACnet_Port.dissector(tvb, pinfo, tree)
|
||||
local BIP_Type = tvb(0,1):uint()
|
||||
if BIP_Type == 0x81 then
|
||||
p_dissector_bipv4:call(tvb, pinfo, tree)
|
||||
elseif BIP_Type == 0x82 then
|
||||
p_BACnetBIPV6.dissector(tvb, pinfo, tree)
|
||||
end
|
||||
end
|
||||
|
||||
-- load the udp.port table
|
||||
local dt_udp_port = DissectorTable.get("udp.port")
|
||||
-- p_dissector_bvlc = dt_udp_port:get_dissector(47808)
|
||||
-- dt_udp_port:remove(47808, p_dissector_bvlc)
|
||||
-- dt_udp_port:add(47808, p_BACnetBIPV6)
|
||||
dt_udp_port:add(47808, p_BACnet_Port)
|
||||
|
||||
end
|
||||
|
||||
@@ -34,9 +34,9 @@
|
||||
|
||||
#include <stdint.h> /* for standard integer types uint8_t etc. */
|
||||
#include <stdbool.h> /* for the standard bool type. */
|
||||
#include "bacdcode.h"
|
||||
#include "bip.h"
|
||||
#include "net.h"
|
||||
#include "bacnet/bacdcode.h"
|
||||
#include "bacnet/datalink/bip.h"
|
||||
#include "bacport.h"
|
||||
|
||||
/** @file linux/bip-init.c Initializes BACnet/IP interface (Linux). */
|
||||
|
||||
|
||||
+8
-7
@@ -32,17 +32,18 @@
|
||||
-------------------------------------------
|
||||
####COPYRIGHTEND####*/
|
||||
|
||||
#include <ifaddrs.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h> /* for standard integer types uint8_t etc. */
|
||||
#include <stdbool.h> /* for the standard bool type. */
|
||||
#include "bacdcode.h"
|
||||
#include "config.h"
|
||||
#include "bip6.h"
|
||||
#include "debug.h"
|
||||
#include "device.h"
|
||||
#include "net.h"
|
||||
#include <ifaddrs.h>
|
||||
#include "bacnet/bacdcode.h"
|
||||
#include "bacnet/config.h"
|
||||
#include "bacnet/datalink/bip6.h"
|
||||
#include "bacnet/basic/sys/debug.h"
|
||||
#include "bacnet/basic/object/device.h"
|
||||
#include "bacnet/basic/bbmd6/h_bbmd6.h"
|
||||
#include "bacport.h"
|
||||
|
||||
static void debug_print_ipv6(const char *str, const struct in6_addr * addr) {
|
||||
debug_printf( "BIP6: %s %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* @file
|
||||
* @author Steve Karg
|
||||
* @date 2009
|
||||
* @brief System time library header file.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* This library provides functions for getting and setting the system time.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include "bacport.h"
|
||||
#include "bacnet/datetime.h"
|
||||
|
||||
/**
|
||||
* @brief Get the date, time, timezone, and UTC offset from system
|
||||
* @param utc_time - the BACnet Date and Time structure to hold UTC time
|
||||
* @param local_time - the BACnet Date and Time structure to hold local time
|
||||
* @param utc_offset_minutes - number of minutes offset from UTC
|
||||
* For example, -6*60 represents 6.00 hours behind UTC/GMT
|
||||
* @param true if DST is enabled and active
|
||||
* @return true if local time was retrieved
|
||||
*/
|
||||
bool datetime_local(
|
||||
BACNET_DATE * bdate,
|
||||
BACNET_TIME * btime,
|
||||
int16_t * utc_offset_minutes,
|
||||
bool * dst_active)
|
||||
{
|
||||
bool status = false;
|
||||
struct tm *tblock = NULL;
|
||||
struct timeval tv;
|
||||
|
||||
if (gettimeofday(&tv, NULL) == 0) {
|
||||
tblock = (struct tm *)localtime((const time_t *)&tv.tv_sec);
|
||||
}
|
||||
if (tblock) {
|
||||
status = true;
|
||||
/** struct tm
|
||||
* int tm_sec Seconds [0,60].
|
||||
* int tm_min Minutes [0,59].
|
||||
* int tm_hour Hour [0,23].
|
||||
* int tm_mday Day of month [1,31].
|
||||
* int tm_mon Month of year [0,11].
|
||||
* int tm_year Years since 1900.
|
||||
* int tm_wday Day of week [0,6] (Sunday =0).
|
||||
* int tm_yday Day of year [0,365].
|
||||
* int tm_isdst Daylight Savings flag.
|
||||
*/
|
||||
datetime_set_date(bdate, (uint16_t)tblock->tm_year + 1900,
|
||||
(uint8_t)tblock->tm_mon + 1,
|
||||
(uint8_t)tblock->tm_mday);
|
||||
datetime_set_time(btime, (uint8_t)tblock->tm_hour,
|
||||
(uint8_t)tblock->tm_min, (uint8_t)tblock->tm_sec,
|
||||
(uint8_t)(tv.tv_usec / 10000));
|
||||
if (dst_active) {
|
||||
/* The value of tm_isdst is:
|
||||
- positive if Daylight Saving Time is in effect,
|
||||
- 0 if Daylight Saving Time is not in effect, and
|
||||
- negative if the information is not available. */
|
||||
if (tblock->tm_isdst > 0) {
|
||||
*dst_active = true;
|
||||
} else {
|
||||
*dst_active = false;
|
||||
}
|
||||
}
|
||||
/* note: timezone is declared in <time.h> stdlib. */
|
||||
if (utc_offset_minutes) {
|
||||
/* timezone is set to the difference, in seconds,
|
||||
between Coordinated Universal Time (UTC) and
|
||||
local standard time */
|
||||
*utc_offset_minutes = timezone / 60;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize the date time
|
||||
*/
|
||||
void datetime_init(void)
|
||||
{
|
||||
/* nothing to do */
|
||||
}
|
||||
@@ -30,17 +30,17 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include "bacdef.h"
|
||||
#include "bacaddr.h"
|
||||
#include "mstp.h"
|
||||
#include "dlmstp.h"
|
||||
#include "bacnet/bacdef.h"
|
||||
#include "bacnet/bacaddr.h"
|
||||
#include "bacnet/datalink/mstp.h"
|
||||
#include "bacnet/datalink/dlmstp.h"
|
||||
#include "rs485.h"
|
||||
#include "npdu.h"
|
||||
#include "bits.h"
|
||||
#include "ringbuf.h"
|
||||
#include "debug.h"
|
||||
#include "bacnet/npdu.h"
|
||||
#include "bacnet/bits.h"
|
||||
#include "bacnet/basic/sys/ringbuf.h"
|
||||
#include "bacnet/basic/sys/debug.h"
|
||||
/* OS Specific include */
|
||||
#include "net.h"
|
||||
#include "bacport.h"
|
||||
|
||||
/** @file linux/dlmstp.c Provides Linux-specific DataLink functions for MS/TP. */
|
||||
|
||||
|
||||
@@ -29,17 +29,17 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "bacdef.h"
|
||||
#include "bacaddr.h"
|
||||
#include "mstp.h"
|
||||
/*#include "dlmstp.h" */
|
||||
#include "bacnet/bacdef.h"
|
||||
#include "bacnet/bacaddr.h"
|
||||
#include "bacnet/datalink/mstp.h"
|
||||
/*#include "bacnet/datalink/dlmstp.h" */
|
||||
#include "dlmstp_linux.h"
|
||||
#include "rs485.h"
|
||||
#include "npdu.h"
|
||||
#include "bits.h"
|
||||
#include "bacnet/npdu.h"
|
||||
#include "bacnet/bits.h"
|
||||
/* OS Specific include */
|
||||
#include "net.h"
|
||||
#include "ringbuf.h"
|
||||
#include "bacport.h"
|
||||
#include "bacnet/basic/sys/ringbuf.h"
|
||||
|
||||
/** @file linux/dlmstp.c Provides Linux-specific DataLink functions for MS/TP. */
|
||||
|
||||
|
||||
@@ -24,19 +24,19 @@
|
||||
#ifndef DLMSTP_LINUX_H
|
||||
#define DLMSTP_LINUX_H
|
||||
|
||||
#include "mstp.h"
|
||||
/*#include "dlmstp.h" */
|
||||
#include "bacnet/datalink/mstp.h"
|
||||
/*#include "bacnet/datalink/dlmstp.h" */
|
||||
#include "bits/pthreadtypes.h"
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "bacdef.h"
|
||||
#include "npdu.h"
|
||||
#include "bacnet/bacdef.h"
|
||||
#include "bacnet/npdu.h"
|
||||
#include <termios.h>
|
||||
#include "fifo.h"
|
||||
#include "ringbuf.h"
|
||||
#include "bacnet/basic/sys/fifo.h"
|
||||
#include "bacnet/basic/sys/ringbuf.h"
|
||||
/* defines specific to MS/TP */
|
||||
/* preamble+type+dest+src+len+crc8+crc16 */
|
||||
#define MAX_HEADER (2+1+1+1+2+1+2)
|
||||
|
||||
@@ -35,10 +35,10 @@
|
||||
#include <stdint.h> /* for standard integer types uint8_t etc. */
|
||||
#include <stdbool.h> /* for the standard bool type. */
|
||||
|
||||
#include "net.h"
|
||||
#include "bacdef.h"
|
||||
#include "ethernet.h"
|
||||
#include "bacint.h"
|
||||
#include "bacport.h"
|
||||
#include "bacnet/bacdef.h"
|
||||
#include "bacnet/datalink/ethernet.h"
|
||||
#include "bacnet/bacint.h"
|
||||
|
||||
/** @file linux/ethernet.c Provides Linux-specific functions for BACnet/Ethernet. */
|
||||
|
||||
|
||||
@@ -20,46 +20,65 @@
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h> /* for timeval */
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#include "bacport.h"
|
||||
#include "bacnet/basic/sys/mstimer.h"
|
||||
|
||||
/* Timer Module */
|
||||
#ifndef MAX_MILLISECOND_TIMERS
|
||||
#define TIMER_SILENCE 0
|
||||
#define MAX_MILLISECOND_TIMERS 1
|
||||
#endif
|
||||
/** @file linux/mstimer.c Provides Linux-specific time and timer functions. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
uint32_t timeGetTime(
|
||||
void);
|
||||
/* counter for the various timers */
|
||||
static volatile unsigned long Millisecond_Counter;
|
||||
|
||||
void timer_init(
|
||||
void);
|
||||
uint32_t timer_milliseconds(
|
||||
unsigned index);
|
||||
bool timer_elapsed_milliseconds(
|
||||
unsigned index,
|
||||
uint32_t value);
|
||||
bool timer_elapsed_seconds(
|
||||
unsigned index,
|
||||
uint32_t value);
|
||||
bool timer_elapsed_minutes(
|
||||
unsigned index,
|
||||
uint32_t seconds);
|
||||
uint32_t timer_milliseconds_set(
|
||||
unsigned index,
|
||||
uint32_t value);
|
||||
uint32_t timer_reset(
|
||||
unsigned index);
|
||||
/* start time for the clock */
|
||||
static struct timespec start;
|
||||
|
||||
#ifdef __cplusplus
|
||||
/** @brief The timeGetTime function retrieves the system time, in milliseconds.
|
||||
* The system time is the time elapsed since Windows was started.
|
||||
*/
|
||||
static unsigned long timeGetTime(
|
||||
void)
|
||||
{
|
||||
struct timespec now;
|
||||
unsigned long ticks;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
||||
ticks =
|
||||
(now.tv_sec - start.tv_sec) * 1000 + (now.tv_nsec -
|
||||
start.tv_nsec) / 1000000;
|
||||
|
||||
return ticks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief returns the current millisecond count
|
||||
* @return millisecond counter
|
||||
*/
|
||||
unsigned long mstimer_now(void)
|
||||
{
|
||||
unsigned long now = timeGetTime();
|
||||
unsigned long delta_time = 0;
|
||||
|
||||
if (Millisecond_Counter <= now) {
|
||||
delta_time = now - Millisecond_Counter;
|
||||
} else {
|
||||
delta_time = (ULONG_MAX - Millisecond_Counter) + now + 1;
|
||||
}
|
||||
|
||||
return delta_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialization for timer
|
||||
*/
|
||||
void mstimer_init(
|
||||
void)
|
||||
{
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
@@ -39,16 +39,16 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
/* OS specific include*/
|
||||
#include "net.h"
|
||||
#include "timer.h"
|
||||
#include "bacport.h"
|
||||
#include "bacnet/basic/sys/mstimer.h"
|
||||
/* local includes */
|
||||
#include "bytes.h"
|
||||
#include "bacnet/bytes.h"
|
||||
#include "rs485.h"
|
||||
#include "crc.h"
|
||||
#include "mstp.h"
|
||||
#include "dlmstp.h"
|
||||
#include "mstptext.h"
|
||||
#include "bacint.h"
|
||||
#include "bacnet/datalink/mstp.h"
|
||||
#include "bacnet/datalink/dlmstp.h"
|
||||
#include "bacnet/datalink/mstptext.h"
|
||||
#include "bacnet/bacint.h"
|
||||
|
||||
/** @file linux/mstpsnap.c Example application testing BACnet MS/TP on Linux. */
|
||||
|
||||
|
||||
+2
-2
@@ -63,9 +63,9 @@
|
||||
#include <libgen.h>
|
||||
|
||||
/* Local includes */
|
||||
#include "mstp.h"
|
||||
#include "bacnet/datalink/mstp.h"
|
||||
#include "rs485.h"
|
||||
#include "fifo.h"
|
||||
#include "bacnet/basic/sys/fifo.h"
|
||||
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@
|
||||
#define RS485_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "mstp.h"
|
||||
#include "bacnet/datalink/mstp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -48,11 +48,11 @@
|
||||
#include <signal.h> /* signal handling functions */
|
||||
|
||||
/* local includes */
|
||||
#include "bytes.h"
|
||||
#include "bacnet/bytes.h"
|
||||
#include "rs485.h"
|
||||
#include "crc.h"
|
||||
#include "mstp.h"
|
||||
#include "mstptext.h"
|
||||
#include "bacnet/datalink/mstp.h"
|
||||
#include "bacnet/datalink/mstptext.h"
|
||||
|
||||
/** @file linux/rx_fsm.c Example app testing MS/TP Rx State Machine on Linux. */
|
||||
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*********************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include "timer.h"
|
||||
|
||||
/** @file linux/timer.c Provides Linux-specific time and timer functions. */
|
||||
|
||||
/* counter for the various timers */
|
||||
static volatile uint32_t Millisecond_Counter[MAX_MILLISECOND_TIMERS];
|
||||
|
||||
/* start time for the clock */
|
||||
static struct timespec start;
|
||||
/* The timeGetTime function retrieves the system time, in milliseconds.
|
||||
The system time is the time elapsed since Windows was started. */
|
||||
uint32_t timeGetTime(
|
||||
void)
|
||||
{
|
||||
struct timespec now;
|
||||
uint32_t ticks;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
||||
ticks =
|
||||
(now.tv_sec - start.tv_sec) * 1000 + (now.tv_nsec -
|
||||
start.tv_nsec) / 1000000;
|
||||
|
||||
return ticks;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Description: returns the current millisecond count
|
||||
* Returns: none
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
uint32_t timer_milliseconds(
|
||||
unsigned index)
|
||||
{
|
||||
uint32_t now = timeGetTime();
|
||||
uint32_t delta_time = 0;
|
||||
|
||||
if (index < MAX_MILLISECOND_TIMERS) {
|
||||
if (Millisecond_Counter[index] <= now) {
|
||||
delta_time = now - Millisecond_Counter[index];
|
||||
} else {
|
||||
delta_time = (UINT32_MAX - Millisecond_Counter[index]) + now + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return delta_time;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Description: compares the current time count with a value
|
||||
* Returns: true if the time has elapsed
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
bool timer_elapsed_milliseconds(
|
||||
unsigned index,
|
||||
uint32_t value)
|
||||
{
|
||||
return (timer_milliseconds(index) >= value);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Description: compares the current time count with a value
|
||||
* Returns: true if the time has elapsed
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
bool timer_elapsed_seconds(
|
||||
unsigned index,
|
||||
uint32_t seconds)
|
||||
{
|
||||
return ((timer_milliseconds(index) / 1000) >= seconds);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Description: compares the current time count with a value
|
||||
* Returns: true if the time has elapsed
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
bool timer_elapsed_minutes(
|
||||
unsigned index,
|
||||
uint32_t minutes)
|
||||
{
|
||||
return ((timer_milliseconds(index) / (1000 * 60)) >= minutes);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Description: Sets the timer counter to zero.
|
||||
* Returns: none
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
uint32_t timer_reset(
|
||||
unsigned index)
|
||||
{
|
||||
uint32_t timer_value = 0;
|
||||
|
||||
if (index < MAX_MILLISECOND_TIMERS) {
|
||||
timer_value = timer_milliseconds(index);
|
||||
Millisecond_Counter[index] = timeGetTime();
|
||||
}
|
||||
|
||||
return timer_value;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Description: Initialization for timer
|
||||
* Returns: none
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
void timer_init(
|
||||
void)
|
||||
{
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
}
|
||||
Reference in New Issue
Block a user