OCStackResult OCStop();
/**
- * This function starts receiving the multicast traffic. This can be only called
- * when stack is in OC_STACK_INITIALIZED state but device is not receiving multicast
- * traffic.
+ * This function starts responding to multicast /oic/res requests. This can be
+ * only called when stack is in OC_STACK_INITIALIZED state but device is not
+ * receiving multicast traffic.
*
* @return ::OC_STACK_OK on success, some other value upon failure.
*/
OCStackResult OCStartMulticastServer();
/**
- * This function stops receiving the multicast traffic. The rest of the stack
- * keeps working and no resource are deleted. Device can still receive the unicast
- * traffic. Once this is set, no response to multicast /oic/res will be sent by the
- * device. This is to be used for devices that uses other entity to push resources.
+ * This function stops responding to multicast /oic/res requests. This is to be
+ * used for devices that uses other entity to push resources.
+ *
+ * Note that other multicast requests, such as those used during ownership
+ * transfer, continue to be responded to.
*
* @return ::OC_STACK_OK on success, some other value upon failure.
*/
static const uint16_t CBOR_MAX_SIZE = 4400;
extern OCResource *headResource;
+extern bool g_multicastServerStopped;
/**
* Prepares a Payload for response.
#endif
)
{
+ if (g_multicastServerStopped && !isUnicast(request))
+ {
+ // Ignore the discovery request
+ FindAndDeleteServerRequest(request);
+ discoveryResult = OC_STACK_CONTINUE;
+ goto exit;
+ }
+
char *interfaceQuery = NULL;
char *resourceTypeQuery = NULL;
OIC_LOG_PAYLOAD(DEBUG, payload);
if(discoveryResult == OC_STACK_OK)
{
-
SendNonPersistantDiscoveryResponse(request, resource, payload, OC_EH_OK);
}
else // Error handling
if (request && request->resourceUrl && SRMIsSecurityResourceURI(request->resourceUrl))
{
type = PAYLOAD_TYPE_SECURITY;
-
}
result = EHRequest(&ehRequest, type, request, resource);
// Number of threads currently executing OCInit2 or OCStop
volatile int32_t g_ocStackStartStopThreadCount = 0;
+bool g_multicastServerStopped = false;
+
//-----------------------------------------------------------------------------
// Macros
//-----------------------------------------------------------------------------
OIC_LOG(ERROR, TAG, "OCStack is not initalized. Cannot start multicast server.");
return OC_STACK_ERROR;
}
- CAResult_t ret = CAStartListeningServer();
- if (CA_STATUS_OK != ret)
- {
- OIC_LOG_V(ERROR, TAG, "Failed starting listening server: %d", ret);
- return OC_STACK_ERROR;
- }
+ g_multicastServerStopped = false;
return OC_STACK_OK;
}
OCStackResult OCStopMulticastServer()
{
- CAResult_t ret = CAStopListeningServer();
- if (CA_STATUS_OK != ret)
- {
- OIC_LOG_V(ERROR, TAG, "Failed stopping listening server: %d", ret);
- return OC_STACK_ERROR;
- }
+ g_multicastServerStopped = true;
return OC_STACK_OK;
}