-
Notifications
You must be signed in to change notification settings - Fork 2
/
ocf_mylight_maintenance.c
160 lines (133 loc) · 4.05 KB
/
ocf_mylight_maintenance.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "ocf_mylight.h"
static OCResourceHandle _mnthandle;
static bool _fr;
static bool _rb;
static OCEntityHandlerResult on_get(OCEntityHandlerFlag flag _UNUSED_,
OCEntityHandlerRequest *req, void *user_data _UNUSED_)
{
OCEntityHandlerResponse resp;
OCRepPayload *payload = NULL;
payload = OCRepPayloadCreate();
OCRepPayloadAddResourceType(payload, "oic.wk.mnt");
OCRepPayloadAddInterface(payload, "oic.if.baseline");
/**
* FIXME: mismatch Spec and CTT
*
* In the OIC 1.1.2 specification document, the 'oic.if.rw' interface is
* correct for the 'oic.wk.mnt' resource type.
* However, CTT 1.5.0.0 tools 'Check_13' test cases report FAIL results
* because the tool want the interface 'oic.if.r'.
*/
// OCRepPayloadAddInterface(payload, "oic.if.rw");
OCRepPayloadAddInterface(payload, "oic.if.r");
OCRepPayloadSetPropBool(payload, "fr", _fr);
OCRepPayloadSetPropBool(payload, "rb", _rb);
memset(&resp, 0, sizeof(OCEntityHandlerResponse));
resp.requestHandle = req->requestHandle;
resp.resourceHandle = req->resource;
resp.ehResult = OC_EH_OK;
resp.payload = (OCPayload*) payload;
ocf_mylight_verbose_response(&resp);
if (OCDoResponse(&resp) != OC_STACK_OK) {
DBG("Error sending response");
OCRepPayloadDestroy(payload);
return OC_EH_ERROR;
}
OCRepPayloadDestroy(payload);
return OC_EH_OK;
}
static OCEntityHandlerResult on_post(OCEntityHandlerFlag flag _UNUSED_,
OCEntityHandlerRequest *req, void *user_data _UNUSED_)
{
OCEntityHandlerResponse resp;
OCRepPayload *payload = NULL;
OCRepPayload *input = (OCRepPayload *) req->payload;
bool val = NULL;
if (req->query) {
/**
* CTT testcase requests POST with if=oic.if.r query.
*/
if (strncmp(req->query, "if=oic.if.r", 11) == 0)
return OC_EH_FORBIDDEN;
}
payload = OCRepPayloadCreate();
OCRepPayloadAddResourceType(payload, "oic.wk.mnt");
OCRepPayloadAddInterface(payload, "oic.if.baseline");
/**
* FIXME: mismatch Spec and CTT
*
* In the OIC 1.1.2 specification document, the 'oic.if.rw' interface is
* correct for the 'oic.wk.mnt' resource type.
* However, CTT 1.5.0.0 tools 'Check_13' test cases report FAIL results
* because the tool want the interface 'oic.if.r'.
*/
// OCRepPayloadAddInterface(payload, "oic.if.rw");
OCRepPayloadAddInterface(payload, "oic.if.r");
if (OCRepPayloadGetPropBool(input, "fr", &val)) {
_fr = val;
/**
* Do Factory Reset
*/
MSG("Factory Reset request");
}
OCRepPayloadSetPropBool(payload, "fr", _fr);
if (OCRepPayloadGetPropBool(input, "rb", &val)) {
_rb = val;
/**
* Do Reboot
*/
MSG("Reboot request");
}
OCRepPayloadSetPropBool(payload, "rb", _rb);
memset(&resp, 0, sizeof(OCEntityHandlerResponse));
resp.requestHandle = req->requestHandle;
resp.resourceHandle = req->resource;
resp.ehResult = OC_EH_OK;
resp.payload = (OCPayload*) payload;
ocf_mylight_verbose_response(&resp);
if (OCDoResponse(&resp) != OC_STACK_OK) {
DBG("Error sending response");
OCRepPayloadDestroy(payload);
return OC_EH_ERROR;
}
OCRepPayloadDestroy(payload);
return OC_EH_OK;
}
static struct ocf_ops mnt_ops = {
.get = on_get,
.post = on_post
};
int ocf_mylight_maintenance_init()
{
OCStackResult ret;
/**
* FIXME: fr(factory reset) and rb(reboot) status
*
* CTT requests update(POST) for fr and rb properties, CTT then
* retrieve(GET) the properties to confirm it has changed.
*/
_fr = false;
_rb = false;
/**
* FIXME: mismatch Spec and CTT
*
* In the OIC 1.1.2 specification document, the 'oic.if.rw' interface is
* correct for the 'oic.wk.mnt' resource type.
* However, CTT 1.5.0.0 tools 'Check_13' test cases report FAIL results
* because the tool want the interface 'oic.if.r'.
*/
// ret = OCCreateResource(&_mnthandle, "oic.wk.mnt", "oic.if.rw",
ret = OCCreateResource(&_mnthandle, "oic.wk.mnt", "oic.if.r",
"/oic/mnt", ocf_mylight_handler, &mnt_ops,
OC_DISCOVERABLE | OC_SECURE);
if (ret != OC_STACK_OK) {
DBG("OCCreateResource() failed. (ret=%d)", ret);
return -1;
}
return 0;
}