Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
hfedcba committed May 29, 2018
2 parents 5f69732 + f0c008e commit d711e80
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 15 deletions.
10 changes: 5 additions & 5 deletions misc/Config Directory/homematicbidcos.conf
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ processBroadcastWithAesEnabled = false
#port = 2017

## The CA certificate
#caFile =
#caFile = /etc/homegear/ca/cacert.pem

## The client certificate
#certFile =
#certFile = /etc/homegear/ca/certs/gateway-client.crt

## The client key file
#keyFile =
#keyFile = /etc/homegear/ca/private/gateway-client.key

## Use the ID defined above to verify the common name of the certificate
## Default: false
#useIdForHostnameVerification = true

## Default: responseDelay = 95
## Should be "95" for CUL or COC, "100" for TI CC1101, "90" for Homegear Gateway and "60" for HM-CFG-LAN or HM-LGW
#responseDelay = 95
## Should be "95" for CUL or COC, "100" for TI CC1101, "98" for Homegear Gateway and "60" for HM-CFG-LAN or HM-LGW
#responseDelay = 98

#######################################
### HomeMatic Wireless LAN Gateway ###
Expand Down
14 changes: 12 additions & 2 deletions src/HomeMaticCentral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3952,7 +3952,12 @@ void HomeMaticCentral::handleAck(int32_t messageCounter, std::shared_ptr<BidCoSP
if((sentPacket && sentPacket->messageType() == 0x01 && sentPacket->payload()->at(0) == 0x00 && sentPacket->payload()->at(1) == 0x06) || (sentPacket && sentPacket->messageType() == 0x11 && sentPacket->payload()->at(0) == 0x04 && sentPacket->payload()->at(1) == 0x00))
{
std::shared_ptr<BidCoSPeer> peer = getPeer(packet->senderAddress());
if(peer) deletePeer(peer->getID());
if(peer)
{
uint64_t peerId = peer->getID();
peer.reset();
deletePeer(peerId);
}
}
}
else if(queue->getQueueType() == BidCoSQueueType::SETAESKEY)
Expand Down Expand Up @@ -4555,7 +4560,12 @@ PVariable HomeMaticCentral::deleteDevice(BaseLib::PRpcClientInfo clientInfo, uin
_bl->threadManager.start(_resetThread, false, &HomeMaticCentral::unpair, this, id, defer);
}
//Force delete
if(force) deletePeer(peer->getID());
if(force)
{
uint64_t peerId = peer->getID();
peer.reset();
deletePeer(peerId);
}
else
{
int32_t waitIndex = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/PhysicalInterfaces/AesHandshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ std::shared_ptr<BidCoSPacket> AesHandshake::getCFrame(std::shared_ptr<BidCoSPack
std::shared_ptr<BidCoSPacket> cFrame;
try
{
if(_myAddress == -1) _out.printWarning("Warning: address is unset in AesHandshake.");

std::vector<uint8_t> cPayload;
cPayload.reserve(8);
cPayload.push_back(0x04);
Expand Down Expand Up @@ -203,6 +205,8 @@ std::shared_ptr<BidCoSPacket> AesHandshake::getAFrame(std::shared_ptr<BidCoSPack

try
{
if(_myAddress == -1) _out.printWarning("Warning: address is unset in AesHandshake.");

std::lock_guard<std::mutex> decryptGuard(_decryptMutex);
if(_bl->debugLevel >= 4)_out.printInfo("Info: r-Frame is: " + rFrame->hexString());
std::vector<uint8_t> rfKey;
Expand Down Expand Up @@ -348,6 +352,7 @@ void AesHandshake::setMFrame(std::shared_ptr<BidCoSPacket> mFrame)

std::shared_ptr<BidCoSPacket> AesHandshake::getRFrame(std::shared_ptr<BidCoSPacket> cFrame, std::shared_ptr<BidCoSPacket>& mFrame, uint32_t keyIndex)
{
if(_myAddress == -1) _out.printWarning("Warning: address is unset in AesHandshake.");
if(_bl->debugLevel >= 4) _out.printInfo("Info: c-Frame is: " + cFrame->hexString());

std::shared_ptr<BidCoSPacket> rFrame;
Expand Down
2 changes: 1 addition & 1 deletion src/PhysicalInterfaces/AesHandshake.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AesHandshake

BaseLib::SharedObjects* _bl = nullptr;
BaseLib::Output _out;
int32_t _myAddress = 0x1C6940;
int32_t _myAddress = -1;
std::vector<uint8_t> _rfKey;
std::vector<uint8_t> _oldRfKey;
uint32_t _currentRfKeyIndex = 0;
Expand Down
1 change: 0 additions & 1 deletion src/PhysicalInterfaces/Cul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Cul::Cul(std::shared_ptr<BaseLib::Systems::PhysicalInterfaceSettings> settings)
settings->listenThreadPolicy = SCHED_FIFO;
}

_aesHandshake.reset(new AesHandshake(_bl, _out, _myAddress, _rfKey, _oldRfKey, _currentRfKeyIndex));
memset(&_termios, 0, sizeof(termios));
}

Expand Down
2 changes: 0 additions & 2 deletions src/PhysicalInterfaces/Cunx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ Cunx::Cunx(std::shared_ptr<BaseLib::Systems::PhysicalInterfaceSettings> settings
settings->listenThreadPriority = 45;
settings->listenThreadPolicy = SCHED_FIFO;
}

_aesHandshake.reset(new AesHandshake(_bl, _out, _myAddress, _rfKey, _oldRfKey, _currentRfKeyIndex));
}

Cunx::~Cunx()
Expand Down
18 changes: 15 additions & 3 deletions src/PhysicalInterfaces/HomegearGateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,25 @@ void HomegearGateway::startListening()
{
stopListening();

if(!_aesHandshake) return; //AES is not initialized

if(!GD::family->getCentral())
{
_stopCallbackThread = true;
_out.printError("Error: Could not get central address. Stopping listening.");
return;
}
_myAddress = GD::family->getCentral()->getAddress();
_aesHandshake->setMyAddress(_myAddress);

if(_settings->host.empty() || _settings->port.empty() || _settings->caFile.empty() || _settings->certFile.empty() || _settings->keyFile.empty())
{
_out.printError("Error: Configuration of Homegear Gateway is incomplete. Please correct it in \"homematicbidcos.conf\".");
return;
}

IBidCoSInterface::startListening();

_tcpSocket.reset(new BaseLib::TcpSocket(_bl, _settings->host, _settings->port, true, _settings->caFile, true, _settings->certFile, _settings->keyFile));
_tcpSocket->setConnectionRetries(1);
_tcpSocket->setReadTimeout(5000000);
Expand All @@ -75,7 +88,6 @@ void HomegearGateway::startListening()
_stopCallbackThread = false;
if(_settings->listenThreadPriority > -1) _bl->threadManager.start(_listenThread, true, _settings->listenThreadPriority, _settings->listenThreadPolicy, &HomegearGateway::listen, this);
else _bl->threadManager.start(_listenThread, true, &HomegearGateway::listen, this);
IPhysicalInterface::startListening();
}
catch(const std::exception& ex)
{
Expand All @@ -95,12 +107,12 @@ void HomegearGateway::stopListening()
{
try
{
IBidCoSInterface::stopListening();
_stopCallbackThread = true;
if(_tcpSocket) _tcpSocket->close();
_bl->threadManager.join(_listenThread);
_stopped = true;
_tcpSocket.reset();
IPhysicalInterface::stopListening();
}
catch(const std::exception& ex)
{
Expand Down Expand Up @@ -410,4 +422,4 @@ void HomegearGateway::processPacket(std::string& data)
}
}

}
}
2 changes: 1 addition & 1 deletion src/PhysicalInterfaces/IBidCoSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ void IBidCoSInterface::processReceivedPacket(std::shared_ptr<BidCoSPacket> packe
queuePacket(mFrame, mFrame->timeSending() + 1200);
}
// }}}

queuePacket(rFrame);
return;
}
Expand Down

0 comments on commit d711e80

Please sign in to comment.