#define MAX_OBSERVER_FAILED_COMM (2)
#define MAX_OBSERVER_NON_COUNT (3)
+#ifdef CA_INT
+// NOTE: These values are based on the observe option values as defined in the CoAP RFC
+// The values should not be changed unless there is a change in the RFC.
+#define OC_RESOURCE_OBSERVE_REGISTER (0)
+#define OC_RESOURCE_OBSERVE_DEREGISTER (1)
+#endif // CA_INT
+
/* This information is stored for each registerd observer */
typedef struct ResourceObserver {
// Observation Identifier for request
ResourceObserver* GetObserverUsingId (const OCObservationId observeId);
+#ifdef CA_INT
+OCStackResult
+CreateObserveHeaderOption (CAHeaderOption_t **caHdrOpt,
+ OCHeaderOption *ocHdrOpt,
+ uint8_t numOptions,
+ uint8_t observeFlag);
+#endif // CA_INT
+
#endif //OC_OBSERVE_H
}
serverObsList = NULL;
}
+
+#ifdef CA_INT
+OCStackResult
+CreateObserveHeaderOption (CAHeaderOption_t **caHdrOpt,
+ OCHeaderOption *ocHdrOpt,
+ uint8_t numOptions,
+ uint8_t observeFlag)
+{
+ CAHeaderOption_t *tmpHdrOpt = NULL;
+
+ tmpHdrOpt = (CAHeaderOption_t *) OCMalloc ((numOptions+1)*sizeof(CAHeaderOption_t));
+ if (NULL == tmpHdrOpt)
+ {
+ return OC_STACK_NO_MEMORY;
+ }
+ tmpHdrOpt[0].protocolID = CA_COAP_ID;
+ // TODO-CA: COAP_OPTION_OBSERVE is defined in CoAP header files which will be abstracted
+ // from resource model. We have to define a new macro for this in the stack layer.
+ tmpHdrOpt[0].optionID = COAP_OPTION_OBSERVE;
+ // Length is one byte
+ tmpHdrOpt[0].optionLength = 1;
+ tmpHdrOpt[0].optionData[0] = observeFlag;
+ for (uint8_t i = 0; i < numOptions; i++)
+ {
+ memcpy (&(tmpHdrOpt[i+1]), &(ocHdrOpt[i]), sizeof(CAHeaderOption_t));
+ }
+
+ *caHdrOpt = tmpHdrOpt;
+ return OC_STACK_OK;
+}
+#endif // CA_INT
// TODO-CA: Map QoS to the right CA msg type
requestData.type = CA_MSG_NONCONFIRM;
requestData.token = caToken;
- requestData.options = (CAHeaderOption_t*)options;
- requestData.numOptions = numOptions;
+ if ((method == OC_REST_OBSERVE) || (method == OC_REST_OBSERVE_ALL))
+ {
+ result = CreateObserveHeaderOption (&(requestData.options), options,
+ numOptions, OC_RESOURCE_OBSERVE_REGISTER);
+ if (result != OC_STACK_OK)
+ {
+ goto exit;
+ }
+ hdrOptionMemAlloc = 1;
+ requestData.numOptions = numOptions + 1;
+ }
+ else
+ {
+ requestData.options = (CAHeaderOption_t*)options;
+ requestData.numOptions = numOptions;
+ }
requestData.payload = (char *)request;
requestInfo.info = requestData;