Leosac  0.8.0
Open Source Access Control
RplethModule.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "RplethModule.hpp"
21 #include "core/auth/Auth.hpp"
24 #include "rplethprotocol.hpp"
25 #include "tools/log.hpp"
26 #include <boost/archive/binary_iarchive.hpp>
27 #include <boost/archive/binary_oarchive.hpp>
28 #include <boost/property_tree/ptree_serialization.hpp>
29 #include <netinet/in.h>
30 
31 using namespace Leosac::Module::Rpleth;
32 
33 RplethModule::RplethModule(zmqpp::context &ctx, zmqpp::socket *pipe,
34  const boost::property_tree::ptree &cfg,
35  CoreUtilsPtr utils)
36  : BaseModule(ctx, pipe, cfg, utils)
37  , ctx_(ctx)
38  , server_(ctx, zmqpp::socket_type::stream)
39  , bus_sub_(ctx, zmqpp::socket_type::sub)
40  , core_(ctx, zmqpp::socket_type::req)
41  , reader_(nullptr)
42  , stream_mode_(false)
43 {
44  core_.connect("inproc://leosac-kernel");
46  bus_sub_.connect("inproc://zmq-bus-pub");
47  bus_sub_.subscribe("S_" + reader_->name());
48  reactor_.add(server_, std::bind(&RplethModule::handle_socket, this));
50 }
51 
53 {
54 }
55 
57 {
58  boost::property_tree::ptree module_config = config_.get_child("module_config");
59 
60  uint16_t port = module_config.get<uint16_t>("port", 4242);
61  std::string reader_name = module_config.get_child("reader").data();
62  stream_mode_ = module_config.get<bool>("stream_mode", true);
63 
64  INFO("Rpleth module will bind to "
65  << port << " and will control the device nammed " << reader_name
66  << "Stream mode = " << stream_mode_);
67  reader_ = std::unique_ptr<Hardware::FWiegandReader>(
68  new Hardware::FWiegandReader(ctx_, reader_name));
69  server_.bind("tcp://*:" + std::to_string(port));
70 }
71 
73 {
74  zmqpp::message msg;
75  std::string identity;
76  std::string content;
77 
78  server_.receive(msg);
79  msg >> identity >> content;
80 
81  if (content.size() == 0)
82  {
83  // handle special 0 length message that indicates connection / disconnection.
84  if (client_connected(
85  identity)) // client exists so this is a disconnection message.
86  {
87  INFO("client disconnected");
88  clients_.erase(identity);
89  if (client_failed(identity))
90  failed_clients_.erase(std::remove(failed_clients_.begin(),
91  failed_clients_.end(), identity),
92  failed_clients_.end());
93  }
94  else
95  {
96  INFO("Client connected");
97  clients_[identity];
98  }
99  return;
100  }
101  if (client_failed(identity))
102  return;
103  assert(clients_.count(identity) && !client_failed(identity));
104  clients_[identity].write(reinterpret_cast<const uint8_t *>(content.c_str()),
105  content.size());
106  if (handle_client_msg(identity, clients_[identity]) == false)
107  failed_clients_.push_back(identity);
108 }
109 
110 bool RplethModule::handle_client_msg(const std::string &client_identity,
111  CircularBuffer &buf)
112 {
114 
115  do
116  {
117  std::array<uint8_t, buffer_size> buffer;
118  packet = RplethProtocol::decodeCommand(buf);
119  if (!packet.isGood)
120  break;
121  RplethPacket response = handle_client_packet(packet);
122  if (response.command == RplethProtocol::HIDCommands::Greenled ||
123  response.command == RplethProtocol::HIDCommands::Beep)
124  continue;
125  std::size_t size =
126  RplethProtocol::encodeCommand(response, &buffer[0], buffer_size);
127 
128  zmqpp::message msg;
129  msg << client_identity;
130  msg.add_raw(&buffer[0], size);
131  if (!server_.send(msg, true))
132  {
133  // would block: peer is probably disconnected already.
134  return false;
135  }
136  } while (packet.isGood && buf.toRead());
137  return true;
138 }
139 
141 {
142  RplethPacket response = packet;
143  try
144  {
146  if (response.type == RplethProtocol::Rpleth &&
147  response.command == RplethProtocol::Ping)
148  {
149  response.status = RplethProtocol::Success;
150  }
151  else if (response.type == RplethProtocol::TypeCode::HID &&
152  response.command == RplethProtocol::HIDCommands::Greenled)
153  rpleth_greenled(packet);
154  else if (response.type == RplethProtocol::TypeCode::HID &&
155  response.command == RplethProtocol::HIDCommands::Beep)
156  rpleth_beep(packet);
157  else if (response.type == RplethProtocol::TypeCode::HID &&
158  response.command == RplethProtocol::HIDCommands::SendCards)
159  rpleth_send_cards(packet);
160  else if (response.type == RplethProtocol::TypeCode::HID &&
161  response.command == RplethProtocol::HIDCommands::ReceiveCardsWaited)
162  response = rpleth_receive_cards(response);
163  else if (response.type == RplethProtocol::TypeCode::Rpleth &&
164  response.command == RplethProtocol::RplethCommands::DHCPState)
165  response = get_dhcp_state();
166  else if (response.type == RplethProtocol::TypeCode::Rpleth &&
167  response.command == RplethProtocol::RplethCommands::SetDHCP)
168  response = set_dhcp_state(response);
169  else if (response.type == RplethProtocol::TypeCode::Rpleth &&
170  response.command == RplethProtocol::RplethCommands::SetIP)
171  response = set_reader_ip(response);
172  else if (response.type == RplethProtocol::TypeCode::Rpleth &&
173  response.command == RplethProtocol::RplethCommands::SetSubnet)
174  response = set_reader_netmask(response);
175  else if (response.type == RplethProtocol::TypeCode::Rpleth &&
176  response.command == RplethProtocol::RplethCommands::SetGateway)
177  response = set_reader_gw(response);
178  else if (response.type == RplethProtocol::TypeCode::Rpleth &&
179  response.command == RplethProtocol::RplethCommands::Reset)
180  restart_reader();
181  else
182  {
183  WARN("Unhandled packet.");
184  response.status = RplethProtocol::Success; // Default response
185  }
186  return response;
187  }
188  catch (std::exception &e)
189  {
190  ERROR("Exception while handling rpleth packet: " << e.what());
191  }
192  response.status = RplethProtocol::Failed;
193  return response;
194 }
195 
197 {
198  zmqpp::message msg;
199  std::string card_id;
200  std::string src; // object that sent event
202  int nb_bit_read;
203 
204  bus_sub_.receive(msg);
205  msg >> src >> type;
207  msg >> card_id >> nb_bit_read;
208 
209  DEBUG("Rpleth module registered card with id "
210  << card_id << " and " << nb_bit_read << " significants bits");
211 
212  if (stream_mode_)
213  cards_read_stream_.push_back(std::make_pair(card_id, nb_bit_read));
214 
215  card_id.erase(std::remove(card_id.begin(), card_id.end(), ':'), card_id.end());
216  if (std::find(cards_pushed_.begin(), cards_pushed_.end(), card_id) !=
217  cards_pushed_.end())
218  {
219  cards_read_.push_back(card_id);
220  }
221  cards_read_.unique();
223 }
224 
226 {
227  auto itr_start = packet.data.begin();
228  std::vector<Byte>::const_iterator my_start = itr_start;
229  std::vector<Byte>::const_iterator it;
230 
231  WARN("Should not be here");
232  cards_pushed_.clear();
233  cards_read_.clear();
234 
235  while (my_start != packet.data.end())
236  {
237  it = std::find(itr_start, packet.data.end(), '|');
238  std::string card;
239  while (my_start != packet.data.end() && my_start != it)
240  {
241  card += *my_start;
242  my_start++;
243  }
244  cards_pushed_.push_back(card);
245  if (my_start == packet.data.end())
246  break;
247  else
248  my_start++;
249  itr_start = ++it;
250  }
251  cards_pushed_.unique();
252 }
253 
255 {
256  std::list<std::string> to_send;
257  RplethPacket response = packet;
258  WARN("Should not be here");
259  DEBUG("Packet size = " << packet.data.size());
260  if (packet.data.size() != 1)
261  {
262  WARN("Invalid Packet");
263  return response;
264  }
265  if (packet.data[0] == 0x01)
266  {
267  DEBUG("Present list");
268  // send present list
269  to_send = cards_read_;
270  }
271  else
272  {
273  DEBUG("Absent list");
274  // send absent list
275  to_send = cards_pushed_;
276  auto lambda = [this](const std::string &str) -> bool {
277  // if entry is not in cards_read_ means user was absent, do not remove
278  // him
279  bool found = std::find(cards_read_.begin(), cards_read_.end(), str) !=
280  cards_read_.end();
281  return found;
282  };
283  to_send.erase(std::remove_if(to_send.begin(), to_send.end(), lambda),
284  to_send.end());
285  }
286  // we reserve approximately what we need, just to avoid useless memory
287  // allocations.
288  std::vector<Byte> data;
289  data.reserve(to_send.size() * 8);
290  for (auto &card : to_send)
291  {
292  // we need to convert the card (ff:ae:32:00) to something like "ffae3200"
293  card.erase(std::remove(card.begin(), card.end(), ':'), card.end());
294  data.insert(data.end(), card.begin(), card.end());
295  data.push_back('|');
296  }
297  response.data = data;
298  response.dataLen = data.size();
299  return response;
300 }
301 
303 {
304  if (packet.data.size() > 0)
305  {
306  if (packet.data[0] == 0x01)
307  reader_->buzzerOn();
308  else if (packet.data[0] == 0x00)
309  reader_->buzzerOff();
310  else
311  WARN("Malformed (Rpleth Beep) packet. Data byte is invalid");
312  }
313  else
314  WARN("Malformed (Rpleth Beep) packet. Not enough data");
315 }
316 
318 {
319  if (packet.data.size() > 0)
320  {
321  if (packet.data[0] == 0x01)
322  reader_->greenLedOn();
323  else if (packet.data[0] == 0x00)
324  reader_->greenLedOff();
325  else
326  WARN("Malformed (Rpleth GreenLed) packet. Data byte is invalid");
327  }
328  else
329  WARN("Malformed (Rpleth GreenLed) packet. Not enough data");
330 }
331 
332 bool RplethModule::client_connected(const std::string &identity) const
333 {
334  return clients_.count(identity);
335 }
336 
337 bool RplethModule::client_failed(const std::string &identity) const
338 {
339  return (std::find(failed_clients_.begin(), failed_clients_.end(), identity) !=
340  failed_clients_.end());
341 }
342 
344 {
345  for (auto const &card_pair : cards_read_stream_)
346  {
347  for (auto &client : clients_)
348  {
349  zmqpp::message msg;
351 
352  msg << client.first;
353  packet.data = card_convert_from_text(card_pair);
355  packet.type = RplethProtocol::HID;
357  packet.dataLen = packet.data.size();
358 
359  std::array<uint8_t, 64> buf;
360  std::size_t size;
361  size = RplethProtocol::encodeCommand(packet, &buf[0], buf.size());
362  msg.add_raw(&buf, size);
363  if (!server_.send(msg, true))
364  failed_clients_.push_back(client.first);
365  }
366  }
367  cards_read_stream_.clear();
368 }
369 
370 static uint64_t htonll(uint64_t value)
371 {
372  int num = 42;
373  if (*(char *)&num == 42)
374  {
375  uint32_t high_part = htonl((uint32_t)(value >> 32));
376  uint32_t low_part = htonl((uint32_t)(value & 0xFFFFFFFFLL));
377  return (((uint64_t)low_part) << 32) | high_part;
378  }
379  else
380  {
381  return value;
382  }
383 }
384 
385 std::vector<uint8_t>
386 RplethModule::card_convert_from_text(const std::pair<std::string, int> &card_info)
387 {
388  Cred::RFIDCard wc;
389  wc.card_id(card_info.first);
390  wc.nb_bits(card_info.second);
391  std::vector<uint8_t> ret;
392 
393  auto num = wc.to_raw_int();
394  // This will go over the network. So we have to convert to network byte order.
395  num = htonll(num);
396 
397  ret.resize(sizeof(num));
398  std::memcpy(&ret[0], &num, sizeof(num));
399  return ret;
400 }
401 
403 {
404  auto network_cfg = get_network_config();
406 
407  response.type = RplethProtocol::TypeCode::Rpleth;
408  response.command = RplethProtocol::RplethCommands::DHCPState;
409  try
410  {
411  if (network_cfg.get<bool>("enabled"))
412  {
413  response.status = RplethProtocol::Success;
414  response.data = network_cfg.get<bool>("dhcp")
415  ? std::vector<uint8_t>({1})
416  : std::vector<uint8_t>({0});
417  response.dataLen = 1;
418  }
419  else // network not handled by leosac. return failure.
420  {
421  response.status = RplethProtocol::Failed;
422  }
423  }
424  catch (const std::exception &e)
425  {
426  ERROR("Exception while getting DHCP state: " << e.what());
427  }
428  return response;
429 }
430 
432 {
433  auto network_cfg = get_network_config();
435 
436  response.status = RplethProtocol::Failed;
437  response.type = RplethProtocol::TypeCode::Rpleth;
438  response.command = RplethProtocol::RplethCommands::SetDHCP;
439 
440  if (p.dataLen < 1)
441  ERROR("Invalid Rpleth Packet");
442  else if (network_cfg.get<bool>("enabled"))
443  {
444  network_cfg.erase("dhcp");
445  network_cfg.put("dhcp", p.data[0] ? true : false);
446  if (push_network_config(network_cfg))
447  response.status = RplethProtocol::Success;
448  else
449  WARN("Failed to update network config.");
450  }
451  else
452  INFO("Network not managed by Leosac, doing nothing.");
453  return response;
454 }
455 
457 {
458  auto network_cfg = get_network_config();
460 
461  response.status = RplethProtocol::Failed;
462  response.type = RplethProtocol::TypeCode::Rpleth;
463  response.command = RplethProtocol::RplethCommands::SetIP;
464 
465  if (p.dataLen < 4)
466  ERROR("Invalid Rpleth Packet");
467  else if (network_cfg.get<bool>("enabled"))
468  {
469  std::ostringstream oss;
470  for (unsigned char i = 0; i < 4; ++i)
471  {
472  oss << std::to_string(p.data[i]);
473  if (i != 3)
474  oss << ".";
475  }
476  INFO("new ip = {" << oss.str() << "}");
477  network_cfg.erase("default_ip");
478  network_cfg.put("default_ip", oss.str());
479  if (push_network_config(network_cfg))
480  response.status = RplethProtocol::Success;
481  else
482  WARN("Failed to update network config.");
483  }
484  else
485  INFO("Network not managed by Leosac, doing nothing.");
486  return response;
487 }
488 
490 {
491  auto network_cfg = get_network_config();
493 
494  response.status = RplethProtocol::Failed;
495  response.type = RplethProtocol::TypeCode::Rpleth;
496  response.command = RplethProtocol::RplethCommands::SetSubnet;
497 
498  if (p.dataLen < 4)
499  ERROR("Invalid Rpleth Packet");
500  else if (network_cfg.get<bool>("enabled"))
501  {
502  std::ostringstream oss;
503  for (unsigned char i = 0; i < 4; ++i)
504  {
505  oss << std::to_string(p.data[i]);
506  if (i != 3)
507  oss << ".";
508  }
509  network_cfg.erase("netmask");
510  network_cfg.put("netmask", oss.str());
511  if (push_network_config(network_cfg))
512  response.status = RplethProtocol::Success;
513  else
514  WARN("Failed to update network config.");
515  }
516  else
517  INFO("Network not managed by Leosac, doing nothing.");
518  return response;
519 }
520 
522 {
523  auto network_cfg = get_network_config();
525 
526  response.status = RplethProtocol::Failed;
527  response.type = RplethProtocol::TypeCode::Rpleth;
528  response.command = RplethProtocol::RplethCommands::SetGateway;
529 
530  if (p.dataLen < 4)
531  ERROR("Invalid Rpleth Packet");
532  else if (network_cfg.get<bool>("enabled"))
533  {
534  std::ostringstream oss;
535  for (unsigned char i = 0; i < 4; ++i)
536  {
537  oss << std::to_string(p.data[i]);
538  if (i != 3)
539  oss << ".";
540  }
541  network_cfg.erase("gateway");
542  network_cfg.put("gateway", oss.str());
543  if (push_network_config(network_cfg))
544  response.status = RplethProtocol::Success;
545  else
546  WARN("Failed to update network config.");
547  }
548  else
549  INFO("Network not managed by Leosac, doing nothing.");
550  return response;
551 }
552 
553 bool RplethModule::push_network_config(boost::property_tree::ptree const &tree)
554 {
555  std::ostringstream oss;
556  boost::archive::binary_oarchive archive(oss);
557  boost::property_tree::save(archive, tree, 1);
558  core_.send(zmqpp::message() << "SET_NETCONFIG" << oss.str());
559 
560  std::string ret;
561  core_.receive(ret);
562  return ret == "OK" ? true : false;
563 }
564 
565 boost::property_tree::ptree RplethModule::get_network_config()
566 {
567  boost::property_tree::ptree network_config;
568  std::string data;
569 
570  core_.send("GET_NETCONFIG");
571 
572  zmqpp::message response;
573  core_.receive(response);
574  assert(response.parts() == 1);
575 
576  response >> data;
577  std::istringstream iss(data);
578  boost::archive::binary_iarchive archive(iss);
579  boost::property_tree::load(archive, network_config, 1);
580 
581  return network_config;
582 }
583 
585 {
586  std::string ret;
587  core_.send("RESTART");
588  core_.receive(ret);
589 }
Leosac::Module::Rpleth::RplethModule::cards_read_stream_
std::list< std::pair< std::string, int > > cards_read_stream_
If stream mode is on, all cards read are stored here.
Definition: RplethModule.hpp:199
Leosac::Module::Rpleth::RplethProtocol::Ping
@ Ping
Definition: rplethprotocol.hpp:69
Leosac::Module::Rpleth::RplethModule::rpleth_beep
void rpleth_beep(const RplethPacket &p)
Handle Rpleth Beep command.
Definition: RplethModule.cpp:302
Leosac::Module::BaseModule
Base class for module implementation.
Definition: BaseModule.hpp:110
WARN
@ WARN
Definition: log.hpp:33
Leosac::Module::Rpleth::RplethModule::push_network_config
bool push_network_config(const boost::property_tree::ptree &tree)
Push a configuration to the core as the new network config.
Definition: RplethModule.cpp:553
zmqpp
Definition: CoreUtils.hpp:27
RplethModule.hpp
Leosac::Module::Rpleth::RplethModule::rpleth_greenled
void rpleth_greenled(const RplethPacket &p)
Handle rpleth greenled command.
Definition: RplethModule.cpp:317
Leosac::Module::Rpleth::RplethModule::rpleth_receive_cards
RplethPacket rpleth_receive_cards(const RplethPacket &packet)
Handle Rpleth ReceiveUnpresentedCards command.
Definition: RplethModule.cpp:254
Leosac::Module::Rpleth::RplethModule::rpleth_publish_card
void rpleth_publish_card()
Flush the cards_read_stream_ list to clients.
Definition: RplethModule.cpp:343
Leosac::Module::Rpleth::RplethPacket::sender
Sender sender
Definition: rplethpacket.hpp:68
ERROR
@ ERROR
Definition: log.hpp:32
DEBUG
@ DEBUG
Definition: log.hpp:35
Leosac::Cred::RFIDCard::nb_bits
virtual int nb_bits() const override
Definition: RFIDCard.cpp:39
Auth.hpp
Leosac::Hardware::FWiegandReader
Facade object for a Wiegand Reader device.
Definition: FWiegandReader.hpp:38
Leosac::Module::Rpleth::RplethModule::reader_
std::unique_ptr< Hardware::FWiegandReader > reader_
Interface to the reader.
Definition: RplethModule.hpp:224
Leosac::Module::Rpleth::RplethModule::set_dhcp_state
RplethPacket set_dhcp_state(const RplethPacket &p)
Enable or disable DHCP.
Definition: RplethModule.cpp:431
RFIDCard.hpp
Leosac::Module::Rpleth::RplethProtocol::decodeCommand
static RplethPacket decodeCommand(CircularBuffer &buffer, bool from_server=false)
Decode a packet from a circular buffer object.
Definition: rplethprotocol.cpp:32
INFO
@ INFO
Definition: log.hpp:34
Leosac::Module::Rpleth::RplethPacket
Definition: rplethpacket.hpp:39
Leosac::Module::Rpleth::RplethPacket::Sender::Client
@ Client
Leosac::Cred::RFIDCard
An RFID card credential.
Definition: RFIDCard.hpp:33
Leosac::Module::Rpleth::RplethModule::restart_reader
void restart_reader()
Definition: RplethModule.cpp:584
Leosac::Module::Rpleth::RplethProtocol::encodeCommand
static std::size_t encodeCommand(const RplethPacket &packet, Byte *buffer, std::size_t size)
Definition: rplethprotocol.cpp:72
Leosac::Module::Rpleth::RplethProtocol::Success
@ Success
Definition: rplethprotocol.hpp:93
Leosac::Module::Rpleth::RplethProtocol::Rpleth
@ Rpleth
Definition: rplethprotocol.hpp:53
Leosac::Module::Rpleth::RplethModule::clients_
std::map< std::string, CircularBuffer > clients_
Definition: RplethModule.hpp:201
Leosac::Module::Rpleth::RplethModule::server_
zmqpp::socket server_
Stream socket to receive Rpleth connection.
Definition: RplethModule.hpp:208
Leosac::Module::Rpleth::RplethModule::~RplethModule
~RplethModule()
Definition: RplethModule.cpp:52
Leosac::Module::Rpleth::RplethPacket::Sender::Server
@ Server
Leosac::Module::Rpleth::RplethPacket::type
Byte type
Definition: rplethpacket.hpp:62
Leosac::Module::Rpleth::RplethModule::RplethModule
RplethModule(zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
Definition: RplethModule.cpp:33
Leosac::Module::Rpleth::RplethModule::handle_client_packet
RplethPacket handle_client_packet(RplethPacket packet)
If we successfully built a packet, lets handle it.
Definition: RplethModule.cpp:140
Leosac::Module::Rpleth::RplethPacket::dataLen
Byte dataLen
Definition: rplethpacket.hpp:64
Leosac::Module::BaseModule::config_
boost::property_tree::ptree config_
The configuration tree passed to the start_module function.
Definition: BaseModule.hpp:193
Leosac::Module::Rpleth
Namespace where implementation for Rpleth support takes place.
Definition: circularbuffer.hpp:38
Leosac::Module::Rpleth::RplethPacket::status
Byte status
Definition: rplethpacket.hpp:61
Leosac::Module::BaseModule::reactor_
zmqpp::reactor reactor_
The reactor object we poll() on in the main loop.
Definition: BaseModule.hpp:214
Leosac::Module::Rpleth::RplethModule::buffer_size
static constexpr int buffer_size
Definition: RplethModule.hpp:81
Leosac::Module::Rpleth::RplethModule::process_config
void process_config()
Definition: RplethModule.cpp:56
Leosac::Module::Rpleth::RplethModule::bus_sub_
zmqpp::socket bus_sub_
Subscribe to the message bus and listen for event sent by the wiegand reader we watch.
Definition: RplethModule.hpp:214
Leosac::Module::Rpleth::RplethModule::set_reader_ip
RplethPacket set_reader_ip(const RplethPacket &p)
Update the IP of this Leosac unit.
Definition: RplethModule.cpp:456
Leosac::Module::Rpleth::RplethModule::handle_client_msg
bool handle_client_msg(const std::string &client_identity, CircularBuffer &buf)
Try to handle a client message.
Definition: RplethModule.cpp:110
Leosac::Module::Rpleth::RplethModule::ctx_
zmqpp::context & ctx_
Definition: RplethModule.hpp:203
Leosac::Cred::RFIDCard::card_id
virtual const std::string & card_id() const override
Definition: RFIDCard.cpp:34
Leosac::Module::Rpleth::RplethModule::stream_mode_
bool stream_mode_
Definition: RplethModule.hpp:234
Leosac::Module::Rpleth::RplethModule::get_dhcp_state
RplethPacket get_dhcp_state()
Handle Rpleth GetDHCP command.
Definition: RplethModule.cpp:402
Leosac::Module::Rpleth::RplethModule::core_
zmqpp::socket core_
REQ socket to core.
Definition: RplethModule.hpp:219
Leosac::Module::Rpleth::RplethModule::card_convert_from_text
static std::vector< uint8_t > card_convert_from_text(const std::pair< std::string, int > &card_info)
Convert a card number from textual hexadecimal representation to a 8 bytes byte-vector in Network Byt...
Definition: RplethModule.cpp:386
Leosac::Module::Rpleth::CircularBuffer::toRead
std::size_t toRead() const
Definition: circularbuffer.cpp:101
Leosac::Module::Rpleth::RplethModule::rpleth_send_cards
void rpleth_send_cards(const RplethPacket &packet)
Handle Rpleth SendCards command: we will store the list of received card somewhere safe.
Definition: RplethModule.cpp:225
Leosac::Module::Rpleth::RplethModule::handle_socket
void handle_socket()
Handle data available on server socket.
Definition: RplethModule.cpp:72
Leosac::Module::Rpleth::RplethModule::set_reader_netmask
RplethPacket set_reader_netmask(const RplethPacket &p)
Update netmask of this Leosac unit.
Definition: RplethModule.cpp:489
log.hpp
Leosac::Module::Rpleth::RplethProtocol::Failed
@ Failed
Definition: rplethprotocol.hpp:94
rplethprotocol.hpp
Rpleth protocol implementation.
Leosac::Cred::RFIDCard::to_raw_int
virtual uint64_t to_raw_int() const override
Convert the bits of the card to an integer.
Definition: RFIDCard.cpp:44
Leosac::Module::Rpleth::RplethModule::client_connected
bool client_connected(const std::string &identity) const
Do we already know this client ?
Definition: RplethModule.cpp:332
Leosac::Module::Rpleth::RplethModule::cards_read_
std::list< std::string > cards_read_
Valid cards our Wiegand reader read: cards that were not pushed are not stored here.
Definition: RplethModule.hpp:193
Leosac::Module::Rpleth::RplethModule::handle_wiegand_event
void handle_wiegand_event()
We received a message (on the BUS, from the wiegand reader we watch), that means a card was inserted.
Definition: RplethModule.cpp:196
Leosac::Module::Rpleth::CircularBuffer
Implementation of a ring buffer.
Definition: circularbuffer.hpp:43
Leosac::Auth::SourceType
SourceType
Definition: Auth.hpp:29
Leosac::CoreUtilsPtr
std::shared_ptr< CoreUtils > CoreUtilsPtr
Definition: LeosacFwd.hpp:35
Leosac::Module::Rpleth::RplethModule::failed_clients_
std::vector< std::string > failed_clients_
Client that are "failed".
Definition: RplethModule.hpp:232
Leosac::Module::Rpleth::RplethModule::client_failed
bool client_failed(const std::string &identity) const
Is the client in an invalid state ?
Definition: RplethModule.cpp:337
Leosac::Module::Rpleth::RplethPacket::command
Byte command
Definition: rplethpacket.hpp:63
Leosac::Module::Rpleth::RplethPacket::data
std::vector< Byte > data
Definition: rplethpacket.hpp:65
Leosac::Module::Rpleth::RplethPacket::isGood
bool isGood
Definition: rplethpacket.hpp:67
FWiegandReader.hpp
Leosac::Auth::SourceType::SIMPLE_WIEGAND
@ SIMPLE_WIEGAND
This define message formatting for data source SIMPLE_WIEGAND.
Leosac::Module::Rpleth::RplethModule::get_network_config
boost::property_tree::ptree get_network_config()
Retrieve the network configuration from the core.
Definition: RplethModule.cpp:565
Leosac::Module::Rpleth::RplethModule::cards_pushed_
std::list< std::string > cards_pushed_
List of cards pushed by SendCards Rpleth command.
Definition: RplethModule.hpp:187
Leosac::Module::Rpleth::RplethModule::set_reader_gw
RplethPacket set_reader_gw(const RplethPacket &p)
Update the reader gateway.
Definition: RplethModule.cpp:521
Leosac::Module::Rpleth::RplethProtocol::HID
@ HID
Definition: rplethprotocol.hpp:54
Leosac::Module::Rpleth::RplethProtocol::Badge
@ Badge
Definition: rplethprotocol.hpp:78