--- /dev/null
+{
+ "acl": {
+ "aclist": {
+ "aces": [
+ {
+ "subjectuuid": "*",
+ "resources": [
+ {
+ "href": "/oic/res",
+ "rel": "",
+ "rt": ["oic.wk.res"],
+ "if": ["oic.if.ll"]
+ },{
+ "href": "/oic/d",
+ "rel": "",
+ "rt": ["oic.wk.d"],
+ "if": ["oic.if.baseline", "oic.if.r"]
+ },{
+ "href": "/oic/p",
+ "rel": "",
+ "rt": ["oic.wk.p"],
+ "if": ["oic.if.baseline", "oic.if.r"]
+ }
+ ],
+ "permission": 2
+ },
+ {
+ "subjectuuid": "*",
+ "resources": [
+ {
+ "href": "/oic/sec/doxm",
+ "rel": "",
+ "rt": ["oic.r.doxm"],
+ "if": ["oic.if.baseline"]
+ },
+ {
+ "href": "/oic/sec/pstat",
+ "rel": "",
+ "rt": ["oic.r.pstat"],
+ "if": ["oic.if.baseline"]
+ },
+ {
+ "href": "/oic/sec/cred",
+ "rel": "",
+ "rt": ["oic.r.cred"],
+ "if": ["oic.if.baseline"]
+ }
+ ],
+ "permission": 6
+ }
+ ]
+ },
+ "rowneruuid": "00000000-0000-0000-0000-000000000000"
+ },
+ "pstat": {
+ "isop": false,
+ "deviceuuid": "00000000-0000-0000-0000-000000000000",
+ "rowneruuid": "00000000-0000-0000-0000-000000000000",
+ "cm": 2,
+ "tm": 0,
+ "om": 4,
+ "sm": 4
+ },
+ "doxm": {
+ "oxms": [0],
+ "oxmsel": 0,
+ "sct": 1,
+ "owned": false,
+ "deviceuuid": "00000000-0000-0000-0000-000000000000",
+ "devowneruuid": "",
+ "rowneruuid": "00000000-0000-0000-0000-000000000000"
+ }
+}
+%define svr_db_dir %{TZ_SYS_GLOBALUSER_DATA}/capmgr
+%define svr_db_path %{svr_db_dir}/oic_svr_db_capmgr.dat
+
Name: capmgr
Summary: Capability Manager
Version: 0.0.1
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(iotivity)
BuildRequires: pkgconfig(jsoncpp)
+BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(pkgmgr)
BuildRequires: pkgconfig(pkgmgr-info)
cp %{SOURCE1001} .
%build
-%cmake .
+%cmake . -DSVR_DB_DIR=%{svr_db_dir} \
+ -DSVR_DB_PATH=%{svr_db_path}
%__make %{?_smp_mflags}
%install
%make_install
+mkdir -p %{buildroot}%{svr_db_dir}
+
%post
/sbin/ldconfig
%license LICENSE
%defattr(-,root,root,-)
%{_bindir}/*
+%{svr_db_path}
#include "src/iotivity.h"
+#include <octypes.h>
+#include <pmtypes.h>
+#include <OCPlatform.h>
+
+#include <OCProvisioningManager.hpp>
+
#include <functional>
#include <iostream>
#include <string>
-#include <OCPlatform.h>
-
#include "src/utils/logging.h"
namespace {
+const int kDiscoverTimeoutSec = 5;
+const int kUUIDLength = UUID_LENGTH;
const char kResourceTypeName[] = "capmgr.capabilities";
const std::string kResourceInterface = OC::DEFAULT_INTERFACE;
+FILE* ServerFopen(const char* /* unused */, const char* mode) {
+ return fopen(SVR_DB_PATH, mode);
+}
+
+std::string ConvertUUIDtoString(const OicUuid_t& uuid) {
+ std::ostringstream oss;
+ for (int i = 0; i < kUUIDLength; i++)
+ oss << uuid.id[i];
+ return oss.str();
+}
+
+void OtmEventCb(void* /* ctx */, const char* addr, uint16_t port,
+ const char* owner_id, OCOtmEvent_t event) {
+ LOG(INFO) << "Get OTM Event";
+ LOG(INFO) << "Addr: " << addr;
+ LOG(INFO) << "owner_id: " << owner_id;
+ switch (event) {
+ case OC_OTM_READY:
+ LOG(INFO) << "OC_OTM_READY";
+ break;
+ case OC_OTM_STARTED:
+ LOG(INFO) << "OC_OTM_STARTED";
+ break;
+ case OC_OTM_DONE:
+ LOG(INFO) << "OC_OTM_DONE";
+ break;
+ case OC_OTM_ERROR:
+ LOG(INFO) << "OC_OTM_ERROR";
+ break;
+ default:
+ LOG(ERROR) << "Unknown OTM event";
+ break;
+ }
+}
+
} // namespace
namespace capmgr {
Iotivity::Iotivity() {
- // legacy constructor
+ OCSetOtmEventHandler(nullptr, OtmEventCb);
+
+ ps_ = {
+ ServerFopen, fread, fwrite, fclose, unlink, nullptr, nullptr
+ };
+
OC::PlatformConfig config = OC::PlatformConfig {
OC::ServiceType::InProc,
OC::ModeType::Both,
"0.0.0.0",
0,
OC::QualityOfService::LowQos,
+ &ps_
};
OC::OCPlatform::Configure(config);
void Iotivity::RegisterResource() {
std::string uri = "/capmgr/capabilities";
- uint8_t property = OC_DISCOVERABLE | OC_OBSERVABLE; // OC_SECURE
+ uint8_t property = OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE;
OCStackResult result = OC::OCPlatform::registerResource(resource_,
uri, kResourceTypeName, kResourceInterface,
});
}
+void Iotivity::DiscoverUnownedDevices() {
+ if (OC::OCSecure::provisionInit(PM_DB_PATH) != OC_STACK_OK)
+ LOG(ERROR) << "provisionInit() failed!";
+
+ unowned_dev_list_.clear();
+ OCStackResult result =
+ OC::OCSecure::discoverUnownedDevices(kDiscoverTimeoutSec,
+ unowned_dev_list_);
+
+ if (result != OC_STACK_OK)
+ LOG(ERROR) << "discoverUnownedDevices() failed: " << result;
+ else
+ LOG(INFO) << "Discovered " << unowned_dev_list_.size()
+ << " unowned devices";
+
+ for (const auto& sec_rsc : unowned_dev_list_) {
+ LOG(INFO) << "Do ownership transfer: " << sec_rsc->getDevAddr();
+ sec_rsc->doOwnershipTransfer([this](OC::PMResultList_t* result, int hasError) {
+ if (hasError) {
+ LOG(ERROR) << "Failed to ownership transfer";
+ return;
+ }
+ LOG(INFO) << "Ownership transferred: "
+ << ConvertUUIDtoString(result->at(0).deviceId);
+ });
+ }
+}
+
OCEntityHandlerResult Iotivity::EntityCb(
std::shared_ptr<OC::OCResourceRequest> request) {
LOG(DEBUG) << "entity cb";