Enable ZigBee eventing in Plugin Interface through to IoTivity.
authorJoseph Morrow <joseph.l.morrow@intel.com>
Wed, 30 Sep 2015 18:33:10 +0000 (11:33 -0700)
committerJon A. Cruz <jonc@osg.samsung.com>
Fri, 2 Oct 2015 20:39:18 +0000 (20:39 +0000)
Change-Id: I1cca24815772c8e4f36e8b2f31775e7611e4f019
Signed-off-by: Joseph Morrow <joseph.l.morrow@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3165
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
plugins/include/internal/pluginlist.h
plugins/include/internal/plugintranslatortypes.h
plugins/samples/linux/IotivityandZigbeeClient.c
plugins/samples/linux/IotivityandZigbeeClient.h
plugins/samples/linux/IotivityandZigbeeServer.c
plugins/src/plugininterface.c
plugins/src/pluginlist.c
plugins/zigbee_wrapper/include/zigbee_wrapper.h
plugins/zigbee_wrapper/src/zigbee_wrapper.c

index b722f2e..ea57da0 100644 (file)
@@ -42,6 +42,9 @@ OCStackResult DeletePluginList();
 OCStackResult GetResourceFromHandle(PIPluginBase * plugin, PIResource ** piResource,
                                     OCResourceHandle * resourceHandle);
 
+OCStackResult GetResourceFromURI(PIPluginBase * plugin, PIResource ** piResource,
+                                    const char * uri);
+
 OCStackResult AddResourceToPlugin(PIPluginBase * plugin, PIResourceBase * resource);
 
 OCStackResult DeleteResource(PIPluginBase * plugin, PIResourceBase * resource);
index 19ab945..901f343 100644 (file)
@@ -54,6 +54,14 @@ typedef void (* PINewResourceFound)(struct PIPluginBase * plugin,
 
 /**
  *
+ * This callback will be called when a resource' representation has changed.
+ *
+ */
+typedef void (* PIObserveNotificationUpdate)(struct PIPluginBase * plugin,
+                                            const char * uri);
+
+/**
+ *
  * This function type is used by the radio's mapping implementation against IoTivity.
  * The mapping implementation must implement this function to handle GET & PUT requests.
  *
@@ -71,7 +79,7 @@ typedef struct PIPluginBase
     PIPluginType type;
 
     /** The file location which represents the interface of the plugin.  */
-    char * comPort;
+    const char * comPort;
 
     /** Linked list of plugins. */
     struct PIPluginBase * next;
@@ -79,6 +87,9 @@ typedef struct PIPluginBase
     /** Callback to be used when a new resource has been found. */
     PINewResourceFound NewResourceFoundCB;
 
+    /** Callback to be used when an Observation update has occurred. */
+    PIObserveNotificationUpdate ObserveNotificationUpdate;
+
     /** Function Pointer to be invoked upon an incoming IoTivity request. */
     PIProcessRequest processEHRequest;
 
@@ -107,8 +118,8 @@ typedef struct
 typedef struct
 {
     OCResourceHandle resourceHandle;
-    char *resourceTypeName;
-    char *resourceInterfaceName;
+    const char *resourceTypeName;
+    const char *resourceInterfaceName;
     char *uri;
     OCEntityHandler entityHandler;
     void* callbackParam;
index a41c6e8..19f0073 100644 (file)
@@ -65,10 +65,12 @@ static DiscoveredResourceInfo g_discoveredResources[MAX_RESOURCES_REMEMBERED];
 static void PrintTestCases()
 {
     printf("\nTest Cases:\n");
-    printf ("\n\t0 : Quit    1: GET    2: Build PUT payload\n\n");
-    printf ("\t3 : Turn binary switch for light ON\n");
-    printf ("\t4 : Turn binary switch for light OFF\n");
-    printf ("\t5 : Change light brightness\n");
+    printf ("\n\t%d : Quit    %d: GET    %d: Build PUT payload %d: OBSERVE\n\n",
+            TEST_QUIT, TEST_GET, TEST_CUSTOM_PUT, TEST_OBSERVE);
+    printf ("\t%d : Turn binary switch for light ON\n", TEST_TURN_SWITCH_ON);
+    printf ("\t%d : Turn binary switch for light OFF\n", TEST_TURN_SWITCH_OFF);
+    printf ("\t%d : Change light brightness\n", TEST_SET_LIGHT_BRIGHTNESS);
+    printf ("\n\t%d : Check for observation updates.\n", TEST_CYCLE);
 }
 
 static void PrintResources ()
@@ -161,6 +163,12 @@ int InitPutRequest (const char *resourceUri, OCPayload* payload)
     return (InvokeOCDoResource(resourceUri, payload, OC_REST_PUT, responseCallbacks));
 }
 
+int InitObserveRequest(const char *resourceUri)
+{
+    OC_LOG_V(INFO, TAG, "Executing %s for resource: %s", __func__, resourceUri);
+    return (InvokeOCDoResource(resourceUri, NULL, OC_REST_OBSERVE, responseCallbacks));
+}
+
 OCPayload * getSwitchStatePayload (bool state)
 {
     OCRepPayload* payload = OCRepPayloadCreate();
@@ -314,6 +322,11 @@ void processUserInput (int resourceNo, int testCase)
             }
             break;
         }
+
+        case TEST_OBSERVE:
+            InitObserveRequest (g_discoveredResources[resourceNo].uri);
+            break;
+
         case TEST_TURN_SWITCH_ON:
             InitPutRequest (g_discoveredResources[resourceNo].uri, getSwitchStatePayload (true));
             break;
@@ -337,6 +350,11 @@ void processUserInput (int resourceNo, int testCase)
             }
             break;
 
+        case TEST_CYCLE:
+            OCProcess();
+            promptUser = true;
+            break;
+
         case TEST_QUIT:
             raise (SIGINT);
             break;
index 217440d..d47879c 100644 (file)
 typedef enum
 {
     TEST_QUIT = 0,
-    TEST_GET  = 1,
+    TEST_GET,
     TEST_CUSTOM_PUT,
+    TEST_OBSERVE,
     TEST_TURN_SWITCH_ON,
     TEST_TURN_SWITCH_OFF,
     TEST_SET_LIGHT_BRIGHTNESS,
+    TEST_CYCLE,
     MAX_TESTS
 } CLIENT_TEST;
 
index 5f05ead..be95b5a 100644 (file)
@@ -92,14 +92,12 @@ int main()
     }
 
     OC_LOG(INFO, TAG, "Stopping Zigbee Plugin...");
-    // PIStopPlugin
-    OC_LOG(INFO, TAG, "Zigbee Plugin Stopped");
     result = PIStopPlugin(plugin);
     if (result != OC_STACK_OK)
     {
         OC_LOG_V(ERROR, TAG, "Zigbee Plugin Stop Failed: %d", result);
     }
-
+    OC_LOG(INFO, TAG, "Zigbee Plugin Stopped");
     // OCStop
 IotivityStop:
     OC_LOG(INFO, TAG, "Stopping IoTivity...");
index e94f040..29ce028 100644 (file)
@@ -109,7 +109,7 @@ void piNewResourceCB(PIPluginBase * p_plugin, PIResourceBase * r_newResource)
         return;
     }
 
-    r_newResource->piResource.resourceProperties = OC_DISCOVERABLE;
+    r_newResource->piResource.resourceProperties = OC_DISCOVERABLE | OC_OBSERVABLE;
     OCStackResult result = OCCreateResource(&r_newResource->piResource.resourceHandle,
                                             r_newResource->piResource.resourceTypeName,
                                             r_newResource->piResource.resourceInterfaceName,
@@ -129,6 +129,28 @@ void piNewResourceCB(PIPluginBase * p_plugin, PIResourceBase * r_newResource)
     result = AddResourceToPlugin(p_plugin, r_newResource);
 }
 
+void piObserveNotificationUpdate(PIPluginBase * plugin, const char * uri)
+{
+    if(!plugin || !uri)
+    {
+        return;
+    }
+    PIResource * piResource = NULL;
+
+    OCStackResult result = GetResourceFromURI(plugin, &piResource, uri);
+    if(result != OC_STACK_OK)
+    {
+        OC_LOG(ERROR, TAG, "Failed to find a matching URI based on observe notification update.");
+        return;
+    }
+
+    result = OCNotifyAllObservers(piResource->resourceHandle, OC_LOW_QOS);
+    if(result != OC_STACK_OK && result != OC_STACK_NO_OBSERVERS)
+    {
+        OC_LOG_V(ERROR, TAG, "Failed to notify observers of update. Result: %d", result);
+    }
+}
+
 OCStackResult PIStartPlugin(const char * comPort, PIPluginType pluginType, PIPlugin ** plugin)
 {
     if (!plugin || !comPort || strlen(comPort) == 0)
@@ -138,7 +160,10 @@ OCStackResult PIStartPlugin(const char * comPort, PIPluginType pluginType, PIPlu
     OCStackResult result = OC_STACK_ERROR;
     if (pluginType == PLUGIN_ZIGBEE)
     {
-        result = ZigbeeInit(comPort, (PIPlugin_Zigbee **) plugin, piNewResourceCB);
+        result = ZigbeeInit(comPort,
+                            (PIPlugin_Zigbee **) plugin,
+                            piNewResourceCB,
+                            piObserveNotificationUpdate);
         if (result != OC_STACK_OK)
         {
             return result;
index ef4c8e1..cf9a331 100644 (file)
@@ -101,6 +101,33 @@ OCStackResult GetResourceFromHandle(PIPluginBase * plugin, PIResource ** piResou
     return OC_STACK_NO_RESOURCE;
 }
 
+OCStackResult GetResourceFromURI(PIPluginBase * plugin, PIResource ** piResource,
+                                    const char * uri)
+{
+    if (!plugin || !piResource || !uri)
+    {
+        return OC_STACK_INVALID_PARAM;
+    }
+    PIResourceBase * out = NULL;
+    PIResourceBase * tmp = NULL;
+    size_t checkUriLength = strlen(uri);
+    size_t indexUriLength = 0;
+    size_t minLength = 0;
+    LL_FOREACH_SAFE(plugin->resourceList, out, tmp)
+    {
+        indexUriLength = strlen(out->piResource.uri);
+        minLength = indexUriLength > checkUriLength ? checkUriLength : indexUriLength;
+        if ((checkUriLength == indexUriLength) &&
+            memcmp(out->piResource.uri, uri, minLength + 1) == 0)
+        {
+            *piResource = (PIResource *) out;
+            return OC_STACK_OK;
+        }
+    }
+    *piResource = NULL;
+    return OC_STACK_NO_RESOURCE;
+}
+
 OCStackResult AddResourceToPlugin (PIPluginBase * plugin, PIResourceBase * resource)
 {
     if (!plugin || !resource)
index 920c079..9efadf2 100644 (file)
  * @param[in] newResourceCB A function pointer to the callback that will be
  *                          invoked when a ZigBee cluster is found that matches
  *                          a valid OIC resource.
+ *
+ * @param[in] observeNotificationUpdate A function pointer to the callback that will be
+ *                                      invoked when a Zigbee Zone IAS update occurs that
+ *                                      should be mapped to IoTivity's observe functionality.
  */
 OCStackResult ZigbeeInit(const char * comPort, PIPlugin_Zigbee ** plugin,
-                         PINewResourceFound newResourceCB);
+                         PINewResourceFound newResourceCB,
+                         PIObserveNotificationUpdate observeNotificationUpdate);
 
 /**
  * Initiates the discovery operation associated with this ZigBee radio.
index 0b242d1..929d184 100644 (file)
 #define ZB_CURRENT_LEVEL_ATTRIBUTE_READONLY  "0000"
 #define ZB_ON_LEVEL_ATTRIBUTE                "0011"
 #define ZB_LEVEL_CONTROL_CLUSTER             "0008"
-#define ZB_CONTACT_CLUSTER                   "0500"
-#define ZB_CONTACT_ATTRIBUTE_ID              "0002"
+#define ZB_IAS_ZONE_CLUSTER                  "0500"
+#define ZB_IAS_ZONE_STATUS_ATTRIBUTE_ID      "0002"
 #define ZB_INDICATOR_CLUSTER                 "0003"
 #define ZB_INDICATOR_ATTRIBUTE_ID            "0000"
 #define ZB_ON_OFF_CLUSTER                    "0006"
 #define ZB_ON_OFF_ATTRIBUTE_ID               "0000"
+#define ZB_IAS_ZONE_TYPE_ATTRIBUTE_ID        "0001"
+
+#define IAS_ZONE_TYPE_MOTION_SENSOR          "000d"
+#define IAS_ZONE_TYPE_CONTACT_SENSOR         "0015"
+#define IAS_ZONE_TYPE_WATER_SENSOR           "002a"
 
 #define ZB_DATA_TYPE_NULL                    "00"
 #define ZB_DATA_TYPE_1_BYTE                  "08"
@@ -92,6 +97,8 @@
 static const char* OIC_TEMPERATURE_SENSOR = "oic.r.temperature";
 static const char* OIC_DIMMABLE_LIGHT = "oic.r.light.dimming";
 static const char* OIC_CONTACT_SENSOR = "oic.r.sensor.contact";
+static const char* OIC_MOTION_SENSOR = "oic.r.sensor.motion";
+static const char* OIC_WATER_SENSOR = "oic.r.sensor.water";
 static const char* OIC_BINARY_SWITCH = "oic.r.switch.binary";
 
 static const char* OIC_TEMPERATURE_ATTRIBUTE = "temperature";
@@ -127,7 +134,7 @@ typedef enum
 } ZigBeeAttributeDataType;
 
 char * getZBDataTypeString(ZigBeeAttributeDataType attrType);
-OCEntityHandlerResult ProcessEHRequest (PIPluginBase * plugin, OCEntityHandlerRequest *ehRequest,
+OCEntityHandlerResult ProcessEHRequest(PIPluginBase * plugin, OCEntityHandlerRequest *ehRequest,
         OCRepPayload **payload);
 
 typedef enum
@@ -169,20 +176,141 @@ typedef struct
     OICZigBeeAttributePair list[MAX_ATTRIBUTES];
 } AttributeList;
 
-const char* ZigBeeClusterIDToOICResourceType (const char * clusterID);
+const char* ZigBeeClusterIDToOICResourceType(const char * clusterID);
 
-OCStackResult getZigBeeAttributesForOICResource (char * OICResourceType,
+OCStackResult getZigBeeAttributesForOICResource(const char * OICResourceType,
                                                     AttributeList *attributeList);
 
-bool getZigBeeAttributesIfValid (char * OICResourceType,
+bool getZigBeeAttributesIfValid(const char * OICResourceType,
                                     AttributeList *attributeList,
                                     OCRepPayload *payload);
 
+const char * getResourceTypeForIASZoneType(TWDevice *device)
+{
+    if(!device)
+    {
+        return NULL;
+    }
+    char *IASZoneType = NULL;
+    const char *resourceType = NULL;
+    uint8_t length = 0;
+
+    OCStackResult ret = TWGetAttribute(
+        NULL,
+        device->nodeId,
+        device->endpointOfInterest->endpointId,
+        ZB_IAS_ZONE_CLUSTER,
+        ZB_IAS_ZONE_TYPE_ATTRIBUTE_ID,
+        &IASZoneType,
+        &length
+    );
+
+    if (ret != OC_STACK_OK || !IASZoneType)
+    {
+        OC_LOG_V (ERROR, TAG, "Error %u getting IAS Zone Type", ret);
+        return NULL;
+    }
+
+    if (strcmp (IASZoneType, IAS_ZONE_TYPE_CONTACT_SENSOR) == 0)
+    {
+        resourceType = OIC_CONTACT_SENSOR;
+    }
+    else if (strcmp (IASZoneType, IAS_ZONE_TYPE_MOTION_SENSOR) == 0)
+    {
+        resourceType = OIC_MOTION_SENSOR;
+    }
+    else if (strcmp (IASZoneType, IAS_ZONE_TYPE_WATER_SENSOR) == 0)
+    {
+        resourceType = OIC_WATER_SENSOR;
+    }
+    else
+    {
+        OC_LOG_V (ERROR, TAG, "Unsupported Zone Type %s", IASZoneType);
+        resourceType = NULL;
+    }
+
+    OICFree(IASZoneType);
+
+    return resourceType;
+}
+
+OCStackResult buildURI(char ** output,
+                       const char * prefix,
+                       const char * nodeId,
+                       const char * endpointId,
+                       const char * clusterId)
+{
+    if(!output || !prefix || !nodeId || !endpointId || !clusterId)
+    {
+        return OC_STACK_INVALID_PARAM;
+    }
+    const char LEN_SEPARATOR[] = "/";
+    size_t lenSeparatorSize = sizeof(LEN_SEPARATOR) - 1;
+    size_t newUriSize = strlen(prefix) + lenSeparatorSize +
+                        strlen(nodeId) + lenSeparatorSize +
+                        strlen(endpointId) + lenSeparatorSize +
+                        strlen(clusterId)
+                        + 1; // NULL Terminator
+    *output = (char *) OICCalloc(1, newUriSize);
+
+    if (!*output)
+    {
+        OC_LOG (ERROR, TAG, "Out of memory");
+        return OC_STACK_NO_MEMORY;
+    }
+
+    char * temp = OICStrcpy(*output, newUriSize, prefix);
+    if(temp != *output)
+    {
+        goto exit;
+    }
+    temp = OICStrcat(*output, newUriSize, LEN_SEPARATOR);
+    if(temp != *output)
+    {
+        goto exit;
+    }
+    temp = OICStrcat(*output, newUriSize, nodeId);
+    if(temp != *output)
+    {
+        goto exit;
+    }
+    temp = OICStrcat(*output, newUriSize, LEN_SEPARATOR);
+    if(temp != *output)
+    {
+        goto exit;
+    }
+    temp = OICStrcat(*output, newUriSize, endpointId);
+    if(temp != *output)
+    {
+        goto exit;
+    }
+    temp = OICStrcat(*output, newUriSize, LEN_SEPARATOR);
+    if(temp != *output)
+    {
+        goto exit;
+    }
+    temp = OICStrcat(*output, newUriSize, clusterId);
+    if(temp != *output)
+    {
+        goto exit;
+    }
+
+    return OC_STACK_OK;
+
+exit:
+    OICFree(*output);
+    *output = NULL;
+    return OC_STACK_NO_MEMORY;
+}
+
 void foundZigbeeCallback(TWDevice *device)
 {
+    if(!device)
+    {
+        OC_LOG(ERROR, TAG, "foundZigbeeCallback: Invalid parameter.");
+        return;
+    }
     int count = device->endpointOfInterest->clusterList->count;
-    size_t lenSeparator = strlen ("/");
-    int ret = 0;
     for(int i=0; i < count; i++)
     {
         PIResource_Zigbee *piResource = (PIResource_Zigbee *) OICMalloc(sizeof(*piResource));
@@ -192,43 +320,46 @@ void foundZigbeeCallback(TWDevice *device)
             return;
         }
         piResource->header.plugin = (PIPluginBase *)gPlugin;
-        size_t newUriSize = strlen(PI_ZIGBEE_PREFIX) + lenSeparator +
-                        sizeof(device->nodeId) + lenSeparator +
-                        sizeof(device->endpointOfInterest->endpointId) + lenSeparator +
-                        sizeof(device->endpointOfInterest->clusterList->clusterIds[i].clusterId)
-                        + 1; // NULL Terminator
-        char * newUri = (char *) OICCalloc(newUriSize, 1);
 
-        if (!newUri)
+        OCStackResult result = buildURI(&piResource->header.piResource.uri,
+                                PI_ZIGBEE_PREFIX,
+                                device->nodeId,
+                                device->endpointOfInterest->endpointId,
+                                device->endpointOfInterest->clusterList->clusterIds[i].clusterId);
+
+        if(result != OC_STACK_OK)
         {
-            OC_LOG (ERROR, TAG, "Out of memory");
+            OICFree(piResource);
             return;
         }
 
-        ret = snprintf(newUri, newUriSize, "%s/%s/%s/%s",
-                      PI_ZIGBEE_PREFIX,
-                      device->nodeId,
-                      device->endpointOfInterest->endpointId,
-                      device->endpointOfInterest->clusterList->clusterIds[i].clusterId);
-        if(ret < 0)
+        char * foundClusterID =
+            device->endpointOfInterest->clusterList->clusterIds[i].clusterId;
+
+        if (strcmp (foundClusterID, ZB_IAS_ZONE_CLUSTER) == 0)
         {
-            OC_LOG (ERROR, TAG, "Encoding error occurred trying to build Zigbee URI.");
+            piResource->header.piResource.resourceTypeName
+                = getResourceTypeForIASZoneType (device);
+
+            OCStackResult ret = TWListenForStatusUpdates (device->nodeId,
+                                      device->endpointOfInterest->endpointId);
+
+            if (ret != OC_STACK_OK)
+            {
+                // Just log it and move on if this fails?
+                // or not create this resource at all?
+                OC_LOG (ERROR, TAG, "Command to listen for status updates failed");
+            }
         }
-        else if(ret > newUriSize)
+        else
         {
-            OC_LOG_V (ERROR, TAG, "Did not allocate enough memory to build URI. Required Size: %d",
-                      ret);
+            piResource->header.piResource.resourceTypeName =
+                    (char *) ZigBeeClusterIDToOICResourceType(foundClusterID);
         }
 
-        piResource->header.piResource.uri = newUri;
-        piResource->header.piResource.resourceTypeName =
-
-            (char *) ZigBeeClusterIDToOICResourceType(
-                device->endpointOfInterest->clusterList->clusterIds[i].clusterId);
-
         if(piResource->header.piResource.resourceTypeName == NULL)
         {
-            OC_LOG_V (ERROR, TAG, "unsupported clusterId : %d",
+            OC_LOG_V (ERROR, TAG, "unsupported clusterId : %s",
                 device->endpointOfInterest->clusterList->clusterIds[i].clusterId);
             OICFree(piResource->header.piResource.uri);
             OICFree(piResource);
@@ -248,8 +379,32 @@ void foundZigbeeCallback(TWDevice *device)
     }
 }
 
+void zigbeeZoneStatusUpdate(TWUpdate * update)
+{
+    if(!update)
+    {
+        return;
+    }
+
+    char * uri = NULL;
+    OCStackResult result = buildURI(&uri,
+                                    PI_ZIGBEE_PREFIX,
+                                    update->nodeId,
+                                    update->endpoint,
+                                    ZB_IAS_ZONE_CLUSTER);
+    if(result != OC_STACK_OK || !uri)
+    {
+        OC_LOG_V(ERROR, TAG, "Failed to build URI with result: %d", result);
+        return;
+    }
+
+    (*gPlugin)->header.ObserveNotificationUpdate((PIPluginBase *)*gPlugin, uri);
+    OICFree(uri);
+}
+
 OCStackResult ZigbeeInit(const char * comPort, PIPlugin_Zigbee ** plugin,
-                         PINewResourceFound newResourceCB)
+                         PINewResourceFound newResourceCB,
+                         PIObserveNotificationUpdate observeNotificationUpdate)
 {
     if(!plugin)
     {
@@ -261,14 +416,21 @@ OCStackResult ZigbeeInit(const char * comPort, PIPlugin_Zigbee ** plugin,
         return OC_STACK_NO_MEMORY;
     }
     ((*plugin)->header).type = PLUGIN_ZIGBEE;
-    ((*plugin)->header).comPort = OICStrdup(comPort);
+    ((*plugin)->header).comPort = comPort;
     ((*plugin)->header).NewResourceFoundCB = newResourceCB;
+    ((*plugin)->header).ObserveNotificationUpdate = observeNotificationUpdate;
     ((*plugin)->header).next = NULL;
     ((*plugin)->header).resourceList = NULL;
     ((*plugin)->header).processEHRequest = ProcessEHRequest;
 
     gPlugin = plugin;
-    return TWInitialize(comPort);
+    OCStackResult result = TWInitialize(comPort);
+    if(result != OC_STACK_OK)
+    {
+        return result;
+    }
+
+    return TWSetStatusUpdateCallback(zigbeeZoneStatusUpdate);
 }
 
 OCStackResult ZigbeeDiscover(PIPlugin_Zigbee * plugin)
@@ -284,7 +446,6 @@ OCStackResult ZigbeeDiscover(PIPlugin_Zigbee * plugin)
 
 OCStackResult ZigbeeStop(PIPlugin_Zigbee * plugin)
 {
-    free((plugin->header).comPort);
     free(plugin);
     return TWUninitialize();
 }
@@ -299,7 +460,7 @@ OCStackResult ZigbeeProcess(PIPlugin_Zigbee * plugin)
 // from the cluster ID. If the cluster is not supported, null is
 // returned.
 // NOTE: The returned string is NOT malloc'ed.
-const char* ZigBeeClusterIDToOICResourceType (const char * clusterID) //Discovery/CreateResource
+const char* ZigBeeClusterIDToOICResourceType(const char * clusterID) //Discovery/CreateResource
 {
     if (strcmp(clusterID, ZB_TEMPERATURE_CLUSTER) == 0)
     {
@@ -309,7 +470,7 @@ const char* ZigBeeClusterIDToOICResourceType (const char * clusterID) //Discover
     {
         return OIC_DIMMABLE_LIGHT;
     }
-    else if (strcmp(clusterID, ZB_CONTACT_CLUSTER) == 0)
+    else if (strcmp(clusterID, ZB_IAS_ZONE_CLUSTER) == 0)
     {
         return OIC_CONTACT_SENSOR;
     }
@@ -323,7 +484,7 @@ const char* ZigBeeClusterIDToOICResourceType (const char * clusterID) //Discover
     }
 }
 
-const char* OICResourceToZigBeeClusterID (char *oicResourceType)
+const char* OICResourceToZigBeeClusterID(char *oicResourceType)
 {
     if (strcmp(oicResourceType, OIC_TEMPERATURE_SENSOR) == 0)
     {
@@ -335,7 +496,7 @@ const char* OICResourceToZigBeeClusterID (char *oicResourceType)
     }
     else if (strcmp(oicResourceType, OIC_CONTACT_SENSOR) == 0)
     {
-        return ZB_CONTACT_CLUSTER;
+        return ZB_IAS_ZONE_CLUSTER;
     }
     else if (strcmp(oicResourceType, OIC_BINARY_SWITCH) == 0)
     {
@@ -351,7 +512,7 @@ const char* OICResourceToZigBeeClusterID (char *oicResourceType)
     }
 }
 
-OCStackResult getZigBeeAttributesForOICResource (char * OICResourceType,
+OCStackResult getZigBeeAttributesForOICResource(const char * OICResourceType,
                                                     AttributeList *attributeList) // GET
 {
     if (strcmp (OICResourceType, OIC_TEMPERATURE_SENSOR) == 0)
@@ -376,7 +537,7 @@ OCStackResult getZigBeeAttributesForOICResource (char * OICResourceType,
     {
         attributeList->count = 1;
         attributeList->list[0].oicAttribute = OICStrdup(OIC_CONTACT_ATTRIBUTE);
-        attributeList->list[0].zigBeeAttribute = ZB_CONTACT_ATTRIBUTE_ID;
+        attributeList->list[0].zigBeeAttribute = ZB_IAS_ZONE_STATUS_ATTRIBUTE_ID;
         attributeList->list[0].oicType = OIC_ATTR_BOOL;
         attributeList->list[0].zigbeeType = ZB_BOOL;
         return OC_STACK_OK;
@@ -394,7 +555,7 @@ OCStackResult getZigBeeAttributesForOICResource (char * OICResourceType,
     return OC_STACK_ERROR;
 }
 
-bool getZigBeeAttributesIfValid (char * OICResourceType,
+bool getZigBeeAttributesIfValid(const char * OICResourceType,
                                     AttributeList *attributeList,
                                     OCRepPayload *payload) // Put
 {
@@ -448,7 +609,7 @@ bool getZigBeeAttributesIfValid (char * OICResourceType,
         {
             attributeList->count = 1;
             attributeList->list[0].oicAttribute = OICStrdup(OIC_CONTACT_ATTRIBUTE);
-            attributeList->list[0].zigBeeAttribute = ZB_CONTACT_ATTRIBUTE_ID;
+            attributeList->list[0].zigBeeAttribute = ZB_IAS_ZONE_STATUS_ATTRIBUTE_ID;
             attributeList->list[0].oicType = OIC_ATTR_BOOL;
             attributeList->list[0].val.i = value;
             attributeList->list[0].zigbeeType = ZB_BOOL;
@@ -651,7 +812,7 @@ exit:
     return stackResult;
 }
 
-OCEntityHandlerResult processPutRequest (PIPluginBase * plugin,
+OCEntityHandlerResult processPutRequest(PIPluginBase * plugin,
     OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
 {
     if (!plugin || !ehRequest || !payload)
@@ -775,7 +936,7 @@ OCEntityHandlerResult processPutRequest (PIPluginBase * plugin,
     return processGetRequest(plugin, ehRequest, payload);
 }
 
-OCEntityHandlerResult ProcessEHRequest (PIPluginBase * plugin,
+OCEntityHandlerResult ProcessEHRequest(PIPluginBase * plugin,
     OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
 {
     if(!ehRequest || !payload)