diff --git a/CMakeLists.txt b/CMakeLists.txt index c7ae29b..3df317e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,7 @@ add_executable(owanalytics src/framework/MicroServiceExtra.h src/framework/ConfigurationValidator.cpp src/framework/ConfigurationValidator.h + src/framework/default_device_types.h src/RESTObjects/RESTAPI_SecurityObjects.h src/RESTObjects/RESTAPI_SecurityObjects.cpp src/RESTObjects/RESTAPI_GWobjects.h src/RESTObjects/RESTAPI_GWobjects.cpp src/RESTObjects/RESTAPI_FMSObjects.h src/RESTObjects/RESTAPI_FMSObjects.cpp diff --git a/build b/build index ca7bf83..3f10ffe 100644 --- a/build +++ b/build @@ -1 +1 @@ -13 \ No newline at end of file +15 \ No newline at end of file diff --git a/src/RESTObjects/RESTAPI_GWobjects.cpp b/src/RESTObjects/RESTAPI_GWobjects.cpp index 57ab524..7d42e74 100644 --- a/src/RESTObjects/RESTAPI_GWobjects.cpp +++ b/src/RESTObjects/RESTAPI_GWobjects.cpp @@ -13,6 +13,7 @@ #ifdef TIP_GATEWAY_SERVICE #include "AP_WS_Server.h" #include "CapabilitiesCache.h" +#include "RADIUSSessionTracker.h" #endif #include "RESTAPI_GWobjects.h" @@ -29,6 +30,7 @@ namespace OpenWifi::GWObjects { field_to_json(Obj, "serialNumber", SerialNumber); #ifdef TIP_GATEWAY_SERVICE field_to_json(Obj, "deviceType", CapabilitiesCache::instance()->GetPlatform(Compatible)); + field_to_json(Obj, "hasRADIUSSessions", RADIUSSessionTracker()->HasSessions(SerialNumber)); #endif field_to_json(Obj, "macAddress", MACAddress); field_to_json(Obj, "manufacturer", Manufacturer); @@ -54,6 +56,9 @@ namespace OpenWifi::GWObjects { field_to_json(Obj, "pendingConfiguration", pendingConfiguration); field_to_json(Obj, "pendingConfigurationCmd", pendingConfigurationCmd); field_to_json(Obj, "restrictionDetails", restrictionDetails); + field_to_json(Obj, "pendingUUID", pendingUUID); + field_to_json(Obj, "simulated", simulated); + field_to_json(Obj, "lastRecordedContact", lastRecordedContact); } void Device::to_json_with_status(Poco::JSON::Object &Obj) const { @@ -63,7 +68,7 @@ namespace OpenWifi::GWObjects { ConnectionState ConState; if (AP_WS_Server()->GetState(SerialNumber, ConState)) { - ConState.to_json(Obj); + ConState.to_json(SerialNumber,Obj); } else { field_to_json(Obj, "ipAddress", ""); field_to_json(Obj, "txBytes", (uint64_t)0); @@ -75,6 +80,13 @@ namespace OpenWifi::GWObjects { field_to_json(Obj, "associations_2G", (uint64_t)0); field_to_json(Obj, "associations_5G", (uint64_t)0); field_to_json(Obj, "associations_6G", (uint64_t)0); + field_to_json(Obj, "hasRADIUSSessions", false); + field_to_json(Obj, "hasGPS", ConState.hasGPS); + field_to_json(Obj, "sanity", ConState.sanity); + field_to_json(Obj, "memoryUsed", ConState.memoryUsed); + field_to_json(Obj, "sanity", ConState.sanity); + field_to_json(Obj, "load", ConState.load); + field_to_json(Obj, "temperature", ConState.temperature); } #endif } @@ -84,20 +96,32 @@ namespace OpenWifi::GWObjects { field_from_json(Obj, "serialNumber", SerialNumber); field_from_json(Obj, "deviceType", DeviceType); field_from_json(Obj, "macAddress", MACAddress); + field_from_json(Obj, "manufacturer", Manufacturer); + field_from_json(Obj, "UUID", UUID); field_from_json(Obj, "configuration", Configuration); field_from_json(Obj, "notes", Notes); - field_from_json(Obj, "manufacturer", Manufacturer); + field_from_json(Obj, "createdTimestamp", CreationTimestamp); + field_from_json(Obj, "lastConfigurationChange", LastConfigurationChange); + field_from_json(Obj, "lastConfigurationDownload", LastConfigurationDownload); + field_from_json(Obj, "lastFWUpdate", LastFWUpdate); field_from_json(Obj, "owner", Owner); field_from_json(Obj, "location", Location); field_from_json(Obj, "venue", Venue); + field_from_json(Obj, "firmware", Firmware); field_from_json(Obj, "compatible", Compatible); + field_from_json(Obj, "fwUpdatePolicy", FWUpdatePolicy); + field_from_json(Obj, "devicePassword", DevicePassword); field_from_json(Obj, "subscriber", subscriber); field_from_json(Obj, "entity", entity); + field_from_json(Obj, "modified", modified); field_from_json(Obj, "locale", locale); field_from_json(Obj, "restrictedDevice", restrictedDevice); field_from_json(Obj, "pendingConfiguration", pendingConfiguration); field_from_json(Obj, "pendingConfigurationCmd", pendingConfigurationCmd); field_from_json(Obj, "restrictionDetails", restrictionDetails); + field_from_json(Obj, "pendingUUID", pendingUUID); + field_from_json(Obj, "simulated", simulated); + field_from_json(Obj, "lastRecordedContact", lastRecordedContact); return true; } catch (const Poco::Exception &E) { } @@ -165,6 +189,8 @@ namespace OpenWifi::GWObjects { field_to_json(Obj, "waitingForFile", WaitingForFile); field_to_json(Obj, "attachFile", AttachDate); field_to_json(Obj, "executionTime", executionTime); + field_to_json(Obj, "lastTry", lastTry); + field_to_json(Obj, "deferred", deferred); } bool DefaultConfiguration::from_json(const Poco::JSON::Object::Ptr &Obj) { @@ -198,7 +224,7 @@ namespace OpenWifi::GWObjects { return false; } - void ConnectionState::to_json(Poco::JSON::Object &Obj) const { + void ConnectionState::to_json([[maybe_unused]] const std::string &SerialNumber, Poco::JSON::Object &Obj) { field_to_json(Obj, "ipAddress", Address); field_to_json(Obj, "txBytes", TX); field_to_json(Obj, "rxBytes", RX); @@ -220,6 +246,20 @@ namespace OpenWifi::GWObjects { field_to_json(Obj, "connectionCompletionTime", connectionCompletionTime); field_to_json(Obj, "totalConnectionTime", Utils::Now() - started); field_to_json(Obj, "certificateExpiryDate", certificateExpiryDate); +#ifdef TIP_GATEWAY_SERVICE + hasRADIUSSessions = RADIUSSessionTracker()->HasSessions(SerialNumber); + AP_WS_Server()->ExtendedAttributes(SerialNumber, hasGPS, sanity, + memoryUsed, + load, + temperature); +#endif + field_to_json(Obj, "hasRADIUSSessions", hasRADIUSSessions ); + field_to_json(Obj, "hasGPS", hasGPS); + field_to_json(Obj, "sanity", sanity); + field_to_json(Obj, "memoryUsed", memoryUsed); + field_to_json(Obj, "sanity", sanity); + field_to_json(Obj, "load", load); + field_to_json(Obj, "temperature", temperature); switch (VerifiedCertificate) { case NO_CERTIFICATE: @@ -234,6 +274,9 @@ namespace OpenWifi::GWObjects { case VERIFIED: field_to_json(Obj, "verifiedCertificate", "VERIFIED"); break; + case SIMULATED: + field_to_json(Obj, "verifiedCertificate", "SIMULATED"); + break; default: field_to_json(Obj, "verifiedCertificate", "NO_CERTIFICATE"); break; @@ -490,6 +533,29 @@ namespace OpenWifi::GWObjects { return false; } + void RangeOptions::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "NO_IR", NO_IR); + field_to_json(Obj, "AUTO_BW", AUTO_BW); + field_to_json(Obj, "DFS", DFS); + field_to_json(Obj, "NO_OUTDOOR", NO_OUTDOOR); + field_to_json(Obj, "wmmrule_ETSI", wmmrule_ETSI); + field_to_json(Obj, "NO_OFDM", NO_OFDM); + } + + void FrequencyRange::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "from", from); + field_to_json(Obj, "to", to); + field_to_json(Obj, "channelWidth", channelWidth); + field_to_json(Obj, "powerDb", powerDb); + field_to_json(Obj, "options", options); + } + + void RegulatoryCountryInfo::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "country", country); + field_to_json(Obj, "domain", domain); + field_to_json(Obj, "ranges", ranges); + } + void DeviceRestrictionsKeyInfo::to_json(Poco::JSON::Object &Obj) const { field_to_json(Obj, "vendor", vendor); field_to_json(Obj, "algo", algo); @@ -544,4 +610,42 @@ namespace OpenWifi::GWObjects { (T.commands != commands) || (T.developer != developer) || (T.ssh != ssh) || (T.key_info != key_info) || (T.country != country)); } + + void RADIUSSession::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "started", started); + field_to_json(Obj, "lastTransaction", lastTransaction); + field_to_json(Obj, "destination", destination); + field_to_json(Obj, "serialNumber", serialNumber); + field_to_json(Obj, "userName", userName); + field_to_json(Obj, "accountingSessionId", accountingSessionId); + field_to_json(Obj, "accountingMultiSessionId", accountingMultiSessionId); + field_to_json(Obj, "inputPackets", inputPackets); + field_to_json(Obj, "outputPackets", outputPackets); + field_to_json(Obj, "inputOctets", inputOctets); + field_to_json(Obj, "outputOctets", outputOctets); + field_to_json(Obj, "inputGigaWords", inputGigaWords); + field_to_json(Obj, "outputGigaWords", outputGigaWords); + field_to_json(Obj, "sessionTime", sessionTime); + field_to_json(Obj, "callingStationId", callingStationId); + field_to_json(Obj, "chargeableUserIdentity", chargeableUserIdentity); + field_to_json(Obj, "interface", interface); + field_to_json(Obj, "secret", secret); + } + + void RADIUSSessionList::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "sessions", sessions); + } + + bool RadiusCoADMParameters::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "accountingSessionId", accountingSessionId); + field_from_json(Obj, "accountingMultiSessionId", accountingMultiSessionId); + field_from_json(Obj, "callingStationId", callingStationId); + field_from_json(Obj, "chargeableUserIdentity", chargeableUserIdentity); + return true; + } catch (const Poco::Exception &E) { + } + return false; + } + } // namespace OpenWifi::GWObjects diff --git a/src/RESTObjects/RESTAPI_GWobjects.h b/src/RESTObjects/RESTAPI_GWobjects.h index ed7b264..7740db1 100644 --- a/src/RESTObjects/RESTAPI_GWobjects.h +++ b/src/RESTObjects/RESTAPI_GWobjects.h @@ -11,9 +11,13 @@ #include "Poco/JSON/Object.h" #include "RESTAPI_SecurityObjects.h" +#ifdef TIP_GATEWAY_SERVICE +#include +#endif + namespace OpenWifi::GWObjects { - enum CertificateValidation { NO_CERTIFICATE, VALID_CERTIFICATE, MISMATCH_SERIAL, VERIFIED }; + enum CertificateValidation { NO_CERTIFICATE, VALID_CERTIFICATE, MISMATCH_SERIAL, VERIFIED, SIMULATED }; struct ConnectionState { uint64_t MessageCount = 0; @@ -38,8 +42,14 @@ namespace OpenWifi::GWObjects { uint64_t sessionId = 0; double connectionCompletionTime = 0.0; std::uint64_t certificateExpiryDate = 0; + bool hasRADIUSSessions = false; + bool hasGPS = false; + std::uint64_t sanity=0; + std::double_t memoryUsed=0.0; + std::double_t load=0.0; + std::double_t temperature=0.0; - void to_json(Poco::JSON::Object &Obj) const; + void to_json(const std::string &SerialNumber, Poco::JSON::Object &Obj) ; }; struct DeviceRestrictionsKeyInfo { @@ -96,6 +106,9 @@ namespace OpenWifi::GWObjects { std::string pendingConfiguration; std::string pendingConfigurationCmd; DeviceRestrictions restrictionDetails; + std::uint64_t pendingUUID = 0; + bool simulated=false; + std::uint64_t lastRecordedContact=0; void to_json(Poco::JSON::Object &Obj) const; void to_json_with_status(Poco::JSON::Object &Obj) const; @@ -188,7 +201,11 @@ namespace OpenWifi::GWObjects { uint64_t AttachSize = 0; std::string AttachType; double executionTime = 0.0; + std::uint64_t lastTry = 0; + bool deferred = false; + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); }; struct BlackListedDevice { @@ -334,4 +351,76 @@ namespace OpenWifi::GWObjects { bool from_json(const Poco::JSON::Object::Ptr &Obj); }; + struct RangeOptions { + bool NO_IR=false; + bool AUTO_BW=false; + bool DFS=false; + bool NO_OUTDOOR=false; + bool wmmrule_ETSI=false; + bool NO_OFDM=false; + + void to_json(Poco::JSON::Object &Obj) const; + }; + + struct FrequencyRange { + float from = 0.0; + float to = 0.0; + int channelWidth = 0; + int powerDb = 0; + RangeOptions options; + + void to_json(Poco::JSON::Object &Obj) const; + }; + + struct RegulatoryCountryInfo { + std::string country; + std::string domain; + std::vector ranges; + + void to_json(Poco::JSON::Object &Obj) const; + }; + + using RegulatoryInfoCountryMap = std::map; + + struct RADIUSSession { + std::uint64_t started=0, + lastTransaction=0; + std::string serialNumber, + destination, + userName, + accountingSessionId, + accountingMultiSessionId, + callingStationId, + chargeableUserIdentity, + secret, + interface; + std::uint64_t inputPackets = 0, + outputPackets = 0, + inputOctets = 0, + outputOctets = 0, + inputGigaWords = 0, + outputGigaWords = 0; + std::uint32_t sessionTime = 0; + +#ifdef TIP_GATEWAY_SERVICE + RADIUS::RadiusPacket accountingPacket; +#endif + + void to_json(Poco::JSON::Object &Obj) const; + }; + + struct RADIUSSessionList { + std::vector sessions; + void to_json(Poco::JSON::Object &Obj) const; + }; + + struct RadiusCoADMParameters { + std::string accountingSessionId, + accountingMultiSessionId, + callingStationId, + chargeableUserIdentity; + + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + } // namespace OpenWifi::GWObjects diff --git a/src/framework/default_device_types.h b/src/framework/default_device_types.h new file mode 100644 index 0000000..02941db --- /dev/null +++ b/src/framework/default_device_types.h @@ -0,0 +1,63 @@ +// +// Created by stephane bourque on 2023-04-19. +// + +#pragma once + +#include +#include + +namespace OpenWifi { + inline const std::vector> DefaultDeviceTypeList{ + {"actiontec_web7200", "AP"}, + {"cig_wf186w", "AP"}, + {"cig_wf188n", "AP"}, + {"cig_wf194c4", "AP"}, + {"cig_wf196", "AP"}, + {"cig_wf196-ca", "AP"}, + {"cig_wf196-ca-ath12", "AP"}, + {"cig_wf196-us", "AP"}, + {"cig_wf610d", "AP"}, + {"cig_wf660a", "AP"}, + {"cig_wf808", "AP"}, + {"cybertan_eww622-a1", "AP"}, + {"edgecore_eap101", "AP"}, + {"edgecore_eap101-ath12", "AP"}, + {"edgecore_eap102", "AP"}, + {"edgecore_eap104", "AP"}, + {"edgecore_eap104-ath12", "AP"}, + {"edgecore_ecs4100-12ph", "AP"}, + {"edgecore_ecw5211", "AP"}, + {"edgecore_ecw5410", "AP"}, + {"edgecore_oap100", "AP"}, + {"edgecore_spw2ac1200", "SWITCH"}, + {"edgecore_spw2ac1200-lan-poe", "SWITCH"}, + {"edgecore_ssw2ac2600", "SWITCH"}, + {"hfcl_ion4", "AP"}, + {"hfcl_ion4x", "AP"}, + {"hfcl_ion4x_2", "AP"}, + {"hfcl_ion4xe", "AP"}, + {"hfcl_ion4xi", "AP"}, + {"indio_um-305ac", "AP"}, + {"indio_um-305ax", "AP"}, + {"indio_um-310ax-v1", "AP"}, + {"indio_um-325ac", "AP"}, + {"indio_um-510ac-v3", "AP"}, + {"indio_um-510axm-v1", "AP"}, + {"indio_um-510axp-v1", "AP"}, + {"indio_um-550ac", "AP"}, + {"linksys_e8450-ubi", "AP"}, + {"linksys_ea6350-v4", "AP"}, + {"linksys_ea8300", "AP"}, + {"liteon_wpx8324", "AP"}, + {"meshpp_s618_cp01", "AP"}, + {"meshpp_s618_cp03", "AP"}, + {"udaya_a5-id2", "AP"}, + {"wallys_dr40x9", "AP"}, + {"wallys_dr6018", "AP"}, + {"wallys_dr6018_v4", "AP"}, + {"x64_vm", "AP"}, + {"yuncore_ax840", "AP"}, + {"yuncore_fap640", "AP"}, + {"yuncore_fap650", "AP"}}; +} diff --git a/src/framework/ow_constants.h b/src/framework/ow_constants.h index 207d5d8..863bc8c 100644 --- a/src/framework/ow_constants.h +++ b/src/framework/ow_constants.h @@ -397,6 +397,18 @@ namespace OpenWifi::RESTAPI::Errors { static const struct msg FirmwareBDInProgress { 1170, "Firmware DB update already in progress." }; + static const struct msg SimulatedDeviceNotSupported { + 1171, "Command not supported on simulated device." + }; + + static const struct msg SimulationDoesNotExist { + 7000, "Simulation Instance ID does not exist." + }; + + static const struct msg SimulationIsAlreadyRunning { + 7001, "There is an instance of this simulation already running.." + }; + } // namespace OpenWifi::RESTAPI::Errors