Compare commits

..

53 Commits

Author SHA1 Message Date
TIP Automation User
a45d351081 Chg: update image tag in helm values to v2.6.2 2022-09-15 11:47:49 +00:00
Dmitry Dunaev
7f291914bd Merge pull request #195 from Telecominfraproject/feature/wifi-10842--docker-compose--iptocountry-2-6
[WIFI-10842] Add: docker-compose support for iptocountry
2022-09-15 14:13:06 +03:00
Dmitry Dunaev
3edbb02187 [WIFI-10842] Add: docker-compose support for iptocountry
Signed-off-by: Dmitry Dunaev <dmitry@opsfleet.com>
2022-09-15 14:12:18 +03:00
TIP Automation User
27beb0bd5d Chg: update image tag in helm values to v2.6.1 2022-09-02 10:03:40 +00:00
Stephane Bourque
24ec3259c6 Merge pull request #158 from Telecominfraproject/master
https://telecominfraproject.atlassian.net/browse/WIFI-9977
2022-07-21 22:51:53 -07:00
Stephane Bourque
b09cec0bc2 Merge pull request #157 from Telecominfraproject/WIFI-9977v4
https://telecominfraproject.atlassian.net/browse/WIFI-9977
2022-07-21 22:12:59 -07:00
stephb9959
d14ca95010 https://telecominfraproject.atlassian.net/browse/WIFI-9977
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-21 22:04:15 -07:00
stephb9959
2df1100795 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-19 21:40:12 -07:00
stephb9959
2f961f992a Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-19 21:20:27 -07:00
stephb9959
ecdc5b3531 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-19 20:53:16 -07:00
stephb9959
5f08a581f2 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-19 20:49:07 -07:00
stephb9959
87b4a5d626 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-19 20:43:53 -07:00
stephb9959
6aa2ef2878 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-19 20:42:18 -07:00
stephb9959
9267a36529 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-19 20:32:01 -07:00
stephb9959
72db313d8d Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-18 23:03:57 -07:00
stephb9959
93f0b2500e Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-18 23:03:21 -07:00
stephb9959
76b7aba5bd Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-18 22:41:32 -07:00
stephb9959
0585884033 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-18 22:36:39 -07:00
stephb9959
c31fa08579 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-18 22:34:26 -07:00
stephb9959
d9c3fea93d Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-18 22:27:51 -07:00
stephb9959
6325476325 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-18 22:24:29 -07:00
stephb9959
054e172b64 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-18 21:56:22 -07:00
stephb9959
7ae51f0fec Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-18 21:52:58 -07:00
stephb9959
531c0e24ba Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-18 21:46:53 -07:00
stephb9959
d97a31e002 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-18 08:51:32 -07:00
stephb9959
70e5b1d0db Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-18 08:43:17 -07:00
stephb9959
63516e85db Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-18 08:34:15 -07:00
stephb9959
35b1dbdc2e Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 23:25:41 -07:00
stephb9959
c9abe16cfe Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 23:21:22 -07:00
stephb9959
aee7530b2b Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 23:13:06 -07:00
stephb9959
ceda99fa84 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 22:56:27 -07:00
stephb9959
ce78b144e6 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 22:51:54 -07:00
stephb9959
3fd3717978 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 22:36:29 -07:00
stephb9959
9be3f1dfa9 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 22:34:11 -07:00
stephb9959
2249367696 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 22:23:46 -07:00
stephb9959
b68af82771 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 22:12:55 -07:00
stephb9959
884d2e323b Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 16:02:31 -07:00
stephb9959
5a21b6f197 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 15:53:41 -07:00
stephb9959
62c0178aa9 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 15:17:39 -07:00
stephb9959
041452cf93 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 15:00:57 -07:00
stephb9959
89ebaf78bc Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 14:45:10 -07:00
stephb9959
295a6496ef Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 14:13:48 -07:00
stephb9959
48fb10bcec Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 13:36:59 -07:00
stephb9959
525e464592 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 12:28:52 -07:00
stephb9959
5f20866a31 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 12:27:51 -07:00
stephb9959
05f60cd08b Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 11:57:45 -07:00
stephb9959
bd7b56757d Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 11:50:41 -07:00
stephb9959
bc3c85fe2d Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 11:37:41 -07:00
stephb9959
22c87decdc Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 11:18:53 -07:00
stephb9959
d13216e0e2 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 11:17:52 -07:00
stephb9959
992d977312 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-17 11:13:04 -07:00
stephb9959
9cb789d0b0 Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-16 23:35:09 -07:00
stephb9959
b4e9747bfa Feature: venue-broadcast
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-07-16 22:44:33 -07:00
17 changed files with 436 additions and 189 deletions

View File

@@ -118,7 +118,7 @@ add_executable( owgw
src/TelemetryStream.cpp src/TelemetryStream.h
src/framework/ConfigurationValidator.cpp src/framework/ConfigurationValidator.h
src/ConfigurationCache.h
src/CapabilitiesCache.h src/FindCountry.h src/rttys/RTTYS_server.cpp src/rttys/RTTYS_server.h src/rttys/RTTYS_device.cpp src/rttys/RTTYS_device.h src/rttys/RTTYS_ClientConnection.cpp src/rttys/RTTYS_ClientConnection.h src/rttys/RTTYS_WebServer.cpp src/rttys/RTTYS_WebServer.h src/RESTAPI/RESTAPI_device_helper.h src/SDKcalls.cpp src/SDKcalls.h src/StateUtils.cpp src/StateUtils.h src/WS_ReactorPool.h src/WS_Connection.h src/WS_Connection.cpp src/TelemetryClient.h src/TelemetryClient.cpp src/RESTAPI/RESTAPI_iptocountry_handler.cpp src/RESTAPI/RESTAPI_iptocountry_handler.h src/framework/ow_constants.h src/GwWebSocketClient.cpp src/GwWebSocketClient.h src/framework/WebSocketClientNotifications.h src/RADIUS_proxy_server.cpp src/RADIUS_proxy_server.h src/RESTAPI/RESTAPI_radiusProxyConfig_handler.cpp src/RESTAPI/RESTAPI_radiusProxyConfig_handler.h src/ParseWifiScan.h src/RADIUS_helpers.h)
src/CapabilitiesCache.h src/FindCountry.h src/rttys/RTTYS_server.cpp src/rttys/RTTYS_server.h src/rttys/RTTYS_device.cpp src/rttys/RTTYS_device.h src/rttys/RTTYS_ClientConnection.cpp src/rttys/RTTYS_ClientConnection.h src/rttys/RTTYS_WebServer.cpp src/rttys/RTTYS_WebServer.h src/RESTAPI/RESTAPI_device_helper.h src/SDKcalls.cpp src/SDKcalls.h src/StateUtils.cpp src/StateUtils.h src/WS_ReactorPool.h src/WS_Connection.h src/WS_Connection.cpp src/TelemetryClient.h src/TelemetryClient.cpp src/RESTAPI/RESTAPI_iptocountry_handler.cpp src/RESTAPI/RESTAPI_iptocountry_handler.h src/framework/ow_constants.h src/GwWebSocketClient.cpp src/GwWebSocketClient.h src/framework/WebSocketClientNotifications.h src/RADIUS_proxy_server.cpp src/RADIUS_proxy_server.h src/RESTAPI/RESTAPI_radiusProxyConfig_handler.cpp src/RESTAPI/RESTAPI_radiusProxyConfig_handler.h src/ParseWifiScan.h src/RADIUS_helpers.h src/VenueBroadcaster.h src/sdks/sdk_prov.h)
if(NOT SMALL_BUILD)

View File

@@ -184,6 +184,21 @@ The device should answer:
}
```
#### Device requests a venue broadcast message
Device send this message when it wants to reach out to all other APs in the same venue. The GW will find the
venue where this device belongs and resend the same message to all other devices in the venue.
```json
{ "jsonrpc" : "2.0" ,
"method" : "venue_broadcast" ,
"params" : {
"serial" : <serial number> ,
"timestamp" : <the UTC timestamp when the message was sent>,
"data" : <an opaque string from the AP. This could be Zipped and so on and most likely base64 encoded>
}
}
```
Upon receiving a `venue_broadcast` message, the GW will simply resent the message to all the APs in the venue.
### Controller commands
Most controller commands include a `when` member. This is a UTC clock time asking the AP
to perform the command at that time. This is a suggestion only. The AP may ignore this

2
build
View File

@@ -1 +1 @@
144
151

View File

@@ -39,6 +39,10 @@ if [[ "$TEMPLATE_CONFIG" = 'true' ]]; then
SYSTEM_URI_PUBLIC=${SYSTEM_URI_PUBLIC:-"https://localhost:16002"} \
SYSTEM_URI_UI=${SYSTEM_URI_UI:-"http://localhost"} \
SIMULATORID=${SIMULATORID:-""} \
IPTOCOUNTRY_PROVIDER=${IPTOCOUNTRY_PROVIDER:-"ipinfo"} \
IPTOCOUNTRY_IPINFO_TOKEN=${IPTOCOUNTRY_IPINFO_TOKEN:-""} \
IPTOCOUNTRY_IPDATA_APIKEY=${IPTOCOUNTRY_IPDATA_APIKEY:-""} \
AUTOPROVISIONING_PROCESS=${AUTOPROVISIONING_PROCESS:-"prov,default"} \
RTTY_INTERNAL=${RTTY_INTERNAL:-"true"} \
RTTY_ENABLED=${RTTY_ENABLED:-"true"} \
RTTY_SERVER=${RTTY_SERVER:-"localhost"} \

View File

@@ -9,7 +9,7 @@ fullnameOverride: ""
images:
owgw:
repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owgw
tag: v2.6.0
tag: v2.6.2
pullPolicy: Always
# regcred:
# registry: tip-tip-wlan-cloud-ucentral.jfrog.io

View File

@@ -52,8 +52,8 @@ openwifi.fileuploader.host.0.cert = ${FILEUPLOADER_HOST_CERT}
openwifi.fileuploader.host.0.key = ${FILEUPLOADER_HOST_KEY}
openwifi.fileuploader.host.0.key.password = ${FILEUPLOADER_HOST_KEY_PASSWORD}
openwifi.fileuploader.path = ${FILEUPLOADER_PATH}
openwifi.fileuploader.uri = ${FILEUPLOADER_URI}
openwifi.fileuploader.maxsize = 10000
openwifi.fileuploader.uri = ${FILEUPLOADER_URI}
#
# Generic section that all microservices must have
@@ -75,8 +75,13 @@ openwifi.devicetypes.0 = AP:linksys_ea8300,edgecore_eap101,linksys_e8450-ubi
openwifi.devicetypes.1 = SWITCH:edgecore_ecs4100-12ph
openwifi.devicetypes.2 = IOT:esp32
oui.download.uri = https://standards-oui.ieee.org/oui/oui.txt
firmware.autoupdate.policy.default = auto
simulatorid = ${SIMULATORID}
iptocountry.default = US
iptocountry.provider = ${IPTOCOUNTRY_PROVIDER}
iptocountry.ipinfo.token = ${IPTOCOUNTRY_IPINFO_TOKEN}
iptocountry.ipdata.apikey = ${IPTOCOUNTRY_IPDATA_APIKEY}
autoprovisioning.process = ${AUTOPROVISIONING_PROCESS}
#
# rtty
@@ -108,6 +113,7 @@ openwifi.kafka.enable = ${KAFKA_ENABLE}
openwifi.kafka.brokerlist = ${KAFKA_BROKERLIST}
openwifi.kafka.auto.commit = false
openwifi.kafka.queue.buffering.max.ms = 50
openwifi.kafka.ssl.ca.location = ${KAFKA_SSL_CA_LOCATION}
openwifi.kafka.ssl.certificate.location = ${KAFKA_SSL_CERTIFICATE_LOCATION}
openwifi.kafka.ssl.key.location = ${KAFKA_SSL_KEY_LOCATION}

View File

@@ -25,6 +25,7 @@
#include "FindCountry.h"
#include "rttys/RTTYS_server.h"
#include "RADIUS_proxy_server.h"
#include "VenueBroadcaster.h"
namespace OpenWifi {
class Daemon *Daemon::instance() {
@@ -47,7 +48,8 @@ namespace OpenWifi {
TelemetryStream(),
RTTYS_server(),
WebSocketServer(),
RADIUS_proxy_server()
RADIUS_proxy_server(),
VenueBroadcaster()
});
return &instance;
}

View File

@@ -1741,7 +1741,6 @@ namespace OpenWifi {
std::cout << "Start of parsing wifi" << std::endl;
if (D.contains("status")) {
auto Status = D["status"];
if (Status.contains("scan") && Status["scan"].is_array()) {
nlohmann::json ScanArray = Status["scan"];
nlohmann::json ParsedScan = nlohmann::json::array();

142
src/VenueBroadcaster.h Normal file
View File

@@ -0,0 +1,142 @@
//
// Created by stephane bourque on 2022-07-16.
//
#pragma once
#include "framework/MicroService.h"
#include "sdks/sdk_prov.h"
#include "DeviceRegistry.h"
namespace OpenWifi {
class VenueBroadcastNotification : public Poco::Notification {
public:
VenueBroadcastNotification(const std::string &SourceSerialNumber, const std::string &Data, uint64_t TimeStamp) :
SourceSerialNumber_(SourceSerialNumber),
Data_(Data),
TimeStamp_(TimeStamp) {
}
std::string SourceSerialNumber_;
std::string Data_;
uint64_t TimeStamp_=OpenWifi::Now();
};
class VenueBroadcaster : public SubSystemServer, Poco::Runnable {
public:
static auto instance() {
static auto instance_ = new VenueBroadcaster;
return instance_;
}
inline int Start() override {
Enabled_ = MicroService::instance().ConfigGetBool("venue_broadcast.enabled",true);
if(Enabled_) {
BroadcastManager_.start(*this);
}
return 0;
}
inline void Stop() override {
if(Enabled_ && Running_) {
BroadcastQueue_.wakeUpAll();
BroadcastManager_.wakeUp();
BroadcastManager_.join();
}
}
inline void reinitialize([[maybe_unused]] Poco::Util::Application &self) override {
Logger().information("Reinitializing.");
}
struct VenueInfo {
uint64_t timestamp=OpenWifi::Now();
Types::StringVec serialNumbers;
};
inline bool FindSerialNumberList(const std::string &Source, OpenWifi::Types::StringVec & SerialNumbers) {
// Can we find our serial number in any of the lists so far...
for(const auto &venue:Venues_) {
auto entry = std::find(venue.second.serialNumbers.begin(),venue.second.serialNumbers.end(),Source);
if(entry!=venue.second.serialNumbers.end() && (OpenWifi::Now()-venue.second.timestamp)<600) {
SerialNumbers = venue.second.serialNumbers;
auto entry2 = std::find(SerialNumbers.begin(),SerialNumbers.end(),Source);
SerialNumbers.erase(entry2);
return true;
}
}
// get the venue from Prov and the serial numbers.
Types::UUID_t Venue;
Types::StringVec TmpSerialNumbers;
if(OpenWifi::SDK::Prov::GetSerialNumbersForVenueOfSerialNumber(Source,Venue,TmpSerialNumbers,Logger())) {
std::sort(TmpSerialNumbers.begin(),TmpSerialNumbers.end());
VenueInfo V{.timestamp=OpenWifi::Now(), .serialNumbers=TmpSerialNumbers};
Venues_[Venue] = V;
auto p = std::find(TmpSerialNumbers.begin(),TmpSerialNumbers.end(),Source);
if(p!=TmpSerialNumbers.end()) {
TmpSerialNumbers.erase(p);
SerialNumbers = TmpSerialNumbers;
return true;
}
}
return false;
}
inline void SendToDevice(const std::string &SerialNumber,const std::string &Payload) {
DeviceRegistry()->SendFrame(SerialNumber,Payload);
}
inline void run() final {
Running_ = true;
Utils::SetThreadName("venue-bcast");
Poco::AutoPtr<Poco::Notification> NextNotification(BroadcastQueue_.waitDequeueNotification());
while (NextNotification && Running_) {
auto Notification = dynamic_cast<VenueBroadcastNotification *>(NextNotification.get());
if (Notification != nullptr) {
Types::StringVec SerialNumbers;
if(FindSerialNumberList(Notification->SourceSerialNumber_,SerialNumbers)) {
Poco::JSON::Object Payload;
Payload.set("jsonrpc","2.0");
Payload.set("method","venue_broadcast");
Poco::JSON::Object ParamBlock;
ParamBlock.set("serial",Notification->SourceSerialNumber_);
ParamBlock.set("timestamp",Notification->TimeStamp_);
ParamBlock.set("data",Notification->Data_);
Payload.set("params", ParamBlock);
std::ostringstream o;
Payload.stringify(o);
for(const auto &Device:SerialNumbers) {
SendToDevice(Device,o.str());
}
}
}
NextNotification = BroadcastQueue_.waitDequeueNotification();
}
Running_=false;
}
inline void Broadcast(const std::string &SourceSerial, const std::string &Data, uint64_t TimeStamp) {
BroadcastQueue_.enqueueNotification(new VenueBroadcastNotification(SourceSerial,Data,TimeStamp));
}
private:
std::atomic_bool Running_=false;
bool Enabled_=false;
Poco::NotificationQueue BroadcastQueue_;
Poco::Thread BroadcastManager_;
std::map<OpenWifi::Types::UUID_t,VenueInfo> Venues_;
VenueBroadcaster() noexcept:
SubSystemServer("VenueBroadcaster", "VENUE-BCAST", "venue.broacast")
{
}
};
inline auto VenueBroadcaster() { return VenueBroadcaster::instance(); }
}

View File

@@ -5,11 +5,13 @@
#include "WS_Connection.h"
#include "Poco/Net/SecureStreamSocketImpl.h"
#include "Poco/Net/SecureServerSocketImpl.h"
#include "Poco/Net/HTTPServerResponseImpl.h"
#include "Poco/Net/HTTPServerSession.h"
#include "Poco/Net/HTTPServerRequestImpl.h"
#include "Poco/Net/NetException.h"
#include "Poco/Net/SSLException.h"
#include "Poco/Net/Context.h"
#include "Poco/Base64Decoder.h"
#include "Poco/Base64Encoder.h"
@@ -24,6 +26,7 @@
#include "TelemetryStream.h"
#include "CentralConfig.h"
#include "FindCountry.h"
#include "VenueBroadcaster.h"
#include "framework/WebSocketClientNotifications.h"
#include "RADIUS_proxy_server.h"
@@ -358,7 +361,8 @@ namespace OpenWifi {
auto Firmware = ParamsObj->get(uCentralProtocol::FIRMWARE).toString();
auto Capabilities = ParamsObj->get(uCentralProtocol::CAPABILITIES).toString();
SerialNumber_ = Serial;
//// change this
CN_ = SerialNumber_ = Serial;
SerialNumberInt_ = Utils::SerialNumberToInt(SerialNumber_);
Conn_ = DeviceRegistry()->Register(SerialNumberInt_, this, ConnectionId_);
Conn_->Conn_.UUID = UUID;
@@ -753,6 +757,14 @@ namespace OpenWifi {
}
} break;
case uCentralProtocol::Events::ET_VENUEBROADCAST: {
if(ParamsObj->has("data") && ParamsObj->has("serial") && ParamsObj->has("timestamp")) {
VenueBroadcaster()->Broadcast(
ParamsObj->get("serial").toString(),
ParamsObj->get("data").toString(),
ParamsObj->get("timestamp"));
}
} break;
// this will never be called but some compilers will complain if we do not have a case for
// every single values of an enum
case uCentralProtocol::Events::ET_UNKNOWN: {

View File

@@ -17,81 +17,81 @@
namespace OpenWifi {
class WSConnection {
static constexpr int BufSize = 128000;
public:
WSConnection(Poco::Net::StreamSocket& Socket, Poco::Net::SocketReactor& Reactor);
~WSConnection();
class WSConnection {
static constexpr int BufSize = 128000;
public:
WSConnection(Poco::Net::StreamSocket& Socket, Poco::Net::SocketReactor& Reactor);
~WSConnection();
void ProcessJSONRPCEvent(Poco::JSON::Object::Ptr & Doc);
void ProcessJSONRPCResult(Poco::JSON::Object::Ptr Doc);
void ProcessIncomingFrame();
void ProcessIncomingRadiusData(const Poco::JSON::Object::Ptr &Doc);
void ProcessJSONRPCEvent(Poco::JSON::Object::Ptr & Doc);
void ProcessJSONRPCResult(Poco::JSON::Object::Ptr Doc);
void ProcessIncomingFrame();
void ProcessIncomingRadiusData(const Poco::JSON::Object::Ptr &Doc);
bool Send(const std::string &Payload);
bool Send(const std::string &Payload);
bool SendRadiusAuthenticationData(const unsigned char * buffer, std::size_t size);
bool SendRadiusAccountingData(const unsigned char * buffer, std::size_t size);
bool SendRadiusCoAData(const unsigned char * buffer, std::size_t size);
bool SendRadiusAuthenticationData(const unsigned char * buffer, std::size_t size);
bool SendRadiusAccountingData(const unsigned char * buffer, std::size_t size);
bool SendRadiusCoAData(const unsigned char * buffer, std::size_t size);
void OnSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
void OnSocketShutdown(const Poco::AutoPtr<Poco::Net::ShutdownNotification>& pNf);
void OnSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification>& pNf);
bool LookForUpgrade(const uint64_t UUID, uint64_t & UpgradedUUID);
static bool ExtractBase64CompressedData(const std::string & CompressedData, std::string & UnCompressedData, uint64_t compress_sz);
void LogException(const Poco::Exception &E);
inline Poco::Logger & Logger() { return Logger_; }
bool SetWebSocketTelemetryReporting(uint64_t interval, uint64_t TelemetryWebSocketTimer);
bool SetKafkaTelemetryReporting(uint64_t interval, uint64_t TelemetryKafkaTimer);
bool StopWebSocketTelemetry();
bool StopKafkaTelemetry();
inline bool GetTelemetryParameters(bool & Reporting, uint64_t & Interval,
uint64_t & WebSocketTimer, uint64_t & KafkaTimer,
uint64_t &WebSocketCount, uint64_t & KafkaCount,
uint64_t &WebSocketPackets,
uint64_t &KafkaPackets ) const {
Reporting = TelemetryReporting_;
WebSocketTimer = TelemetryWebSocketTimer_;
KafkaTimer = TelemetryKafkaTimer_;
WebSocketCount = TelemetryWebSocketRefCount_;
KafkaCount = TelemetryKafkaRefCount_;
Interval = TelemetryInterval_;
WebSocketPackets = TelemetryWebSocketPackets_;
KafkaPackets = TelemetryKafkaPackets_;
return true;
}
void OnSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
void OnSocketShutdown(const Poco::AutoPtr<Poco::Net::ShutdownNotification>& pNf);
void OnSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification>& pNf);
bool LookForUpgrade(const uint64_t UUID, uint64_t & UpgradedUUID);
static bool ExtractBase64CompressedData(const std::string & CompressedData, std::string & UnCompressedData, uint64_t compress_sz);
void LogException(const Poco::Exception &E);
inline Poco::Logger & Logger() { return Logger_; }
bool SetWebSocketTelemetryReporting(uint64_t interval, uint64_t TelemetryWebSocketTimer);
bool SetKafkaTelemetryReporting(uint64_t interval, uint64_t TelemetryKafkaTimer);
bool StopWebSocketTelemetry();
bool StopKafkaTelemetry();
inline bool GetTelemetryParameters(bool & Reporting, uint64_t & Interval,
uint64_t & WebSocketTimer, uint64_t & KafkaTimer,
uint64_t &WebSocketCount, uint64_t & KafkaCount,
uint64_t &WebSocketPackets,
uint64_t &KafkaPackets ) const {
Reporting = TelemetryReporting_;
WebSocketTimer = TelemetryWebSocketTimer_;
KafkaTimer = TelemetryKafkaTimer_;
WebSocketCount = TelemetryWebSocketRefCount_;
KafkaCount = TelemetryKafkaRefCount_;
Interval = TelemetryInterval_;
WebSocketPackets = TelemetryWebSocketPackets_;
KafkaPackets = TelemetryKafkaPackets_;
return true;
}
private:
std::recursive_mutex Mutex_;
Poco::Logger &Logger_;
Poco::Net::StreamSocket Socket_;
Poco::Net::SocketReactor & Reactor_;
std::unique_ptr<Poco::Net::WebSocket> WS_;
std::string SerialNumber_;
uint64_t SerialNumberInt_=0;
std::string Compatible_;
std::shared_ptr<DeviceRegistry::ConnectionEntry> Conn_;
volatile bool Registered_ = false ;
std::string CId_;
std::string CN_;
GWObjects::CertificateValidation CertValidation_ = GWObjects::CertificateValidation::NO_CERTIFICATE;
uint64_t Errors_=0;
volatile bool Connected_=false;
uint64_t ConnectionId_=0;
Poco::Net::IPAddress PeerAddress_;
volatile std::atomic_bool TelemetryReporting_ = false;
volatile uint64_t TelemetryWebSocketRefCount_ = 0;
volatile uint64_t TelemetryKafkaRefCount_ = 0;
uint64_t TelemetryWebSocketTimer_ = 0;
uint64_t TelemetryKafkaTimer_ = 0 ;
uint64_t TelemetryInterval_ = 0;
volatile uint64_t TelemetryWebSocketPackets_=0;
volatile uint64_t TelemetryKafkaPackets_=0;
private:
std::recursive_mutex Mutex_;
Poco::Logger &Logger_;
Poco::Net::StreamSocket Socket_;
Poco::Net::SocketReactor & Reactor_;
std::unique_ptr<Poco::Net::WebSocket> WS_;
std::string SerialNumber_;
uint64_t SerialNumberInt_=0;
std::string Compatible_;
std::shared_ptr<DeviceRegistry::ConnectionEntry> Conn_;
volatile bool Registered_ = false ;
std::string CId_;
std::string CN_;
GWObjects::CertificateValidation CertValidation_ = GWObjects::CertificateValidation::NO_CERTIFICATE;
uint64_t Errors_=0;
volatile bool Connected_=false;
uint64_t ConnectionId_=0;
Poco::Net::IPAddress PeerAddress_;
volatile std::atomic_bool TelemetryReporting_ = false;
volatile uint64_t TelemetryWebSocketRefCount_ = 0;
volatile uint64_t TelemetryKafkaRefCount_ = 0;
uint64_t TelemetryWebSocketTimer_ = 0;
uint64_t TelemetryKafkaTimer_ = 0 ;
uint64_t TelemetryInterval_ = 0;
volatile uint64_t TelemetryWebSocketPackets_=0;
volatile uint64_t TelemetryKafkaPackets_=0;
void CompleteStartup();
bool StartTelemetry();
bool StopTelemetry();
void UpdateCounts();
};
void CompleteStartup();
bool StartTelemetry();
bool StopTelemetry();
void UpdateCounts();
};
}

View File

@@ -8,75 +8,77 @@
#include "Poco/Net/HTTPHeaderStream.h"
#include "Poco/JSON/Array.h"
#include "Poco/Net/Context.h"
#include "ConfigurationCache.h"
#include "TelemetryStream.h"
#include "WS_Server.h"
#include <openssl/ssl.h>
namespace OpenWifi {
bool WebSocketServer::ValidateCertificate(const std::string & ConnectionId, const Poco::Crypto::X509Certificate & Certificate) {
if(IsCertOk()) {
Logger().debug(fmt::format("CERTIFICATE({}): issuer='{}' cn='{}'", ConnectionId, Certificate.issuerName(),Certificate.commonName()));
if(!Certificate.issuedBy(*IssuerCert_)) {
Logger().debug(fmt::format("CERTIFICATE({}): issuer mismatch. Local='{}' Incoming='{}'", ConnectionId, IssuerCert_->issuerName(), Certificate.issuerName()));
return false;
}
return true;
bool WebSocketServer::ValidateCertificate(const std::string & ConnectionId, const Poco::Crypto::X509Certificate & Certificate) {
if(IsCertOk()) {
Logger().debug(fmt::format("CERTIFICATE({}): issuer='{}' cn='{}'", ConnectionId, Certificate.issuerName(),Certificate.commonName()));
if(!Certificate.issuedBy(*IssuerCert_)) {
Logger().debug(fmt::format("CERTIFICATE({}): issuer mismatch. Local='{}' Incoming='{}'", ConnectionId, IssuerCert_->issuerName(), Certificate.issuerName()));
return false;
}
return false;
return true;
}
return false;
}
int WebSocketServer::Start() {
// ReactorPool_.Start("DeviceReactorPool_");
for(const auto & Svr : ConfigServersList_ ) {
Logger().notice( fmt::format("Starting: {}:{} Keyfile:{} CertFile: {}",
Svr.Address(),
Svr.Port(),
Svr.KeyFile(),Svr.CertFile()));
Svr.LogCert(Logger());
if(!Svr.RootCA().empty())
Svr.LogCas(Logger());
auto Sock{Svr.CreateSecureSocket(Logger())};
if(!IsCertOk()) {
IssuerCert_ = std::make_unique<Poco::Crypto::X509Certificate>(Svr.IssuerCertFile());
Logger().information( fmt::format("Certificate Issuer Name:{}",IssuerCert_->issuerName()));
}
auto NewSocketAcceptor = std::make_unique<ws_server_reactor_type_t>(Sock, Reactor_); // , 2 /*Poco::Environment::processorCount()*2) */ );
Acceptors_.push_back(std::move(NewSocketAcceptor));
}
int WebSocketServer::Start() {
// ReactorPool_.Start("DeviceReactorPool_");
for(const auto & Svr : ConfigServersList_ ) {
Logger().notice( fmt::format("Starting: {}:{} Keyfile:{} CertFile: {}",
Svr.Address(),
Svr.Port(),
Svr.KeyFile(),Svr.CertFile()));
Svr.LogCert(Logger());
if(!Svr.RootCA().empty())
Svr.LogCas(Logger());
auto Sock{Svr.CreateSecureSocket(Logger())};
if(!IsCertOk()) {
IssuerCert_ = std::make_unique<Poco::Crypto::X509Certificate>(Svr.IssuerCertFile());
Logger().information( fmt::format("Certificate Issuer Name:{}",IssuerCert_->issuerName()));
}
auto NewSocketAcceptor = std::make_unique<ws_server_reactor_type_t>(Sock, Reactor_); // , 2 /*Poco::Environment::processorCount()*2) */ );
Acceptors_.push_back(std::move(NewSocketAcceptor));
}
auto ProvString = MicroService::instance().ConfigGetString("autoprovisioning.process","default");
if(ProvString!="default") {
auto Tokens = Poco::StringTokenizer(ProvString, ",");
for (const auto &i : Tokens) {
if (i == "prov")
LookAtProvisioning_ = true;
else
UseDefaultConfig_ = true;
}
} else {
UseDefaultConfig_ = true;
auto ProvString = MicroService::instance().ConfigGetString("autoprovisioning.process","default");
if(ProvString!="default") {
auto Tokens = Poco::StringTokenizer(ProvString, ",");
for (const auto &i : Tokens) {
if (i == "prov")
LookAtProvisioning_ = true;
else
UseDefaultConfig_ = true;
}
} else {
UseDefaultConfig_ = true;
}
SimulatorId_ = MicroService::instance().ConfigGetString("simulatorid","");
SimulatorEnabled_ = !SimulatorId_.empty();
SimulatorId_ = MicroService::instance().ConfigGetString("simulatorid","");
SimulatorEnabled_ = !SimulatorId_.empty();
ReactorThread_.setStackSize(3000000);
ReactorThread_.start(Reactor_);
Utils::SetThreadName(ReactorThread_,"device-reactor");
ReactorThread_.setStackSize(3000000);
ReactorThread_.start(Reactor_);
Utils::SetThreadName(ReactorThread_,"device-reactor");
return 0;
}
return 0;
}
void WebSocketServer::Stop() {
Logger().notice("Stopping reactors...");
// ReactorPool_.Stop();
Reactor_.stop();
ReactorThread_.join();
}
void WebSocketServer::Stop() {
Logger().notice("Stopping reactors...");
// ReactorPool_.Stop();
Reactor_.stop();
ReactorThread_.join();
}
} //namespace
} //namespace

View File

@@ -25,52 +25,52 @@
namespace OpenWifi {
class WebSocketServer : public SubSystemServer {
public:
static auto instance() {
static auto instance_ = new WebSocketServer;
return instance_;
}
class WebSocketServer : public SubSystemServer {
public:
static auto instance() {
static auto instance_ = new WebSocketServer;
return instance_;
}
int Start() override;
void Stop() override;
bool IsCertOk() { return IssuerCert_!= nullptr; }
bool ValidateCertificate(const std::string & ConnectionId, const Poco::Crypto::X509Certificate & Certificate);
// Poco::Net::SocketReactor & GetNextReactor() { return ReactorPool_.NextReactor(); }
int Start() override;
void Stop() override;
bool IsCertOk() { return IssuerCert_!= nullptr; }
bool ValidateCertificate(const std::string & ConnectionId, const Poco::Crypto::X509Certificate & Certificate);
// Poco::Net::SocketReactor & GetNextReactor() { return ReactorPool_.NextReactor(); }
inline bool IsSimSerialNumber(const std::string & SerialNumber) const {
return IsSim(SerialNumber) && SerialNumber == SimulatorId_;
}
inline bool IsSimSerialNumber(const std::string & SerialNumber) const {
return IsSim(SerialNumber) && SerialNumber == SimulatorId_;
}
inline static bool IsSim(const std::string & SerialNumber) {
return SerialNumber.substr(0,6) == "53494d";
}
inline static bool IsSim(const std::string & SerialNumber) {
return SerialNumber.substr(0,6) == "53494d";
}
inline bool IsSimEnabled() const {
return SimulatorEnabled_;
}
inline bool IsSimEnabled() const {
return SimulatorEnabled_;
}
inline bool UseProvisioning() const { return LookAtProvisioning_; }
inline bool UseDefaults() const { return UseDefaultConfig_; }
inline bool UseProvisioning() const { return LookAtProvisioning_; }
inline bool UseDefaults() const { return UseDefaultConfig_; }
private:
std::unique_ptr<Poco::Crypto::X509Certificate> IssuerCert_;
// typedef std::unique_ptr<Poco::Net::ParallelSocketAcceptor<WSConnection, Poco::Net::SocketReactor>> ws_server_reactor_type_t;
typedef Poco::Net::SocketAcceptor<WSConnection> ws_server_reactor_type_t;
std::vector<std::unique_ptr<ws_server_reactor_type_t>> Acceptors_;
Poco::Net::SocketReactor Reactor_;
Poco::Thread ReactorThread_;
std::string SimulatorId_;
bool LookAtProvisioning_ = false;
bool UseDefaultConfig_ = true;
bool SimulatorEnabled_=false;
private:
std::unique_ptr<Poco::Crypto::X509Certificate> IssuerCert_;
// typedef std::unique_ptr<Poco::Net::ParallelSocketAcceptor<WSConnection, Poco::Net::SocketReactor>> ws_server_reactor_type_t;
typedef Poco::Net::SocketAcceptor<WSConnection> ws_server_reactor_type_t;
std::vector<std::unique_ptr<ws_server_reactor_type_t>> Acceptors_;
Poco::Net::SocketReactor Reactor_;
Poco::Thread ReactorThread_;
std::string SimulatorId_;
bool LookAtProvisioning_ = false;
bool UseDefaultConfig_ = true;
bool SimulatorEnabled_=false;
WebSocketServer() noexcept:
SubSystemServer("WebSocketServer", "WS-SVR", "ucentral.websocket") {
WebSocketServer() noexcept:
SubSystemServer("WebSocketServer", "WS-SVR", "ucentral.websocket") {
}
};
}
};
inline auto WebSocketServer() { return WebSocketServer::instance(); }
inline auto WebSocketServer() { return WebSocketServer::instance(); }
} //namespace
} //namespace

View File

@@ -3264,7 +3264,12 @@ namespace OpenWifi {
return Poco::Logger::get(Name);
}
static inline void Exit(int Reason);
virtual void GetExtraConfiguration(Poco::JSON::Object & Cfg) {
Cfg.set("additionalConfiguration",false);
}
static inline void Exit(int Reason);
inline void BusMessageReceived(const std::string &Key, const std::string & Payload);
inline MicroServiceMetaVec GetServices(const std::string & Type);
inline MicroServiceMetaVec GetServices();
@@ -4355,6 +4360,11 @@ namespace OpenWifi {
Answer.set("certificates", Certificates);
return ReturnObject(Answer);
}
if(GetBoolParameter("extraConfiguration")) {
Poco::JSON::Object Answer;
MicroService::instance().GetExtraConfiguration(Answer);
return ReturnObject(Answer);
}
BadRequest(RESTAPI::Errors::InvalidCommand);
}

View File

@@ -445,6 +445,7 @@ namespace OpenWifi::uCentralProtocol::Events {
static const char *RECOVERY = "recovery";
static const char *TELEMETRY = "telemetry";
static const char *DEVICEUPDATE = "deviceupdate";
static const char *VENUE_BROADCAST = "venue_broadcast";
enum EVENT_MSG {
ET_UNKNOWN,
@@ -457,7 +458,8 @@ namespace OpenWifi::uCentralProtocol::Events {
ET_CFGPENDING,
ET_RECOVERY,
ET_DEVICEUPDATE,
ET_TELEMETRY
ET_TELEMETRY,
ET_VENUEBROADCAST
};
inline EVENT_MSG EventFromString(const std::string & Method) {
@@ -481,6 +483,8 @@ namespace OpenWifi::uCentralProtocol::Events {
return ET_RECOVERY;
else if(strcmp(TELEMETRY,Method.c_str())==0)
return ET_TELEMETRY;
else if(strcmp(VENUE_BROADCAST,Method.c_str())==0)
return ET_VENUEBROADCAST;
return ET_UNKNOWN;
};
}

View File

@@ -23,19 +23,18 @@ namespace OpenWifi {
try {
valid_=true;
device_address_ = socket_.peerAddress();
if (MicroService::instance().NoAPISecurity()) {
poco_information(Logger(),"Unsecured connection.");
} else {
auto SS = dynamic_cast<Poco::Net::SecureStreamSocketImpl *>(socket_.impl());
while (true) {
auto V = SS->completeHandshake();
if (V == 1)
break;
}
if ((SS->secure())) {
poco_information(Logger(), "Secure connection.");
}
auto SS = dynamic_cast<Poco::Net::SecureStreamSocketImpl *>(socket_.impl());
while (true) {
auto V = SS->completeHandshake();
if (V == 1)
break;
}
if ((SS->secure())) {
poco_information(Logger(), "Secure connection.");
}
reactor_.addEventHandler(
socket_,
Poco::NObserver<RTTYS_Device_ConnectionHandler, Poco::Net::ReadableNotification>(
@@ -404,8 +403,8 @@ namespace OpenWifi {
}
bool RTTYS_Device_ConnectionHandler::do_msgTypeHeartbeat([[maybe_unused]] std::size_t msg_len) {
if(!RTTYS_server()->ValidClient(Id_))
return false;
// if(!RTTYS_server()->ValidClient(Id_))
// return false;
u_char MsgBuf[3]{0};
MsgBuf[0] = msgTypeHeartbeat;
return socket_.sendBytes(MsgBuf, 3)==3;

52
src/sdks/sdk_prov.h Normal file
View File

@@ -0,0 +1,52 @@
//
// Created by stephane bourque on 2022-07-16.
//
#pragma once
#include "framework/MicroService.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
namespace OpenWifi::SDK::Prov {
inline bool GetSerialNumbersForVenueOfSerialNumber( const std::string & SerialNumber, Types::UUID_t &Venue, Types::StringVec & AdjacentSerialNumbers , Poco::Logger &Logger ) {
OpenAPIRequestGet GetInventoryForSerialNumber( uSERVICE_PROVISIONING, "/api/v1/inventory/" + SerialNumber , {} , 30000);
auto CallResponse1 = Poco::makeShared<Poco::JSON::Object>();
if(!GetInventoryForSerialNumber.Do(CallResponse1,"")) {
Logger.error(fmt::format("{}: Cannot find serial number in inventory.", SerialNumber));
return false;
}
ProvObjects::InventoryTag Device;
if(!Device.from_json(CallResponse1)) {
Logger.error(fmt::format("{}: Invalid Inventory response.", SerialNumber));
return false;
}
Venue = Device.venue;
OpenAPIRequestGet GetInventoryForVenue( uSERVICE_PROVISIONING, "/api/v1/inventory" ,
{
{"serialOnly","true"},
{"venue", Venue}
}, 30000);
auto CallResponse2 = Poco::makeShared<Poco::JSON::Object>();
if(!GetInventoryForVenue.Do(CallResponse2,"")) {
Logger.error(fmt::format("{}: Cannot get inventory for venue.", SerialNumber));
return false;
}
try {
OpenWifi::RESTAPI_utils::field_from_json(CallResponse2, "serialNumbers",
AdjacentSerialNumbers);
} catch(...) {
Logger.error(fmt::format("{}: Cannot parse inventory list", SerialNumber));
return false;
}
return true;
}
}