knx
ETS configurable knx-stack
bau27B0.cpp
Go to the documentation of this file.
1 #include "config.h"
2 #if MASK_VERSION == 0x27B0
3 
4 #include "bau27B0.h"
5 #include "bits.h"
6 #include <string.h>
7 #include <stdio.h>
8 
9 using namespace std;
10 
12  : BauSystemBDevice(platform),
13  _dlLayer(_deviceObj, _rfMediumObj, _netLayer.getInterface(), _platform)
14 #ifdef USE_CEMI_SERVER
15  , _cemiServer(*this)
16 #endif
17 {
19  _memory.addSaveRestore(&_rfMediumObj);
20 #ifdef USE_CEMI_SERVER
22  _cemiServer.dataLinkLayer(_dlLayer);
23  _dlLayer.cemiServer(_cemiServer);
24  _memory.addSaveRestore(&_cemiServerObject);
25 #endif
26 
27  // Set Mask Version in Device Object depending on the BAU
28  _deviceObj.maskVersion(0x27B0);
29 
30  // Set the maximum APDU length
31  // ETS will consider this value while programming the device
32  // For KNX-RF we use a smallest allowed value for now,
33  // although long frame are also supported by the implementation.
34  // Needs some experimentation.
36 
37  // Set which interface objects are available in the device object
38  // This differs from BAU to BAU with different medium types.
39  // See PID_IO_LIST
41  prop->write(1, (uint16_t) OT_DEVICE);
42  prop->write(2, (uint16_t) OT_ADDR_TABLE);
43  prop->write(3, (uint16_t) OT_ASSOC_TABLE);
44  prop->write(4, (uint16_t) OT_GRP_OBJ_TABLE);
45  prop->write(5, (uint16_t) OT_APPLICATION_PROG);
46  prop->write(6, (uint16_t) OT_RF_MEDIUM);
47 #if defined(USE_DATASECURE) && defined(USE_CEMI_SERVER)
48  prop->write(7, (uint16_t) OT_SECURITY);
49  prop->write(8, (uint16_t) OT_CEMI_SERVER);
50 #elif defined(USE_DATASECURE)
51  prop->write(7, (uint16_t) OT_SECURITY);
52 #elif defined(USE_CEMI_SERVER)
53  prop->write(7, (uint16_t)OT_CEMI_SERVER);
54 #endif
55 }
56 
57 // see KNX AN160 p.74 for mask 27B0
59 {
60  switch (idx)
61  {
62  case 0:
63  return &_deviceObj;
64 
65  case 1:
66  return &_addrTable;
67 
68  case 2:
69  return &_assocTable;
70 
71  case 3:
72  return &_groupObjTable;
73 
74  case 4:
75  return &_appProgram;
76 
77  case 5: // would be app_program 2
78  return nullptr;
79 
80  case 6:
81  return &_rfMediumObj;
82 #if defined(USE_DATASECURE) && defined(USE_CEMI_SERVER)
83 
84  case 7:
85  return &_secIfObj;
86 
87  case 8:
88  return &_cemiServerObject;
89 #elif defined(USE_CEMI_SERVER)
90 
91  case 7:
92  return &_cemiServerObject;
93 #elif defined(USE_DATASECURE)
94 
95  case 7:
96  return &_secIfObj;
97 #endif
98 
99  default:
100  return nullptr;
101  }
102 }
103 
104 InterfaceObject* Bau27B0::getInterfaceObject(ObjectType objectType, uint16_t objectInstance)
105 {
106  // We do not use it right now.
107  // Required for coupler mode as there are multiple router objects for example
108  (void) objectInstance;
109 
110  switch (objectType)
111  {
112  case OT_DEVICE:
113  return &_deviceObj;
114 
115  case OT_ADDR_TABLE:
116  return &_addrTable;
117 
118  case OT_ASSOC_TABLE:
119  return &_assocTable;
120 
121  case OT_GRP_OBJ_TABLE:
122  return &_groupObjTable;
123 
124  case OT_APPLICATION_PROG:
125  return &_appProgram;
126 
127  case OT_RF_MEDIUM:
128  return &_rfMediumObj;
129 #ifdef USE_DATASECURE
130 
131  case OT_SECURITY:
132  return &_secIfObj;
133 #endif
134 #ifdef USE_CEMI_SERVER
135 
136  case OT_CEMI_SERVER:
137  return &_cemiServerObject;
138 #endif
139 
140  default:
141  return nullptr;
142  }
143 }
144 
145 void Bau27B0::doMasterReset(EraseCode eraseCode, uint8_t channel)
146 {
147  // Common SystemB objects
148  BauSystemB::doMasterReset(eraseCode, channel);
149 
150  _rfMediumObj.masterReset(eraseCode, channel);
151 }
152 
154 {
155  return _dlLayer.enabled();
156 }
157 
158 void Bau27B0::enabled(bool value)
159 {
160  _dlLayer.enabled(value);
161 }
162 
164 {
165  _dlLayer.loop();
167 #ifdef USE_CEMI_SERVER
168  _cemiServer.loop();
169 #endif
170 }
171 
172 void Bau27B0::domainAddressSerialNumberWriteIndication(Priority priority, HopCountType hopType, const SecurityControl& secCtrl, const uint8_t* rfDoA,
173  const uint8_t* knxSerialNumber)
174 {
175  // If the received serial number matches our serial number
176  // then store the received RF domain address in the RF medium object
177  if (!memcmp(knxSerialNumber, _deviceObj.propertyData(PID_SERIAL_NUMBER), 6))
178  _rfMediumObj.rfDomainAddress(rfDoA);
179 }
180 
181 void Bau27B0::domainAddressSerialNumberReadIndication(Priority priority, HopCountType hopType, const SecurityControl& secCtrl, const uint8_t* knxSerialNumber)
182 {
183  // If the received serial number matches our serial number
184  // then send a response with the current RF domain address stored in the RF medium object
185  if (!memcmp(knxSerialNumber, _deviceObj.propertyData(PID_SERIAL_NUMBER), 6))
186  _appLayer.domainAddressSerialNumberReadResponse(priority, hopType, secCtrl, _rfMediumObj.rfDomainAddress(), knxSerialNumber);
187 }
188 
189 void Bau27B0::individualAddressSerialNumberReadIndication(Priority priority, HopCountType hopType, const SecurityControl& secCtrl, uint8_t* knxSerialNumber)
190 {
191 #pragma warning "individualAddressSerialNumberReadIndication is not available for rf"
192 }
193 
194 void Bau27B0::domainAddressSerialNumberWriteLocalConfirm(Priority priority, HopCountType hopType, const SecurityControl& secCtrl, const uint8_t* rfDoA,
195  const uint8_t* knxSerialNumber, bool status)
196 {
197 }
198 
199 void Bau27B0::domainAddressSerialNumberReadLocalConfirm(Priority priority, HopCountType hopType, const SecurityControl& secCtrl, const uint8_t* knxSerialNumber, bool status)
200 {
201 }
202 
204 {
205  return (RfDataLinkLayer*)&_dlLayer;
206 }
207 #endif // #ifdef USE_RF
void domainAddressSerialNumberReadResponse(Priority priority, HopCountType hopType, const SecurityControl &secCtrl, const uint8_t *rfDoA, const uint8_t *knxSerialNumber)
RfDataLinkLayer * getDataLinkLayer()
Definition: bau27B0.cpp:203
bool enabled() override
Definition: bau27B0.cpp:153
InterfaceObject * getInterfaceObject(uint8_t idx)
void loop() override
Definition: bau27B0.cpp:163
Bau27B0(Platform &platform)
Definition: bau27B0.cpp:11
void doMasterReset(EraseCode eraseCode, uint8_t channel) override
Definition: bau27B0.cpp:145
void loop() override
AssociationTableObject _assocTable
SecureApplicationLayer _appLayer
NetworkLayerDevice _netLayer
AddressTableObject _addrTable
GroupObjectTableObject _groupObjTable
SecurityInterfaceObject _secIfObj
virtual void doMasterReset(EraseCode eraseCode, uint8_t channel)
Memory _memory
Definition: bau_systemB.h:123
ApplicationProgramObject _appProgram
Definition: bau_systemB.h:125
DeviceObject _deviceObj
Definition: bau_systemB.h:124
void dataLinkLayer(DataLinkLayer &layer)
void setMediumTypeAsSupported(DptMedium dptMedium)
uint16_t maskVersion()
uint16_t maxApduLength()
This class represents and interface object.
const uint8_t * propertyData(PropertyID id)
virtual void masterReset(EraseCode eraseCode, uint8_t channel)
Property * property(PropertyID id)
Gets property with PropertyID id if it exists and nullptr otherwise.
void addSaveRestore(SaveRestore *obj)
Definition: memory.cpp:209
NetworkLayerEntity & getInterface()
void dataLinkLayer(DataLinkLayer &layer)
virtual uint8_t write(uint16_t start, uint8_t count, const uint8_t *data)=0
const uint8_t * rfDomainAddress()
ObjectType
Enum for the type of an interface object.
@ OT_RF_MEDIUM
RF Medium Object.
@ OT_CEMI_SERVER
cEMI Server Object
@ OT_APPLICATION_PROG
Application program object.
@ OT_GRP_OBJ_TABLE
Group Object Table Object.
@ OT_ADDR_TABLE
Address table object.
@ OT_DEVICE
Device object.
@ OT_SECURITY
Security Interface Object.
@ OT_ASSOC_TABLE
Association table object.
HopCountType
Definition: knx_types.h:124
Priority
Definition: knx_types.h:10
EraseCode
Definition: knx_types.h:242
@ KNX_RF
Definition: knx_types.h:259
@ PID_SERIAL_NUMBER
Definition: property.h:78
@ PID_IO_LIST
Definition: property.h:98