Skip to content

Commit

Permalink
Merge pull request #340 from Telecominfraproject/WIFI-13507
Browse files Browse the repository at this point in the history
  • Loading branch information
stephb9959 authored Mar 15, 2024
2 parents aa8486c + 3a1011a commit f22b3e3
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 87 deletions.
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
91
93
8 changes: 3 additions & 5 deletions openapi/owgw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ components:
schemas:
DeviceType:
type: string
default: AP
default: ap
enum:
- AP
- SWITCH
- IOT
- MESH
- ap
- switch

DeviceRestrictionsKeyInfo:
type: object
Expand Down
7 changes: 4 additions & 3 deletions src/CapabilitiesCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <string>

#include "framework/MicroServiceFuncs.h"
#include "framework/ow_constants.h"

#include "CentralConfig.h"
#include "nlohmann/json.hpp"
Expand All @@ -34,7 +35,7 @@ namespace OpenWifi {
std::lock_guard G(Mutex_);
if (!PlatformsLoaded_)
LoadPlatforms();
auto P = Poco::toUpper(Caps.Platform());
auto P = Poco::toLower(Caps.Platform());
auto Hint = Platforms_.find(Caps.Compatible());
if (Hint == Platforms_.end()) {
Platforms_.insert(std::make_pair(Caps.Compatible(), P));
Expand Down Expand Up @@ -68,7 +69,7 @@ namespace OpenWifi {

auto Hint = Platforms_.find(DeviceType);
if (Hint == Platforms_.end())
return "AP";
return Platforms::AP;
return Hint->second;
}

Expand Down Expand Up @@ -110,7 +111,7 @@ namespace OpenWifi {
i >> cache;

for (const auto &[Type, Platform] : cache.items()) {
Platforms_[Type] = Platform;
Platforms_[Type] = Poco::toLower(to_string(Platform));
}
} catch (...) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/Daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace OpenWifi {
if (Id == DeviceType)
return Type;
}
return "AP";
return Platforms::AP;
}

void DaemonPostInitialization(Poco::Util::Application &self) {
Expand Down
8 changes: 4 additions & 4 deletions src/RESTAPI/RESTAPI_default_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::ModelIDListCannotBeEmpty);
}

DefConfig.Platform = DefConfig.Platform.empty() ? "AP" : DefConfig.Platform;
if(DefConfig.Platform != "AP" && DefConfig.Platform != "SWITCH") {
DefConfig.Platform = DefConfig.Platform.empty() ? Platforms::AP : DefConfig.Platform;
if(DefConfig.Platform != Platforms::AP && DefConfig.Platform != Platforms::SWITCH) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}

Expand Down Expand Up @@ -95,11 +95,11 @@ namespace OpenWifi {
}

if(Existing.Platform.empty()) {
Existing.Platform = "AP";
Existing.Platform = Platforms::AP;
}

if(ParsedBody_->has("platform")) {
if(NewConfig.Platform.empty() || (NewConfig.Platform != "AP" && NewConfig.Platform != "SWITCH")) {
if(NewConfig.Platform.empty() || (NewConfig.Platform != Platforms::AP && NewConfig.Platform != Platforms::SWITCH)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
Existing.Platform = NewConfig.Platform;
Expand Down
2 changes: 1 addition & 1 deletion src/RESTAPI/RESTAPI_device_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace OpenWifi {
auto Config = Obj->get("configuration").toString();
Poco::JSON::Object Answer;
std::string Error;
auto DeviceType = GetParameter("deviceType", "AP");
auto DeviceType = Poco::toLower(GetParameter("deviceType", Platforms::AP));
auto Res =
ValidateUCentralConfiguration(ConfigurationValidator::GetType(DeviceType),Config, Error, GetBoolParameter("strict", false));
Answer.set("valid", Res);
Expand Down
2 changes: 1 addition & 1 deletion src/RESTAPI/RESTAPI_devices_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace OpenWifi {
auto deviceWithStatus = GetBoolParameter(RESTAPI::Protocol::DEVICEWITHSTATUS, false);
auto completeInfo = GetBoolParameter("completeInfo", false);

if(!platform.empty() && (platform!="ap" && platform!="switch" && platform!="all")) {
if(!platform.empty() && (platform!=Platforms::AP && platform!=Platforms::SWITCH && platform!="all")) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}

Expand Down
1 change: 1 addition & 0 deletions src/RESTObjects/RESTAPI_AnalyticsObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "RESTAPI_ProvObjects.h"
#include "framework/utils.h"
#include <vector>
#include "framework/ow_constants.h"

namespace OpenWifi {

Expand Down
2 changes: 1 addition & 1 deletion src/RESTObjects/RESTAPI_ProvObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ namespace OpenWifi::ProvObjects {
bool doNotAllowOverrides = false;
std::uint64_t imported=0;
std::uint64_t connected=0;
std::string platform{"AP"};
std::string platform{Platforms::AP};

void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
Expand Down
2 changes: 2 additions & 0 deletions src/StorageService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace OpenWifi {
ScriptDB_->Create();
ScriptDB_->Initialize();

FixDeviceTypeBug();

return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions src/StorageService.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ namespace OpenWifi {
bool AnalyzeCommands(Types::CountedMap &R);
bool AnalyzeDevices(GWObjects::Dashboard &D);

void FixDeviceTypeBug();

int Start() override;
void Stop() override;

Expand Down
6 changes: 3 additions & 3 deletions src/framework/ConfigurationValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#pragma once

#include "framework/SubSystemServer.h"

#include "framework/ow_constants.h"
#include <valijson/adapters/poco_json_adapter.hpp>
#include <valijson/constraints/constraint.hpp>
#include <valijson/constraints/constraint_visitor.hpp>
Expand All @@ -32,9 +32,9 @@ namespace OpenWifi {

inline static ConfigurationType GetType(const std::string &type) {
std::string Type = Poco::toUpper(type);
if (Type == "AP")
if (Type == Platforms::AP)
return ConfigurationType::AP;
if (Type == "SWITCH")
if (Type == Platforms::SWITCH)
return ConfigurationType::SWITCH;
return ConfigurationType::AP;
}
Expand Down
104 changes: 53 additions & 51 deletions src/framework/default_device_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,59 @@
#include <vector>
#include <string>

#include "ow_constants.h"

namespace OpenWifi {
inline const std::vector<std::pair<std::string, std::string>> 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"}};
{"actiontec_web7200", Platforms::AP},
{"cig_wf186w", Platforms::AP},
{"cig_wf188n", Platforms::AP},
{"cig_wf194c4", Platforms::AP},
{"cig_wf196", Platforms::AP},
{"cig_wf196-ca", Platforms::AP},
{"cig_wf196-ca-ath12", Platforms::AP},
{"cig_wf196-us", Platforms::AP},
{"cig_wf610d", Platforms::AP},
{"cig_wf660a", Platforms::AP},
{"cig_wf808", Platforms::AP},
{"cybertan_eww622-a1", Platforms::AP},
{"edgecore_eap101", Platforms::AP},
{"edgecore_eap101-ath12", Platforms::AP},
{"edgecore_eap102", Platforms::AP},
{"edgecore_eap104", Platforms::AP},
{"edgecore_eap104-ath12", Platforms::AP},
{"edgecore_ecs4100-12ph", Platforms::AP},
{"edgecore_ecw5211", Platforms::AP},
{"edgecore_ecw5410", Platforms::AP},
{"edgecore_oap100", Platforms::AP},
{"edgecore_spw2ac1200", Platforms::SWITCH},
{"edgecore_spw2ac1200-lan-poe", Platforms::SWITCH},
{"edgecore_ssw2ac2600", Platforms::SWITCH},
{"hfcl_ion4", Platforms::AP},
{"hfcl_ion4x", Platforms::AP},
{"hfcl_ion4x_2", Platforms::AP},
{"hfcl_ion4xe", Platforms::AP},
{"hfcl_ion4xi", Platforms::AP},
{"indio_um-305ac", Platforms::AP},
{"indio_um-305ax", Platforms::AP},
{"indio_um-310ax-v1", Platforms::AP},
{"indio_um-325ac", Platforms::AP},
{"indio_um-510ac-v3", Platforms::AP},
{"indio_um-510axm-v1", Platforms::AP},
{"indio_um-510axp-v1", Platforms::AP},
{"indio_um-550ac", Platforms::AP},
{"linksys_e8450-ubi", Platforms::AP},
{"linksys_ea6350-v4", Platforms::AP},
{"linksys_ea8300", Platforms::AP},
{"liteon_wpx8324", Platforms::AP},
{"meshpp_s618_cp01", Platforms::AP},
{"meshpp_s618_cp03", Platforms::AP},
{"udaya_a5-id2", Platforms::AP},
{"wallys_dr40x9", Platforms::AP},
{"wallys_dr6018", Platforms::AP},
{"wallys_dr6018_v4", Platforms::AP},
{"x64_vm", Platforms::AP},
{"yuncore_ax840", Platforms::AP},
{"yuncore_fap640", Platforms::AP},
{"yuncore_fap650", Platforms::AP}};
}
5 changes: 5 additions & 0 deletions src/framework/ow_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,11 @@ namespace OpenWifi::Provisioning::DeviceClass {

} // namespace OpenWifi::Provisioning::DeviceClass

namespace OpenWifi::Platforms {
static const std::string AP = "ap";
static const std::string SWITCH = "switch";
}

#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
Expand Down
23 changes: 11 additions & 12 deletions src/storage/storage_defconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,31 +221,30 @@ namespace OpenWifi {
return false;
}

bool Storage::FindDefaultConfigurationForModel(const std::string &Model, const std::string &Platform,
GWObjects::DefaultConfiguration &DefConfig) {
bool Storage::FindDefaultConfigurationForModel(const std::string &DeviceModel, const std::string &Platform,
GWObjects::DefaultConfiguration &Config) {
try {
DefConfigRecordList Records;
DefConfigRecordList DefConfigs;

Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement Select(Sess);

Select << "SELECT " + DB_DefConfig_SelectFields + " FROM DefaultConfigs",
Poco::Data::Keywords::into(Records);
Poco::Data::Keywords::into(DefConfigs);
Select.execute();

for (const auto &i : Records) {
GWObjects::DefaultConfiguration Config;
Convert(i, Config);
for (const auto &j : Config.Models) {
if ((j == "*" || j == Model) && (Poco::toUpper(Config.Platform) == Poco::toUpper(Platform))){
DefConfig = Config;
for (const auto &DefConfig : DefConfigs) {
GWObjects::DefaultConfiguration C;
Convert(DefConfig, C);
for (const auto &Model : C.Models) {
if ((Model == "*" || Model == DeviceModel) && (Config.Platform == Platform)){
Config = C;
return true;
}
}
}
Logger().information(
fmt::format("AUTO-PROVISIONING: no default configuration for model:{}", Model));
return false;
fmt::format("AUTO-PROVISIONING: no default configuration for model:{}", DeviceModel));
} catch (const Poco::Exception &E) {
poco_warning(Logger(), fmt::format("{}: Failed with: {}", std::string(__func__),
E.displayText()));
Expand Down
37 changes: 33 additions & 4 deletions src/storage/storage_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,18 @@ namespace OpenWifi {
Config::Config NewConfig(DefConfig.Configuration);
NewConfig.SetUUID(Now);
D.Configuration = NewConfig.get();
} else if (!Found && Caps.Platform()=="AP") {
Config::Config NewConfig;
NewConfig.SetUUID(Now);
D.Configuration = NewConfig.get();
} else if (!Found) {
if(Caps.Platform()==Platforms::AP) {
Config::Config NewConfig;
NewConfig.SetUUID(Now);
D.Configuration = NewConfig.get();
} else {
Poco::JSON::Object Obj;
Obj.set("uuid", Now);
std::ostringstream os;
Obj.stringify(os);
D.Configuration = os.str();
}
}

// We need to insert the country code according to the IP in the radios section...
Expand Down Expand Up @@ -1107,4 +1115,25 @@ namespace OpenWifi {
FieldList.push_back(field);
}

void Storage::FixDeviceTypeBug() {
try {
std::vector<std::string> ScriptLines{
"update devices set devicetype='ap' where devicetype='AP';",
"update devices set devicetype='switch' where devicetype='SWITCH';",
"update devices set devicetype='ap' where devicetype!='ap' and devicetype!='switch';"
};

for (const auto &ScriptLine : ScriptLines) {
try {
Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement SqlStatement(Sess);
SqlStatement << ScriptLine, Poco::Data::Keywords::now;
} catch (...) {
}
}
} catch (const Poco::Exception &E) {
Logger().log(E);
}
}

} // namespace OpenWifi

0 comments on commit f22b3e3

Please sign in to comment.