knx
ETS configurable knx-stack
knx_ip_search_response_extended.cpp
Go to the documentation of this file.
2 #include "service_families.h"
3 #if KNX_SERVICE_FAMILY_CORE >= 2
4 #ifdef USE_IP
5 
6 #define LEN_SERVICE_FAMILIES 2
7 #if MASK_VERSION == 0x091A
8  #ifdef KNX_TUNNELING
9  #define LEN_SERVICE_DIB (2 + 4 * LEN_SERVICE_FAMILIES)
10  #else
11  #define LEN_SERVICE_DIB (2 + 3 * LEN_SERVICE_FAMILIES)
12  #endif
13 #else
14  #ifdef KNX_TUNNELING
15  #define LEN_SERVICE_DIB (2 + 3 * LEN_SERVICE_FAMILIES)
16  #else
17  #define LEN_SERVICE_DIB (2 + 2 * LEN_SERVICE_FAMILIES)
18  #endif
19 #endif
20 
22  : KnxIpFrame(LEN_KNXIP_HEADER + LEN_IPHPAI + dibLength),
23  _controlEndpoint(_data + LEN_KNXIP_HEADER)
24 {
26 
27  _controlEndpoint.length(LEN_IPHPAI);
28  _controlEndpoint.code(IPV4_UDP);
29  _controlEndpoint.ipAddress(parameters.propertyValue<uint32_t>(PID_CURRENT_IP_ADDRESS));
30  _controlEndpoint.ipPortNumber(KNXIP_MULTICAST_PORT);
31 
32  currentPos = LEN_KNXIP_HEADER + LEN_IPHPAI;
33 }
34 
36 {
37  //setDeviceInfo");
38  KnxIpDeviceInformationDIB _deviceInfo(_data + currentPos);
39  _deviceInfo.length(LEN_DEVICE_INFORMATION_DIB);
40  _deviceInfo.code(DEVICE_INFO);
41 #if MASK_VERSION == 0x57B0
42  _deviceInfo.medium(0x20); //MediumType is IP (for IP-Only Devices)
43 #else
44  _deviceInfo.medium(0x02); //MediumType is TP
45 #endif
46  _deviceInfo.status(deviceObject.progMode());
47  _deviceInfo.individualAddress(parameters.propertyValue<uint16_t>(PID_KNX_INDIVIDUAL_ADDRESS));
49  _deviceInfo.serialNumber(deviceObject.propertyData(PID_SERIAL_NUMBER));
50  _deviceInfo.routingMulticastAddress(parameters.propertyValue<uint32_t>(PID_ROUTING_MULTICAST_ADDRESS));
51  //_deviceInfo.routingMulticastAddress(0);
52 
53  uint8_t mac_address[LEN_MAC_ADDRESS] = {0};
54  Property* prop = parameters.property(PID_MAC_ADDRESS);
55  prop->read(mac_address);
56  _deviceInfo.macAddress(mac_address);
57 
58  uint8_t friendlyName[LEN_FRIENDLY_NAME] = {0};
59  prop = parameters.property(PID_FRIENDLY_NAME);
60  prop->read(1, LEN_FRIENDLY_NAME, friendlyName);
61  _deviceInfo.friendlyName(friendlyName);
62 
63  currentPos += LEN_DEVICE_INFORMATION_DIB;
64 }
65 
67 {
68  //println("setSupportedServices");
69  KnxIpSupportedServiceDIB _supportedServices(_data + currentPos);
70  _supportedServices.length(LEN_SERVICE_DIB);
71  _supportedServices.code(SUPP_SVC_FAMILIES);
72  _supportedServices.serviceVersion(Core, KNX_SERVICE_FAMILY_CORE);
73  _supportedServices.serviceVersion(DeviceManagement, KNX_SERVICE_FAMILY_DEVICE_MANAGEMENT);
74 #ifdef KNX_TUNNELING
75  _supportedServices.serviceVersion(Tunnelling, KNX_SERVICE_FAMILY_TUNNELING);
76 #endif
77 #if MASK_VERSION == 0x091A
78  _supportedServices.serviceVersion(Routing, KNX_SERVICE_FAMILY_ROUTING);
79 #endif
80  currentPos += LEN_SERVICE_DIB;
81 }
82 
84 {
85  //println("setIpConfig");
86  KnxIpConfigDIB _ipConfig(_data + currentPos);
87  _ipConfig.length(LEN_IP_CONFIG_DIB);
88  _ipConfig.code(IP_CONFIG);
89  _ipConfig.address(parameters.propertyValue<uint32_t>(PID_IP_ADDRESS));
90  _ipConfig.subnet(parameters.propertyValue<uint32_t>(PID_SUBNET_MASK));
91  _ipConfig.gateway(parameters.propertyValue<uint32_t>(PID_DEFAULT_GATEWAY));
92  _ipConfig.info1(parameters.propertyValue<uint8_t>(PID_IP_CAPABILITIES));
93  _ipConfig.info2(parameters.propertyValue<uint8_t>(PID_IP_ASSIGNMENT_METHOD));
94 
95  currentPos += LEN_IP_CONFIG_DIB;
96 }
97 
99 {
100  //println("setIpCurrentConfig");
101  KnxIpConfigDIB _ipCurConfig(_data + currentPos, true);
102  _ipCurConfig.length(LEN_IP_CURRENT_CONFIG_DIB);
103  _ipCurConfig.code(IP_CUR_CONFIG);
104  _ipCurConfig.address(parameters.propertyValue<uint32_t>(PID_CURRENT_IP_ADDRESS));
105  _ipCurConfig.subnet(parameters.propertyValue<uint32_t>(PID_CURRENT_SUBNET_MASK));
106  _ipCurConfig.gateway(parameters.propertyValue<uint32_t>(PID_CURRENT_DEFAULT_GATEWAY));
107  _ipCurConfig.dhcp(0);
108  _ipCurConfig.info1(parameters.propertyValue<uint8_t>(PID_CURRENT_IP_ASSIGNMENT_METHOD));
109  _ipCurConfig.info2(0x00); //Reserved
110 
111  currentPos += LEN_IP_CURRENT_CONFIG_DIB;
112 }
113 
115 {
116  //println("setKnxAddresses");
117  KnxIpKnxAddressesDIB _knxAddresses(_data + currentPos);
118  _knxAddresses.length(4); //minimum
119  _knxAddresses.code(KNX_ADDRESSES);
120  _knxAddresses.individualAddress(deviceObject.individualAddress());
121 
122  uint16_t length = 0;
124 
125  const uint8_t* addresses = parameters.propertyData(PID_ADDITIONAL_INDIVIDUAL_ADDRESSES);
126 
127  for (int i = 0; i < length; i++)
128  {
129  uint16_t additional = 0;
130  popWord(additional, addresses + i * 2);
131  _knxAddresses.additional(additional);
132  }
133 
134  currentPos += _knxAddresses.length();
135 }
136 
138 {
139  //println("setTunnelingInfo");
140  KnxIpTunnelingInfoDIB _tunnelInfo(_data + currentPos);
141  _tunnelInfo.length(4); //minlength
142  _tunnelInfo.code(TUNNELING_INFO);
143  _tunnelInfo.apduLength(254); //FIXME where to get from
144 
145  uint16_t length = 0;
147 
148  const uint8_t* addresses;
149 
150  if (length == KNX_TUNNELING)
151  {
152  addresses = parameters.propertyData(PID_ADDITIONAL_INDIVIDUAL_ADDRESSES);
153  }
154  else
155  {
156  uint8_t addrbuffer[KNX_TUNNELING * 2];
157  addresses = (uint8_t*)addrbuffer;
158 
159  for (int i = 0; i < KNX_TUNNELING; i++)
160  {
161  addrbuffer[i * 2 + 1] = i + 1;
162  addrbuffer[i * 2] = deviceObject.individualAddress() / 0x0100;
163  }
164  }
165 
166  for (int i = 0; i < length; i++)
167  {
168  uint16_t additional = 0;
169  popWord(additional, addresses + i * 2);
170  uint16_t flags = 0;
171 
172  uint8_t doubleCounter = 0;
173  bool used = false;
174 
175  for (int i = 0; i < KNX_TUNNELING; i++)
176  {
177  if (tunnels[i].IndividualAddress == additional)
178  {
179  doubleCounter += 1;
180 
181  if (tunnels[i].ChannelId != 0)
182  used = true;
183  }
184  }
185 
186  if (doubleCounter > 1 && used)
187  flags |= 1 << 2; //Slot is not usable; double PA is already used
188 
189  if (used)
190  {
191  flags |= 1 << 2; //Slot is not usable; PA is already used
192  flags |= 1; //Slot is not free
193  }
194 
195  flags = ~flags;
196 
197  _tunnelInfo.tunnelingSlot(additional, flags);
198  }
199 
200  currentPos += _tunnelInfo.length();
201 }
202 
204 {
205  //println("setExtendedDeviceInfo");
206  KnxIpExtendedDeviceInformationDIB _extended(_data + currentPos);
207  _extended.length(LEN_EXTENDED_DEVICE_INFORMATION_DIB);
208  _extended.code(EXTENDED_DEVICE_INFO);
209  _extended.status(0x01); //FIXME dont know encoding PID_MEDIUM_STATUS=51 RouterObject
210  _extended.localMaxApdu(254); //FIXME is this correct?
211  _extended.deviceDescriptor(MASK_VERSION);
212 
213  currentPos += LEN_EXTENDED_DEVICE_INFORMATION_DIB;
214 }
215 
217 {
218  return _controlEndpoint;
219 }
220 
221 
223 {
224  return _data + LEN_KNXIP_HEADER + LEN_IPHPAI;
225 }
226 #endif
227 #endif
const uint8_t * popWord(uint16_t &w, const uint8_t *data)
Definition: bits.cpp:34
uint16_t individualAddress()
const uint8_t * propertyData(PropertyID id)
virtual void readPropertyLength(PropertyID id, uint16_t &length)
Read length of a property of the interface object.
T propertyValue(PropertyID id)
Property * property(PropertyID id)
Gets property with PropertyID id if it exists and nullptr otherwise.
DescriptionTypeCode code() const
Definition: knx_ip_dib.cpp:19
uint8_t length() const
Definition: knx_ip_dib.cpp:9
uint16_t serviceTypeIdentifier() const
uint8_t * _data
Definition: knx_ip_frame.h:54
void additional(uint16_t addr)
void setIpCurrentConfig(IpParameterObject &parameters)
void setIpConfig(IpParameterObject &parameters)
void setKnxAddresses(IpParameterObject &parameters, DeviceObject &deviceObject)
void setTunnelingInfo(IpParameterObject &parameters, DeviceObject &deviceObject, KnxIpTunnelConnection tunnels[])
IpHostProtocolAddressInformation & controlEndpoint()
void setDeviceInfo(IpParameterObject &parameters, DeviceObject &deviceObject)
KnxIpSearchResponseExtended(IpParameterObject &parameters, DeviceObject &deviceObj, int dibLength)
uint8_t serviceVersion(ServiceFamily family)
void tunnelingSlot(uint16_t addr, uint16_t state)
virtual uint8_t read(uint16_t start, uint8_t count, uint8_t *data) const =0
@ IP_CONFIG
Definition: knx_ip_dib.h:12
@ SUPP_SVC_FAMILIES
Definition: knx_ip_dib.h:11
@ EXTENDED_DEVICE_INFO
Definition: knx_ip_dib.h:17
@ DEVICE_INFO
Definition: knx_ip_dib.h:10
@ TUNNELING_INFO
Definition: knx_ip_dib.h:16
@ KNX_ADDRESSES
Definition: knx_ip_dib.h:14
@ IP_CUR_CONFIG
Definition: knx_ip_dib.h:13
@ SearchResponseExt
Definition: knx_ip_frame.h:27
@ IndividualAddress
Definition: knx_types.h:34
@ PID_MAC_ADDRESS
Definition: property.h:128
@ PID_FRIENDLY_NAME
Definition: property.h:140
@ PID_CURRENT_DEFAULT_GATEWAY
Definition: property.h:123
@ PID_PROJECT_INSTALLATION_ID
KNXnet/IP Parameter Object.
Definition: property.h:115
@ PID_ADDITIONAL_INDIVIDUAL_ADDRESSES
Definition: property.h:117
@ PID_DEFAULT_GATEWAY
Definition: property.h:126
@ PID_SUBNET_MASK
Definition: property.h:125
@ PID_CURRENT_IP_ASSIGNMENT_METHOD
Definition: property.h:118
@ PID_IP_ADDRESS
Definition: property.h:124
@ PID_SERIAL_NUMBER
Definition: property.h:78
@ PID_CURRENT_SUBNET_MASK
Definition: property.h:122
@ PID_CURRENT_IP_ADDRESS
Definition: property.h:121
@ PID_KNX_INDIVIDUAL_ADDRESS
Definition: property.h:116
@ PID_ROUTING_MULTICAST_ADDRESS
Definition: property.h:130
@ PID_IP_ASSIGNMENT_METHOD
Definition: property.h:119
@ PID_IP_CAPABILITIES
Definition: property.h:120