IP address plumbing changes to support IPv6
authorSachin Agrawal <sachin.agrawal@intel.com>
Tue, 16 Jun 2015 19:07:57 +0000 (12:07 -0700)
committerSachin Agrawal <sachin.agrawal@intel.com>
Tue, 16 Jun 2015 20:04:45 +0000 (20:04 +0000)
IPv6 selection logic and IPv6 modifiers are now available throughout
the stack.
Builds with all samples and tests.
Works with IPv4.
Merged with security update.
Supports JIRA IOT-476,477,488,489,493,509,548

Change-Id: I539879aeeb5aeddf2b136d81fdf1247c2af12b5f
Signed-off-by: John Light <john.j.light@intel.com>
Signed-off-by: Sachin Agrawal <sachin.agrawal@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1081
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
117 files changed:
android/android_api/base/jni/JniUtils.h
examples/OICMiddle/Client.cpp
extlibs/android/sdk/SConscript
resource/csdk/connectivity/SConscript
resource/csdk/connectivity/api/cacommon.h
resource/csdk/connectivity/api/cainterface.h
resource/csdk/connectivity/inc/caadapterinterface.h
resource/csdk/connectivity/inc/caadapternetdtls.h
resource/csdk/connectivity/inc/caadapterutils.h
resource/csdk/connectivity/inc/caedradapter.h
resource/csdk/connectivity/inc/caedradapter_singlethread.h
resource/csdk/connectivity/inc/caedrinterface.h
resource/csdk/connectivity/inc/cainterfacecontroller.h
resource/csdk/connectivity/inc/cainterfacecontroller_singlethread.h
resource/csdk/connectivity/inc/caipadapter.h
resource/csdk/connectivity/inc/caipadapter_singlethread.h
resource/csdk/connectivity/inc/caipinterface.h
resource/csdk/connectivity/inc/caleadapter.h
resource/csdk/connectivity/inc/caleadapter_singlethread.h
resource/csdk/connectivity/inc/camessagehandler.h
resource/csdk/connectivity/inc/camessagehandler_singlethread.h
resource/csdk/connectivity/inc/canetworkconfigurator.h
resource/csdk/connectivity/inc/caprotocolmessage.h
resource/csdk/connectivity/inc/caremotehandler.h
resource/csdk/connectivity/inc/caretransmission.h
resource/csdk/connectivity/inc/caretransmission_singlethread.h
resource/csdk/connectivity/samples/android/sample_service/jni/ResourceModel.c
resource/csdk/connectivity/samples/arduino/casample.cpp
resource/csdk/connectivity/samples/linux/sample_main.c
resource/csdk/connectivity/samples/tizen/casample.c
resource/csdk/connectivity/src/SConscript
resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c
resource/csdk/connectivity/src/adapter_util/caadapterutils.c
resource/csdk/connectivity/src/bt_edr_adapter/android/caedrclient.c
resource/csdk/connectivity/src/bt_edr_adapter/caedradapter.c
resource/csdk/connectivity/src/bt_edr_adapter/linux/caedradapter.c
resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c
resource/csdk/connectivity/src/bt_le_adapter/linux/caleadapter.c
resource/csdk/connectivity/src/caconnectivitymanager.c
resource/csdk/connectivity/src/caconnectivitymanager_singlethread.c
resource/csdk/connectivity/src/cainterfacecontroller.c
resource/csdk/connectivity/src/cainterfacecontroller_singlethread.c
resource/csdk/connectivity/src/camessagehandler.c
resource/csdk/connectivity/src/camessagehandler_singlethread.c
resource/csdk/connectivity/src/canetworkconfigurator.c
resource/csdk/connectivity/src/caprotocolmessage.c
resource/csdk/connectivity/src/caremotehandler.c
resource/csdk/connectivity/src/caretransmission.c
resource/csdk/connectivity/src/caretransmission_singlethread.c
resource/csdk/connectivity/src/ip_adapter/SConscript
resource/csdk/connectivity/src/ip_adapter/caipadapter.c
resource/csdk/connectivity/src/ip_adapter/caipadapter_singlethread.c
resource/csdk/connectivity/src/ip_adapter/caipclient.c
resource/csdk/connectivity/src/ip_adapter/caipserver.c
resource/csdk/connectivity/test/ca_api_unittest.cpp
resource/csdk/security/provisioning/include/provisioningmanager.h
resource/csdk/security/provisioning/src/provisioningmanager.c
resource/csdk/security/src/doxmresource.c
resource/csdk/security/src/secureresourcemanager.c
resource/csdk/security/unittest/securityresourcemanager.cpp
resource/csdk/stack/include/internal/occlientcb.h
resource/csdk/stack/include/internal/ocobserve.h
resource/csdk/stack/include/internal/ocresourcehandler.h
resource/csdk/stack/include/internal/ocserverrequest.h
resource/csdk/stack/include/internal/ocstackinternal.h
resource/csdk/stack/include/ocstack.h
resource/csdk/stack/include/octypes.h
resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp
resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp
resource/csdk/stack/src/occlientcb.c
resource/csdk/stack/src/occollection.c
resource/csdk/stack/src/ocobserve.c
resource/csdk/stack/src/ocresource.c
resource/csdk/stack/src/ocserverrequest.c
resource/csdk/stack/src/ocstack.c
resource/csdk/stack/src/oicgroup.c
resource/csdk/stack/test/linux/occlient.c
resource/csdk/stack/test/stacktests.cpp
resource/examples/devicediscoveryclient.cpp
resource/examples/fridgeclient.cpp
resource/examples/garageclient.cpp
resource/examples/groupclient.cpp
resource/examples/groupserver.cpp
resource/examples/presenceclient.cpp
resource/examples/roomclient.cpp
resource/examples/simpleclient.cpp
resource/examples/simpleclientHQ.cpp
resource/examples/simpleclientserver.cpp
resource/examples/threadingsample.cpp
resource/include/IClientWrapper.h
resource/include/InProcClientWrapper.h
resource/include/OCApi.h
resource/include/OCPlatform.h
resource/include/OCResource.h
resource/include/OCSerialization.h
resource/include/OutOfProcClientWrapper.h
resource/src/InProcClientWrapper.cpp
resource/src/InProcServerWrapper.cpp
resource/src/OCPlatform.cpp
resource/src/OCPlatform_impl.cpp
resource/src/OCResource.cpp
resource/unittests/OCPlatformTest.cpp
resource/unittests/OCResourceResponseTest.cpp
resource/unittests/OCResourceTest.cpp
service/notification-manager/NotificationManager/include/hosting.h
service/notification-manager/NotificationManager/src/hosting.c
service/notification-manager/SampleApp/linux/sampleConsumer/SampleConsumer.cpp
service/protocol-plugin/sample-app/linux/mqtt/mqttclient.cpp
service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.cpp
service/things-manager/sampleapp/linux/groupaction/groupserver.cpp
service/things-manager/sampleapp/linux/groupsyncaction/group.cpp
service/things-manager/sdk/src/GroupManager.cpp
service/things-manager/sdk/src/GroupSynchronization.cpp
service/things-manager/sdk/src/ThingsConfiguration.cpp

index c4553ff..92f2aa9 100644 (file)
@@ -128,18 +128,16 @@ public:
     {\r
         switch (type) {\r
         case 0:\r
-            return OCConnectivityType::OC_IPV4;\r
+            return OCConnectivityType::CT_DEFAULT;\r
         case 1:\r
-            return OCConnectivityType::OC_IPV6;\r
+            return OCConnectivityType::CT_ADAPTER_IP;\r
         case 2:\r
-            return OCConnectivityType::OC_EDR;\r
+            return OCConnectivityType::CT_ADAPTER_RFCOMM_BTEDR;\r
         case 3:\r
-            return OCConnectivityType::OC_LE;\r
-        case 4:\r
-            return OCConnectivityType::OC_ALL;\r
+            return OCConnectivityType::CT_ADAPTER_GATT_BTLE;\r
         default:\r
             ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected connectivity type");\r
-            return OCConnectivityType::OC_ALL;\r
+            return OCConnectivityType::CT_DEFAULT;\r
         };\r
     }\r
 \r
index b753b94..205212e 100644 (file)
@@ -39,7 +39,7 @@ void MiddleClient::findResources()
 {
     m_resourceMap.clear();
 
-    OC::OCPlatform::findResource("", OC_WELL_KNOWN_QUERY, OC_ALL, m_findCB);
+    OC::OCPlatform::findResource("", OC_WELL_KNOWN_QUERY, CT_DEFAULT, m_findCB);
 }
 
 void MiddleClient::foundOCResource(shared_ptr<OCResource> resource)
index aa268e6..17331bd 100644 (file)
@@ -45,7 +45,7 @@ if target_os == 'android':
                        print 'Unzipping android lib...'
                        env.UnpackAll(androidlib_dir, androidlib_zip)
                        print 'Unzipping android lib complete'
-    
+
                        # Remove downloaded file
 #                      os.remove(androidlib_zip_file)
        else:
index bec1000..ae0e16b 100644 (file)
@@ -62,4 +62,4 @@ env.SConscript('./src/SConscript')
 if build_sample == 'ON':
        if target_os in ['linux', 'arduino', 'android']:
                env.SConscript('./samples/' + target_os + '/SConscript')
-       
+
index ea05c4a..360ceb1 100644 (file)
@@ -110,17 +110,40 @@ typedef char *CAURI_t;
  */
 typedef char *CAToken_t;
 
-/**
- * @enum CATransportType_t
- * @brief Different connectivities that are handled in Connectivity Abstraction
- */
+// The following flags are the same as the equivalent OIC values in
+// octypes.h, allowing direct copying with slight fixup.
+// The CA layer should used the OC types when build allows that.
+#define MAX_ADDR_STR_SIZE_CA (40)
+
+typedef enum
+{
+    CA_DEFAULT_ADAPTER = 0,
+
+    // value zero indicates discovery
+    CA_ADAPTER_IP           = (1 << 0),   // IPv4 and IPv6, including 6LoWPAN
+    CA_ADAPTER_GATT_BTLE    = (1 << 1),   // GATT over Bluetooth LE
+    CA_ADAPTER_RFCOMM_BTEDR = (1 << 2),   // RFCOMM over Bluetooth EDR
+} CATransportAdapter_t;
+
 typedef enum
 {
-    CA_IPV4 = (1 << 0),     /**< IPV4 Transport Type */
-    CA_IPV6 = (1 << 1),     /**< IPV6 Transport Type */
-    CA_EDR = (1 << 2),      /**< EDR Transport Type */
-    CA_LE = (1 << 3)        /**< LE Transport Type */
-} CATransportType_t;
+    CA_DEFAULT_FLAGS = 0,
+
+    // Insecure transport is the default (subject to change)
+    CA_SECURE          = (1 << 4),   // secure the transport path
+    // IPv4 & IPv6 autoselection is the default
+    CA_IPV6            = (1 << 5),   // IP adapter only
+    CA_IPV4            = (1 << 6),   // IP adapter only
+    // Link-Local multicast is the default multicast scope for IPv6.
+    // These correspond in both value and position to the IPv6 address bits.
+    CA_SCOPE_INTERFACE = 0x1, // IPv6 Interface-Local scope
+    CA_SCOPE_LINK      = 0x2, // IPv6 Link-Local scope (default)
+    CA_SCOPE_REALM     = 0x3, // IPv6 Realm-Local scope
+    CA_SCOPE_ADMIN     = 0x4, // IPv6 Admin-Local scope
+    CA_SCOPE_SITE      = 0x5, // IPv6 Site-Local scope
+    CA_SCOPE_ORG       = 0x8, // IPv6 Organization-Local scope
+    CA_SCOPE_GLOBAL    = 0xE, // IPv6 Global scope
+} CATransportFlags_t;
 
 /**
  * @enum CANetworkStatus_t
@@ -132,37 +155,6 @@ typedef enum
     CA_INTERFACE_UP    /**< Connection is Available */
 } CANetworkStatus_t;
 
-/**
- * @brief  Address of the local or remote endpoint
- */
-typedef union
-{
-    /**
-     * @brief BT Mac Information
-     */
-    struct
-    {
-        char btMacAddress[CA_MACADDR_SIZE];   /**< BT mac address **/
-    } BT;
-
-    /**
-     * @brief LE MAC Information
-     */
-    struct
-    {
-        char leMacAddress[CA_MACADDR_SIZE];   /**< BLE mac address **/
-    } LE;
-
-    /**
-     * @brief IP Information
-     */
-    struct
-    {
-        char ipAddress[CA_IPADDR_SIZE]; /**< Ip address of the interface**/
-        uint16_t port;                  /**< port information**/
-    } IP;
-} CAAddress_t;
-
 /*
  * @brief remoteEndpoint identity
  */
@@ -170,7 +162,7 @@ typedef struct
 {
     uint16_t id_length;
     unsigned char id[CA_MAX_ENDPOINT_IDENTITY_LEN];
-}CARemoteId_t;
+} CARemoteId_t;
 
 /**
  * @enum CAMessageType_t
@@ -198,37 +190,18 @@ typedef enum
 } CAMethod_t;
 
 /**
- * @brief Remote endpoint information for connectivities
+ * @brief Endpoint information for connectivities
+ * Must be identical to OCDevAddr.
  */
 typedef struct
 {
-
-    CAURI_t resourceUri;                    /**< Resource URI information **/
-    CAAddress_t addressInfo;                /**< Remote Endpoint address **/
-    CATransportType_t transportType;  /**< Connectivity of the endpoint**/
-    bool isSecured;                         /**< Secure connection**/
-    CARemoteId_t identity;                  /**< Endpoint identity **/
-} CARemoteEndpoint_t;
-
-
-/**
- * @brief Group endpoint information for connectivities
- */
-typedef struct
-{
-    CAURI_t resourceUri;                    /**< Resource URI information **/
-    CATransportType_t transportType;  /**< Transport type of the endpoint**/
-} CAGroupEndpoint_t;
-
-/**
- @brief Local Connectivity information
- */
-typedef struct
-{
-    CAAddress_t addressInfo;    /**< Address of the interface  **/
-    CATransportType_t type;  /**< Transport type of local device **/
-    bool isSecured;         /**< Secure connection**/
-} CALocalConnectivity_t;
+    CATransportAdapter_t    adapter;    // adapter type
+    CATransportFlags_t      flags;      // transport modifiers
+    char                    addr[MAX_ADDR_STR_SIZE_CA]; // address for all
+    uint32_t                interface;  // usually zero for default interface
+    uint16_t                port;       // for IP
+    CARemoteId_t identity;              // endpoint identity
+} CAEndpoint_t;
 
 /**
  * @enum CAResult_t
@@ -307,7 +280,7 @@ typedef struct
     uint16_t optionID;                                      /**< The header option ID which will be
                                                             added to communication packets */
     uint16_t optionLength;                                  /**< Option Length **/
-    uint8_t optionData[CA_MAX_HEADER_OPTION_DATA_LENGTH];   /**< Optional data values**/
+    char optionData[CA_MAX_HEADER_OPTION_DATA_LENGTH];      /**< Optional data values**/
 } CAHeaderOption_t;
 
 /**
@@ -327,6 +300,7 @@ typedef struct
     CAHeaderOption_t *options;  /** Header Options for the request */
     uint8_t numOptions;         /**< Number of Header options */
     CAPayload_t payload;        /**< payload of the request  */
+    CAURI_t resourceUri;        /**< Resource URI information **/
 } CAInfo_t;
 
 /**
@@ -338,6 +312,7 @@ typedef struct
 {
     CAMethod_t method;  /**< Name of the Method Allowed */
     CAInfo_t info;      /**< Information of the request. */
+    bool isMulticast;   /**< is multicast request */
 } CARequestInfo_t;
 
 /**
@@ -364,9 +339,20 @@ typedef struct
                              helpful to identify the error */
 } CAErrorInfo_t;
 
+/**
+ * @brief Hold global variables for CA layer (also used by RI layer)
+ */
+typedef struct
+{
+    CATransportFlags_t serverFlags;
+    CATransportFlags_t clientFlags;
+} CAGlobals_t;
+
+extern CAGlobals_t caglobals;
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
 
-#endif /* CA_COMMON_H_ */
+#endif //#ifndef CA_COMMON_H_
 
index 760df09..90aeb67 100644 (file)
@@ -48,7 +48,7 @@ extern "C"
  * @param   requestInfo [OUT] Info for resource model to understand about the request.
  * @return  NONE
  */
-typedef void (*CARequestCallback)(const CARemoteEndpoint_t *object,
+typedef void (*CARequestCallback)(const CAEndpoint_t *object,
                                   const CARequestInfo_t *requestInfo);
 
 /**
@@ -57,7 +57,7 @@ typedef void (*CARequestCallback)(const CARemoteEndpoint_t *object,
  * @param   responseInfo    [OUT] Identifier which needs to be mapped with response.
  * @return  NONE
  */
-typedef void (*CAResponseCallback)(const CARemoteEndpoint_t *object,
+typedef void (*CAResponseCallback)(const CAEndpoint_t *object,
                                    const CAResponseInfo_t *responseInfo);
 /**
  * @brief   Callback function type for error
@@ -65,7 +65,7 @@ typedef void (*CAResponseCallback)(const CARemoteEndpoint_t *object,
  * @param   errorInfo       [OUT] CA Error information
  * @return  NONE
  */
-typedef void (*CAErrorCallback)(const CARemoteEndpoint_t *object,
+typedef void (*CAErrorCallback)(const CAEndpoint_t *object,
                                 const CAErrorInfo_t *errorInfo);
 
 #ifdef __WITH_DTLS__
@@ -146,29 +146,28 @@ CAResult_t CARegisterDTLSCredentialsHandler(CAGetDTLSCredentialsHandler GetDTLSC
 #endif //__WITH_DTLS__
 
 /**
- * @brief   Create a Remote endpoint if the URI is available already.
- *          This is a Helper function which can be used before calling
- *          CASendRequest / CASendNotification.
- * @param   uri                 [IN]  Absolute URI of the resource to be used to generate the
- *                                    Remote endpoint
- *                                    \n For ex : coap://10.11.12.13:4545/resource_uri ( for IP)
- *                                    \n coap://10:11:12:13:45:45/resource_uri ( for BT)
- * @param   transportType    [IN]  Transport type of the endpoint
- * @param   object              [OUT] Endpoint object which contains the above parsed data
+ * @brief   Create an endpoint description
+ * @param   flags               [IN]  how the adapter should be used
+ * @param   adapter             [IN]  which adapter to use
+ * @param   addr                [IN]  string representation of address
+ * @param   port                [IN]  port (for IP_ADAPTER)
+ * @param   endpoint            [OUT] Endpoint which contains the above
  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED
- * @remark  The created Remote endpoint can be freed using CADestroyRemoteEndpoint() API.
- * @see     CADestroyRemoteEndpoint
+ * @remark  The created Remote endpoint can be freed using CADestroyEndpoint().
+ * @see     CADestroyEndpoint
  */
-CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
-                                  const CATransportType_t transportType,
-                                  CARemoteEndpoint_t **object);
+CAResult_t CACreateEndpoint(CATransportFlags_t flags,
+                            CATransportAdapter_t adapter,
+                            const char *addr,
+                            uint16_t port,
+                            CAEndpoint_t **object);
 
 /**
  * @brief   Destroy the remote endpoint created
- * @param   object  [IN] Remote Endpoint object created with CACreateRemoteEndpoint
+ * @param   object  [IN] Remote Endpoint object created with CACreateEndpoint
  * @return  NONE
  */
-void CADestroyRemoteEndpoint(CARemoteEndpoint_t *object);
+void CADestroyEndpoint(CAEndpoint_t *object);
 
 /**
  * @brief   Generating the token for matching the request and response.
@@ -189,71 +188,34 @@ CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength);
 void CADestroyToken(CAToken_t token);
 
 /**
- * @brief   Find the resource in the network. This API internally sends multicast messages on all
- *          selected connectivity adapters. Responses are delivered via response callbacks.
- *
- * @param   resourceUri [IN] Uri to send multicast search request. Must contain only relative
- *                           path of Uri to be search.
- * @param   token       [IN] Token for the request
- * @param   tokenLength [IN]  length of the token
- * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_NOT_INITIALIZED
- */
-CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token, uint8_t tokenLength);
-
-/**
  * @brief   Send control Request on a resource
- * @param   object      [IN] Remote Endpoint where the payload need to be sent.
- *                           This Remote endpoint is delivered with Request or response callback.
+ * @param   object      [IN] Endpoint where the payload need to be sent.
+ *                           This endpoint is delivered with Request or response callback.
  * @param   requestInfo [IN] Information for the request.
  * @return  #CA_STATUS_OK #CA_STATUS_FAILED #CA_MEMORY_ALLOC_FAILED
  */
-CAResult_t CASendRequest(const CARemoteEndpoint_t *object, const CARequestInfo_t *requestInfo);
-
-/**
- * @brief   Send control Request on a resource to multicast group
- * @param   object      [IN] Group Endpoint where the payload need to be sent.
- *                           This Remote endpoint is delivered with Request or response callback.
- * @param   requestInfo [IN] Information for the request.
- * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
- */
-CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
-                              const CARequestInfo_t *requestInfo);
+CAResult_t CASendRequest(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo);
 
 /**
  * @brief   Send the response
- * @param   object          [IN] Remote Endpoint where the payload need to be sent.
- *                               This Remote endpoint is delivered with Request or response callback
+ * @param   object          [IN] Endpoint where the payload need to be sent.
+ *                               This endpoint is delivered with Request or response callback
  * @param   responseInfo    [IN] Information for the response
  * @return  #CA_STATUS_OK or  #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
  */
-CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
-                const CAResponseInfo_t *responseInfo);
+CAResult_t CASendResponse(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo);
 
 /**
  * @brief   Send notification to the remote object
- * @param   object          [IN] Remote Endpoint where the payload need to be sent.
- *                               This Remote endpoint is delivered with Request or response callback.
+ * @param   object          [IN] Endpoint where the payload need to be sent.
+ *                               This endpoint is delivered with Request or response callback.
  * @param   responseInfo    [IN] Information for the response.
  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
  */
-CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
+CAResult_t CASendNotification(const CAEndpoint_t *object,
                       const  CAResponseInfo_t *responseInfo);
 
 /**
- * @brief   To advertise the resource
- * @param   resourceUri [IN] URI to be advertised
- * @param   token       [IN] Token for the request
- * @param   tokenLength [IN] length of the token
- * @param   options     [IN] Header options information
- * @param   numOptions  [IN] Number of options
- * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or
- *          #CA_MEMORY_ALLOC_FAILED or #CA_STATUS_NOT_INITIALIZED
- */
-CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
-                               uint8_t tokenLength, const CAHeaderOption_t *options,
-                               const uint8_t numOptions);
-
-/**
  * @brief   Select network to use
  * @param   interestedNetwork   [IN] Connectivity Type enum
  * @return  #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED or #CA_NOT_SUPPORTED
@@ -275,7 +237,7 @@ CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_INVALID_PARAM or
 *                #CA_MEMORY_ALLOC_FAILED
  */
-CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
+CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size);
 
 /**
  * @brief    To Handle the Request or Response
@@ -319,8 +281,7 @@ CAResult_t CAEnableAnonECDHCipherSuite(const bool enable);
  *                                    'ID of new device(Resource Server)',
  *                                    'ID of owner smart-phone(Provisioning Server)')
  *
- * @param[IN] addrInfo  information of network address
- * @param[IN] transportType  transport type
+ * @param[IN] endpoint  information of network address
  * @param[IN] label  Ownership transfer method e.g)"oic.sec.doxm.jw"
  * @param[IN] labelLen  Byte length of label
  * @param[IN] rsrcServerDeviceID  ID of new device(Resource Server)
@@ -333,8 +294,7 @@ CAResult_t CAEnableAnonECDHCipherSuite(const bool enable);
  * @retval  CA_STATUS_OK    Successful
  * @retval  CA_STATUS_FAILED Operation failed
  */
-CAResult_t CAGenerateOwnerPSK(const CAAddress_t* addrInfo,
-                              const CATransportType_t transportType,
+CAResult_t CAGenerateOwnerPSK(const CAEndpoint_t *endpoint,
                               const uint8_t* label, const size_t labelLen,
                               const uint8_t* rsrcServerDeviceID,
                               const size_t rsrcServerDeviceIDLen,
@@ -345,27 +305,22 @@ CAResult_t CAGenerateOwnerPSK(const CAAddress_t* addrInfo,
 /**
  * Initiate DTLS handshake with selected cipher suite
  *
- * @param[IN] addrInfo    information of network address
- * @param[IN] transportType  transport type
+ * @param[IN] endpoint  information of network address
  *
  * @retval  CA_STATUS_OK    Successful
  * @retval  CA_STATUS_FAILED Operation failed
  */
-CAResult_t CAInitiateHandshake(const CAAddress_t* addrInfo,
-                               const CATransportType_t transportType);
+CAResult_t CAInitiateHandshake(const CAEndpoint_t *endpoint);
 
 /**
  * Close the DTLS session
  *
- * @param[IN] addrInfo       information of network address
- * @param[IN] transportType  transport type
+ * @param[IN] endpoint  information of network address
  *
  * @retval  CA_STATUS_OK    Successful
  * @retval  CA_STATUS_FAILED Operation failed
  */
-CAResult_t CACloseDtlsSession(const CAAddress_t* addrInfo,
-                              const CATransportType_t transportType);
-
+CAResult_t CACloseDtlsSession(const CAEndpoint_t *endpoint);
 
 #endif /* __WITH_DTLS__ */
 
index 31b81e0..6b16ce1 100644 (file)
@@ -79,17 +79,19 @@ typedef CAResult_t (*CAAdapterStartDiscoveryServer)();
  * @param   dataLen     [IN]    Size of data to be sent.
  * @return The number of bytes sent on the network. Return value equal to -1 indicates error.
  */
-typedef int32_t (*CAAdapterSendUnicastData)(const CARemoteEndpoint_t *endpoint,
-        const void *data, uint32_t dataLen);
+typedef int32_t (*CAAdapterSendUnicastData)(const CAEndpoint_t *endpoint,
+                                            const void *data, uint32_t dataLen);
 
 /**
  * @brief Sends Multicast data to the endpoint using the adapter connectivity.
  * Note: length must be > 0.
+ * @param   endpoint    [IN]    Remote Endpoint information (like ipaddress , port,
  * @param   data        [IN]    Data which required to be sent.
  * @param   dataLen     [IN]    Size of data to be sent.
  * @return The number of bytes sent on the network. Return value equal to -1 indicates error.
  */
-typedef int32_t (*CAAdapterSendMulticastData)(const void *data, uint32_t dataLen);
+typedef int32_t (*CAAdapterSendMulticastData)(const CAEndpoint_t *endpoint,
+        const void *data, uint32_t dataLen);
 
 /**
  * @brief Get Network Information
@@ -97,7 +99,7 @@ typedef int32_t (*CAAdapterSendMulticastData)(const void *data, uint32_t dataLen
  * @param   size        [OUT]   Number of local connectivity structures.
  * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-typedef CAResult_t (*CAAdapterGetNetworkInfo)(CALocalConnectivity_t **info, uint32_t *size);
+typedef CAResult_t (*CAAdapterGetNetworkInfo)(CAEndpoint_t **info, uint32_t *size);
 
 /**
  * @brief Read Synchronous API callback.
@@ -157,29 +159,30 @@ typedef struct
 
 /**
  * @brief This will be used during the registration of adapters call backs to the common logic
- * @see CAConnectivityHandler_t , CATransportType_t
+ * @see CAConnectivityHandler_t , CATransportAdapter_t
  */
 typedef void (*CARegisterConnectivityCallback)(CAConnectivityHandler_t handler,
-        CATransportType_t cType);
+        CATransportAdapter_t cType);
 
 /**
  * @brief This will be used during the recive of network requests and response.
  * @see SendUnicastData(), SendMulticastData()
  */
-typedef void (*CANetworkPacketReceivedCallback)(CARemoteEndpoint_t *endPoint, void *data,
+typedef void (*CANetworkPacketReceivedCallback)(const CAEndpoint_t *endPoint, void *data,
         uint32_t dataLen);
 
 /**
  * @brief This will be used to notify network changes to the connectivity common logic layer
  * @see SendUnicastData(), SendMulticastData()
  */
-typedef void (*CANetworkChangeCallback)(CALocalConnectivity_t *info, CANetworkStatus_t status);
+typedef void (*CANetworkChangeCallback)(const CAEndpoint_t *info, CANetworkStatus_t status);
 
 /**
  * @brief This will be used to notify error result to the connectivity common logic layer
  */
-typedef void (*CAErrorHandleCallback)(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
-                                      uint32_t dataLen, CAResult_t result);
+typedef void (*CAErrorHandleCallback)(const CAEndpoint_t *endpoint,
+                                      const void *data, uint32_t dataLen,
+                                      CAResult_t result);
 
 #ifdef __cplusplus
 } /* extern "C" */
index f9f99d8..402c746 100644 (file)
  */
 extern void OCGetDtlsPskCredentials(CADtlsPskCredsBlob_t **credInfo);
 
-typedef void (*CAPacketReceivedCallback)(const char *ipAddress, const uint16_t port,
-                                         const void *data, const uint32_t dataLength,
-                                         const bool isSecured, const CARemoteId_t *identity);
+typedef void (*CAPacketReceivedCallback)(const CAEndpoint_t *endpoint,
+                                         const void *data, uint32_t dataLength);
 
-typedef uint32_t (*CAPacketSendCallback)(const char *ipAddress, const uint16_t port,
-                                         const void *data, const uint32_t dataLength);
+typedef uint32_t (*CAPacketSendCallback)(const CAEndpoint_t *endpoint,
+                                         const void *data, uint32_t dataLength);
 
 /**
  * @struct stCAAdapterCallbacks_t
@@ -125,17 +124,6 @@ typedef struct CACacheMessage
 
 
 /**
- * @struct stCADtlsPeerInfo_t
- * @brief structure associates the peer psk id with peer n/w address
- */
-typedef struct stCADtlsPeerInfo
-{
-    CAAddress_t address;
-    CARemoteId_t identity;
-}stCADtlsPeerInfo_t;
-
-
-/**
  * @fn  CADTLSSetAdapterCallbacks
  * @brief  Used set send and recv callbacks for different adapters(WIFI,EtherNet)
  *
@@ -147,7 +135,8 @@ typedef struct stCADtlsPeerInfo
  *
  */
 void CADTLSSetAdapterCallbacks(CAPacketReceivedCallback recvCallback,
-                               CAPacketSendCallback sendCallback, CATransportType_t type);
+                               CAPacketSendCallback sendCallback,
+                               CATransportAdapter_t type);
 
 /**
  * @brief   Register callback to get DTLS PSK credentials.
@@ -180,24 +169,20 @@ CAResult_t CADtlsEnableAnonECDHCipherSuite(const bool enable);
 /**
  * Initiate DTLS handshake with selected cipher suite
  *
- * @param[in] addrInfo  information of network address
- * @param[in] transportType  transport type
+ * @param[in] endpoint  information of network address
  *
  * @retval  CA_STATUS_OK for success, otherwise some error value
  */
-CAResult_t CADtlsInitiateHandshake(const CAAddress_t* addrInfo,
-                                   const CATransportType_t transportType);
+CAResult_t CADtlsInitiateHandshake(const CAEndpoint_t *endpoint);
 
 /**
  * Close the DTLS session
  *
- * @param[in] addrInfo  information of network address
- * @param[in] transportType  transport type
+ * @param[in] endpoint  information of network address
  *
  * @retval  CA_STATUS_OK for success, otherwise some error value
  */
-CAResult_t CADtlsClose(const CAAddress_t* addrInfo,
-                       const CATransportType_t transportType);
+CAResult_t CADtlsClose(const CAEndpoint_t *endpoint);
 
 /**
  * Generate ownerPSK using PRF
@@ -205,8 +190,7 @@ CAResult_t CADtlsClose(const CAAddress_t* addrInfo,
  *                                    'ID of new device(Resource Server)',
  *                                    'ID of owner smart-phone(Provisioning Server)')
  *
- * @param[in] addrInfo  information of network address
- * @param[in] transportType  transport type
+ * @param[in] endpoint  information of network address
  * @param[in] label  Ownership transfer method e.g)"oic.sec.doxm.jw"
  * @param[in] labelLen  Byte length of label
  * @param[in] rsrcServerDeviceID  ID of new device(Resource Server)
@@ -218,8 +202,7 @@ CAResult_t CADtlsClose(const CAAddress_t* addrInfo,
  *
  * @retval  CA_STATUS_OK for success, otherwise some error value
  */
-CAResult_t CADtlsGenerateOwnerPSK(const CAAddress_t* addrInfo,
-                    const CATransportType_t transportType,
+CAResult_t CADtlsGenerateOwnerPSK(const CAEndpoint_t *endpoint,
                     const uint8_t* label, const size_t labelLen,
                     const uint8_t* rsrcServerDeviceID, const size_t rsrcServerDeviceIDLen,
                     const uint8_t* provServerDeviceID, const size_t provServerDeviceIDLen,
@@ -255,11 +238,10 @@ void CAAdapterNetDtlsDeInit();
  *              a new DTLS handshake is started, pdu info is
  *              cached to be send when session setup is finished.
  *
- * @param[in]  remoteAddress  address to which data will be sent.
+ * @param[in]  endpoint  address to which data will be sent.
  * @param[in]  port  port to which data will be sent.
  * @param[in]  data  length of data.
  * @param[in]  dataLen  length of given data
- * @param[in]  type  transport at which packet needs to be send
  *
  * @return  0 on success otherwise a positive error value.
  * @retval  CA_STATUS_OK  Successful
@@ -268,11 +250,9 @@ void CAAdapterNetDtlsDeInit();
  *
  */
 
-CAResult_t CAAdapterNetDtlsEncrypt(const char *remoteAddress,
-                                   const uint16_t port,
+CAResult_t CAAdapterNetDtlsEncrypt(const CAEndpoint_t *endpoint,
                                    void *data,
-                                   uint32_t dataLen,
-                                   CATransportType_t type);
+                                   uint32_t dataLen);
 
 /**
  * @fn  CAAdapterNetDtlsDecrypt
@@ -289,11 +269,9 @@ CAResult_t CAAdapterNetDtlsEncrypt(const char *remoteAddress,
  * @retval  CA_STATUS_FAILED Operation failed
  *
  */
-CAResult_t CAAdapterNetDtlsDecrypt(const char *remoteAddress,
-                                   const uint16_t port,
+CAResult_t CAAdapterNetDtlsDecrypt(const CAEndpoint_t *endpoint,
                                    uint8_t *data,
-                                   uint32_t dataLen,
-                                   CATransportType_t type);
+                                   uint32_t dataLen);
 
 #endif /* CA_ADAPTER_NET_DTLS_H_ */
 
index f78cebb..a9b3d9e 100644 (file)
 #include <jni.h>
 #endif
 
+#ifndef WITH_ARDUINO
+#include <sys/socket.h>
+#endif
+
 #include "cacommon.h"
 #include "logger.h"
 #include "pdu.h"
@@ -99,9 +103,7 @@ typedef struct
 typedef struct
 {
     int socketFd;                               /**< Socket decriptor **/
-    char ipAddress[CA_IPADDR_SIZE];             /**< Address of the ip **/
-    uint16_t port;                              /**< Server port number **/
-    bool isSecured;                             /**< Indicates secured server **/
+    CAEndpoint_t endpoint;                      /**< endpoint description **/
     bool isServerStarted;                       /**< Indicates server started **/
     bool isMulticastServer;                     /**< Indicates multicast server **/
     char ifAddr[CA_IPADDR_SIZE];                /**< Address of the multicast interface  **/
@@ -115,42 +117,23 @@ typedef struct
 void CALogPDUData(coap_pdu_t *pdu);
 
 /**
- * @fn CAAdapterCreateLocalEndpoint
- * @brief Create CALocalConnectivity_t instance.
- */
-CALocalConnectivity_t *CAAdapterCreateLocalEndpoint(CATransportType_t type, const char *address);
-
-/**
- * @fn CAAdapterCopyLocalEndpoint
- * @brief Create CALocalConnectivity_t duplicate instance.
- */
-CALocalConnectivity_t *CAAdapterCopyLocalEndpoint(const CALocalConnectivity_t *connectivity);
-
-/**
- * @fn CAAdapterFreeLocalEndpoint
- * @brief Deallocate CALocalConnectivity_t instance.
- */
-void CAAdapterFreeLocalEndpoint(CALocalConnectivity_t *localEndPoint);
-
-/**
- * @fn CAAdapterCreateRemoteEndpoint
- * @brief Allocate CARemoteEndpoint_t instance.
+ * @fn CAAdapterCloneEndpoint
+ * @brief Create CAEndpoint_t duplicate instance.
  */
-CARemoteEndpoint_t *CAAdapterCreateRemoteEndpoint(CATransportType_t type, const char *address,
-                                                  const char *resourceUri);
+CAEndpoint_t *CAAdapterCloneEndpoint(const CAEndpoint_t *endpoint);
 
 /**
- * @fn CAAdapterCopyRemoteEndpoint
- * @brief Create CARemoteEndpoint_t duplicate instance.
+ * @fn CAAdapterFreeEndpoint
+ * @brief Deallocate CAEndpoint_t instance.
  */
-CARemoteEndpoint_t *CAAdapterCopyRemoteEndpoint(
-    const CARemoteEndpoint_t *remoteEndpoint);
+void CAAdapterFreeEndpoint(CAEndpoint_t *localEndPoint);
 
 /**
- * @fn CAAdapterFreeRemoteEndpoint
- * @brief Deallocate CARemoteEndpoint_t instance.
+ * @fn CAAdapterCreateEndpoint
+ * @brief Allocate CAEndpoint_t instance.
  */
-void CAAdapterFreeRemoteEndpoint(CARemoteEndpoint_t *remoteEndPoint);
+CAEndpoint_t *CAAdapterCreateEndpoint(CATransportFlags_t flags,
+              CATransportAdapter_t adapter, const char *address, uint16_t port);
 
 /**
  * @fn CAParseIPv4AddressInternal
@@ -215,15 +198,13 @@ uint16_t CAGetServerPort(const u_arraylist_t *serverInfoList, const char *ipAddr
  * @brief  Used to get the socket fd for given server information.
  *
  * @param   serverInfoList  [IN] Server information list.
- * @param   ipAddress       [IN] Ip address of the server.
- * @param   isSecured       [IN] To check whether it is secured server or not.
  * @param   isMulticast     [IN] To check whether it is multicast server or not.
- * @param   type            [IN] CA_IPV4, CA_IPV6 etc.
+ * @param   endpoint        [IN] network address
 
  * @return  positive value on success and -1 on error.
  */
-int CAGetSocketFdForUnicastServer(const u_arraylist_t *serverInfoList, const char *ipAddress,
-                                  bool isSecured, bool isMulticast, CATransportType_t type);
+int CAGetSocketFdForUnicastServer(const u_arraylist_t *serverInfoList,
+                         bool isMulticast, const CAEndpoint_t *endpoint);
 
 /**
  * @brief  Used to add the server information into serverinfo list
@@ -268,6 +249,22 @@ void CAClearNetInterfaceInfoList(u_arraylist_t *infoList);
  */
 void CAClearServerInfoList(u_arraylist_t *serverInfoList);
 
+/**
+ * @brief   Convert address from binary to string
+ * @param   ipaddr  [IN] IP address info
+ * @param   host    [OUT] address string (must be CA_IPADDR_SIZE)
+ * @param   port    [OUT] host order port number
+ */
+void CAConvertAddrToName(const struct sockaddr_storage *sockaddr, char *host, uint16_t *port);
+
+/**
+ * @brief   Convert address from string to binary
+ * @param   host    [IN] address string
+ * @param   port    [IN] host order port number
+ * @param   ipaddr  [OUT] IP address info
+ */
+void CAConvertNameToAddr(const char *host, uint16_t port, struct sockaddr_storage *sockaddr);
+
 #ifdef __ANDROID__
 /**
  * @fn CANativeJNISetContext
index 678f864..b9d7839 100644 (file)
@@ -79,24 +79,25 @@ CAResult_t CAStartEDRDiscoveryServer();
 
 /**
  * @brief  Sends data to the peer bluetooth OIC device using the adapter connectivity.
- * @param  remoteEndpoint  [IN] Remote Endpoint information (like ipaddress, port, reference uri and
+ * @param  endpoint        [IN] Remote Endpoint information (like ipaddress, port, and
  *                              connectivity type) to which the unicast data has to be sent.
  * @param  data            [IN] Data to be sent.
  * @param  dataLength      [IN] Size of data to be sent.
  * @return The number of bytes sent on the network. Returns -1 on error.
  *
  */
-int32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
+int32_t CASendEDRUnicastData(const CAEndpoint_t *endpoint, const void *data,
                              uint32_t dataLength);
 
 /**
  * @brief  Sends multicast data to all discovered bluetooth OIC devices using the adapter
- *         connectivity.
- * @param  data         [IN]  Data which needs to be sent to all discovered bluetooth OIC device.
- * @param  dataLength   [IN]  Length of data in bytes.
+ * @param  endpoint     [IN] Remote Endpoint information (like ipaddress, port, and connectivity.
+ * @param  data         [IN] Data which needs to be sent to all discovered bluetooth OIC device.
+ * @param  dataLength   [IN] Length of data in bytes.
  * @return Number of bytes sent on the network. Returns -1 on error.
  */
-int32_t CASendEDRMulticastData(const void *data, uint32_t dataLength);
+int32_t CASendEDRMulticastData(const CAEndpoint_t *endpoint, const void *data,
+                               uint32_t dataLength);
 
 /**
  * @brief  Get EDR Connectivity network information.
@@ -106,7 +107,7 @@ int32_t CASendEDRMulticastData(const void *data, uint32_t dataLength);
  *
  * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
  */
-CAResult_t CAGetEDRInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
+CAResult_t CAGetEDRInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
 
 /**
  * @brief  Read Synchronous API callback.
index a5996d0..eea4e42 100644 (file)
@@ -91,13 +91,13 @@ CAResult_t CAStartEDRDiscoveryServer();
 
 /**
  * @brief  Sends data to the peer bluetooth OIC device using the adapter connectivity.
- * @param  remoteEndpoint  [IN] Remote Endpoint information (like ipaddress, port, reference uri and
+ * @param  endpoint        [IN] Remote Endpoint information (like ipaddress, port, reference uri and
  *                              connectivity type) to which the unicast data has to be sent.
  * @param  data            [IN] Data to be sent.
  * @param  dataLength      [IN] Size of data to be sent.
  * @return Number of bytes sent on the network. Returns -1 on error.
  */
-int32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
+int32_t CASendEDRUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data,
                               uint32_t dataLength);
 
 /**
@@ -122,7 +122,7 @@ int32_t CASendEDRMulticastData(const void *data, uint32_t dataLength);
  * @retval #CA_STATUS_FAILED Operation failed
  * @remarks info is allocated in this API and should be freed by the caller.
  */
-CAResult_t CAGetEDRInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
+CAResult_t CAGetEDRInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
 
 /**
  * @brief  Read Synchronous API callback.
index 57ac40e..7904c02 100644 (file)
@@ -68,7 +68,7 @@ typedef enum
  */
 typedef struct
 {
-    CARemoteEndpoint_t *remoteEndpoint; /**< Remote Endpoint */
+    CAEndpoint_t *remoteEndpoint;       /**< Remote Endpoint */
     void *data;                         /**< Data to be sent */
     uint32_t dataLen;                   /**< Length of the data to be sent */
 } CAEDRData;
@@ -79,7 +79,7 @@ typedef struct
  */
 typedef struct
 {
-    CALocalConnectivity_t *info; /**< Local Connectivity Information */
+    CAEndpoint_t *info;          /**< Local Connectivity Information */
     CANetworkStatus_t status;    /**< Network Status */
 } CAEDRNetworkEvent;
 
@@ -200,7 +200,7 @@ void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChange
  * @see #CALocalConnectivity_t
  *
  */
-CAResult_t CAEDRGetInterfaceInformation(CALocalConnectivity_t **info);
+CAResult_t CAEDRGetInterfaceInformation(CAEndpoint_t **info);
 
 /**
  * @brief  Start RFCOMM server for given service UUID
index 6725216..efadd1a 100644 (file)
@@ -68,14 +68,14 @@ void CASetNetworkChangeCallback(CANetworkChangeCallback callback);
  * @param   transportType   [IN]    interested network for starting
  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CAStartAdapter(CATransportType_t transportType);
+CAResult_t CAStartAdapter(CATransportAdapter_t transportType);
 
 /**
  * @brief   Stopping different connectivity adapters based on the network un-selection.
  * @param   transportType   [IN]    network type that want to stop
  * @return  none
  */
-void CAStopAdapter(CATransportType_t transportType);
+void CAStopAdapter(CATransportAdapter_t transportType);
 
 /**
  * @brief   Get network information such as ipaddress and mac information
@@ -83,7 +83,7 @@ void CAStopAdapter(CATransportType_t transportType);
  * @param   size           [OUT]    number of connectivity information structures
  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size);
+CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size);
 
 /**
  * @brief   Sends unicast data to the remote endpoint
@@ -92,16 +92,17 @@ CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size);
  * @param   length         [IN]    length of the data that needs to be sent
  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CASendUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t length);
+CAResult_t CASendUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length);
 
 /**
  * @brief   Sends multicast data to all endpoints in the network.
+ * @param   endpoint       [IN]    endpoint information where the data has to be sent
  * @param   data           [IN]    data that needs to be sent
  * @param   length         [IN]    length of the data that needs to be sent
  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
 
-CAResult_t CASendMulticastData(const void *data, uint32_t length);
+CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length);
 
 /**
  * @brief   Start listening servers to receive search requests from clients
index 2c048f8..db003a2 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "caadapterinterface.h"
 
-
 #ifdef __cplusplus
 extern "C"
 {
@@ -68,17 +67,17 @@ void CASetErrorHandleCallback(CAErrorHandleCallback errorCallback);
 
 /**
  * @brief   Starting different connectivity adapters based on the network selection.
- * @param   transportType    [IN]    network type that want to stop
+ * @param   transportAdapter [IN]    network type that want to stop
  * @return  none
  */
-CAResult_t CAStartAdapter(CATransportType_t transportType);
+CAResult_t CAStartAdapter(CATransportAdapter_t transportType);
 
 /**
  * @brief   Stopping different connectivity adapters based on the network un-selection.
- * @param   transportType    [IN]    un selected network for stopping the packets transfer
+ * @param   transportAdapter [IN]    un selected network for stopping the packets transfer
  * @return   none
  */
-void CAStopAdapter(CATransportType_t transportType);
+void CAStopAdapter(CATransportAdapter_t transportType);
 
 /**
  * @brief   Get network information such as ipaddress and mac information.  Gets the network
@@ -87,7 +86,7 @@ void CAStopAdapter(CATransportType_t transportType);
  * @param   size            [OUT]    number of connectivity information structures
  * @return   CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size);
+CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size);
 
 /**
  * @brief   Sends unicast data to the remote endpoint
@@ -96,15 +95,16 @@ CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size);
  * @param   length          [IN]    length of the data that needs to be sent
  * @return   CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CASendUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t length);
+CAResult_t CASendUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length);
 
 /**
  * @brief   Sends multicast data to all endpoints in the network.
+ * @param   endpoint        [IN]    endpoint information where the data has to be sent
  * @param   data            [IN]    data that needs to be sent
  * @param   length          [IN]    length of the data that needs to be sent
  * @return   CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CASendMulticastData(const void *data, uint32_t length);
+CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length);
 
 /**
  * @brief   Start listening servers to receive search requests from clients
index fc1e697..22ab8ce 100644 (file)
@@ -83,17 +83,18 @@ CAResult_t CAStartIPDiscoveryServer();
  * @return The number of bytes sent on the network. Return value equal to -1 indicates error.
  * @remarks dataLen must be > 0.
  */
-int32_t CASendIPUnicastData(const CARemoteEndpoint_t *endpoint, const void *data,
+int32_t CASendIPUnicastData(const CAEndpoint_t *endpoint, const void *data,
                                    uint32_t dataLen);
 
 /**
  * @brief Sends Multicast data to the endpoint using the IP connectivity.
+ * @param   endpoint    [IN]    Remote Endpoint information (like ipaddress , port)
  * @param   data        [IN]    Data which required to be sent.
  * @param   dataLen     [IN]    Size of data to be sent.
  * @return The number of bytes sent on the network. Return value equal to -1 indicates error.
  * @remarks dataLen must be > 0.
  */
-int32_t CASendIPMulticastData(const void *data, uint32_t dataLen);
+int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen);
 
 /**
  * @brief Get IP Connectivity network information
@@ -102,7 +103,7 @@ int32_t CASendIPMulticastData(const void *data, uint32_t dataLen);
  * @return  #CA_STATUS_OK or Appropriate error code
  * @remarks info is allocated in this API and should be freed by the caller.
  */
-CAResult_t CAGetIPInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
+CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
 
 /**
  * @brief Read Synchronous API callback.
index 7625a04..f772c88 100644 (file)
@@ -80,7 +80,7 @@ CAResult_t CAStartIPDiscoveryServer();
  * @return  The number of bytes sent on the network. Return value equal to -1 indicates error.
  * @remark  dataLen must be > 0.
  */
-int32_t CASendIPUnicastData(const CARemoteEndpoint_t *endpoint, const void *data,
+int32_t CASendIPUnicastData(const CAEndpoint_t *endpoint, const void *data,
                                   uint32_t dataLen);
 
 /**
@@ -90,7 +90,7 @@ int32_t CASendIPUnicastData(const CARemoteEndpoint_t *endpoint, const void *data
  * @return  The number of bytes sent on the network. Return value equal to -1 indicates error.
  * @remark  dataLen must be > 0.
  */
-int32_t CASendIPMulticastData(const void *data, uint32_t dataLen);
+int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen);
 
 /**
  * @brief Get IP Connectivity network information
@@ -99,7 +99,7 @@ int32_t CASendIPMulticastData(const void *data, uint32_t dataLen);
  * @return  #CA_STATUS_OK or Appropriate error code
  * @remarks info is allocated in this API and should be freed by the caller.
  */
-CAResult_t CAGetIPInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
+CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
 
 /**
  * @brief Read Synchronous API callback.
index b440285..8d61e90 100644 (file)
@@ -51,19 +51,16 @@ typedef enum
 /**
  * @brief Callback to be notified on reception of any data from remote OIC devices.
  *
- * @param  ipAddress    [IN] IP address of remote OIC device.
- * @param  port         [IN] Port number on which data is received.
+ * @param  endpoint     [IN] network endpoint description
  * @param  data         [IN] Data received from remote OIC device.
  * @param  dataLength   [IN] Length of data in bytes.
- * @param  isSecured    [IN] Indicates the data is secure or not.
- * @param  identity     [IN] Identity of the remote OIC device.
  *
  * @return NONE
  * @pre  Callback must be registered using CAIPSetPacketReceiveCallback()
  */
-typedef void (*CAIPPacketReceivedCallback)(const char *ipAddress, uint16_t port,
-                                           const void *data, uint32_t dataLength,
-                                           bool isSecured, const CARemoteId_t *identity);
+typedef void (*CAIPPacketReceivedCallback)(const CAEndpoint_t *endpoint,
+                                           const void *data,
+                                           uint32_t dataLength);
 
 /**
  * @brief  Callback to be notified when exception occures on multicast/unicast server.
@@ -220,18 +217,18 @@ void CAIPSetExceptionCallback(CAIPExceptionCallback callback);
 /**
  * @brief  API to send unicast UDP data
  *
- * @param  remoteAddress    [IN] IP address to which data needs to be sent.
- * @param  port             [IN] Port to which data needs to be send.
+ * @param  endpoint         [IN] complete network address to send to
  * @param  data             [IN] Data to be send.
  * @param  dataLength       [IN] Length of data in bytes
  * @param  isMulticast      [IN] Whether data needs to be sent to multicast ip
- * @param  isSecured        [IN] Whether data to be sent on secured channel.
  *
  * @return  The number of bytes sent on the network. Returns 0 on error.
  * @remarks isSecure will be ignored when isMulticast is true.
  */
-uint32_t CAIPSendData(const char *remoteAddress, uint16_t port, const void *data,
-                      uint32_t dataLength, bool isMulticast, bool isSecure);
+uint32_t CAIPSendData(const CAEndpoint_t *endpoint,
+                      const void *data,
+                      uint32_t dataLength,
+                      bool isMulticast);
 
 /**
  * @brief  Callback to be notified when IP adapter connection state changes.
index ad6e4bb..58ffe7e 100644 (file)
@@ -46,7 +46,7 @@ extern "C"
  */
 typedef struct
 {
-    CARemoteEndpoint_t
+    CAEndpoint_t
     *remoteEndpoint;   /**< Remote endpoint contains the inforamtion of remote device */
     void *data;        /**< Data to be transmitted over LE tranport */
     uint32_t dataLen;  /**< Length of the data being transmitted */
@@ -100,17 +100,18 @@ CAResult_t CAStartLEDiscoveryServer();
  * @return  The number of bytes sent on the network. Returns -1 on error.
  * @remarks  dataLen must be > 0.
  */
-int32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, const void *data,
+int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint, const void *data,
                              uint32_t dataLen);
 
 /**
  * @brief Sends Multicast data to the endpoint using the LE connectivity.
- * @param   data        [IN]    Data which required to be sent.
- * @param   dataLen     [IN]    Size of data to be sent.
+ * @param   endpoint    [IN]  Remote Endpoint information to which the unicast data has to be sent.
+ * @param   data        [IN]  Data which required to be sent.
+ * @param   dataLen     [IN]  Size of data to be sent.
  * @return  The number of bytes sent on the network. Returns -1 on error.
  * @remarks  dataLen must be > 0.
  */
-int32_t CASendLEMulticastData(const void *data, uint32_t dataLen);
+int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen);
 
 /**
  * @brief Starts notification server on EDR adapters.
@@ -127,7 +128,7 @@ CAResult_t CAStartLENotifyServer();
  * @return  The number of bytes sent on the network. Returns 0 on error.
  * @remarks dataLen must be > 0.
  */
-uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, const void *data,
+uint32_t CASendLENotification(const CAEndpoint_t *endpoint, const void *data,
                               uint32_t dataLen);
 
 /**
@@ -136,7 +137,7 @@ uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, const void *da
  * @param  size        [OUT]   Number of local connectivity structures.
  * @return #CA_STATUS_OK or Appropriate error code
  */
-CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
+CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
 
 /**
  * @brief Read Synchronous API callback.
@@ -210,7 +211,7 @@ void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint,
+CAResult_t CABLEServerSendData(const CAEndpoint_t *remoteEndpoint,
                                const void *data, uint32_t dataLen);
 
 /**
@@ -225,7 +226,7 @@ CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint,
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CABLEClientSendData(const CARemoteEndpoint_t *remoteEndpoint,
+CAResult_t CABLEClientSendData(const CAEndpoint_t *remoteEndpoint,
                                const void *data,  uint32_t dataLen);
 
 /**
@@ -383,7 +384,7 @@ CAResult_t CAInitBleClientReceiverQueue();
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CALEData_t *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
+CALEData_t *CACreateBLEData(const CAEndpoint_t *remoteEndpoint, const void *data,
                            uint32_t dataLength);
 
 /**
index c790889..5e8134d 100644 (file)
@@ -45,8 +45,7 @@ extern "C"
  */
 typedef struct
 {
-    CARemoteEndpoint_t
-    *remoteEndpoint;    /**< Remote endpoint contains the inforamtion of remote device */
+    CAEndpoint_t *remoteEndpoint; /**< Remote endpoint contains the inforamtion of remote device */
     void *data;         /**< Data to be transmitted over LE tranport */
     uint32_t dataLen;   /**< Length of the data being transmitted */
 } CALEData_t;
@@ -96,7 +95,7 @@ CAResult_t CAStartLEDiscoveryServer();
  * @return  The number of bytes sent on the network. Returns -1 on error.
  * @remarks dataLen must be > 0.
  */
-int32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, const void *data,
+int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint, const void *data,
                              uint32_t dataLen);
 
 /**
@@ -123,7 +122,7 @@ CAResult_t CAStartLENotifyServer();
  * @return  The number of bytes sent on the network. Returns 0 on error.
  * @remarks dataLen must be > 0.
  */
-uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, const void *data,
+uint32_t CASendLENotification(const CAEndpoint_t *endpoint, const void *data,
                               uint32_t dataLen);
 
 /**
@@ -132,7 +131,7 @@ uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, const void *da
  * @param   size        [OUT]   Number of local connectivity structures.
  * @return  #CA_STATUS_OK or Appropriate error code
  */
-CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
+CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
 
 /**
  * @brief Read Synchronous API callback.
@@ -205,7 +204,7 @@ void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint,
+CAResult_t CABLEServerSendData(const CAEndpoint_t *remoteEndpoint,
                                const void *data, uint32_t dataLen);
 
 /**
@@ -220,7 +219,7 @@ CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint,
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CAResult_t CABLEClientSendData(const CARemoteEndpoint_t *remoteEndpoint,
+CAResult_t CABLEClientSendData(const CAEndpoint_t *remoteEndpoint,
                                const void *data, uint32_t dataLen);
 
 /**
@@ -371,7 +370,7 @@ void CABLEServerSendDataThread(void *threadData);
  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
  * @retval #CA_STATUS_FAILED Operation failed
  */
-CALEData_t *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
+CALEData_t *CACreateBLEData(const CAEndpoint_t *remoteEndpoint, const void *data,
                             uint32_t dataLength);
 
 /**
index 76085df..9e58735 100644 (file)
@@ -63,7 +63,7 @@ extern "C"
  * @param   request        [IN]    request that needs to be sent
  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
  */
-CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *endpoint,
+CAResult_t CADetachRequestMessage(const CAEndpoint_t *endpoint,
                                   const CARequestInfo_t *request);
 
 /**
@@ -72,7 +72,7 @@ CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *endpoint,
  * @param   request        [IN]    request that needs to be sent
  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
  */
-CAResult_t CADetachRequestToAllMessage(const CAGroupEndpoint_t *object,
+CAResult_t CADetachRequestToAllMessage(const CAEndpoint_t *object,
                                        const CARequestInfo_t *request);
 
 /**
@@ -81,7 +81,7 @@ CAResult_t CADetachRequestToAllMessage(const CAGroupEndpoint_t *object,
  * @param   response       [IN]    response that needs to be sent
  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
  */
-CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *endpoint,
+CAResult_t CADetachResponseMessage(const CAEndpoint_t *endpoint,
                                    const CAResponseInfo_t *response);
 
 /**
index 0db6219..10f2416 100644 (file)
@@ -63,7 +63,7 @@ extern "C"
  * @param   request        [IN]    request that needs to be sent
  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
  */
-CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *endpoint,
+CAResult_t CADetachRequestMessage(const CAEndpoint_t *endpoint,
                                   const CARequestInfo_t *request);
 
 /**
@@ -72,7 +72,7 @@ CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *endpoint,
  * @param   request        [IN]    request that needs to be sent
  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
  */
-CAResult_t CADetachRequestToAllMessage(const CAGroupEndpoint_t *object,
+CAResult_t CADetachRequestToAllMessage(const CAEndpoint_t *object,
                                        const CARequestInfo_t *request);
 
 /**
@@ -81,7 +81,7 @@ CAResult_t CADetachRequestToAllMessage(const CAGroupEndpoint_t *object,
  * @param   response       [IN]    response that needs to be sent
  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
  */
-CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *endpoint,
+CAResult_t CADetachResponseMessage(const CAEndpoint_t *endpoint,
                                    const CAResponseInfo_t *response);
 
 /**
index 2031ab6..0ace516 100644 (file)
@@ -37,17 +37,17 @@ extern "C"
 
 /**
  * @brief   Add network type to the selected networks for network packets reception
- * @param   transportType       [IN]    Transport type that needs to be added
+ * @param   transportAdapter     [IN]  Adapter that needs to be added
  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CAAddNetworkType(CATransportType_t transportType);
+CAResult_t CAAddNetworkType(CATransportAdapter_t transportAdapter);
 
 /**
  * @brief   Remove network type from the selected configuration
- * @param   transportType       [IN]    Transport type that needs to be removed
+ * @param   transportAdapter     [IN]  Adapter that needs to be removed
  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CARemoveNetworkType(CATransportType_t transportType);
+CAResult_t CARemoveNetworkType(CATransportAdapter_t transportAdapter);
 
 /**
  * @brief   Get selected network information
@@ -61,7 +61,7 @@ u_arraylist_t *CAGetSelectedNetworkList();
  * @param   size    [OUT]   No Of Array objects
  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CAGetNetworkInformationInternal(CALocalConnectivity_t **info, uint32_t *size);
+CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, uint32_t *size);
 
 /**
  * @brief   Terminate network type from selected configuration
index a0a2db9..c190ddf 100644 (file)
@@ -42,12 +42,11 @@ typedef uint32_t code_t;
 
 /**
  * @brief   generates pdu structure from the given information.
- * @param   uri              [IN]    uri information of the pdu
  * @param   code             [IN]    code of the pdu packet
  * @param   info             [IN]    pdu information
  * @return  generated pdu
  */
-coap_pdu_t *CAGeneratePDU(const char *uri, uint32_t code, const CAInfo_t info);
+coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info);
 
 /**
  * function for generating
@@ -57,34 +56,26 @@ coap_pdu_t *CAGeneratePDU(const char *uri, uint32_t code, const CAInfo_t info);
  * @brief   extracts request information from received pdu.
  * @param   pdu              [IN]     received pdu
  * @param   outReqInfo       [OUT]    request info structure made from received pdu
- * @param   outUri           [OUT]    uri received in the received pdu
- * @param   buflen           [IN]     Buffer Length for outUri parameter
  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CAGetRequestInfoFromPDU(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo, char *outUri,
-                                   uint32_t buflen);
+CAResult_t CAGetRequestInfoFromPDU(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo);
 
 /**
  * @brief   extracts response information from received pdu.
  * @param   pdu              [IN]     received pdu
  * @param   outResInfo       [OUT]    response info structure made from received pdu
- * @param   outUri           [OUT]    uri received in the received pdu
- * @param   buflen           [IN]     Buffer Length for outUri parameter
  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CAGetResponseInfoFromPDU(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo,
-                                    char *outUri, uint32_t buflen);
+CAResult_t CAGetResponseInfoFromPDU(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo);
 
 /**
  * @brief   extracts error information from received pdu.
  * @param   pdu              [IN]     received pdu
  * @param   errorInfo        [OUT]    error info structure made from received pdu
- * @param   outUri           [OUT]    uri received in the received pdu
- * @param   buflen           [IN]     length of outUri
  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CAGetErrorInfoFromPDU(const coap_pdu_t *pdu, CAErrorInfo_t *errorInfo,
-                                 char *outUri, uint32_t buflen);
+CAResult_t CAGetErrorInfoFromPDU(const coap_pdu_t *pdu, CAErrorInfo_t *errorInfo);
+
 /**
  * @brief   creates pdu from the request information
  * @param   code             [IN]    request or response code
@@ -93,7 +84,7 @@ CAResult_t CAGetErrorInfoFromPDU(const coap_pdu_t *pdu, CAErrorInfo_t *errorInfo
  * @param   payload          [IN]    payload for the request or response consumed
  * @return  generated pdu
  */
-coap_pdu_t *CAGeneratePDUImpl(code_t code, coap_list_t *options, const CAInfo_t info,
+coap_pdu_t *CAGeneratePDUImpl(code_t code, coap_list_t *options, const CAInfo_t *info,
                               const char *payload, size_t payloadSize);
 
 /**
@@ -125,7 +116,7 @@ CAResult_t CAParseUriPartial(const unsigned char *str, size_t length, int target
  * @param   optlist          [OUT]   options information
  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t info, coap_list_t **optlist);
+CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t *info, coap_list_t **optlist);
 
 /**
  * @brief   creates option node from key length and data
@@ -134,7 +125,7 @@ CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t info, coap_list_t **o
  * @param   data             [IN]    data that needs to be sent
  * @return  created list
  */
-coap_list_t *CACreateNewOptionNode(uint16_t key, uint32_t length, const uint8_t *data);
+coap_list_t *CACreateNewOptionNode(uint16_t key, uint32_t length, const char *data);
 
 /**
  * @brief   order the inserted options
@@ -167,12 +158,9 @@ uint32_t CAGetOptionData(const uint8_t *data, uint32_t len, uint8_t *option, uin
  * @param   pdu              [IN]     received pdu
  * @param   outCode          [OUT]    code of the received pdu
  * @param   outInfo          [OUT]    request info structure made from received pdu
- * @param   outUri           [OUT]    uri received in the received pdu
- * @param   buflen           [IN]     Buffer Length for outUri parameter
  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
-CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo,
-                            char *outUri, uint32_t buflen);
+CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo);
 
 /**
  * @brief   create pdu from received data
index 002a6c5..0aed071 100644 (file)
@@ -39,34 +39,14 @@ extern "C"
  * @param   endpoint       [IN]    endpoint information where the data has to be sent
  * @return  remote endpoint created
  */
-CARemoteEndpoint_t *CACloneRemoteEndpoint(const CARemoteEndpoint_t *endpoint);
-
-/**
- * @brief   Creates a new remote endpoint from the input uri
- * @param   uri                 [IN]    absolute uri information to create remote endpoint
- * @param   transportType       [IN]    transport type of the endpoint
- * @return  remote endpoint created
- */
-CARemoteEndpoint_t *CACreateRemoteEndpointUriInternal(const CAURI_t uri,
-                                                      const CATransportType_t transportType);
-
-/**
- * @brief   Creates a new remote endpoint from the input and other information
- * @param   resourceUri         [IN]    absolute uri information to create remote endpoint
- * @param   addr                [IN]    address of the endpoint
- * @param   type                [IN]    transport  type of the endpoint
- * @return  remote endpoint created
- */
-CARemoteEndpoint_t *CACreateRemoteEndpointInternal(const CAURI_t resourceUri,
-                                                   const CAAddress_t addr,
-                                                   const CATransportType_t type);
+CAEndpoint_t *CACloneEndpoint(const CAEndpoint_t *endpoint);
 
 /**
  * @brief   Destroy remote endpoint
  * @param   endpoint       [IN]    endpoint information where the data has to be sent
  * @return  none
  */
-void CADestroyRemoteEndpointInternal(CARemoteEndpoint_t *rep);
+void CADestroyEndpointInternal(CAEndpoint_t *rep);
 
 /**
  * @brief   Creates a new request information
index 052fa41..0882584 100644 (file)
 #include "uarraylist.h"
 #include "cacommon.h"
 
-/** CA_IPV4, CA_EDR, CA_LE **/
-#define DEFAULT_RETRANSMISSION_TYPE     (CA_IPV4 | CA_EDR | CA_LE)
+/** IP, EDR, LE **/
+#define DEFAULT_RETRANSMISSION_TYPE (CA_ADAPTER_IP | \
+                                     CA_ADAPTER_RFCOMM_BTEDR | \
+                                     CA_ADAPTER_GATT_BTLE)
 
 /** default ACK time is 2 sec.(CoAP) **/
 #define DEFAULT_ACK_TIMEOUT_SEC     2
 #define RETRANSMISSION_CHECK_PERIOD_SEC     1
 
 /** retransmission data send method type**/
-typedef CAResult_t (*CADataSendMethod_t)(const CARemoteEndpoint_t *endpoint, const void *pdu,
+typedef CAResult_t (*CADataSendMethod_t)(const CAEndpoint_t *endpoint,
+                                         const void *pdu,
                                          uint32_t size);
 
 /** retransmission timeout callback type**/
-typedef void (*CATimeoutCallback_t)(const CARemoteEndpoint_t *endpoint, const void *pdu,
+typedef void (*CATimeoutCallback_t)(const CAEndpoint_t *endpoint,
+                                    const void *pdu,
                                     uint32_t size);
 
 typedef struct
 {
     /** retransmission support transport type **/
-    CATransportType_t supportType;
+    CATransportAdapter_t supportType;
 
     /** retransmission trying count **/
     uint8_t tryingCount;
@@ -128,8 +132,8 @@ CAResult_t CARetransmissionStart(CARetransmission_t *context);
  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
  */
 CAResult_t CARetransmissionSentData(CARetransmission_t* context,
-                                    const CARemoteEndpoint_t* endpoint, const void* pdu,
-                                    uint32_t size);
+                                    const CAEndpoint_t* endpoint,
+                                    const void* pdu, uint32_t size);
 
 /**
  * @brief   Pass the received pdu data. if received pdu is ACK data for the retransmission CON data,
@@ -142,7 +146,7 @@ CAResult_t CARetransmissionSentData(CARetransmission_t* context,
  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
  */
 CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
-                                        const CARemoteEndpoint_t *endpoint, const void *pdu,
+                                        const CAEndpoint_t *endpoint, const void *pdu,
                                         uint32_t size, void **retransmissionPdu);
 
 /**
index 5e581be..e73d687 100644 (file)
@@ -32,7 +32,7 @@
 #include "cacommon.h"
 
 /** CA_IPV4, CA_LE **/
-#define DEFAULT_RETRANSMISSION_TYPE     (CA_IPV4 | CA_LE)
+#define DEFAULT_RETRANSMISSION_TYPE     (CA_ADAPTER_IP | CA_ADAPTER_GATT_BTLE)
 
 /** default retransmission trying count is 4. **/
 #define DEFAULT_RETRANSMISSION_COUNT    4
 #define RETRANSMISSION_CHECK_PERIOD_SEC     1
 
 /** retransmission data send method type**/
-typedef CAResult_t (*CADataSendMethod_t)(const CARemoteEndpoint_t *endpoint, const void *pdu,
+typedef CAResult_t (*CADataSendMethod_t)(const CAEndpoint_t *endpoint, const void *pdu,
                                          uint32_t size);
 
 /** retransmission timeout callback type**/
-typedef void (*CATimeoutCallback_t)(const CARemoteEndpoint_t *endpoint, const void *pdu,
+typedef void (*CATimeoutCallback_t)(const CAEndpoint_t *endpoint, const void *pdu,
                                     uint32_t size);
 
 typedef struct
 {
     /** retransmission support transport type **/
-    CATransportType_t supportType;
+    CATransportAdapter_t supportType;
 
     /** retransmission trying count **/
     uint8_t tryingCount;
@@ -105,7 +105,7 @@ CAResult_t CARetransmissionInitialize(CARetransmission_t *context,
  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
  */
 CAResult_t CARetransmissionSentData(CARetransmission_t *context,
-                                    const CARemoteEndpoint_t *endpoint,
+                                    const CAEndpoint_t *endpoint,
                                     const void *pdu, uint32_t size);
 
 /**
@@ -119,7 +119,7 @@ CAResult_t CARetransmissionSentData(CARetransmission_t *context,
  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
  */
 CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
-                                        const CARemoteEndpoint_t *endpoint, const void *pdu,
+                                        const CAEndpoint_t *endpoint, const void *pdu,
                                         uint32_t size, void **retransmissionPdu);
 
 /**
index cfce9b5..65006dc 100644 (file)
 
 uint16_t g_localSecurePort = SECURE_DEFAULT_PORT;
 
-void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* requestInfo);
-void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t* responseInfo);
-void error_handler(const CARemoteEndpoint_t *object, const CAErrorInfo_t* errorInfo);
-
+void request_handler(const CAEndpoint_t* object, const CARequestInfo_t* requestInfo);
+void response_handler(const CAEndpoint_t* object, const CAResponseInfo_t* responseInfo);
+void error_handler(const CAEndpoint_t *object, const CAErrorInfo_t* errorInfo);
 void get_resource_uri(const char *URI, char *resourceURI, uint32_t length);
 uint32_t get_secure_information(CAPayload_t payLoad);
 CAResult_t get_network_type(uint32_t selectedNetwork);
 void callback(char *subject, char *receivedData);
-CAResult_t get_remote_address(CATransportType_t transportType, CAAddress_t addressInfo);
+CAResult_t get_remote_address(CATransportAdapter_t transportType, const char *address);
 
-CATransportType_t g_selectedNwType = CA_IPV4;
+CATransportAdapter_t g_selectedNwType = CA_ADAPTER_IP;
 static CAToken_t g_lastRequestToken = NULL;
 static uint8_t g_lastRequestTokenLength;
 
@@ -55,11 +54,11 @@ static const char NORMAL_INFO_DATA[]
                                    = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
                                      "\"if\":[\"oic.if.baseline\"],\"obs\":1}}]}";
 
-
 static jobject g_responseListenerObject = NULL;
 static JavaVM *g_jvm;
 
-static CARemoteEndpoint_t *g_clientEndpoint = NULL;
+static CAEndpoint_t *g_clientEndpoint = NULL;
+static char *g_resourceUri;
 static CAToken_t g_clientToken;
 static uint8_t g_clientTokenLength = NULL;
 
@@ -253,40 +252,7 @@ Java_org_iotivity_ca_service_RMInterface_RMRegisterHandler(JNIEnv *env, jobject
 JNIEXPORT void JNICALL
 Java_org_iotivity_ca_service_RMInterface_RMFindResource(JNIEnv *env, jobject obj, jstring uri)
 {
-    // create token
-    CAToken_t token = NULL;
-    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
-
-    CAResult_t res = CAGenerateToken(&token, tokenLength);
-    if ((CA_STATUS_OK != res) || (!token))
-    {
-        LOGE("token generate error!!");
-        return;
-    }
-
-    printf("Generated token %s\n", token);
-
-    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
-    LOGI("RMFindResource - %s", strUri);
-
-    res = CAFindResource((const CAURI_t) strUri, token, tokenLength);
-
-    //ReleseStringUTFCharss for strUri
-    (*env)->ReleaseStringUTFChars(env, uri, strUri);
-
-    if (CA_STATUS_OK != res)
-    {
-        LOGE("Could not find resource");
-        //destroy token
-        CADestroyToken(token);
-    }
-    else
-    {
-        LOGI("find resource to %s URI", strUri);
-        CADestroyToken(g_lastRequestToken);
-        g_lastRequestToken = token;
-        g_lastRequestTokenLength = tokenLength;
-    }
+    LOGE("Java_org_iotivity_service_RMInterface_RMFindResource not implemented");
 }
 
 JNIEXPORT void JNICALL
@@ -305,9 +271,8 @@ Java_org_iotivity_ca_service_RMInterface_RMSendRequest(JNIEnv *env, jobject obj,
     LOGI("RMSendRequest - %s", strUri);
 
     //create remote endpoint
-    CARemoteEndpoint_t* endpoint = NULL;
-    res = CACreateRemoteEndpoint((const CAURI_t) strUri, g_selectedNwType, &endpoint);
-
+    CAEndpoint_t* endpoint = NULL;
+    res = CACreateEndpoint(CA_DEFAULT_FLAGS, g_selectedNwType, strUri, 0, &endpoint);
     //ReleaseStringUTFChars for strUri
     (*env)->ReleaseStringUTFChars(env, uri, strUri);
 
@@ -328,7 +293,7 @@ Java_org_iotivity_ca_service_RMInterface_RMSendRequest(JNIEnv *env, jobject obj,
     {
         LOGE("token generate error!!");
         // destroy remote endpoint
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
         return;
     }
 
@@ -350,7 +315,7 @@ Java_org_iotivity_ca_service_RMInterface_RMSendRequest(JNIEnv *env, jobject obj,
             // destroy token
             CADestroyToken(token);
             // destroy remote endpoint
-            CADestroyRemoteEndpoint(endpoint);
+            CADestroyEndpoint(endpoint);
             return;
         }
         snprintf(requestData.payload, length, SECURE_INFO_DATA, resourceURI, g_localSecurePort);
@@ -365,7 +330,7 @@ Java_org_iotivity_ca_service_RMInterface_RMSendRequest(JNIEnv *env, jobject obj,
             // destroy token
             CADestroyToken(token);
             // destroy remote endpoint
-            CADestroyRemoteEndpoint(endpoint);
+            CADestroyEndpoint(endpoint);
             return;
         }
         snprintf(requestData.payload, length, NORMAL_INFO_DATA, resourceURI);
@@ -375,6 +340,7 @@ Java_org_iotivity_ca_service_RMInterface_RMSendRequest(JNIEnv *env, jobject obj,
 
     CARequestInfo_t requestInfo = { 0 };
     requestInfo.method = CA_GET;
+    requestInfo.isMulticast = false;
     requestInfo.info = requestData;
 
     // send request
@@ -387,7 +353,7 @@ Java_org_iotivity_ca_service_RMInterface_RMSendRequest(JNIEnv *env, jobject obj,
     CADestroyToken(token);
 
     // destroy remote endpoint
-    CADestroyRemoteEndpoint(endpoint);
+    CADestroyEndpoint(endpoint);
 
     free(requestData.payload);
 }
@@ -407,8 +373,8 @@ Java_org_iotivity_ca_service_RMInterface_RMSendReqestToAll(JNIEnv *env, jobject
     LOGI("RMSendReqestToAll - %s", strUri);
 
     // create remote endpoint
-    CARemoteEndpoint_t *endpoint = NULL;
-    res = CACreateRemoteEndpoint((const CAURI_t) strUri, g_selectedNwType, &endpoint);
+    CAEndpoint_t *endpoint = NULL;
+    res = CACreateEndpoint(CA_DEFAULT_FLAGS, g_selectedNwType, strUri, 0, &endpoint);
 
     //ReleaseStringUTFChars for strUri
     (*env)->ReleaseStringUTFChars(env, uri, strUri);
@@ -419,16 +385,6 @@ Java_org_iotivity_ca_service_RMInterface_RMSendReqestToAll(JNIEnv *env, jobject
         return;
     }
 
-    CAGroupEndpoint_t *group = (CAGroupEndpoint_t *) malloc(sizeof(CAGroupEndpoint_t));
-    if (NULL == group)
-    {
-        LOGE("Memory allocation failed!");
-        CADestroyRemoteEndpoint(endpoint);
-        return;
-    }
-    group->transportType = endpoint->transportType;
-    group->resourceUri = endpoint->resourceUri;
-
     // create token
     CAToken_t token = NULL;
     uint8_t tokenLength = CA_MAX_TOKEN_LEN;
@@ -438,8 +394,7 @@ Java_org_iotivity_ca_service_RMInterface_RMSendReqestToAll(JNIEnv *env, jobject
     {
         LOGE("token generate error!!");
         // destroy remote endpoint
-        CADestroyRemoteEndpoint(endpoint);
-        free(group);
+        CADestroyEndpoint(endpoint);
         return;
     }
 
@@ -453,10 +408,11 @@ Java_org_iotivity_ca_service_RMInterface_RMSendReqestToAll(JNIEnv *env, jobject
 
     CARequestInfo_t requestInfo = { 0 };
     requestInfo.method = CA_GET;
+    requestInfo.isMulticast = true;
     requestInfo.info = requestData;
 
     // send request to all
-    res = CASendRequestToAll(group, &requestInfo);
+    res = CASendRequest(endpoint, &requestInfo);
     if (CA_STATUS_OK != res)
     {
         LOGE("Could not send request to all");
@@ -471,9 +427,7 @@ Java_org_iotivity_ca_service_RMInterface_RMSendReqestToAll(JNIEnv *env, jobject
     }
 
     // destroy remote endpoint
-    CADestroyRemoteEndpoint(endpoint);
-    free(group);
-
+    CADestroyEndpoint(endpoint);
 }
 
 JNIEXPORT void JNICALL
@@ -515,16 +469,16 @@ Java_org_iotivity_ca_service_RMInterface_RMSendResponse(JNIEnv *env, jobject obj
 
         if (1 == isSecured)
         {
-            uint32_t length = strlen(SECURE_INFO_DATA) + strlen(g_clientEndpoint->resourceUri) + 1;
+            uint32_t length = strlen(SECURE_INFO_DATA) + strlen(g_resourceUri) + 1;
             responseData.payload = (CAPayload_t) malloc(length);
-            sprintf(responseData.payload, SECURE_INFO_DATA, g_clientEndpoint->resourceUri,
+            sprintf(responseData.payload, SECURE_INFO_DATA, g_resourceUri,
                     g_localSecurePort);
         }
         else
         {
-            uint32_t length = strlen(NORMAL_INFO_DATA) + strlen(g_clientEndpoint->resourceUri) + 1;
+            uint32_t length = strlen(NORMAL_INFO_DATA) + strlen(g_resourceUri) + 1;
             responseData.payload = (CAPayload_t) malloc(length);
-            sprintf(responseData.payload, NORMAL_INFO_DATA, g_clientEndpoint->resourceUri);
+            sprintf(responseData.payload, NORMAL_INFO_DATA, g_resourceUri);
         }
     }
     //msgType is RESET
@@ -548,70 +502,11 @@ Java_org_iotivity_ca_service_RMInterface_RMSendResponse(JNIEnv *env, jobject obj
     g_clientTokenLength = 0;
 
     // destroy remote endpoint
-    CADestroyRemoteEndpoint(g_clientEndpoint);
+    CADestroyEndpoint(g_clientEndpoint);
     g_clientEndpoint = NULL;
 }
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_ca_service_RMInterface_RMAdvertiseResource(JNIEnv *env, jobject obj, jstring uri)
-{
-    LOGI("RMAdvertiseResource");
-
-    uint32_t optionNum = 2;
-
-    CAHeaderOption_t *headerOpt = (CAHeaderOption_t*) calloc(1,
-                                                             sizeof(CAHeaderOption_t) * optionNum);
-    if (NULL == headerOpt)
-    {
-        LOGE("Memory allocation failed!");
-        return;
-    }
-
-    char* tmpOptionData1 = "Hello";
-    headerOpt[0].optionID = 3000;
-    memcpy(headerOpt[0].optionData, tmpOptionData1, strlen(tmpOptionData1));
-    headerOpt[0].optionLength = (uint16_t) strlen(tmpOptionData1);
-
-    char* tmpOptionData2 = "World";
-    headerOpt[1].optionID = 3001;
-    memcpy(headerOpt[1].optionData, tmpOptionData2, strlen(tmpOptionData2));
-    headerOpt[1].optionLength = (uint16_t) strlen(tmpOptionData2);
-
-    // create token
-    CAToken_t token = NULL;
-    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
-
-    CAResult_t res = CAGenerateToken(&token, tokenLength);
-    if ((CA_STATUS_OK != res) || (!token))
-    {
-        LOGE("token generate error!");
-        free(headerOpt);
-        return;
-    }
-
-    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
-
-    res = CAAdvertiseResource((const CAURI_t) strUri, token, tokenLength,
-                              headerOpt, (uint8_t) optionNum);
-    if (CA_STATUS_OK != res)
-    {
-        LOGE("Could not start advertise resource");
-        CADestroyToken(token);
-    }
-    else
-    {
-        CADestroyToken(g_lastRequestToken);
-        g_lastRequestToken = token;
-        g_lastRequestTokenLength = tokenLength;
-    }
-
-    free(headerOpt);
-
-    //ReleaseStringUTFChars for strUri
-    (*env)->ReleaseStringUTFChars(env, uri, strUri);
-}
-
-JNIEXPORT void JNICALL
 Java_org_iotivity_ca_service_RMInterface_RMSendNotification(JNIEnv *env, jobject obj, jstring uri,
                                                          jstring payload, jint selectedNetwork,
                                                          jint isSecured, jint msgType,
@@ -630,9 +525,8 @@ Java_org_iotivity_ca_service_RMInterface_RMSendNotification(JNIEnv *env, jobject
     LOGI("RMSendNotification - %s", strUri);
 
     //create remote endpoint
-    CARemoteEndpoint_t* endpoint = NULL;
-    if (CA_STATUS_OK != CACreateRemoteEndpoint((const CAURI_t) strUri,
-                                               g_selectedNwType, &endpoint))
+    CAEndpoint_t* endpoint = NULL;
+    if (CA_STATUS_OK != CACreateEndpoint(CA_DEFAULT_FLAGS, g_selectedNwType, strUri, 0, &endpoint))
     {
         //ReleaseStringUTFChars for strUri
         (*env)->ReleaseStringUTFChars(env, uri, strUri);
@@ -641,7 +535,7 @@ Java_org_iotivity_ca_service_RMInterface_RMSendNotification(JNIEnv *env, jobject
     }
 
     char resourceURI[RESOURCE_URI_LENGTH + 1] = { 0 };
-    get_resource_uri((const CAURI_t) strUri, resourceURI, RESOURCE_URI_LENGTH);
+    get_resource_uri(strUri, resourceURI, RESOURCE_URI_LENGTH);
 
     //ReleaseStringUTFChars for strUri
     (*env)->ReleaseStringUTFChars(env, uri, strUri);
@@ -656,7 +550,7 @@ Java_org_iotivity_ca_service_RMInterface_RMSendNotification(JNIEnv *env, jobject
     if ((CA_STATUS_OK != res) || (!token))
     {
         LOGE("token generate error!");
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
         return;
     }
 
@@ -674,7 +568,7 @@ Java_org_iotivity_ca_service_RMInterface_RMSendNotification(JNIEnv *env, jobject
             // destroy token
             CADestroyToken(token);
             // destroy remote endpoint
-            CADestroyRemoteEndpoint(endpoint);
+            CADestroyEndpoint(endpoint);
             return;
         }
         snprintf(responseData.payload, length, SECURE_INFO_DATA, resourceURI, g_localSecurePort);
@@ -689,7 +583,7 @@ Java_org_iotivity_ca_service_RMInterface_RMSendNotification(JNIEnv *env, jobject
             // destroy token
             CADestroyToken(token);
             // destroy remote endpoint
-            CADestroyRemoteEndpoint(endpoint);
+            CADestroyEndpoint(endpoint);
             return;
         }
         snprintf(responseData.payload, length, NORMAL_INFO_DATA, resourceURI);
@@ -713,7 +607,7 @@ Java_org_iotivity_ca_service_RMInterface_RMSendNotification(JNIEnv *env, jobject
     CADestroyToken(token);
 
     // destroy remote endpoint
-    CADestroyRemoteEndpoint(endpoint);
+    CADestroyEndpoint(endpoint);
 
     free(responseData.payload);
 }
@@ -745,14 +639,14 @@ Java_org_iotivity_ca_service_RMInterface_RMGetNetworkInfomation(JNIEnv *env, job
 {
     LOGI("RMGetNetworkInfomation");
 
-    CALocalConnectivity_t *tempInfo = NULL;
+    CAEndpoint_t *tempInfo = NULL;
     uint32_t tempSize = 0;
 
     CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize);
     if (CA_STATUS_OK != res)
     {
         LOGE("Could not start get network information");
-        OICFree(tempInfo);
+        free(tempInfo);
         return;
     }
 
@@ -763,37 +657,37 @@ Java_org_iotivity_ca_service_RMInterface_RMGetNetworkInfomation(JNIEnv *env, job
     uint32_t index;
     for (index = 0; index < tempSize; index++)
     {
-        res = get_remote_address(tempInfo[index].type, tempInfo[index].addressInfo);
+        res = get_remote_address(tempInfo[index].adapter, tempInfo[index].addr);
         if (CA_STATUS_OK != res)
         {
-            OICFree(tempInfo);
+            free(tempInfo);
             return;
         }
         if (NULL != g_responseListenerObject)
         {
             char networkInfo[NETWORK_INFO_LENGTH];
-            LOGI("Type: %d", tempInfo[index].type);
-            sprintf(networkInfo, "%d",tempInfo[index].type);
+            LOGI("Type: %d", tempInfo[index].adapter);
+            sprintf(networkInfo, "%d",tempInfo[index].adapter);
             callback("Type :", networkInfo);
-            if (CA_IPV4 == tempInfo[index].type)
+            if (CA_ADAPTER_IP == tempInfo[index].adapter)
             {
-                LOGI("Port: %d", tempInfo[index].addressInfo.IP.port);
-                sprintf(networkInfo, "%d",tempInfo[index].addressInfo.IP.port);
+                LOGI("Port: %d", tempInfo[index].port);
+                sprintf(networkInfo, "%d",tempInfo[index].port);
                 callback("Port: ", networkInfo);
             }
-            LOGI("Secured: %d", tempInfo[index].isSecured);
+            LOGI("Secured: %d", (tempInfo[index].flags & CA_SECURE));
             LOGI("Address: %s", g_remoteAddress);
             callback("Address: ", g_remoteAddress);
             free(g_remoteAddress);
         }
-        if (true == tempInfo[index].isSecured)
+        if (tempInfo[index].flags & CA_SECURE)
         {
-            g_localSecurePort = tempInfo[index].addressInfo.IP.port;
+            g_localSecurePort = tempInfo[index].port;
         }
     }
 
     // free
-    OICFree(tempInfo);
+    free(tempInfo);
 
     LOGI("##############################################################");
 }
@@ -809,7 +703,7 @@ Java_org_iotivity_ca_service_RMInterface_RMHandleRequestResponse(JNIEnv *env, jo
     }
 }
 
-void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* requestInfo)
+void request_handler(const CAEndpoint_t* object, const CARequestInfo_t* requestInfo)
 {
 
     if (!object)
@@ -832,18 +726,15 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re
         return;
     }
 
-    CAResult_t res = get_remote_address(object->transportType, object->addressInfo);
+    CAResult_t res = get_remote_address(object->adapter, object->addr);
     if (CA_STATUS_OK != res)
     {
         return;
     }
 
     LOGI("##########received request from remote device #############");
-    if (object->resourceUri)
-    {
-        LOGI("Uri: %s", object->resourceUri);
-    }
     LOGI("Remote Address: %s", g_remoteAddress);
+    LOGI("Uri: %s", requestInfo->info.resourceUri);
     LOGI("Data: %s", requestInfo->info.payload);
     LOGI("Token: %s", requestInfo->info.token);
     LOGI("Code: %d", requestInfo->method);
@@ -855,10 +746,10 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re
         char *cloneUri = NULL;
         uint32_t len = 0;
 
-        if (NULL != object->resourceUri)
+        if (NULL != requestInfo->info.resourceUri)
         {
-            len = strlen(object->resourceUri);
-            cloneUri = (char *) malloc(sizeof(char) * (len + 1));
+            len = strlen(requestInfo->info.resourceUri);
+            cloneUri = (char *)malloc(sizeof(char) * (len + 1));
 
             if (NULL == cloneUri)
             {
@@ -867,7 +758,7 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re
                 return;
             }
 
-            memcpy(cloneUri, object->resourceUri, len + 1);
+            memcpy(cloneUri, requestInfo->info.resourceUri, len + 1);
             callback("Uri: ", cloneUri);
         }
 
@@ -889,27 +780,27 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re
         free(g_remoteAddress);
 
         //clone g_clientEndpoint
-        g_clientEndpoint = (CARemoteEndpoint_t *) malloc(sizeof(CARemoteEndpoint_t));
+        g_clientEndpoint = (CAEndpoint_t *) malloc(sizeof(CAEndpoint_t));
         if (NULL == g_clientEndpoint)
         {
             LOGE("g_clientEndpoint Out of memory");
             free(cloneUri);
             return;
         }
-        memcpy(g_clientEndpoint, object, sizeof(CARemoteEndpoint_t));
+        memcpy(g_clientEndpoint, object, sizeof(CAEndpoint_t));
 
         if (NULL != cloneUri)
         {
             len = strlen(cloneUri);
-            g_clientEndpoint->resourceUri = (char *) malloc(sizeof(char) * (len + 1));
-            if (NULL == g_clientEndpoint)
+            g_resourceUri = (char *) malloc(sizeof(char) * (len + 1));
+            if (NULL == g_resourceUri)
             {
                 LOGE("g_clientEndpoint->resourceUri Out of memory");
                 free(g_clientEndpoint);
                 free(cloneUri);
                 return;
             }
-            memcpy(g_clientEndpoint->resourceUri, cloneUri, len + 1);
+            memcpy(g_resourceUri, cloneUri, len + 1);
             free(cloneUri);
         }
         //clone g_clientToken
@@ -919,7 +810,6 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re
         if (NULL == g_clientToken)
         {
             LOGE("g_clientToken Out of memory");
-            free(g_clientEndpoint->resourceUri);
             free(g_clientEndpoint);
             return;
         }
@@ -942,7 +832,6 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re
             if (NULL == clonePayload)
             {
                 LOGE("clonePayload Out of memory");
-                free(g_clientEndpoint->resourceUri);
                 free(g_clientEndpoint);
                 return;
             }
@@ -977,12 +866,11 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re
 
                 callback("Option info: ", optionInfo);
 
-                uint32_t optionDataLen = strlen(requestInfo->info.options[i].optionData);
+                size_t optionDataLen = strlen(requestInfo->info.options[i].optionData);
                 char *cloneOptionData = (char *) malloc(sizeof(char) * (optionDataLen + 1));
                 if (NULL == cloneOptionData)
                 {
                     LOGE("cloneOptionData Out of memory");
-                    free(g_clientEndpoint->resourceUri);
                     free(g_clientEndpoint);
                     return;
                 }
@@ -998,7 +886,7 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re
     LOGI("############################################################");
 
     //Check if this has secure communication information
-    if (requestInfo->info.payload && CA_IPV4 == object->transportType)
+    if (requestInfo->info.payload && CA_ADAPTER_IP == object->adapter)
     {
         uint32_t securePort = get_secure_information(requestInfo->info.payload);
         if (0 < securePort) //Set the remote endpoint secure details and send response
@@ -1009,8 +897,8 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re
 
             length = sizeof(SECURE_COAPS_PREFIX) - 1; //length of "coaps://"
             // length of "ipaddress:port"
-            length += strlen(object->addressInfo.IP.ipAddress) + PORT_LENGTH;
-            length += strlen(object->resourceUri) + 1;
+            length += strlen(object->addr) + PORT_LENGTH;
+            length += strlen(requestInfo->info.resourceUri) + 1;
 
             uri = calloc(1, sizeof(char) * length);
             if (!uri)
@@ -1019,17 +907,17 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re
                 free(uri);
                 return;
             }
-            sprintf(uri, "%s%s:%d/%s", SECURE_COAPS_PREFIX, object->addressInfo.IP.ipAddress,
-                    securePort, object->resourceUri);
+            sprintf(uri, "%s%s:%d/%s", SECURE_COAPS_PREFIX, object->addr,
+                    securePort, requestInfo->info.resourceUri);
 
-            CARemoteEndpoint_t *endpoint = NULL;
-            if (CA_STATUS_OK != CACreateRemoteEndpoint(uri, object->transportType, &endpoint))
+            CAEndpoint_t *endpoint = NULL;
+            if (CA_STATUS_OK != CACreateEndpoint(CA_SECURE,
+                        object->adapter, uri, securePort, &endpoint))
             {
                 LOGE("Failed to create duplicate of remote endpoint!");
                 free(uri);
                 return;
             }
-            endpoint->isSecured = true;
             object = endpoint;
 
             free(uri);
@@ -1037,17 +925,17 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re
     }
 }
 
-void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t* responseInfo)
+void response_handler(const CAEndpoint_t* object, const CAResponseInfo_t* responseInfo)
 {
 
-    CAResult_t res = get_remote_address(object->transportType, object->addressInfo);
+    CAResult_t res = get_remote_address(object->adapter, object->addr);
     if (CA_STATUS_OK != res)
     {
         return;
     }
 
     LOGI("##########Received response from remote device #############");
-    LOGI("Uri: %s", object->resourceUri);
+    LOGI("Uri: %s", responseInfo->info.resourceUri);
     LOGI("Remote Address: %s", g_remoteAddress);
     LOGI("response result: %d", responseInfo->result);
     LOGI("Data: %s", responseInfo->info.payload);
@@ -1058,9 +946,9 @@ void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t*
     {
         uint32_t len = 0;
 
-        if (NULL != object->resourceUri)
+        if (NULL != responseInfo->info.resourceUri)
         {
-            len = strlen(object->resourceUri);
+            len = strlen(responseInfo->info.resourceUri);
             char *cloneUri = (char *) malloc(sizeof(char) * (len + 1));
 
             if (NULL == cloneUri)
@@ -1070,7 +958,7 @@ void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t*
                 return;
             }
 
-            memcpy(cloneUri, object->resourceUri, len + 1);
+            memcpy(cloneUri, responseInfo->info.resourceUri, len + 1);
 
             callback("Uri: ", cloneUri);
             free(cloneUri);
@@ -1130,7 +1018,7 @@ void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t*
 
                 callback("Option info: ", optionInfo);
 
-                uint32_t optionDataLen = strlen(responseInfo->info.options[i].optionData);
+                size_t optionDataLen = strlen(responseInfo->info.options[i].optionData);
                 char *cloneOptionData = (char *) malloc(sizeof(char) * (optionDataLen + 1));
                 if (NULL == cloneOptionData)
                 {
@@ -1147,7 +1035,7 @@ void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t*
     LOGI("############################################################");
 
     //Check if this has secure communication information
-    if (responseInfo->info.payload && CA_IPV4 == object->transportType)
+    if (responseInfo->info.payload && CA_ADAPTER_IP == object->adapter)
     {
         uint32_t securePort = get_secure_information(responseInfo->info.payload);
         if (0 < securePort) //Set the remote endpoint secure details and send response
@@ -1157,19 +1045,10 @@ void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t*
     }
 }
 
-void error_handler(const CARemoteEndpoint_t *rep, const CAErrorInfo_t* errorInfo)
+void error_handler(const CAEndpoint_t *rep, const CAErrorInfo_t* errorInfo)
 {
     printf("+++++++++++++++++++++++++++++++++++ErrorInfo+++++++++++++++++++++++++++++++++++");
 
-    if(rep && rep->resourceUri  )
-    {
-        LOGI("Error Handler, RemoteEndpoint Info resourceUri : %s", rep->resourceUri);
-    }
-    else
-    {
-        LOGI("Error Handler, RemoteEndpoint is NULL");
-    }
-
     if(errorInfo)
     {
         const CAInfo_t *info = &errorInfo->info;
@@ -1177,6 +1056,7 @@ void error_handler(const CARemoteEndpoint_t *rep, const CAErrorInfo_t* errorInfo
         LOGI("Error Handler result    : %d", errorInfo->result);
         LOGI("Error Handler token     : %s", info->token);
         LOGI("Error Handler messageId : %d", (uint16_t) info->messageId);
+        LOGI("Error Handler resourceUri : %s", info->resourceUri);
         LOGI("Error Handler type      : %d", info->type);
         LOGI("Error Handler payload   : %s", info->payload);
 
@@ -1209,8 +1089,8 @@ void error_handler(const CARemoteEndpoint_t *rep, const CAErrorInfo_t* errorInfo
 void get_resource_uri(const char *URI, char *resourceURI, uint32_t length)
 {
     const char *startPos = URI;
-    const char *temp = NULL;
-    if (NULL != (temp = strstr(URI, "://")))
+    const char *temp = strstr(URI, "://");
+    if (NULL != temp)
     {
         startPos = strchr(temp + 3, '/');
         if (!startPos)
@@ -1288,19 +1168,19 @@ CAResult_t get_network_type(uint32_t selectedNetwork)
     {
         return CA_NOT_SUPPORTED;
     }
-    if (number & CA_IPV4)
+    if (number & CA_ADAPTER_IP)
     {
-        g_selectedNwType = CA_IPV4;
+        g_selectedNwType = CA_ADAPTER_IP;
         return CA_STATUS_OK;
     }
-    if (number & CA_EDR)
+    if (number & CA_ADAPTER_RFCOMM_BTEDR)
     {
-        g_selectedNwType = CA_EDR;
+        g_selectedNwType = CA_ADAPTER_RFCOMM_BTEDR;
         return CA_STATUS_OK;
     }
-    if (number & CA_LE)
+    if (number & CA_ADAPTER_GATT_BTLE)
     {
-        g_selectedNwType = CA_LE;
+        g_selectedNwType = CA_ADAPTER_GATT_BTLE;
         return CA_STATUS_OK;
     }
 
@@ -1323,51 +1203,18 @@ void callback(char *subject, char *receivedData)
 
 }
 
-CAResult_t get_remote_address(CATransportType_t transportType, CAAddress_t addressInfo)
+CAResult_t get_remote_address(CATransportAdapter_t transportType, const char *address)
 {
+    uint32_t len = strlen(address);
 
-    uint32_t len = 0;
-    if (CA_IPV4 == transportType)
+    g_remoteAddress = (char *)malloc(sizeof (char) * (len + 1));
+    if (NULL == g_remoteAddress)
     {
-        len = strlen(addressInfo.IP.ipAddress);
-        g_remoteAddress = (char *) malloc(sizeof(char) * (len + 1));
-
-        if (NULL == g_remoteAddress)
-        {
-            LOGE("g_remoteAddress Out of memory");
-            return CA_MEMORY_ALLOC_FAILED;
-        }
-
-        memcpy(g_remoteAddress, addressInfo.IP.ipAddress, len + 1);
-    }
-
-    else if (CA_EDR == transportType)
-    {
-        len = strlen(addressInfo.BT.btMacAddress);
-        g_remoteAddress = (char *) malloc(sizeof(char) * (len + 1));
-
-        if (NULL == g_remoteAddress)
-        {
-            LOGE("g_remoteAddress Out of memory");
-            return CA_MEMORY_ALLOC_FAILED;
-        }
-
-        memcpy(g_remoteAddress, addressInfo.BT.btMacAddress, len + 1);
+        LOGE("g_remoteAddress Out of memory");
+        return CA_MEMORY_ALLOC_FAILED;
     }
 
-    else if (CA_LE == transportType)
-    {
-        len = strlen(addressInfo.LE.leMacAddress);
-        g_remoteAddress = (char *) malloc(sizeof(char) * (len + 1));
-
-        if (NULL == g_remoteAddress)
-        {
-            LOGE("g_remoteAddress Out of memory");
-            return CA_MEMORY_ALLOC_FAILED;
-        }
-
-        memcpy(g_remoteAddress, addressInfo.LE.leMacAddress, len + 1);
-    }
+    memcpy(g_remoteAddress, address, len + 1);
 
     return CA_STATUS_OK;
 }
index 5d8a65a..ee045de 100644 (file)
@@ -47,19 +47,17 @@ static void Process();
 static void Initialize();
 static void StartListeningServer();
 static void StartDiscoveryServer();
-static void FindResource();
 static void SendRequest();
 static void SendRequestAll();
-static void SendResponse(CARemoteEndpoint_t *endpoint, const CAInfo_t* info);
-static void AdvertiseResource();
+static void SendResponse(CAEndpoint_t *endpoint, const CAInfo_t* info);
 static void SendNotification();
 static void SelectNetwork();
 static void UnselectNetwork();
 static void HandleRequestResponse();
 
-static void RequestHandler(const CARemoteEndpoint_t *object, const CARequestInfo_t *requestInfo);
-static void ResponseHandler(const CARemoteEndpoint_t *object, const CAResponseInfo_t *responseInfo);
-static void ErrorHandler(const CARemoteEndpoint_t *object, const CAErrorInfo_t* errorInfo);
+static void RequestHandler(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo);
+static void ResponseHandler(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo);
+static void ErrorHandler(const CAEndpoint_t *object, const CAErrorInfo_t* errorInfo);
 static void Terminate();
 
 void GetData(char *readInput, size_t bufferLength, size_t *dataLength)
@@ -96,31 +94,56 @@ void GetData(char *readInput, size_t bufferLength, size_t *dataLength)
     (*dataLength) = len;
 }
 
-CATransportType_t GetConnectivityType()
+bool ParseData(char *buf, char *url, char *resourceUri)
+{
+    char *slash = strchr(buf, '/');
+    if (!slash)
+    {
+        return false;
+    }
+
+    strcpy(resourceUri, slash);
+
+    char *dot = strchr(buf, '.');
+    if (dot && dot < slash)
+    {
+        char *colon = strchr(buf, ':');
+        if (colon && colon < slash)
+        {
+            strncpy(url, buf, colon - buf);
+            return true;
+        }
+    }
+
+    strncpy(url, buf, slash - buf);
+    return true;
+}
+
+CATransportAdapter_t GetConnectivityType()
 {
     char type[2] = {0};
     Serial.println("Select network");
-    Serial.println("IPv4: 0");
-    Serial.println("EDR: 2");
-    Serial.println("LE: 3");
+    Serial.println("IP: 0");
+    Serial.println("RFCOMM (EDR): 1");
+    Serial.println("GATT (BLE): 2");
 
     size_t typeLen = 0;
     GetData(type, sizeof(type), &typeLen);
     if (0 >= typeLen)
     {
         Serial.println("i/p err,default ethernet");
-        return CA_IPV4;
+        return CA_ADAPTER_IP;
     }
     switch (type[0])
     {
         case '0':
-            return CA_IPV4;
+            return CA_ADAPTER_IP;
+        case '1':
+            return CA_ADAPTER_RFCOMM_BTEDR;
         case '2':
-            return CA_EDR;
-        case '3':
-            return CA_LE;
+            return CA_ADAPTER_GATT_BTLE;
     }
-    return CA_IPV4;
+    return CA_ADAPTER_IP;
 }
 
 void setup()
@@ -168,7 +191,7 @@ void loop()
                 break;
 
             case 'F': // find resource
-                FindResource();
+                SendRequestAll();
                 break;
 
             case 'R': // send request
@@ -177,10 +200,6 @@ void loop()
             case 'E': //send request to all
                 SendRequestAll();
                 break;
-            case 'A': // advertise resource
-                AdvertiseResource();
-                break;
-
             case 'B': // send notification
                 SendNotification();
                 break;
@@ -250,51 +269,12 @@ void StartDiscoveryServer()
     }
 }
 
-void FindResource()
-{
-    char buf[MAX_BUF_LEN] = {0};
-    Serial.println("============");
-    Serial.println("ex) /a/light");
-    Serial.println("uri: ");
-    size_t len = 0;
-    GetData(buf, sizeof(buf), &len);
-    if (0 >= len)
-    {
-        Serial.println("i/p err");
-        return;
-    }
-    // create token
-    CAToken_t token = NULL;
-    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
-
-    CAResult_t res = CAGenerateToken(&token, tokenLength);
-    if (res != CA_STATUS_OK || (!token))
-    {
-        Serial.println("token error");
-        return;
-    }
-
-    Serial.print("token:");
-    Serial.println(token);
-
-    res = CAFindResource(buf, token, tokenLength);
-    if (res != CA_STATUS_OK)
-    {
-        Serial.print("find error: ");
-        Serial.println(res);
-    }
-    else
-    {
-        Serial.println("success: ");
-        Serial.println(buf);
-    }
-    CADestroyToken(token);
-}
-
 void SendRequest()
 {
     char buf[MAX_BUF_LEN] = {0};
-    CATransportType_t selectedNetwork;
+    char address[MAX_BUF_LEN] = {0};
+    char resourceUri[MAX_BUF_LEN] = {0};
+    CATransportAdapter_t selectedNetwork;
     selectedNetwork = GetConnectivityType();
 
     Serial.println("============");
@@ -310,13 +290,19 @@ void SendRequest()
         return;
     }
 
+    if (!ParseData(buf, address, resourceUri))
+    {
+        Serial.println("bad uri");
+        return;
+    }
+
     // create remote endpoint
-    CARemoteEndpoint_t *endpoint = NULL;
-    CAResult_t res = CACreateRemoteEndpoint(buf,selectedNetwork,&endpoint);
+    CAEndpoint_t *endpoint = NULL;
+    CAResult_t res = CACreateEndpoint(CA_DEFAULT_FLAGS, selectedNetwork, address, 0, &endpoint);
     if (res != CA_STATUS_OK)
     {
         Serial.println("Out of memory");
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
         return;
     }
 
@@ -355,9 +341,12 @@ void SendRequest()
     requestData.payload = (CAPayload_t)"Json Payload";
 
     requestData.type = msgType;
+    requestData.resourceUri = (char *)OICMalloc(strlen(resourceUri) + 1);
+    strcpy(requestData.resourceUri, resourceUri);
 
     CARequestInfo_t requestInfo = {CA_GET, {CA_MSG_RESET}};
     requestInfo.method = CA_GET;
+    requestInfo.isMulticast = false;
     requestInfo.info = requestData;
 
     // send request
@@ -370,7 +359,7 @@ void SendRequest()
     // destroy remote endpoint
     if (endpoint != NULL)
     {
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
     }
 
     Serial.println("============");
@@ -379,13 +368,16 @@ void SendRequest()
 void SendRequestAll()
 {
     char buf[MAX_BUF_LEN] = {0};
+    char address[MAX_BUF_LEN] = {0};
+    char resourceUri[MAX_BUF_LEN] = {0};
 
-    CATransportType_t selectedNetwork;
+    CATransportAdapter_t selectedNetwork;
     selectedNetwork = GetConnectivityType();
 
     Serial.println("=========");
     Serial.println("10.11.12.13:4545/resource_uri ( for IP )");
     Serial.println("10:11:12:13:45:45/resource_uri ( for BT )");
+    Serial.println("/resource_uri               (any adapter)");
     Serial.println("uri : ");
 
     size_t len = 0;
@@ -396,22 +388,23 @@ void SendRequestAll()
         return;
     }
 
+    if (!ParseData(buf, address, resourceUri))
+    {
+        Serial.println("bad uri");
+        return;
+    }
+
     // create remote endpoint
-    CARemoteEndpoint_t *endpoint = NULL;
-    CAResult_t res = CACreateRemoteEndpoint(buf, selectedNetwork, &endpoint);
+    CAEndpoint_t *endpoint = NULL;
+    CAResult_t res = CACreateEndpoint(CA_DEFAULT_FLAGS, selectedNetwork, address, 0, &endpoint);
 
     if (res != CA_STATUS_OK)
     {
         Serial.println("create remote endpoint error");
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
         return;
     }
 
-    CAGroupEndpoint_t *group = NULL;
-    group = (CAGroupEndpoint_t *)OICMalloc(sizeof(CAGroupEndpoint_t));
-    group->transportType = endpoint->transportType;
-    group->resourceUri = endpoint->resourceUri;
-
     // create token
     CAToken_t token = NULL;
     uint8_t tokenLength = CA_MAX_TOKEN_LEN;
@@ -430,14 +423,17 @@ void SendRequestAll()
     requestData.tokenLength = tokenLength;
     requestData.payload = "Temp Json Payload";
     requestData.type = CA_MSG_NONCONFIRM;
+    requestData.resourceUri = (char *)OICMalloc(strlen(resourceUri) + 1);
+    strcpy(requestData.resourceUri, resourceUri);
 
     CARequestInfo_t requestInfo = {CA_GET, {CA_MSG_RESET}};
     requestInfo.method = CA_GET;
+    requestInfo.isMulticast = true;
     requestInfo.info = requestData;
 
     // send request
     // CASendRequest(endpoint, &requestInfo);
-    CASendRequestToAll(group, &requestInfo);
+    CASendRequest(endpoint, &requestInfo);
 
     if (NULL != token)
     {
@@ -447,115 +443,18 @@ void SendRequestAll()
     // destroy remote endpoint
     if (endpoint != NULL)
     {
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
     }
 
-    OICFree(group);
     Serial.println("==========");
 }
 
-void AdvertiseResource()
-{
-    char buf[MAX_BUF_LEN] = {0};
-
-    Serial.println("============");
-    Serial.println("uri: ");
-
-    size_t len = 0;
-    GetData(buf, sizeof(buf), &len);
-    if (0 >= len)
-    {
-        Serial.println("no i/p");
-        return;
-    }
-
-    int16_t optionNum = 0;
-    char optionData[MAX_OPT_LEN] = {0};
-    char optionNumBuf[2] = {0};
-
-    Serial.println("Option Num: ");
-    GetData(optionNumBuf, sizeof(optionNumBuf), &len);
-    if (0 >= len)
-    {
-        Serial.println("no i/p,0 option");
-    }
-    else
-    {
-        optionNum = atoi(optionNumBuf);
-        Serial.println(optionNum);
-    }
-
-    CAHeaderOption_t *headerOpt = NULL;
-    if (optionNum > 0)
-    {
-        headerOpt = (CAHeaderOption_t *) OICCalloc(optionNum, sizeof(CAHeaderOption_t));
-        if (NULL == headerOpt)
-        {
-            Serial.println("Out of memory");
-            return;
-        }
-    }
-
-    int i;
-    for (i = 0 ; i < optionNum ; i++)
-    {
-        int optionID = 0;
-        char getOptionID[4];
-        Serial.println("Opt ID:");
-        GetData(getOptionID, sizeof(getOptionID), &len);
-        if (0 >= len)
-        {
-            Serial.println("no i/p");
-            continue;
-        }
-        else
-        {
-            optionID = atoi(getOptionID);
-        }
-
-        memset(optionData, 0, sizeof(optionData));
-        Serial.println("Opt Data:");
-        GetData(optionData, sizeof(optionData), &len);
-        if (0 >= len)
-        {
-            Serial.println("no i/p");
-            continue;
-        }
-
-        headerOpt[i].optionID = optionID;
-        memcpy(headerOpt[i].optionData, optionData, strlen(optionData));
-        Serial.println("ID:");
-        Serial.println(optionID);
-        Serial.println("Data:");
-        Serial.println(optionData);
-
-        headerOpt[i].optionLength = (uint16_t)strlen(optionData);
-    }
-
-    Serial.println("============");
-    // create token
-    CAToken_t token = NULL;
-    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
-
-    CAResult_t res = CAGenerateToken(&token, tokenLength);
-    if (res != CA_STATUS_OK || (!token))
-    {
-        Serial.println("token error");
-        return;
-    }
-
-    Serial.println("token");
-    Serial.println(token);
-
-    CAAdvertiseResource(buf, token, tokenLength, headerOpt, (uint8_t)optionNum);
-    OICFree(headerOpt);
-    CADestroyToken(token);
-}
-
 void SendNotification()
 {
     char buf[MAX_BUF_LEN] = {0};
-    CATransportType_t selectedNetwork;
+    char address[MAX_BUF_LEN] = {0};
+    char resourceUri[MAX_BUF_LEN] = {0};
+    CATransportAdapter_t selectedNetwork;
     selectedNetwork = GetConnectivityType();
 
     Serial.println("============");
@@ -571,13 +470,19 @@ void SendNotification()
         return;
     }
 
+    if (!ParseData(buf, address, resourceUri))
+    {
+        Serial.println("bad uri");
+        return;
+    }
+
     // create remote endpoint
-    CARemoteEndpoint_t *endpoint = NULL;
-    CAResult_t res = CACreateRemoteEndpoint(buf,selectedNetwork,&endpoint);
+    CAEndpoint_t *endpoint = NULL;
+    CAResult_t res = CACreateEndpoint(CA_DEFAULT_FLAGS, selectedNetwork, address, 0, &endpoint);
     if (CA_STATUS_OK != res)
     {
         Serial.println("Out of memory");
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
         return;
     }
 
@@ -596,6 +501,8 @@ void SendNotification()
     respondData.token = token;
     respondData.tokenLength = tokenLength;
     respondData.payload = (CAPayload_t)"Notification Data";
+    respondData.resourceUri = (char *)OICMalloc(strlen(resourceUri) + 1);
+    strcpy(respondData.resourceUri, resourceUri);
 
     CAResponseInfo_t responseInfo = {CA_BAD_REQ, {CA_MSG_RESET}};
     responseInfo.result = CA_SUCCESS;
@@ -606,7 +513,7 @@ void SendNotification()
     // destroy remote endpoint
     if (NULL != endpoint)
     {
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
     }
 
     CADestroyToken(token);
@@ -619,9 +526,9 @@ void SelectNetwork()
 
     Serial.println("============");
     Serial.println("Select network");
-    Serial.println("IPv4: 0");
-    Serial.println("EDR: 2");
-    Serial.println("LE: 3\n");
+    Serial.println("IP: 0");
+    Serial.println("EDR: 1");
+    Serial.println("LE: 2\n");
 
     size_t len = 0;
     GetData(buf, sizeof(buf), &len);
@@ -676,7 +583,7 @@ void SelectNetwork()
             break;
     }
 
-    CASelectNetwork(CATransportType_t(1<<number));
+    CASelectNetwork(CATransportAdapter_t(1<<number));
     Serial.println("============");
 }
 
@@ -734,11 +641,11 @@ void HandleRequestResponse()
     CAHandleRequestResponse();
 }
 
-void RequestHandler(const CARemoteEndpoint_t *object, const CARequestInfo_t *requestInfo)
+void RequestHandler(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo)
 {
     if (!object)
     {
-        Serial.println("Remote endpoint is NULL!");
+        Serial.println("endpoint is NULL!");
         return;
     }
 
@@ -748,12 +655,12 @@ void RequestHandler(const CARemoteEndpoint_t *object, const CARequestInfo_t *req
         return;
     }
 
-    Serial.println("uri: ");
-    Serial.println(object->resourceUri);
     Serial.println("RAddr: ");
-    Serial.println(object->addressInfo.IP.ipAddress);
+    Serial.println(object->addr);
     Serial.println("Port: ");
-    Serial.println(object->addressInfo.IP.port);
+    Serial.println(object->port);
+    Serial.println("uri: ");
+    Serial.println(requestInfo->info.resourceUri);
     Serial.println("data: ");
     Serial.println(requestInfo->info.payload);
     Serial.println("Type: ");
@@ -774,19 +681,21 @@ void RequestHandler(const CARemoteEndpoint_t *object, const CARequestInfo_t *req
         }
     }
     Serial.println("send response");
-    SendResponse((CARemoteEndpoint_t *)object, (requestInfo != NULL) ? &requestInfo->info : NULL);
+    SendResponse((CAEndpoint_t *)object, (requestInfo != NULL) ? &requestInfo->info : NULL);
 }
 
-void ResponseHandler(const CARemoteEndpoint_t *object, const CAResponseInfo_t *responseInfo)
+void ResponseHandler(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo)
 {
-    if (object && object->resourceUri)
+    if (object)
     {
         Serial.print("uri: ");
-        Serial.println(object->resourceUri);
+        Serial.println(object->addr);
     }
 
     if (responseInfo)
     {
+        Serial.print("uri: ");
+        Serial.println(responseInfo->info.resourceUri);
         Serial.print("data: ");
         Serial.println(responseInfo->info.payload);
         Serial.print("Type: ");
@@ -796,19 +705,10 @@ void ResponseHandler(const CARemoteEndpoint_t *object, const CAResponseInfo_t *r
     }
 }
 
-void ErrorHandler(const CARemoteEndpoint_t *rep, const CAErrorInfo_t* errorInfo)
+void ErrorHandler(const CAEndpoint_t *rep, const CAErrorInfo_t* errorInfo)
 {
     printf("+++++++++++++++++++++++++++++++++++ErrorInfo+++++++++++++++++++++++++++++++++++\n");
 
-    if(rep && rep->resourceUri  )
-    {
-        printf("Error Handler, RemoteEndpoint Info resourceUri : %s\n", rep->resourceUri);
-    }
-    else
-    {
-        printf("Error Handler, RemoteEndpoint is NULL");
-    }
-
     if(errorInfo)
     {
         const CAInfo_t *info = &errorInfo->info;
@@ -817,6 +717,7 @@ void ErrorHandler(const CARemoteEndpoint_t *rep, const CAErrorInfo_t* errorInfo)
         printf("Error Handler token     : %s\n", info->token);
         printf("Error Handler messageId : %d\n", (uint16_t) info->messageId);
         printf("Error Handler type      : %d\n", info->type);
+        printf("Error Handler resourceUri : %s\n", info->resourceUri);
         printf("Error Handler payload   : %s\n", info->payload);
 
         if(CA_ADAPTER_NOT_ENABLED == errorInfo->result)
@@ -845,7 +746,7 @@ void ErrorHandler(const CARemoteEndpoint_t *rep, const CAErrorInfo_t* errorInfo)
     return;
 }
 
-void SendResponse(CARemoteEndpoint_t *endpoint, const CAInfo_t* info)
+void SendResponse(CAEndpoint_t *endpoint, const CAInfo_t* info)
 {
     char buf[MAX_BUF_LEN] = {0};
 
index 041daed..e3c8483 100644 (file)
@@ -56,7 +56,7 @@
 
 int g_received;
 uint16_t g_local_secure_port = SECURE_DEFAULT_PORT;
-CATransportType_t g_selected_nw_type = CA_IPV4;
+CATransportAdapter_t g_selected_nw_type = CA_ADAPTER_IP;
 const char *MESSAGE_TYPE[] = {"CON", "NON", "ACK", "RESET"};
 
 char get_menu();
@@ -66,23 +66,19 @@ CAResult_t get_input_data(char *buf, int32_t length);
 
 void start_listening_server();
 void start_discovery_server();
-void find_resource();
 void send_request();
 void send_request_all();
-void advertise_resource();
 void send_notification();
 void select_network();
 void unselect_network();
 void handle_request_response();
-void find_fixed_resource();
 void get_network_info();
 void send_secure_request();
 
-void request_handler(const CARemoteEndpoint_t *object, const CARequestInfo_t *requestInfo);
-void response_handler(const CARemoteEndpoint_t *object, const CAResponseInfo_t *responseInfo);
-void error_handler(const CARemoteEndpoint_t *object, const CAErrorInfo_t* errorInfo);
-
-void send_response(const CARemoteEndpoint_t *endpoint, const CAInfo_t *info);
+void request_handler(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo);
+void response_handler(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo);
+void error_handler(const CAEndpoint_t *object, const CAErrorInfo_t* errorInfo);
+void send_response(const CAEndpoint_t *endpoint, const CAInfo_t *info);
 void get_resource_uri(char *URI, char *resourceURI, int length);
 int get_secure_information(CAPayload_t payLoad);
 
@@ -271,21 +267,11 @@ void process()
                 start_discovery_server();
                 break;
 
-            case 'f': // find resource
-            case 'F':
-                find_resource();
-                break;
-
             case 'r': // send request
             case 'R':
                 send_request();
                 break;
 
-            case 'a': // advertise resource
-            case 'A':
-                advertise_resource();
-                break;
-
             case 'b': // send notification
             case 'B':
                 send_notification();
@@ -306,21 +292,6 @@ void process()
                 handle_request_response();
                 break;
 
-            case 'y':
-            case 'Y':
-                while (1)
-                {
-                    g_received = 0;
-                    find_fixed_resource();
-                    while (g_received == 0)
-                    {
-                        sleep(1);
-                        handle_request_response();
-
-                    }
-                }
-                break;
-
             case 'w':
             case 'W':
                 g_received = 0;
@@ -385,80 +356,6 @@ void start_discovery_server()
     }
 }
 
-void find_fixed_resource()
-{
-    // create token
-    CAToken_t token = NULL;
-    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
-
-    CAResult_t res = CAGenerateToken(&token, tokenLength);
-    if ((CA_STATUS_OK != res) || (!token))
-    {
-        printf("Token generate error!!");
-        return;
-    }
-    printf("Generated token %s\n", token);
-
-    char buf[MAX_BUF_LEN] = { 0 };
-    strcpy(buf, "/a/light");
-
-    res = CAFindResource(buf, token, tokenLength);
-    if (CA_STATUS_OK != res)
-    {
-        printf("Find resource error : %d\n", res);
-    }
-    else
-    {
-        printf("Find resource to %s URI\n", buf);
-    }
-
-    // delete token
-    CADestroyToken(token);
-
-    printf("=============================================\n");
-}
-
-void find_resource()
-{
-    printf("\n=============================================\n");
-    printf("ex) /a/light\n");
-    printf("reference uri : ");
-
-    char buf[MAX_BUF_LEN] = { 0 };
-    if (CA_STATUS_OK != get_input_data(buf, MAX_BUF_LEN))
-    {
-        return;
-    }
-
-    // create token
-    CAToken_t token = NULL;
-    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
-
-    CAResult_t res = CAGenerateToken(&token, tokenLength);
-    if ((CA_STATUS_OK != res) || (!token))
-    {
-        printf("Token generate error!!\n");
-        return;
-    }
-
-    printf("Generated token %s\n", token);
-
-    res = CAFindResource(buf, token, tokenLength);
-    if (CA_STATUS_OK != res)
-    {
-        printf("Find resource error : %d\n", res);
-        CADestroyToken(token);
-    }
-    else
-    {
-        printf("Find resource to %s URI\n", buf);
-        CADestroyToken(g_last_request_token);
-        g_last_request_token = token;
-    }
-
-    printf("=============================================\n");
-}
-
 void send_request()
 {
     CAResult_t res = get_network_type();
@@ -499,8 +396,8 @@ void send_request()
     }
 
     // create remote endpoint
-    CARemoteEndpoint_t *endpoint = NULL;
-    res = CACreateRemoteEndpoint(uri, g_selected_nw_type, &endpoint);
+    CAEndpoint_t *endpoint = NULL;
+    res = CACreateEndpoint(CA_DEFAULT_FLAGS, g_selected_nw_type, uri, 0, &endpoint);
     if (CA_STATUS_OK != res || !endpoint)
     {
         printf("Failed to create remote endpoint, error code : %d\n", res);
@@ -514,7 +411,7 @@ void send_request()
     char buf[MAX_BUF_LEN] = { 0 };
     if (CA_STATUS_OK != get_input_data(buf, MAX_BUF_LEN))
     {
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
         return;
     }
 
@@ -528,7 +425,7 @@ void send_request()
     if ((CA_STATUS_OK != res) || (!token))
     {
         printf("Token generate error, error code : %d\n", res);
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
         return;
     }
 
@@ -552,7 +449,7 @@ void send_request()
         if (NULL == requestData.payload)
         {
             printf("Memory allocation fail\n");
-            CADestroyRemoteEndpoint(endpoint);
+            CADestroyEndpoint(endpoint);
             CADestroyToken(token);
             return;
         }
@@ -565,7 +462,7 @@ void send_request()
         if (NULL == requestData.payload)
         {
             printf("Memory allocation fail\n");
-            CADestroyRemoteEndpoint(endpoint);
+            CADestroyEndpoint(endpoint);
             CADestroyToken(token);
             return;
         }
@@ -587,7 +484,7 @@ void send_request()
     //destroy token
     CADestroyToken(token);
     // destroy remote endpoint
-    CADestroyRemoteEndpoint(endpoint);
+    CADestroyEndpoint(endpoint);
     free(requestData.payload);
 
 
@@ -609,8 +506,8 @@ void send_secure_request()
     snprintf(uri, MAX_BUF_LEN, "%s%s:5684/a/light", SECURE_COAPS_PREFIX, ipv4addr);
 
     // create remote endpoint
-    CARemoteEndpoint_t *endpoint = NULL;
-    CAResult_t res = CACreateRemoteEndpoint(uri, CA_IPV4, &endpoint);
+    CAEndpoint_t *endpoint = NULL;
+    CAResult_t res = CACreateEndpoint(0, CA_ADAPTER_IP, uri, 0, &endpoint);
     if (CA_STATUS_OK != res)
     {
         printf("Failed to create remote endpoint, error code: %d\n", res);
@@ -647,7 +544,7 @@ void send_secure_request()
 exit:
     // cleanup
     CADestroyToken(token);
-    CADestroyRemoteEndpoint(endpoint);
+    CADestroyEndpoint(endpoint);
     printf("=============================================\n");
 }
 
@@ -671,23 +568,22 @@ void send_request_all()
     }
 
     // create remote endpoint
-    CARemoteEndpoint_t *endpoint = NULL;
-    res = CACreateRemoteEndpoint(buf, g_selected_nw_type, &endpoint);
+    CAEndpoint_t *endpoint = NULL;
+    res = CACreateEndpoint(0, g_selected_nw_type, buf, 0, &endpoint);
     if (CA_STATUS_OK != res)
     {
         printf("Create remote endpoint error, error code: %d\n", res);
         return;
     }
 
-    CAGroupEndpoint_t *group = (CAGroupEndpoint_t *) malloc(sizeof(CAGroupEndpoint_t));
+    CAEndpoint_t *group = (CAEndpoint_t *) malloc(sizeof(CAEndpoint_t));
     if (NULL == group)
     {
         printf("Memory allocation failed!\n");
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
         return;
     }
-    group->transportType = endpoint->transportType;
-    group->resourceUri = endpoint->resourceUri;
+    group->adapter = endpoint->adapter;
 
     // create token
     CAToken_t token = NULL;
@@ -697,7 +593,7 @@ void send_request_all()
     if ((CA_STATUS_OK != res) || (!token))
     {
         printf("Token generate error!!\n");
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
         free(group);
         return;
     }
@@ -713,9 +609,10 @@ void send_request_all()
     CARequestInfo_t requestInfo = { 0 };
     requestInfo.method = CA_GET;
     requestInfo.info = requestData;
+    requestInfo.isMulticast = true;
 
     // send request
-    res = CASendRequestToAll(group, &requestInfo);
+    res = CASendRequest(group, &requestInfo);
     if (CA_STATUS_OK != res)
     {
         printf("Could not send request to all\n");
@@ -728,99 +625,12 @@ void send_request_all()
     }
 
     // destroy remote endpoint
-    CADestroyRemoteEndpoint(endpoint);
+    CADestroyEndpoint(endpoint);
     free(group);
 
     printf("=============================================\n");
 }
 
-void advertise_resource()
-{
-    printf("\n=============================================\n");
-    printf("uri : ");
-
-    char buf[MAX_BUF_LEN] = { 0 };
-    if (CA_STATUS_OK != get_input_data(buf, MAX_BUF_LEN))
-    {
-        return;
-    }
-
-    char optionNumBuf[MAX_BUF_LEN] = { 0 };
-    char optionData[MAX_OPT_LEN] = { 0 } ;
-
-    printf("Option Num : ");
-    if (CA_STATUS_OK != get_input_data(optionNumBuf, MAX_BUF_LEN))
-    {
-        return;
-    }
-    int optionNum = atoi(optionNumBuf);
-
-    CAHeaderOption_t * headerOpt = (CAHeaderOption_t *)
-            calloc(1, optionNum * sizeof(CAHeaderOption_t));
-    if (NULL == headerOpt)
-    {
-        printf("Memory allocation failed!\n");
-        return;
-    }
-
-    int i;
-    for (i = 0; i < optionNum; i++)
-    {
-        char getOptionID[MAX_BUF_LEN] = { 0 } ;
-
-        printf("[%d] Option ID : ", i + 1);
-        if (CA_STATUS_OK != get_input_data(getOptionID, MAX_BUF_LEN))
-        {
-            free(headerOpt);
-            return;
-        }
-        int optionID = atoi(getOptionID);
-
-        headerOpt[i].optionID = optionID;
-
-        printf("[%d] Option Data : ", i + 1);
-        if (CA_STATUS_OK != get_input_data(optionData, MAX_OPT_LEN))
-        {
-            free(headerOpt);
-            return;
-        }
-
-        memcpy(headerOpt[i].optionData, optionData, strlen(optionData));
-        printf("[%d] inputed option : ID : %d, data : %s\n", i + 1, optionID, optionData);
-
-        headerOpt[i].optionLength = (uint16_t) strlen(optionData);
-    }
-    printf("\n=============================================\n");
-
-    // create token
-    CAToken_t token = NULL;
-    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
-
-    CAResult_t res = CAGenerateToken(&token, tokenLength);
-    if ((CA_STATUS_OK != res) || (!token))
-    {
-        printf("Token generate error!!\n");
-        free(headerOpt);
-        return;
-    }
-
-    printf("Generated token %s\n", token);
-
-    res = CAAdvertiseResource(buf, token, tokenLength, headerOpt, (uint8_t) optionNum);
-    if (CA_STATUS_OK != res)
-    {
-        printf("Could not start advertise resource\n");
-        CADestroyToken(token);
-    }
-    else
-    {
-        CADestroyToken(g_last_request_token);
-        g_last_request_token = token;
-    }
-
-    free(headerOpt);
-}
-
 void send_notification()
 {
     CAResult_t res = get_network_type();
@@ -858,8 +668,8 @@ void send_notification()
     int messageType = messageTypeBuf[0] - '0';
 
     // create remote endpoint
-    CARemoteEndpoint_t *endpoint = NULL;
-    res = CACreateRemoteEndpoint(buf, g_selected_nw_type, &endpoint);
+    CAEndpoint_t *endpoint = NULL;
+    res = CACreateEndpoint(0, g_selected_nw_type, buf, 0, &endpoint);
     if (CA_STATUS_OK != res)
     {
         printf("Create remote endpoint error, error code: %d\n", res);
@@ -874,7 +684,7 @@ void send_notification()
     if ((CA_STATUS_OK != res) || (!token))
     {
         printf("Token generate error!!\n");
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
         return;
     }
 
@@ -903,7 +713,7 @@ void send_notification()
     // destroy token
     CADestroyToken(token);
     // destroy remote endpoint
-    CADestroyRemoteEndpoint(endpoint);
+    CADestroyEndpoint(endpoint);
 
     printf("\n=============================================\n");
 }
@@ -1028,7 +838,7 @@ void handle_request_response()
 
 void get_network_info()
 {
-    CALocalConnectivity_t *tempInfo = NULL;
+    CAEndpoint_t *tempInfo = NULL;
     uint32_t tempSize = 0;
 
     CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize);
@@ -1045,25 +855,25 @@ void get_network_info()
     int index;
     for (index = 0; index < tempSize; index++)
     {
-        printf("Type: %d\n", tempInfo[index].type);
-        if (CA_IPV4 == tempInfo[index].type)
+        printf("Type: %d\n", tempInfo[index].adapter);
+        if (CA_ADAPTER_IP == tempInfo[index].adapter)
         {
-            printf("Address: %s\n", tempInfo[index].addressInfo.IP.ipAddress);
-            printf("Port: %d\n", tempInfo[index].addressInfo.IP.port);
+            printf("Address: %s\n", tempInfo[index].addr);
+            printf("Port: %d\n", tempInfo[index].port);
         }
-        else if (CA_EDR == tempInfo[index].type)
+        else if (CA_ADAPTER_RFCOMM_BTEDR == tempInfo[index].adapter)
         {
-            printf("Address: %s\n", tempInfo[index].addressInfo.BT.btMacAddress);
+            printf("Address: %s\n", tempInfo[index].addr);
         }
-        else if (CA_LE == tempInfo[index].type)
+        else if (CA_ADAPTER_GATT_BTLE == tempInfo[index].adapter)
         {
-            printf("Address: %s\n", tempInfo[index].addressInfo.LE.leMacAddress);
+            printf("Address: %s\n", tempInfo[index].addr);
         }
-        printf("Secured: %s\n\n", tempInfo[index].isSecured ? "true" : "false");
+        printf("Secured: %s\n\n", (tempInfo[index].flags & CA_SECURE) ? "true" : "false");
 
-        if (tempInfo[index].isSecured)
+        if (tempInfo[index].flags & CA_SECURE)
         {
-            g_local_secure_port = tempInfo[index].addressInfo.IP.port;
+            g_local_secure_port = tempInfo[index].port;
             printf("Secured: in global %d\n\n", g_local_secure_port);
         }
     }
@@ -1072,7 +882,7 @@ void get_network_info()
     printf("##############################################################");
 }
 
-void request_handler(const CARemoteEndpoint_t *object, const CARequestInfo_t *requestInfo)
+void request_handler(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo)
 {
     if (NULL == object || NULL == requestInfo)
     {
@@ -1089,19 +899,18 @@ void request_handler(const CARemoteEndpoint_t *object, const CARequestInfo_t *re
     }
 
     printf("##########received request from remote device #############\n");
-    printf("Uri: %s\n", object->resourceUri);
-    if (CA_IPV4 == object->transportType)
+    if (CA_ADAPTER_IP == object->adapter)
     {
-        printf("Remote Address: %s Port: %d secured:%d\n", object->addressInfo.IP.ipAddress,
-               object->addressInfo.IP.port, object->isSecured);
+        printf("Remote Address: %s Port: %d secured:%d\n", object->addr,
+               object->port, object->flags & CA_SECURE);
     }
-    else if (CA_EDR == object->transportType)
+    else if (CA_ADAPTER_RFCOMM_BTEDR == object->adapter)
     {
-        printf("Remote Address: %s \n", object->addressInfo.BT.btMacAddress);
+        printf("Remote Address: %s \n", object->addr);
     }
-    else if (CA_LE == object->transportType)
+    else if (CA_ADAPTER_GATT_BTLE == object->adapter)
     {
-        printf("Remote Address: %s \n", object->addressInfo.LE.leMacAddress);
+        printf("Remote Address: %s \n", object->addr);
     }
     printf("Data: %s\n", requestInfo->info.payload);
     printf("Message type: %s\n", MESSAGE_TYPE[requestInfo->info.type]);
@@ -1122,7 +931,7 @@ void request_handler(const CARemoteEndpoint_t *object, const CARequestInfo_t *re
 
     //Check if this has secure communication information
     if (requestInfo->info.payload &&
-            (CA_IPV4 == object->transportType))
+            (CA_ADAPTER_IP == object->adapter))
     {
         int securePort = get_secure_information(requestInfo->info.payload);
         if (0 < securePort) //Set the remote endpoint secure details and send response
@@ -1133,8 +942,8 @@ void request_handler(const CARemoteEndpoint_t *object, const CARequestInfo_t *re
             size_t length = sizeof(SECURE_COAPS_PREFIX) - 1;
 
             // length of "ipaddress:port"
-            length += strlen(object->addressInfo.IP.ipAddress) + PORT_LENGTH;
-            length += strlen(object->resourceUri) + 1;
+            length += strlen(object->addr) + PORT_LENGTH;
+            length += 1;
 
             char *uri = calloc(1, sizeof(char) * length);
             if (!uri)
@@ -1142,16 +951,16 @@ void request_handler(const CARemoteEndpoint_t *object, const CARequestInfo_t *re
                 printf("Failed to create new uri\n");
                 return;
             }
-            sprintf(uri, "%s%s:%d/%s", SECURE_COAPS_PREFIX, object->addressInfo.IP.ipAddress,
-                    object->addressInfo.IP.port, object->resourceUri);
+            sprintf(uri, "%s%s:%d/", SECURE_COAPS_PREFIX, object->addr,
+                    object->port);
 
-            CARemoteEndpoint_t *endpoint = NULL;
-            if (CA_STATUS_OK != CACreateRemoteEndpoint(uri, object->transportType, &endpoint))
+            CAEndpoint_t *endpoint = NULL;
+            if (CA_STATUS_OK != CACreateEndpoint(0, object->adapter, uri, 0, &endpoint))
             {
                 printf("Failed to create duplicate of remote endpoint!\n");
                 return;
             }
-            endpoint->isSecured = true;
+            endpoint->flags = CA_SECURE;
             object = endpoint;
 
             free(uri);
@@ -1164,22 +973,21 @@ void request_handler(const CARemoteEndpoint_t *object, const CARequestInfo_t *re
     g_received = 1;
 }
 
-void response_handler(const CARemoteEndpoint_t *object, const CAResponseInfo_t *responseInfo)
+void response_handler(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo)
 {
     printf("##########Received response from remote device #############\n");
-    printf("Uri: %s\n", object->resourceUri);
-    if (CA_IPV4 == object->transportType)
+    if (CA_ADAPTER_IP == object->adapter)
     {
-        printf("Remote Address: %s Port: %d secured:%d\n", object->addressInfo.IP.ipAddress,
-               object->addressInfo.IP.port, object->isSecured);
+        printf("Remote Address: %s Port: %d secured:%d\n", object->addr,
+               object->port, object->flags & CA_SECURE);
     }
-    else if (CA_EDR == object->transportType)
+    else if (CA_ADAPTER_RFCOMM_BTEDR == object->adapter)
     {
-        printf("Remote Address: %s \n", object->addressInfo.BT.btMacAddress);
+        printf("Remote Address: %s \n", object->addr);
     }
-    else if (CA_LE == object->transportType)
+    else if (CA_ADAPTER_GATT_BTLE == object->adapter)
     {
-        printf("Remote Address: %s \n", object->addressInfo.LE.leMacAddress);
+        printf("Remote Address: %s \n", object->addr);
     }
     printf("response result : %d\n", responseInfo->result);
     printf("Data: %s\n", responseInfo->info.payload);
@@ -1211,19 +1019,10 @@ void response_handler(const CARemoteEndpoint_t *object, const CAResponseInfo_t *
     }
 }
 
-void error_handler(const CARemoteEndpoint_t *rep, const CAErrorInfo_t* errorInfo)
+void error_handler(const CAEndpoint_t *rep, const CAErrorInfo_t* errorInfo)
 {
     printf("+++++++++++++++++++++++++++++++++++ErrorInfo+++++++++++++++++++++++++++++++++++\n");
 
-    if(rep && rep->resourceUri  )
-    {
-        printf("Error Handler, RemoteEndpoint Info resourceUri : %s\n", rep->resourceUri);
-    }
-    else
-    {
-        printf("Error Handler, RemoteEndpoint is NULL");
-    }
-
     if(errorInfo)
     {
         const CAInfo_t *info = &errorInfo->info;
@@ -1232,6 +1031,7 @@ void error_handler(const CARemoteEndpoint_t *rep, const CAErrorInfo_t* errorInfo
         printf("Error Handler token     : %s\n", info->token);
         printf("Error Handler messageId : %d\n", (uint16_t) info->messageId);
         printf("Error Handler type      : %d\n", info->type);
+        printf("Error Handler resourceUri : %s\n", info->resourceUri);
         printf("Error Handler payload   : %s\n", info->payload);
 
         if(CA_ADAPTER_NOT_ENABLED == errorInfo->result)
@@ -1260,7 +1060,7 @@ void error_handler(const CARemoteEndpoint_t *rep, const CAErrorInfo_t* errorInfo
     return;
 }
 
-void send_response(const CARemoteEndpoint_t *endpoint, const CAInfo_t *info)
+void send_response(const CAEndpoint_t *endpoint, const CAInfo_t *info)
 {
     printf("entering send_response\n");
 
@@ -1317,32 +1117,33 @@ void send_response(const CARemoteEndpoint_t *endpoint, const CAInfo_t *info)
         responseData.token = (info != NULL) ? info->token : NULL;
         responseData.tokenLength = (info != NULL) ? info->tokenLength : 0;
 
-        if (endpoint->isSecured)
+        if (endpoint->flags & CA_SECURE)
         {
             printf("Sending response on secure communication\n");
 
-            uint32_t length = sizeof(SECURE_INFO_DATA) + strlen(endpoint->resourceUri);
+            uint32_t length = sizeof(SECURE_INFO_DATA);
             responseData.payload = (CAPayload_t) calloc(length,  sizeof(char));
             if (NULL == responseData.payload)
             {
                 printf("Memory allocation fail\n");
                 return;
             }
-            snprintf(responseData.payload, length, SECURE_INFO_DATA, endpoint->resourceUri,
-                     g_local_secure_port);
+            snprintf(responseData.payload, length, SECURE_INFO_DATA, info->resourceUri, g_local_secure_port);
+            return;
         }
         else
         {
             printf("Sending response on non-secure communication\n");
 
-            uint32_t length = sizeof(NORMAL_INFO_DATA) + strlen(endpoint->resourceUri);
+            uint32_t length = sizeof(NORMAL_INFO_DATA);
             responseData.payload = (CAPayload_t) calloc(length, sizeof(char));
             if (NULL == responseData.payload)
             {
                 printf("Memory allocation fail\n");
                 return;
             }
-            snprintf(responseData.payload, length, NORMAL_INFO_DATA, endpoint->resourceUri);
+            snprintf(responseData.payload, length, NORMAL_INFO_DATA, info->resourceUri);
+            return;
         }
     }
 
@@ -1443,9 +1244,9 @@ CAResult_t get_network_type()
 
     printf("\n=============================================\n");
     printf("\tselect network type\n");
-    printf("IPv4 : 0\n");
-    printf("BT : 2\n");
-    printf("LE : 3\n");
+    printf("IP : 1\n");
+    printf("GATT : 2\n");
+    printf("RFCOMM : 3\n");
     printf("select : ");
 
     if (CA_STATUS_OK != get_input_data(buf, MAX_BUF_LEN))
@@ -1457,29 +1258,23 @@ CAResult_t get_network_type()
 
     number = (number < 0 || number > 3) ? 0 : 1 << number;
 
-    if (!(number & 0xf))
+    if (number == 1)
     {
-        return CA_NOT_SUPPORTED;
-    }
-    if (number & CA_IPV4)
-    {
-        g_selected_nw_type = CA_IPV4;
+        g_selected_nw_type = CA_ADAPTER_IP;
         return CA_STATUS_OK;
     }
-    if (number & CA_EDR)
+    if (number == 2)
     {
-        g_selected_nw_type = CA_EDR;
+        g_selected_nw_type = CA_ADAPTER_GATT_BTLE;
         return CA_STATUS_OK;
     }
-    if (number & CA_LE)
+    if (number == 3)
     {
-        g_selected_nw_type = CA_LE;
+        g_selected_nw_type = CA_ADAPTER_RFCOMM_BTEDR;
         return CA_STATUS_OK;
     }
 
-    printf("\n=============================================\n");
-
-    return CA_STATUS_FAILED;
+    return CA_NOT_SUPPORTED;
 }
 
 CAResult_t get_input_data(char *buf, int32_t length)
index e0f5b0c..14cbccc 100644 (file)
@@ -85,7 +85,6 @@ void start_discovery_server();
 void find_resource();
 void send_request();
 void send_request_all();
-void advertise_resource();
 void send_notification();
 void select_network();
 void unselect_network();
@@ -321,11 +320,6 @@ void process()
                 send_request();
                 break;
 
-            case 'a': // advertise resource
-            case 'A':
-                advertise_resource();
-                break;
-
             case 'b': // send notification
             case 'B':
                 send_notification();
@@ -718,93 +712,6 @@ void send_request_all()
     printf("=============================================\n");
 }
 
-void advertise_resource()
-{
-    printf("\n=============================================\n");
-    printf("uri : ");
-
-    char buf[MAX_BUF_LEN] = { 0 };
-    if (CA_STATUS_OK != get_input_data(buf, MAX_BUF_LEN))
-    {
-        return;
-    }
-
-    char optionNumBuf[MAX_BUF_LEN] = { 0 };
-    char optionData[MAX_OPT_LEN] = { 0 } ;
-
-    printf("Option Num : ");
-    if (CA_STATUS_OK != get_input_data(optionNumBuf, MAX_BUF_LEN))
-    {
-        return;
-    }
-    int optionNum = atoi(optionNumBuf);
-
-    CAHeaderOption_t * headerOpt = (CAHeaderOption_t *)
-            calloc(1, optionNum * sizeof(CAHeaderOption_t));
-    if (NULL == headerOpt)
-    {
-        printf("Memory allocation failed!\n");
-        return;
-    }
-
-    int i;
-    for (i = 0; i < optionNum; i++)
-    {
-        char getOptionID[MAX_BUF_LEN] = { 0 } ;
-
-        printf("[%d] Option ID : ", i + 1);
-        if (CA_STATUS_OK != get_input_data(getOptionID, MAX_BUF_LEN))
-        {
-            free(headerOpt);
-            return;
-        }
-        int optionID = atoi(getOptionID);
-
-        headerOpt[i].optionID = optionID;
-
-        printf("[%d] Option Data : ", i + 1);
-        if (CA_STATUS_OK != get_input_data(optionData, MAX_OPT_LEN))
-        {
-            free(headerOpt);
-            return;
-        }
-
-        memcpy(headerOpt[i].optionData, optionData, strlen(optionData));
-        printf("[%d] inputed option : ID : %d, data : %s\n", i + 1, optionID, optionData);
-
-        headerOpt[i].optionLength = (uint16_t) strlen(optionData);
-    }
-    printf("\n=============================================\n");
-
-    // create token
-    CAToken_t token = NULL;
-    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
-
-    CAResult_t res = CAGenerateToken(&token, tokenLength);
-    if ((CA_STATUS_OK != res) || (!token))
-    {
-        printf("Token generate error!!\n");
-        free(headerOpt);
-        return;
-    }
-
-    printf("Generated token %s\n", token);
-
-    res = CAAdvertiseResource(buf, token, tokenLength, headerOpt, (uint8_t) optionNum);
-    if (CA_STATUS_OK != res)
-    {
-        printf("Could not start advertise resource\n");
-        CADestroyToken(token);
-    }
-    else
-    {
-        CADestroyToken(g_last_request_token);
-        g_last_request_token = token;
-    }
-
-    free(headerOpt);
-}
-
 void send_notification()
 {
     CAResult_t res = get_network_type();
index 9d2be70..207fce8 100755 (executable)
@@ -54,6 +54,8 @@ if env.get('SECURED') == '1':
 
 if ca_os == 'arduino':
        env.AppendUnique(CPPDEFINES = ['SINGLE_THREAD'])
+       env.AppendUnique(CPPDEFINES = ['WITH_ARDUINO'])
+       print "setting WITH_ARDUINO"
        ca_common_src = [
                ca_path + 'caconnectivitymanager_singlethread.c',
                ca_path + 'cainterfacecontroller_singlethread.c',
index 59919ef..8d58aca 100644 (file)
@@ -24,6 +24,7 @@
 #include "oic_malloc.h"
 #include "oic_string.h"
 #include "global.h"
+#include <netdb.h>
 
 /**
  * @def NET_DTLS_TAG
@@ -43,36 +44,35 @@ static stCADtlsContext_t *g_caDtlsContext = NULL;
  */
 static ca_mutex g_dtlsContextMutex = NULL;
 
-
 /**
  * @var g_getCredentialsCallback
  * @brief callback to get DTLS credentials
  */
 static CAGetDTLSCredentialsHandler g_getCredentialsCallback = NULL;
 
-static stCADtlsPeerInfo_t * GetPeerInfo(const char *peerAddr, uint32_t port)
+static CAEndpoint_t *GetPeerInfo(const CAEndpoint_t *peer)
 {
     uint32_t list_index = 0;
     uint32_t list_length = 0;
 
-    if(NULL == peerAddr || 0 == port)
+    if(NULL == peer)
     {
         OIC_LOG(ERROR, NET_DTLS_TAG, "CAPeerInfoListContains invalid parameters");
         return NULL;
     }
 
-    stCADtlsPeerInfo_t *peerInfo;
+    CAEndpoint_t *peerInfo;
     list_length = u_arraylist_length(g_caDtlsContext->peerInfoList);
     for (list_index = 0; list_index < list_length; list_index++)
     {
-        peerInfo = (stCADtlsPeerInfo_t *)u_arraylist_get(g_caDtlsContext->peerInfoList, list_index);
+        peerInfo = (CAEndpoint_t *)u_arraylist_get(g_caDtlsContext->peerInfoList, list_index);
         if (NULL == peerInfo)
         {
             continue;
         }
 
-        if((0 == strncmp(peerAddr, peerInfo->address.IP.ipAddress, CA_IPADDR_SIZE)) &&
-                (port == peerInfo->address.IP.port))
+        if((0 == strncmp(peer->addr, peerInfo->addr, MAX_ADDR_STR_SIZE_CA)) &&
+                (peer->port == peerInfo->port))
         {
             return peerInfo;
         }
@@ -81,7 +81,7 @@ static stCADtlsPeerInfo_t * GetPeerInfo(const char *peerAddr, uint32_t port)
 }
 
 static CAResult_t CAAddIdToPeerInfoList(const char *peerAddr, uint32_t port,
-       const unsigned char * id,uint16_t id_length)
+                                    const unsigned char *id, uint16_t id_length)
 {
     if(NULL == peerAddr || NULL == id || 0 == port || 0 == id_length)
     {
@@ -89,45 +89,42 @@ static CAResult_t CAAddIdToPeerInfoList(const char *peerAddr, uint32_t port,
         return CA_STATUS_INVALID_PARAM;
     }
 
-    if(NULL != GetPeerInfo(peerAddr, port))
-    {
-        OIC_LOG(ERROR, NET_DTLS_TAG, "CAAddIdToPeerInfoList peer already exist");
-        return CA_STATUS_FAILED;
-    }
-
-    stCADtlsPeerInfo_t *peerInfo = (stCADtlsPeerInfo_t *)
-                                    OICCalloc(1, sizeof(stCADtlsPeerInfo_t));
-    if (NULL == peerInfo)
+    CAEndpoint_t *peer = (CAEndpoint_t *)OICCalloc(1, sizeof (CAEndpoint_t));
+    if (NULL == peer)
     {
         OIC_LOG(ERROR, NET_DTLS_TAG, "peerInfo malloc failed!");
         return CA_MEMORY_ALLOC_FAILED;
     }
 
-    OICStrcpy(peerInfo->address.IP.ipAddress, sizeof(peerInfo->address.IP.ipAddress),
-            peerAddr);
-    peerInfo->address.IP.port = port;
-    OICStrcpyPartial(peerInfo->identity.id, sizeof(peerInfo->identity.id), id, id_length);
-    peerInfo->identity.id_length = id_length;
+    OICStrcpy(peer->addr, sizeof(peer->addr), peerAddr);
+    peer->port = port;
+    OICStrcpyPartial(peer->identity.id, sizeof(peer->identity.id), id, id_length);
+    peer->identity.id_length = id_length;
 
-    CAResult_t result = u_arraylist_add(g_caDtlsContext->peerInfoList, (void *)peerInfo);
+    if(NULL != GetPeerInfo(peer))
+    {
+        OIC_LOG(ERROR, NET_DTLS_TAG, "CAAddIdToPeerInfoList peer already exist");
+        OICFree(peer);
+        return CA_STATUS_FAILED;
+    }
 
+    CAResult_t result = u_arraylist_add(g_caDtlsContext->peerInfoList, (void *)peer);
     if (CA_STATUS_OK != result)
     {
         OIC_LOG(ERROR, NET_DTLS_TAG, "u_arraylist_add failed!");
-        OICFree(peerInfo);
+        OICFree(peer);
     }
 
     return result;
 }
 
-
 static void CAFreePeerInfoList()
 {
     uint32_t list_length = u_arraylist_length(g_caDtlsContext->peerInfoList);
     for (uint32_t list_index = 0; list_index < list_length; list_index++)
     {
-        stCADtlsPeerInfo_t * peerInfo = (stCADtlsPeerInfo_t *)u_arraylist_get(
-                                g_caDtlsContext->peerInfoList, list_index);
+        CAEndpoint_t *peerInfo = (CAEndpoint_t *)u_arraylist_get(
+                                     g_caDtlsContext->peerInfoList, list_index);
         OICFree(peerInfo);
     }
     u_arraylist_free(&(g_caDtlsContext->peerInfoList));
@@ -136,7 +133,7 @@ static void CAFreePeerInfoList()
 
 static void CARemovePeerFromPeerInfoList(const char * addr, uint32_t port)
 {
-    if(NULL == addr || 0 >= port)
+    if (NULL == addr || 0 >= port)
     {
         OIC_LOG(ERROR, NET_DTLS_TAG, "CADTLSGetPeerPSKId invalid parameters");
         return;
@@ -145,14 +142,14 @@ static void CARemovePeerFromPeerInfoList(const char * addr, uint32_t port)
     uint32_t list_length = u_arraylist_length(g_caDtlsContext->peerInfoList);
     for (uint32_t list_index = 0; list_index < list_length; list_index++)
     {
-        stCADtlsPeerInfo_t * peerInfo = (stCADtlsPeerInfo_t *)u_arraylist_get(
+        CAEndpoint_t *peerInfo = (CAEndpoint_t *)u_arraylist_get(
                                 g_caDtlsContext->peerInfoList,list_index);
         if (NULL == peerInfo)
         {
             continue;
         }
-        if((0 == strncmp(addr, peerInfo->address.IP.ipAddress, CA_IPADDR_SIZE)) &&
-                (port == peerInfo->address.IP.port))
+        if((0 == strncmp(addr, peerInfo->addr, MAX_ADDR_STR_SIZE_CA)) &&
+                (port == peerInfo->port))
         {
             OICFree(u_arraylist_remove(g_caDtlsContext->peerInfoList, list_index));
             return;
@@ -160,6 +157,28 @@ static void CARemovePeerFromPeerInfoList(const char * addr, uint32_t port)
     }
 }
 
+static int CASizeOfAddrInfo(stCADtlsAddrInfo_t *addrInfo)
+{
+    VERIFY_NON_NULL_RET(addrInfo, NET_DTLS_TAG, "addrInfo is NULL" , DTLS_FAIL);
+
+    switch (addrInfo->addr.st.ss_family)
+    {
+    case AF_INET:
+        {
+            return sizeof (struct sockaddr_in);
+        }
+    case AF_INET6:
+        {
+            return sizeof (struct sockaddr_in6);
+        }
+    default:
+        {
+            break;
+        }
+    }
+    return sizeof (struct sockaddr_storage);
+}
+
 static eDtlsRet_t CAAdapterNetDtlsEncryptInternal(const stCADtlsAddrInfo_t *dstSession,
         uint8_t *data, uint32_t dataLen)
 {
@@ -282,10 +301,15 @@ static CAResult_t CADtlsCacheMsg(stCACacheMessage_t *msg)
 
 static bool CAIsAddressMatching(const stCADtlsAddrInfo_t *a,  const stCADtlsAddrInfo_t *b)
 {
-    return (a->size == b->size) &&
-           (a->addr.sa.sa_family == b->addr.sa.sa_family) &&
-           (a->addr.sin.sin_port == b->addr.sin.sin_port) &&
-           memcmp(&a->addr.sin.sin_addr, &b->addr.sin.sin_addr, sizeof(struct in_addr)) == 0;
+    if (a->size != b->size)
+    {
+        return false;
+    }
+    if (memcmp(&a->addr, &b->addr, a->size))
+    {
+        return false;
+    }
+    return true;
 }
 
 static void CASendCachedMsg(const stCADtlsAddrInfo_t *dstSession)
@@ -347,9 +371,12 @@ static int32_t CAReadDecryptedPayload(dtls_context_t *dtlsContext,
 
     stCADtlsAddrInfo_t *addrInfo = (stCADtlsAddrInfo_t *)session;
 
-    char *remoteAddress = inet_ntoa(addrInfo->addr.sin.sin_addr);
-    uint32_t port = ntohs(addrInfo->addr.sin.sin_port);
-    CATransportType_t type = (CATransportType_t)addrInfo->ifIndex;
+    CAEndpoint_t endpoint = { 0 };
+    CAConvertAddrToName(&(addrInfo->addr.st), endpoint.addr, &endpoint.port);
+    endpoint.flags = addrInfo->addr.st.ss_family == AF_INET ? CA_IPV4 : CA_IPV6;
+    endpoint.flags |= CA_SECURE;
+    endpoint.adapter = CA_ADAPTER_IP;
+    int type = 0;
 
     if (NULL == g_caDtlsContext)
     {
@@ -360,12 +387,14 @@ static int32_t CAReadDecryptedPayload(dtls_context_t *dtlsContext,
     if ((0 <= type) && (MAX_SUPPORTED_ADAPTERS > type) &&
         (NULL != g_caDtlsContext->adapterCallbacks[type].recvCallback))
     {
-        // Get identity of sthe source of packet
-        stCADtlsPeerInfo_t * peerInfo = GetPeerInfo(remoteAddress, port);
+        // Get identity of the source of packet
+        CAEndpoint_t *peerInfo = GetPeerInfo(&endpoint);
+        if (peerInfo)
+        {
+            endpoint.identity = peerInfo->identity;
+        }
 
-        g_caDtlsContext->adapterCallbacks[type].recvCallback(remoteAddress, port,
-                buf,  bufLen, true,
-                (peerInfo) ? &(peerInfo->identity) : NULL);
+        g_caDtlsContext->adapterCallbacks[type].recvCallback(&endpoint, buf, bufLen);
     }
     else
     {
@@ -394,17 +423,19 @@ static int32_t CASendSecureData(dtls_context_t *dtlsContext,
 
     stCADtlsAddrInfo_t *addrInfo = (stCADtlsAddrInfo_t *)session;
 
-    char *remoteAddress = inet_ntoa(addrInfo->addr.sin.sin_addr);
-    uint16_t port = ntohs(addrInfo->addr.sin.sin_port);
-    CATransportType_t type = (CATransportType_t)addrInfo->ifIndex;
+    CAEndpoint_t endpoint;
+    CAConvertAddrToName(&(addrInfo->addr.st), endpoint.addr, &endpoint.port);
+    endpoint.flags = addrInfo->addr.st.ss_family == AF_INET ? CA_IPV4 : CA_IPV6;
+    endpoint.flags |= CA_SECURE;
+    endpoint.adapter = CA_ADAPTER_IP;
+    int type = 0;
 
     //Mutex is not required for g_caDtlsContext. It will be called in same thread.
     int32_t sentLen = 0;
     if ((0 <= type) && (MAX_SUPPORTED_ADAPTERS > type) &&
         (NULL != g_caDtlsContext->adapterCallbacks[type].sendCallback))
     {
-        sentLen = g_caDtlsContext->adapterCallbacks[type].sendCallback(remoteAddress, port,
-                  buf,  bufLen);
+        sentLen = g_caDtlsContext->adapterCallbacks[type].sendCallback(&endpoint, buf, bufLen);
     }
     else
     {
@@ -535,7 +566,8 @@ static int32_t CAGetPskCredentials(dtls_context_t *ctx,
 }
 
 void CADTLSSetAdapterCallbacks(CAPacketReceivedCallback recvCallback,
-                               CAPacketSendCallback sendCallback, CATransportType_t type)
+                               CAPacketSendCallback sendCallback,
+                               CATransportAdapter_t type)
 {
     OIC_LOG(DEBUG, NET_DTLS_TAG, "IN");
     ca_mutex_lock(g_dtlsContextMutex);
@@ -548,8 +580,9 @@ void CADTLSSetAdapterCallbacks(CAPacketReceivedCallback recvCallback,
 
     if ((0 <= type) && (MAX_SUPPORTED_ADAPTERS > type))
     {
-        g_caDtlsContext->adapterCallbacks[type].recvCallback = recvCallback;
-        g_caDtlsContext->adapterCallbacks[type].sendCallback = sendCallback;
+        // TODO: change the zeros to better values.
+        g_caDtlsContext->adapterCallbacks[0].recvCallback = recvCallback;
+        g_caDtlsContext->adapterCallbacks[0].sendCallback = sendCallback;
     }
 
     ca_mutex_unlock(g_dtlsContextMutex);
@@ -608,28 +641,20 @@ CAResult_t CADtlsEnableAnonECDHCipherSuite(const bool enable)
     return CA_STATUS_OK ;
 }
 
-CAResult_t CADtlsInitiateHandshake(const CAAddress_t* addrInfo,
-                                   const CATransportType_t transportType)
+CAResult_t CADtlsInitiateHandshake(const CAEndpoint_t *endpoint)
 {
     stCADtlsAddrInfo_t dst = {};
 
     OIC_LOG(DEBUG, NET_DTLS_TAG, "IN CADtlsInitiateHandshake");
 
-    if(!addrInfo)
+    if(!endpoint)
     {
         return CA_STATUS_INVALID_PARAM;
     }
 
-    if(inet_aton(addrInfo->IP.ipAddress, &dst.addr.sin.sin_addr) == 0)
-    {
-        OIC_LOG(ERROR, NET_DTLS_TAG, "Failed to convert from ASCII to Network Address");
-        return CA_STATUS_FAILED;
-    }
-    dst.addr.sin.sin_family = AF_INET;
-    dst.addr.sin.sin_port = htons(addrInfo->IP.port);
-    dst.size = sizeof(dst.addr);
-
-    dst.ifIndex = transportType;
+    CAConvertNameToAddr(endpoint->addr, endpoint->port, &(dst.addr.st));
+    dst.ifIndex = 0;
+    dst.size = CASizeOfAddrInfo(&dst);
 
     ca_mutex_lock(g_dtlsContextMutex);
     if(NULL == g_caDtlsContext)
@@ -653,37 +678,30 @@ CAResult_t CADtlsInitiateHandshake(const CAAddress_t* addrInfo,
     return CA_STATUS_OK;
 }
 
-CAResult_t CADtlsClose(const CAAddress_t* addrInfo, const CATransportType_t transportType)
+CAResult_t CADtlsClose(const CAEndpoint_t *endpoint)
 {
     stCADtlsAddrInfo_t dst = {};
 
     OIC_LOG(DEBUG, NET_DTLS_TAG, "IN CADtlsDisconnect");
 
-    if(!addrInfo)
+    if(!endpoint)
     {
         return CA_STATUS_INVALID_PARAM;
     }
 
-    if(inet_aton(addrInfo->IP.ipAddress, &dst.addr.sin.sin_addr) == 0)
-    {
-        OIC_LOG(ERROR, NET_DTLS_TAG, "Failed to convert from ASCII to Network Address");
-        return CA_STATUS_FAILED;
-    }
-    dst.addr.sin.sin_family = AF_INET;
-    dst.addr.sin.sin_port = htons(addrInfo->IP.port);
-    dst.size = sizeof(dst.addr);
-
-    dst.ifIndex = transportType;
+    CAConvertNameToAddr(endpoint->addr, endpoint->port, &(dst.addr.st));
+    dst.ifIndex = 0;
+    dst.size = CASizeOfAddrInfo(&dst);
 
     ca_mutex_lock(g_dtlsContextMutex);
-    if(NULL == g_caDtlsContext)
+    if (NULL == g_caDtlsContext)
     {
         OIC_LOG(ERROR, NET_DTLS_TAG, "Context is NULL");
         ca_mutex_unlock(g_dtlsContextMutex);
         return CA_STATUS_FAILED;
     }
 
-    if(0 > dtls_close(g_caDtlsContext->dtlsContext, (session_t*)(&dst)))
+    if (0 > dtls_close(g_caDtlsContext->dtlsContext, (session_t*)(&dst)))
     {
         OIC_LOG(ERROR, NET_DTLS_TAG, "Failed to close the session");
         ca_mutex_unlock(g_dtlsContextMutex);
@@ -697,8 +715,7 @@ CAResult_t CADtlsClose(const CAAddress_t* addrInfo, const CATransportType_t tran
     return CA_STATUS_OK;
 }
 
-CAResult_t CADtlsGenerateOwnerPSK(const CAAddress_t* addrInfo,
-                    const CATransportType_t transportType,
+CAResult_t CADtlsGenerateOwnerPSK(const CAEndpoint_t *endpoint,
                     const uint8_t* label, const size_t labelLen,
                     const uint8_t* rsrcServerDeviceID, const size_t rsrcServerDeviceIDLen,
                     const uint8_t* provServerDeviceID, const size_t provServerDeviceIDLen,
@@ -706,23 +723,16 @@ CAResult_t CADtlsGenerateOwnerPSK(const CAAddress_t* addrInfo,
 {
     OIC_LOG(DEBUG, NET_DTLS_TAG, "IN CADtlsGenerateOwnerPSK");
 
-    if(!addrInfo || !label || 0 == labelLen || !ownerPSK || 0 == ownerPSKSize)
+    if(!endpoint || !label || 0 == labelLen || !ownerPSK || 0 == ownerPSKSize)
     {
         return CA_STATUS_INVALID_PARAM;
     }
 
     stCADtlsAddrInfo_t dst = {};
 
-    if(inet_aton(addrInfo->IP.ipAddress, &dst.addr.sin.sin_addr) == 0)
-    {
-        OIC_LOG(ERROR, NET_DTLS_TAG, "Failed to convert from ASCII to Network Address");
-        return CA_STATUS_FAILED;
-    }
-    dst.addr.sin.sin_family = AF_INET;
-    dst.addr.sin.sin_port = htons(addrInfo->IP.port);
-    dst.size = sizeof(dst.addr);
-
-    dst.ifIndex = transportType;
+    CAConvertNameToAddr(endpoint->addr, endpoint->port, &(dst.addr.st));
+    dst.ifIndex = 0;
+    dst.size = CASizeOfAddrInfo(&dst);
 
     ca_mutex_lock(g_dtlsContextMutex);
     if (NULL == g_caDtlsContext)
@@ -784,7 +794,7 @@ CAResult_t CAAdapterNetDtlsInit()
     if( (NULL == g_caDtlsContext->peerInfoList) ||
         (NULL == g_caDtlsContext->cacheList))
     {
-        OIC_LOG(ERROR, NET_DTLS_TAG, "peerInfoList or cacheList initialization failed!");
+    OIC_LOG(ERROR, NET_DTLS_TAG, "peerInfoList or cacheList initialization failed!");
         CAClearCacheList();
         CAFreePeerInfoList();
         OICFree(g_caDtlsContext);
@@ -849,18 +859,16 @@ void CAAdapterNetDtlsDeInit()
     OIC_LOG(DEBUG, NET_DTLS_TAG, "OUT");
 }
 
-CAResult_t CAAdapterNetDtlsEncrypt(const char *remoteAddress,
-                                   const uint16_t port,
-                                   void *data,
-                                   uint32_t dataLen,
-                                   CATransportType_t transportType)
+CAResult_t CAAdapterNetDtlsEncrypt(const CAEndpoint_t *endpoint,
+                                   void *data, uint32_t dataLen)
 {
 
     OIC_LOG(DEBUG, NET_DTLS_TAG, "IN");
 
-    VERIFY_NON_NULL_RET(remoteAddress, NET_DTLS_TAG,"Param remoteAddress is NULL",CA_STATUS_FAILED);
-
-    VERIFY_NON_NULL_RET(data, NET_DTLS_TAG, "Param data is NULL" , CA_STATUS_FAILED);
+    VERIFY_NON_NULL_RET(endpoint, NET_DTLS_TAG,"Param remoteAddress is NULL",
+                        CA_STATUS_INVALID_PARAM);
+    VERIFY_NON_NULL_RET(data, NET_DTLS_TAG, "Param data is NULL" ,
+                        CA_STATUS_INVALID_PARAM);
 
     if (0 == dataLen)
     {
@@ -872,16 +880,9 @@ CAResult_t CAAdapterNetDtlsEncrypt(const char *remoteAddress,
 
     stCADtlsAddrInfo_t addrInfo = {};
 
-    addrInfo.addr.sin.sin_family = AF_INET;
-    addrInfo.addr.sin.sin_port = htons(port);
-    // Conversion from ASCII format to Network format
-    if (inet_aton(remoteAddress, &addrInfo.addr.sin.sin_addr) == 0)
-    {
-        OIC_LOG(ERROR, NET_DTLS_TAG, "Failed to convert from ASCII to Network Address");
-        return CA_STATUS_FAILED;
-    }
-    addrInfo.size = sizeof(addrInfo.addr);
-    addrInfo.ifIndex = transportType;
+    CAConvertNameToAddr(endpoint->addr, endpoint->port, &(addrInfo.addr.st));
+    addrInfo.ifIndex = 0;
+    addrInfo.size = CASizeOfAddrInfo(&addrInfo);
 
     ca_mutex_lock(g_dtlsContextMutex);
     if(NULL == g_caDtlsContext)
@@ -927,41 +928,30 @@ CAResult_t CAAdapterNetDtlsEncrypt(const char *remoteAddress,
 
     ca_mutex_unlock(g_dtlsContextMutex);
 
-    if (ret == DTLS_OK)
+    if (ret != DTLS_OK)
     {
-        OIC_LOG(DEBUG, NET_DTLS_TAG, "OUT");
-        return CA_STATUS_OK;
+        OIC_LOG(ERROR, NET_DTLS_TAG, "OUT FAILURE");
+        return CA_STATUS_FAILED;
     }
 
-    OIC_LOG(ERROR, NET_DTLS_TAG, "OUT FAILURE");
-    return CA_STATUS_FAILED;
+    OIC_LOG(DEBUG, NET_DTLS_TAG, "OUT");
+    return CA_STATUS_OK;
 }
 
-
-CAResult_t CAAdapterNetDtlsDecrypt(const char *remoteAddress,
-                                   const uint16_t port,
-                                   uint8_t *data,
-                                   uint32_t dataLen,
-                                   CATransportType_t transportType)
+CAResult_t CAAdapterNetDtlsDecrypt(const CAEndpoint_t *endpoint,
+                                   uint8_t *data, uint32_t dataLen)
 {
     OIC_LOG(DEBUG, NET_DTLS_TAG, "IN");
+    VERIFY_NON_NULL_RET(endpoint, NET_DTLS_TAG, "endpoint is NULL" , CA_STATUS_INVALID_PARAM);
 
     stCADtlsAddrInfo_t addrInfo = {};
 
-    addrInfo.addr.sin.sin_family = AF_INET;
-    addrInfo.addr.sin.sin_port = htons(port);
-
-    // Conversion from ASCII format to Network format
-    if (inet_aton(remoteAddress, &addrInfo.addr.sin.sin_addr) == 0)
-    {
-        OIC_LOG(ERROR, NET_DTLS_TAG, "Failed to convert from ASCII to Network Address");
-        return CA_STATUS_FAILED;
-    }
-    addrInfo.size = sizeof(addrInfo.addr);
-    addrInfo.ifIndex = transportType;
+    CAConvertNameToAddr(endpoint->addr, endpoint->port, &(addrInfo.addr.st));
+    addrInfo.ifIndex = 0;
+    addrInfo.size = CASizeOfAddrInfo(&addrInfo);
 
     ca_mutex_lock(g_dtlsContextMutex);
-    if(NULL == g_caDtlsContext)
+    if (NULL == g_caDtlsContext)
     {
         OIC_LOG(ERROR, NET_DTLS_TAG, "Context is NULL");
         ca_mutex_unlock(g_dtlsContextMutex);
index 3209d8b..b21d3d0 100644 (file)
 #include <ctype.h>
 #include "oic_string.h"
 #include "oic_malloc.h"
+#include <errno.h>
+
+#ifndef WITH_ARDUINO
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#endif
 
 #ifdef __ANDROID__
 #include <jni.h>
@@ -58,215 +65,69 @@ void CALogPDUData(coap_pdu_t *pdu)
 
     OIC_LOG_V(DEBUG, CA_ADAPTER_UTILS_TAG, "PDU Maker - token : %s", pdu->hdr->token);
 }
-
-CALocalConnectivity_t *CAAdapterCreateLocalEndpoint(CATransportType_t type, const char *address)
-{
-    CALocalConnectivity_t *info = (CALocalConnectivity_t *)
-                                  OICCalloc(1, sizeof(CALocalConnectivity_t));
-    if (NULL == info)
-    {
-        OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "Memory allocation failed !");
-        return NULL;
-    }
-
-    info->type = type;
-    if (address && strlen(address))
-    {
-        if (CA_EDR == type)
-        {
-            OICStrcpy(info->addressInfo.BT.btMacAddress, sizeof(info->addressInfo.BT.btMacAddress),
-                    address);
-        }
-        else if (CA_LE == type)
-        {
-            OICStrcpy(info->addressInfo.LE.leMacAddress, sizeof(info->addressInfo.LE.leMacAddress),
-                    address);
-        }
-        else if (CA_IPV4 == type)
-        {
-            OICStrcpy(info->addressInfo.IP.ipAddress, sizeof(info->addressInfo.IP.ipAddress),
-                    address);
-        }
-        else if (CA_IPV6 == type)
-        {
-            OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "Currently IPV6 is not supported");
-            OICFree(info);
-            return NULL;
-        }
-        else
-        {
-            OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "type is not matched with any transport!");
-            OICFree(info);
-            return NULL;
-        }
-    }
-
-    return info;
-}
-
-CALocalConnectivity_t *CAAdapterCopyLocalEndpoint(const CALocalConnectivity_t *connectivity)
+CAEndpoint_t *CAAdapterCreateEndpoint(CATransportFlags_t flags,
+                                      CATransportAdapter_t adapter,
+                                      const char *address,
+                                      uint16_t port)
 {
-    VERIFY_NON_NULL_RET(connectivity, CA_ADAPTER_UTILS_TAG, "connectivity is NULL", NULL);
-
-    CALocalConnectivity_t *info = (CALocalConnectivity_t *)
-                                  OICCalloc(1, sizeof(CALocalConnectivity_t));
+    VERIFY_NON_NULL_RET(address, CA_ADAPTER_UTILS_TAG, "Endpoint is NULL", NULL);
+    CAEndpoint_t *info = (CAEndpoint_t *)OICCalloc(1, sizeof(CAEndpoint_t));
     if (NULL == info)
     {
         OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "Memory allocation failed !");
         return NULL;
     }
 
-    info->type = connectivity->type;
-    if (CA_EDR == info->type && strlen(connectivity->addressInfo.BT.btMacAddress))
-    {
-        OICStrcpy(info->addressInfo.BT.btMacAddress, sizeof(info->addressInfo.BT.btMacAddress),
-                connectivity->addressInfo.BT.btMacAddress);
-    }
-    else if (CA_LE == info->type && strlen(connectivity->addressInfo.LE.leMacAddress))
-    {
-        OICStrcpy(info->addressInfo.LE.leMacAddress, sizeof(info->addressInfo.LE.leMacAddress),
-            connectivity->addressInfo.LE.leMacAddress);
-    }
-    else if ((CA_IPV4 == info->type)
-
-            && strlen(connectivity->addressInfo.IP.ipAddress))
-    {
-        OICStrcpy(info->addressInfo.IP.ipAddress, sizeof(info->addressInfo.IP.ipAddress),
-                connectivity->addressInfo.IP.ipAddress);
-        info->addressInfo.IP.port = connectivity->addressInfo.IP.port;
-    }
-    else if (CA_IPV6 == info->type)
-    {
-        OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "Currently IPV6 is not supported");
-        OICFree(info);
-        return NULL;
-    }
-    else
-    {
-        OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "type is not matched with any transport!");
-        OICFree(info);
-        return NULL;
-    }
+    OICStrcpy(info->addr, sizeof(info->addr), address);
+    info->addr[MAX_ADDR_STR_SIZE_CA - 1] = '\0';
+    info->flags = flags;
+    info->adapter = adapter;
+    info->port = port;
 
-    info->isSecured = connectivity->isSecured;
     return info;
 }
 
-void CAAdapterFreeLocalEndpoint(CALocalConnectivity_t *localEndpoint)
+CAEndpoint_t *CAAdapterCreateLocalEndpoint(CATransportFlags_t flags,
+                        CATransportAdapter_t adapter, const char *address)
 {
-    OICFree(localEndpoint);
+    return CAAdapterCreateEndpoint(flags, adapter, address, 0);
 }
 
-CARemoteEndpoint_t *CAAdapterCreateRemoteEndpoint(CATransportType_t type, const char *address,
-                                                  const char *resourceUri)
+CAResult_t CACreateEndpoint(CATransportFlags_t flags,
+                            CATransportAdapter_t adapter,
+                            const CAURI_t uri,
+                            uint16_t port,
+                            CAEndpoint_t **object)
 {
-    CARemoteEndpoint_t *info = (CARemoteEndpoint_t *)
-                               OICCalloc(1, sizeof(CARemoteEndpoint_t));
-    if (NULL == info)
-    {
-        OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "Memory allocation failed !");
-        return NULL;
-    }
-
-    info->transportType = type;
-    if (address && strlen(address))
-    {
-        if (CA_EDR == type)
-        {
-            OICStrcpy(info->addressInfo.BT.btMacAddress, sizeof(info->addressInfo.BT.btMacAddress),
-                    address);
-        }
-        else if (CA_LE == type)
-        {
-            OICStrcpy(info->addressInfo.LE.leMacAddress, sizeof(info->addressInfo.LE.leMacAddress),
-                    address);
-        }
-        else if (CA_IPV4 == type)
-        {
-            OICStrcpy(info->addressInfo.IP.ipAddress, sizeof(info->addressInfo.IP.ipAddress),
-                    address);
-        }
-        else if (CA_IPV6 == type)
-        {
-            OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "Currently IPV6 is not supported");
-            OICFree(info);
-            return NULL;
-        }
-        else
-        {
-            OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "type is not matched with any transport!");
-            OICFree(info);
-            return NULL;
-        }
-    }
-
-    if (resourceUri && strlen(resourceUri))
+    VERIFY_NON_NULL_RET(object, CA_ADAPTER_UTILS_TAG, "Endpoint is NULL", CA_STATUS_INVALID_PARAM);
+    CAEndpoint_t *endpoint = CAAdapterCreateEndpoint(flags, adapter, uri, port);
+    if (!endpoint)
     {
-        info->resourceUri = OICStrdup(resourceUri);
+        return CA_STATUS_FAILED;
     }
-
-    return info;
+    *object = endpoint;
+    return CA_STATUS_OK;
 }
 
-CARemoteEndpoint_t *CAAdapterCopyRemoteEndpoint(const CARemoteEndpoint_t *remoteEndpoint)
+
+CAEndpoint_t *CAAdapterCloneEndpoint(const CAEndpoint_t *endpoint)
 {
-    VERIFY_NON_NULL_RET(remoteEndpoint, CA_ADAPTER_UTILS_TAG, "Remote endpoint is NULL", NULL);
+    VERIFY_NON_NULL_RET(endpoint, CA_ADAPTER_UTILS_TAG, "endpoint is NULL", NULL);
 
-    CARemoteEndpoint_t *info = (CARemoteEndpoint_t *)
-                               OICCalloc(1, sizeof(CARemoteEndpoint_t));
+    CAEndpoint_t *info = (CAEndpoint_t *)OICCalloc(1, sizeof (CAEndpoint_t));
     if (NULL == info)
     {
         OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "Memory allocation failed !");
         return NULL;
     }
+    *info = *endpoint;
 
-    info->transportType = remoteEndpoint->transportType;
-    if (CA_EDR == info->transportType && ('\0' != remoteEndpoint->addressInfo.BT.btMacAddress[0]))
-    {
-        OICStrcpy(info->addressInfo.BT.btMacAddress, sizeof(info->addressInfo.BT.btMacAddress),
-                remoteEndpoint->addressInfo.BT.btMacAddress);
-    }
-    else if (CA_LE == info->transportType
-             && ('\0' != remoteEndpoint->addressInfo.LE.leMacAddress[0]))
-    {
-        OICStrcpy(info->addressInfo.LE.leMacAddress, sizeof(info->addressInfo.LE.leMacAddress),
-                remoteEndpoint->addressInfo.LE.leMacAddress);
-    }
-    else if ((CA_IPV4 == info->transportType)
-            && ('\0' != remoteEndpoint->addressInfo.IP.ipAddress[0]))
-    {
-        OICStrcpy(info->addressInfo.IP.ipAddress, sizeof(info->addressInfo.IP.ipAddress),
-                remoteEndpoint->addressInfo.IP.ipAddress);
-        info->addressInfo.IP.port = remoteEndpoint->addressInfo.IP.port;
-    }
-    else if (CA_IPV6 == info->transportType)
-    {
-        OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "Currently IPV6 is not supported");
-    }
-    else
-    {
-        OIC_LOG(DEBUG, CA_ADAPTER_UTILS_TAG, "Its not matching. May be multicast.");
-    }
-
-    //For Multicast, remote address will be null while resourceUri will have the service UUID
-
-    if (remoteEndpoint->resourceUri && strlen(remoteEndpoint->resourceUri))
-    {
-        info->resourceUri = OICStrdup(remoteEndpoint->resourceUri);
-    }
-
-    info->isSecured = remoteEndpoint->isSecured;
-    info->identity  = remoteEndpoint->identity;
     return info;
 }
 
-void CAAdapterFreeRemoteEndpoint(CARemoteEndpoint_t *remoteEndpoint)
+void CAAdapterFreeEndpoint(CAEndpoint_t *remoteEndpoint)
 {
-    if (remoteEndpoint)
-    {
-        OICFree(remoteEndpoint->resourceUri);
-        OICFree(remoteEndpoint);
-    }
+    OICFree(remoteEndpoint);
 }
 
 CAResult_t CAParseIPv4AddressInternal(const char *ipAddrStr, uint8_t *ipAddr,
@@ -378,7 +239,6 @@ bool CAAdapterIsSameSubnet(const char *ipAddress1, const char *ipAddress2, const
            && ((ipList1[3] & maskList[3]) == (ipList2[3] & maskList[3]));
 }
 
-
 bool CAIsMulticastServerStarted(const u_arraylist_t *serverInfoList, const char *ipAddress,
                                 const char *multicastAddress, uint16_t port)
 {
@@ -396,9 +256,9 @@ bool CAIsMulticastServerStarted(const u_arraylist_t *serverInfoList, const char
             return false;
         }
 
-        if (info->isMulticastServer && (strncmp(info->ipAddress, multicastAddress,
-                                                strlen(multicastAddress) == 0))
-            && (info->port == port) && (strncmp(info->ifAddr, ipAddress, strlen(ipAddress)) == 0))
+        if (info->isMulticastServer && (strncmp(info->endpoint.addr, multicastAddress,
+                                                strlen(multicastAddress)) == 0)
+            && (info->endpoint.port == port) && (strncmp(info->ifAddr, ipAddress, strlen(ipAddress)) == 0))
         {
             return info->isServerStarted;
         }
@@ -421,9 +281,9 @@ bool CAIsUnicastServerStarted(const u_arraylist_t *serverInfoList, const char *i
             continue;
         }
 
-        if (!info->isMulticastServer && (strncmp(info->ipAddress, ipAddress,
+        if (!info->isMulticastServer && (strncmp(info->endpoint.addr, ipAddress,
                                                  strlen(ipAddress)) == 0)
-            && (info->port == port))
+            && (info->endpoint.port == port))
         {
             return info->isServerStarted;
         }
@@ -444,21 +304,24 @@ uint16_t CAGetServerPort(const u_arraylist_t *serverInfoList, const char *ipAddr
         {
             continue;
         }
-        if ((strncmp(info->ipAddress, ipAddress, strlen(ipAddress)) == 0) &&
-                    (info->isSecured == isSecured))
+        bool ifSecured = info->endpoint.flags & CA_SECURE;
+        if ((strncmp(info->endpoint.addr, ipAddress, strlen(ipAddress)) == 0) &&
+                    (ifSecured == isSecured))
         {
-            return info->port;
+            return info->endpoint.port;
         }
     }
 
     return 0;
 }
 
-int CAGetSocketFdForUnicastServer(const u_arraylist_t *serverInfoList, const char *ipAddress,
-                                  bool isSecured, bool isMulticast, CATransportType_t type)
+int CAGetSocketFdForUnicastServer(const u_arraylist_t *serverInfoList,
+                                bool isMulticast, const CAEndpoint_t *endpoint)
 {
     VERIFY_NON_NULL_RET(serverInfoList, CA_ADAPTER_UTILS_TAG, "serverInfoList is null", -1);
-    VERIFY_NON_NULL_RET(ipAddress, CA_ADAPTER_UTILS_TAG, "ipAddress is null", -1);
+    VERIFY_NON_NULL_RET(endpoint, CA_ADAPTER_UTILS_TAG, "endpoint is null", -1);
+
+    bool isSecured = (endpoint->flags & CA_SECURE) != 0;
 
     uint32_t listLength = u_arraylist_length(serverInfoList);
 
@@ -470,12 +333,13 @@ int CAGetSocketFdForUnicastServer(const u_arraylist_t *serverInfoList, const cha
             continue;
         }
 
-        if (!CAAdapterIsSameSubnet(info->ipAddress, ipAddress, info->subNetMask))
+        if (!CAAdapterIsSameSubnet(info->endpoint.addr, endpoint->addr, info->subNetMask))
         {
             continue;
         }
 
-        if (!info->isMulticastServer && (info->isSecured == isSecured))
+        bool ifSecured = info->endpoint.flags & CA_SECURE;
+        if (!info->isMulticastServer && (ifSecured == isSecured))
         {
             OIC_LOG_V(DEBUG, CA_ADAPTER_UTILS_TAG,
                       "CAGetSocketFdForServer found socket [%d]", info->socketFd);
@@ -566,6 +430,81 @@ void CAClearServerInfoList(u_arraylist_t *serverInfoList)
     u_arraylist_free(&serverInfoList);
 }
 
+#ifndef WITH_ARDUINO
+/*
+ * These two conversion functions return void because errors can't happen
+ * (because of NI_NUMERIC), and there's nothing to do if they do happen.
+ */
+void CAConvertAddrToName(const struct sockaddr_storage *sockAddr, char *host, uint16_t *port)
+{
+    VERIFY_NON_NULL_VOID(sockAddr, CA_ADAPTER_UTILS_TAG, "sockAddr is null");
+    VERIFY_NON_NULL_VOID(host, CA_ADAPTER_UTILS_TAG, "host is null");
+    VERIFY_NON_NULL_VOID(port, CA_ADAPTER_UTILS_TAG, "port is null");
+
+    int r = getnameinfo((struct sockaddr *)sockAddr,
+                        sizeof (struct sockaddr_storage),
+                        host, CA_IPADDR_SIZE,
+                        NULL, 0,
+                        NI_NUMERICHOST|NI_NUMERICSERV);
+    if (r)
+    {
+        if (EAI_SYSTEM == r)
+        {
+            OIC_LOG_V(ERROR, CA_ADAPTER_UTILS_TAG,
+                            "getaddrinfo failed: errno %s", strerror(errno));
+        }
+        else
+        {
+            OIC_LOG_V(ERROR, CA_ADAPTER_UTILS_TAG,
+                            "getaddrinfo failed: %s", gai_strerror(r));
+        }
+        return;
+    }
+    *port = ntohs(((struct sockaddr_in *)sockAddr)->sin_port); // IPv4 and IPv6
+}
+
+void CAConvertNameToAddr(const char *host, uint16_t port, struct sockaddr_storage *sockaddr)
+{
+    VERIFY_NON_NULL_VOID(host, CA_ADAPTER_UTILS_TAG, "host is null");
+    VERIFY_NON_NULL_VOID(sockaddr, CA_ADAPTER_UTILS_TAG, "sockaddr is null");
+
+    struct addrinfo *addrs;
+    struct addrinfo hints = { 0 };
+    hints.ai_family = AF_UNSPEC;
+    hints.ai_socktype = SOCK_DGRAM;
+    hints.ai_flags = AI_NUMERICHOST;
+
+    int r = getaddrinfo(host, NULL, &hints, &addrs);
+    if (r)
+    {
+        if (EAI_SYSTEM == r)
+        {
+            OIC_LOG_V(ERROR, CA_ADAPTER_UTILS_TAG,
+                            "getaddrinfo failed: errno %s", strerror(errno));
+        }
+        else
+        {
+            OIC_LOG_V(ERROR, CA_ADAPTER_UTILS_TAG,
+                            "getaddrinfo failed: %s", gai_strerror(r));
+        }
+        return;
+    }
+    // assumption: in this case, getaddrinfo will only return one addrinfo
+    // or first is the one we want.
+    if (addrs[0].ai_family == AF_INET6)
+    {
+        memcpy(sockaddr, addrs[0].ai_addr, sizeof (struct sockaddr_in6));
+        ((struct sockaddr_in6 *)sockaddr)->sin6_port = htons(port);
+    }
+    else
+    {
+        memcpy(sockaddr, addrs[0].ai_addr, sizeof (struct sockaddr_in));
+        ((struct sockaddr_in *)sockaddr)->sin_port = htons(port);
+    }
+    freeaddrinfo(addrs);
+}
+#endif // WITH_ARDUINO
+
 #ifdef __ANDROID__
 void CANativeJNISetContext(JNIEnv *env, jobject context)
 {
index 4536343..99122f6 100644 (file)
@@ -121,13 +121,13 @@ typedef struct
 /**
  * implement for BT-EDR adapter common method
  */
-CAResult_t CAEDRGetInterfaceInformation(CALocalConnectivity_t **info)
+CAResult_t CAEDRGetInterfaceInformation(CAEndpoint_t **info)
 {
     OIC_LOG(DEBUG, TAG, "IN - CAEDRGetInterfaceInformation");
 
     if (!info)
     {
-        OIC_LOG(ERROR, TAG, "LocalConnectivity info is null");
+        OIC_LOG(ERROR, TAG, "endpoint info is null");
         return CA_STATUS_FAILED;
     }
 
@@ -151,7 +151,8 @@ CAResult_t CAEDRGetInterfaceInformation(CALocalConnectivity_t **info)
     }
 
     // Create local endpoint using util function
-    CALocalConnectivity_t *endpoint = CAAdapterCreateLocalEndpoint(CA_EDR, macAddress);
+    CAEndpoint_t *endpoint = CAAdapterCreateEndpoint(CA_DEFAULT_FLAGS,
+                                            CA_RFCOMM_ADAPTER, macAddress, 0);
     if (NULL == endpoint)
     {
         OIC_LOG(ERROR, TAG, "Failed to create Local Endpoint!");
@@ -160,21 +161,19 @@ CAResult_t CAEDRGetInterfaceInformation(CALocalConnectivity_t **info)
     }
 
     // copy unicast server information
-    endpoint->isSecured = false;
-    CALocalConnectivity_t *netInfo = (CALocalConnectivity_t *) OICMalloc(
-            sizeof(CALocalConnectivity_t) * netInfoSize);
+    CAEndpoint_t *netInfo = (CAEndpoint_t *)OICMalloc(sizeof(CAEndpoint_t) * netInfoSize);
     if (NULL == netInfo)
     {
         OIC_LOG(ERROR, TAG, "Invalid input..");
         OICFree(macAddress);
-        CAAdapterFreeLocalEndpoint(endpoint);
+        CAAdapterFreeEndpoint(endpoint);
         return CA_MEMORY_ALLOC_FAILED;
     }
-    memcpy(netInfo, endpoint, sizeof(CALocalConnectivity_t));
+    *netInfo = *endpoint;
     *info = netInfo;
 
     OICFree(macAddress);
-    CAAdapterFreeLocalEndpoint(endpoint);
+    CAAdapterFreeEndpoint(endpoint);
 
     OIC_LOG(DEBUG, TAG, "OUT - CAEDRGetInterfaceInformation");
     return CA_STATUS_OK;
index 9425988..2db5548 100644 (file)
@@ -86,7 +86,7 @@ static CANetworkChangeCallback g_networkChangeCallback = NULL;
  * @var g_localConnectivity
  * @brief Information of local Bluetooth adapter.
  */
-static CALocalConnectivity_t *g_localConnectivity = NULL;
+static CAEndpoint_t *g_localConnectivity = NULL;
 
 /**
  * @var g_serverId
@@ -114,7 +114,7 @@ void CAEDRNotifyNetworkStatus(CANetworkStatus_t status);
 void CAEDROnNetworkStatusChanged(void *context);
 CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID, const void *data,
                              uint32_t dataLength, uint32_t *sentLength);
-CAEDRNetworkEvent *CAEDRCreateNetworkEvent(CALocalConnectivity_t *connectivity,
+CAEDRNetworkEvent *CAEDRCreateNetworkEvent(CAEndpoint_t *connectivity,
                                            CANetworkStatus_t status);
 CAResult_t CAEDRClientSendData(const char *remoteAddress, const char *serviceUUID,
                                const void *data, uint32_t dataLength, uint32_t *sentLength);
@@ -122,7 +122,7 @@ CAResult_t CAEDRClientSendData(const char *remoteAddress, const char *serviceUUI
  * @fn CACreateEDRData
  * @brief Helper function to create CAEDRData
  */
-static CAEDRData *CACreateEDRData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
+static CAEDRData *CACreateEDRData(const CAEndpoint_t *remoteEndpoint, const void *data,
                                   uint32_t dataLength);
 
 /**
@@ -182,7 +182,7 @@ CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
     handler.readData = CAReadEDRData;
     handler.stopAdapter = CAStopEDR;
     handler.terminate = CATerminateEDR;
-    registerCallback(handler, CA_EDR);
+    registerCallback(handler, CA_ADAPTER_RFCOMM_BTEDR);
 
     // Initialize Send/Receive data message queues
     if (CA_STATUS_OK != CAEDRInitializeQueueHandlers())
@@ -251,7 +251,7 @@ CAResult_t CAStartEDRDiscoveryServer()
     return CAStartServer();
 }
 
-int32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
+int32_t CASendEDRUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data,
                              uint32_t dataLength)
 {
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
@@ -266,7 +266,7 @@ int32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const voi
         return -1;
     }
 
-    if (0 == strlen(remoteEndpoint->addressInfo.BT.btMacAddress))
+    if (0 == strlen(remoteEndpoint->addr))
     {
         OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Invalid input: EDR Address is empty!");
         return -1;
@@ -274,7 +274,7 @@ int32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const voi
 
     uint32_t sentLength = 0;
     const char *serviceUUID = OIC_EDR_SERVICE_ID;
-    const char *address = remoteEndpoint->addressInfo.BT.btMacAddress;
+    const char *address = remoteEndpoint->addr;
     CAResult_t err = CAAdapterSendData(address, serviceUUID, data, dataLength, &sentLength);
     if (CA_STATUS_OK != err)
     {
@@ -286,7 +286,7 @@ int32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const voi
     return sentLength;
 }
 
-int32_t CASendEDRMulticastData(const void *data, uint32_t dataLength)
+int32_t CASendEDRMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLength)
 {
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN - CASendEDRMulticastData");
 
@@ -312,8 +312,7 @@ int32_t CASendEDRMulticastData(const void *data, uint32_t dataLength)
     return sentLen;
 }
 
-
-CAResult_t CAGetEDRInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size)
+CAResult_t CAGetEDRInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
 {
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
 
@@ -392,7 +391,7 @@ void CATerminateEDR()
     CAEDRServerTerminate();
 
     // Free LocalConnectivity information
-    CAAdapterFreeLocalEndpoint(g_localConnectivity);
+    CAAdapterFreeEndpoint(g_localConnectivity);
     g_localConnectivity = NULL;
 
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
@@ -529,7 +528,7 @@ void CAAdapterDataSendHandler(void *context)
     }
 
     const char *remoteAddress = NULL;
-    const char *serviceUUID = NULL;
+    const char *serviceUUID = OIC_EDR_SERVICE_ID;
     uint32_t sentLength = 0;
 
     if (NULL == message->remoteEndpoint)
@@ -538,8 +537,7 @@ void CAAdapterDataSendHandler(void *context)
     }
     else
     {
-        remoteAddress = message->remoteEndpoint->addressInfo.BT.btMacAddress;
-        serviceUUID = message->remoteEndpoint->resourceUri;
+        remoteAddress = message->remoteEndpoint->addr;
     }
 
     uint32_t dataSegmentLength = message->dataLen + CA_HEADER_LENGTH;
@@ -665,7 +663,7 @@ void CAAdapterDataReceiverHandler(void *context)
     static uint32_t recvDataLen = 0;
     static uint32_t totalDataLen = 0;
     static char *defragData = NULL;
-    static CARemoteEndpoint_t *remoteEndpoint = NULL;
+    static CAEndpoint_t *remoteEndpoint = NULL;
 
     if (!g_isHeaderAvailable)
     {
@@ -685,10 +683,10 @@ void CAAdapterDataReceiverHandler(void *context)
             return;
         }
 
-        const char *remoteAddress = message->remoteEndpoint->addressInfo.BT.btMacAddress;
-        const char *serviceUUID = message->remoteEndpoint->resourceUri;
+        const char *remoteAddress = message->remoteEndpoint->addr;
+        uint16_t port = message->remoteEndpoint->port;
 
-        remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_EDR, remoteAddress, serviceUUID);
+        remoteEndpoint = CAAdapterCreateEndpoint(0, CA_ADAPTER_RFCOMM_BTEDR, remoteAddress, port);
 
         memcpy(defragData + recvDataLen, message->data + CA_HEADER_LENGTH,
                message->dataLen - CA_HEADER_LENGTH);
@@ -768,10 +766,11 @@ void CAAdapterRecvData(const char *remoteAddress, const void *data, uint32_t dat
     VERIFY_NON_NULL_VOID(data, EDR_ADAPTER_TAG, "Data is null");
     VERIFY_NON_NULL_VOID(sentLength, EDR_ADAPTER_TAG, "Sent data length holder is null");
 
-    static const char serviceUUID[] = OIC_EDR_SERVICE_ID;
     // Create remote endpoint
-    CARemoteEndpoint_t *remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_EDR, remoteAddress,
-                                                                       serviceUUID);
+    CAEndpoint_t *remoteEndpoint = CAAdapterCreateEndpoint(0,
+                                                        CA_ADAPTER_RFCOMM_BTEDR,
+                                                        remoteAddress,
+                                                        0);
     if (NULL == remoteEndpoint)
     {
         OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to create remote endpoint !");
@@ -784,7 +783,7 @@ void CAAdapterRecvData(const char *remoteAddress, const void *data, uint32_t dat
     *sentLength = dataLength;
 
     // Free remote endpoint
-    CAAdapterFreeRemoteEndpoint(remoteEndpoint);
+    CAAdapterFreeEndpoint(remoteEndpoint);
 
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
 }
@@ -806,8 +805,7 @@ CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID,
     VERIFY_NON_NULL(sentLength, EDR_ADAPTER_TAG, "Sent data length holder is null");
 
     // Create remote endpoint
-    CARemoteEndpoint_t *remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_EDR, remoteAddress,
-                                                                       serviceUUID);
+    CAEndpoint_t *remoteEndpoint = CAAdapterCreateEndpoint(0, CA_ADAPTER_RFCOMM_BTEDR, remoteAddress, 0);
     if (NULL == remoteEndpoint)
     {
         OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to create remote endpoint !");
@@ -816,11 +814,11 @@ CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID,
 
     // Add message to data queue
     CAEDRData *edrData =  CACreateEDRData(remoteEndpoint, data, dataLength);
-    CAQueueingThreadAddData(g_sendQueueHandle, edrData, sizeof(CAEDRData));
+    CAQueueingThreadAddData(g_sendQueueHandle, edrData, sizeof (CAEDRData));
     *sentLength = dataLength;
 
     // Free remote endpoint
-    CAAdapterFreeRemoteEndpoint(remoteEndpoint);
+    CAAdapterFreeEndpoint(remoteEndpoint);
 
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT - CAAdapterSendData");
     return CA_STATUS_OK;
@@ -913,7 +911,7 @@ void CAEDROnNetworkStatusChanged(void *context)
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
 }
 
-CAEDRNetworkEvent *CAEDRCreateNetworkEvent(CALocalConnectivity_t *connectivity,
+CAEDRNetworkEvent *CAEDRCreateNetworkEvent(CAEndpoint_t *connectivity,
                                            CANetworkStatus_t status)
 {
     VERIFY_NON_NULL_RET(connectivity, EDR_ADAPTER_TAG, "connectivity is NULL", NULL);
@@ -927,7 +925,7 @@ CAEDRNetworkEvent *CAEDRCreateNetworkEvent(CALocalConnectivity_t *connectivity,
     }
 
     // Create duplicate of Local connectivity
-    event->info = CAAdapterCopyLocalEndpoint(connectivity);
+    event->info = CAAdapterCloneEndpoint(connectivity);
     event->status = status;
     return event;
 }
@@ -936,22 +934,23 @@ void CAEDRFreeNetworkEvent(CAEDRNetworkEvent *event)
 {
     if (event)
     {
-        CAAdapterFreeLocalEndpoint(event->info);
+        CAAdapterFreeEndpoint(event->info);
         OICFree(event);
     }
 }
 
-CAEDRData *CACreateEDRData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
-                           uint32_t dataLength)
+CAEDRData *CACreateEDRData(const CAEndpoint_t *remoteEndpoint,
+                                        const void *data, uint32_t dataLength)
 {
-    CAEDRData *edrData = (CAEDRData *) OICMalloc(sizeof(CAEDRData));
+    CAEDRData *edrData = (CAEDRData *)OICMalloc(sizeof (CAEDRData));
     if (!edrData)
     {
         OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Memory allocation failed!");
         return NULL;
     }
 
-    edrData->remoteEndpoint = CAAdapterCopyRemoteEndpoint(remoteEndpoint);
+    edrData->remoteEndpoint = CAAdapterCloneEndpoint(remoteEndpoint);
+
     edrData->data = OICMalloc(dataLength);
     if (NULL == edrData->data)
     {
@@ -969,7 +968,7 @@ void CAFreeEDRData(CAEDRData *edrData)
 {
     VERIFY_NON_NULL_VOID(edrData, EDR_ADAPTER_TAG, "edrData is NULL");
 
-    CAAdapterFreeRemoteEndpoint(edrData->remoteEndpoint);
+    CAAdapterFreeEndpoint(edrData->remoteEndpoint);
     OICFree(edrData->data);
     OICFree(edrData);
 }
index ff65d33..820e706 100644 (file)
@@ -52,7 +52,7 @@ CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
     handler.stopAdapter = CAStopEDR;
     handler.terminate = CATerminateEDR;
 
-    registerCallback(handler, CA_EDR);
+    registerCallback(handler, CA_ADAPTER_RFCOMM_BTEDR);
 
     return CA_STATUS_OK;
 }
@@ -78,7 +78,7 @@ CAResult_t CAStartEDRDiscoveryServer()
     return CA_STATUS_OK;
 }
 
-int32_t CASendEDRUnicastData(const CARemoteEndpoint_t *endpoint, const void *data,
+int32_t CASendEDRUnicastData(const CAEndpoint_t *endpoint, const void *data,
     uint32_t dataLen)
 {
     OIC_LOG(DEBUG, TAG, "CASendEDRUnicastData");
@@ -86,14 +86,14 @@ int32_t CASendEDRUnicastData(const CARemoteEndpoint_t *endpoint, const void *dat
     return -1;
 }
 
-int32_t CASendEDRMulticastData(const void *data, uint32_t dataLen)
+int32_t CASendEDRMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
 {
     OIC_LOG(DEBUG, TAG, "CASendEDRMulticastData");
 
     return -1;
 }
 
-CAResult_t CAGetEDRInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size)
+CAResult_t CAGetEDRInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
 {
     OIC_LOG(DEBUG, TAG, "CAGetEDRInterfaceInformation");
 
index ae85eff..69cde76 100644 (file)
@@ -281,7 +281,7 @@ CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
     connHandler.GetnetInfo = CAGetLEInterfaceInformation;
     connHandler.readData = CAReadLEData;
     connHandler.terminate = CATerminateLE;
-    registerCallback(connHandler, CA_LE);
+    registerCallback(connHandler, CA_ADAPTER_GATT_BTLE);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 
@@ -425,7 +425,7 @@ CAResult_t CAStartLENotifyServer()
     return CA_STATUS_OK;
 }
 
-uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t dataLen)
+uint32_t CASendLENotification(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -441,7 +441,7 @@ CAResult_t CAReadLEData()
     return CA_STATUS_OK;
 }
 
-int32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t dataLen)
+int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -480,7 +480,7 @@ int32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, const void *data
     return dataLen;
 }
 
-int32_t CASendLEMulticastData(const void *data, uint32_t dataLen)
+int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -524,7 +524,7 @@ int32_t CASendLEMulticastData(const void *data, uint32_t dataLen)
     return dataLen;
 }
 
-CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size)
+CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
@@ -546,7 +546,7 @@ CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *s
     }
 
     *size = 0;
-    (*info) = (CALocalConnectivity_t *) OICCalloc(1, sizeof(CALocalConnectivity_t));
+    (*info) = (CAEndpoint_t *) OICCalloc(1, sizeof (CAEndpoint_t));
     if (NULL == (*info))
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Malloc failure!");
@@ -557,7 +557,7 @@ CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *s
     size_t local_address_len = strlen(local_address);
 
     if(local_address_len >= sizeof(g_localBLEAddress) ||
-            local_address_len >= sizeof((*info)->addressInfo.BT.btMacAddress))
+            local_address_len >= MAX_ADDR_STR_SIZE_CA - 1)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "local_address is too long");
         OICFree(*info);
@@ -565,13 +565,12 @@ CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *s
         return CA_STATUS_FAILED;
     }
 
-    OICStrcpy((*info)->addressInfo.BT.btMacAddress, sizeof ((*info)->addressInfo.BT.btMacAddress),
-            local_address);
+    OICStrcpy((*info)->addr, sizeof((*info)->addr), local_address);
     ca_mutex_lock(g_bleLocalAddressMutex);
     OICStrcpy(g_localBLEAddress, sizeof(g_localBLEAddress), local_address);
     ca_mutex_unlock(g_bleLocalAddressMutex);
 
-    (*info)->type = CA_LE;
+    (*info)->adapter = CA_ADAPTER_GATT_BTLE;
     *size = 1;
     OICFree(local_address);
 
@@ -613,12 +612,10 @@ void CALEDeviceStateChangedCb( CAAdapterState_t adapter_state)
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
     VERIFY_NON_NULL_VOID(g_localBLEAddress, NULL, "g_localBLEAddress is null");
-    CALocalConnectivity_t localEndpoint = {};
-
+    CAEndpoint_t localEndpoint = {};
+    localEndpoint.adapter = CA_ADAPTER_GATT_BTLE;
     ca_mutex_lock(g_bleLocalAddressMutex);
-    OICStrcpy(localEndpoint.addressInfo.BT.btMacAddress,
-            sizeof(localEndpoint.addressInfo.BT.btMacAddress),
-            g_localBLEAddress);
+    OICStrcpy(localEndpoint.addr, sizeof(localEndpoint.addr), g_localBLEAddress);
     ca_mutex_unlock(g_bleLocalAddressMutex);
 
     // Start a GattServer/Client if gLeServerStatus is SET
@@ -1089,7 +1086,7 @@ void CABLEServerDataReceiverHandler(void *threadData)
     static uint32_t totalDataLen = 0;
     static char *defragData = NULL;
     static bool isHeaderAvailable = false;
-    static CARemoteEndpoint_t *remoteEndpoint = NULL;
+    static CAEndpoint_t *remoteEndpoint = NULL;
 
     ca_mutex_lock(g_bleServerReceiveDataMutex);
 
@@ -1121,11 +1118,9 @@ void CABLEServerDataReceiverHandler(void *threadData)
                 return;
             }
 
-            const char *remoteAddress = bleData->remoteEndpoint->addressInfo.LE.leMacAddress;
-            const char *serviceUUID = bleData->remoteEndpoint->resourceUri;
+            const char *remoteAddress = bleData->remoteEndpoint->addr;
 
-            remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_LE, remoteAddress,
-                             serviceUUID);
+            remoteEndpoint = CAAdapterCreateEndpoint(0, CA_ADAPTER_GATT_BTLE, remoteAddress, 0);
 
             memcpy(defragData + recvDataLen, bleData->data + CA_HEADER_LENGTH,
                    bleData->dataLen - CA_HEADER_LENGTH);
@@ -1166,7 +1161,7 @@ void CABLEServerDataReceiverHandler(void *threadData)
             totalDataLen = 0;
             isHeaderAvailable = false;
             OICFree(defragData);
-            CAAdapterFreeRemoteEndpoint(remoteEndpoint);
+            CAAdapterFreeEndpoint(remoteEndpoint);
             ca_mutex_unlock(g_bleServerReceiveDataMutex);
             return;
         }
@@ -1180,12 +1175,11 @@ void CABLEClientDataReceiverHandler(void *threadData)
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
     static const char *remoteAddress = NULL;
-    static const char *serviceUUID = NULL;
     static uint32_t recvDataLen = 0;
     static uint32_t totalDataLen = 0;
     static char *defragData = NULL;
     static bool isHeaderAvailable = false;
-    static CARemoteEndpoint_t *remoteEndpoint = NULL;
+    static CAEndpoint_t *remoteEndpoint = NULL;
 
     ca_mutex_lock(g_bleClientReceiveDataMutex);
 
@@ -1219,11 +1213,9 @@ void CABLEClientDataReceiverHandler(void *threadData)
                 return;
             }
 
-            remoteAddress = bleData->remoteEndpoint->addressInfo.LE.leMacAddress;
-            serviceUUID = bleData->remoteEndpoint->resourceUri;
+            remoteAddress = bleData->remoteEndpoint->addr;
 
-            remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_LE, remoteAddress,
-                                                           serviceUUID);
+            remoteEndpoint = CAAdapterCreateEndpoint(0, CA_ADAPTER_GATT_BTLE, remoteAddress, 0);
 
             memcpy(defragData, bleData->data + CA_HEADER_LENGTH,
                    bleData->dataLen - CA_HEADER_LENGTH);
@@ -1261,7 +1253,7 @@ void CABLEClientDataReceiverHandler(void *threadData)
         {
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "GATTClient is terminating. Cleaning up");
             OICFree(defragData);
-            CAAdapterFreeRemoteEndpoint(remoteEndpoint);
+            CAAdapterFreeEndpoint(remoteEndpoint);
             ca_mutex_unlock(g_bleClientReceiveDataMutex);
             return;
         }
@@ -1327,7 +1319,7 @@ void CABLEServerSendDataThread(void *threadData)
     {
         OIC_LOG(DEBUG, CALEADAPTER_TAG, "Server Sending Unicast Data");
         result = CAUpdateCharacteristicsToGattClient(
-                    bleData->remoteEndpoint->addressInfo.LE.leMacAddress, dataSegment, length);
+                    bleData->remoteEndpoint->addr, dataSegment, length);
         if (CA_STATUS_OK != result)
         {
             OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]", result);
@@ -1341,7 +1333,7 @@ void CABLEServerSendDataThread(void *threadData)
             // Send the remaining header.
             OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Sending the chunk number [%d]", index);
             result = CAUpdateCharacteristicsToGattClient(
-                         bleData->remoteEndpoint->addressInfo.LE.leMacAddress,
+                         bleData->remoteEndpoint->addr,
                          bleData->data + ((index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH),
                          CA_SUPPORTED_BLE_MTU_SIZE);
             if (CA_STATUS_OK != result)
@@ -1361,7 +1353,7 @@ void CABLEServerSendDataThread(void *threadData)
             // send the last segment of the data (Ex: 22 bytes of 622 bytes of data when MTU is 200)
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
             result = CAUpdateCharacteristicsToGattClient(
-                         bleData->remoteEndpoint->addressInfo.LE.leMacAddress,
+                         bleData->remoteEndpoint->addr,
                          bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
                          remainingLen);
             if (CA_STATUS_OK != result)
@@ -1479,7 +1471,7 @@ void CABLEClientSendDataThread(void *threadData)
     {
         OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending Unicast Data");
         // Send the first segment with the header.
-        result = CAUpdateCharacteristicsToGattServer(bleData->remoteEndpoint->addressInfo.LE.leMacAddress,
+        result = CAUpdateCharacteristicsToGattServer(bleData->remoteEndpoint->addr,
                  dataSegment,
                  length,
                  LE_UNICAST, 0);
@@ -1496,7 +1488,7 @@ void CABLEClientSendDataThread(void *threadData)
         {
             // Send the remaining header.
             result = CAUpdateCharacteristicsToGattServer(
-                     bleData->remoteEndpoint->addressInfo.LE.leMacAddress,
+                     bleData->remoteEndpoint->addr,
                      bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
                      CA_SUPPORTED_BLE_MTU_SIZE,
                      LE_UNICAST, 0);
@@ -1517,7 +1509,7 @@ void CABLEClientSendDataThread(void *threadData)
             // send the last segment of the data (Ex: 22 bytes of 622 bytes of data when MTU is 200)
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
             result = CAUpdateCharacteristicsToGattServer(
-                     bleData->remoteEndpoint->addressInfo.LE.leMacAddress,
+                     bleData->remoteEndpoint->addr,
                      bleData->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
                      remainingLen,
                      LE_UNICAST, 0);
@@ -1584,7 +1576,7 @@ void CABLEClientSendDataThread(void *threadData)
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT - CABLEClientSendDataThread");
 }
 
-CALEData_t *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
+CALEData_t *CACreateBLEData(const CAEndpoint_t *remoteEndpoint, const void *data,
                            uint32_t dataLength)
 {
     CALEData_t *bleData = (CALEData_t *) OICMalloc(sizeof(CALEData_t));
@@ -1594,7 +1586,7 @@ CALEData_t *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, const void
         return NULL;
     }
 
-    bleData->remoteEndpoint = CAAdapterCopyRemoteEndpoint(remoteEndpoint);
+    bleData->remoteEndpoint = CAAdapterCloneEndpoint(remoteEndpoint);
     bleData->data = (void *)OICCalloc(dataLength + 1, 1);
     if (NULL == bleData->data)
     {
@@ -1612,7 +1604,7 @@ void CAFreeBLEData(CALEData_t *bleData)
 {
     VERIFY_NON_NULL_VOID(bleData, NULL, "Param bleData is NULL");
 
-    CAAdapterFreeRemoteEndpoint(bleData->remoteEndpoint);
+    CAAdapterFreeEndpoint(bleData->remoteEndpoint);
     OICFree(bleData->data);
     OICFree(bleData);
 }
@@ -1625,7 +1617,7 @@ void CALEDataDestroyer(void *data, uint32_t size)
 }
 
 
-CAResult_t CABLEClientSendData(const CARemoteEndpoint_t *remoteEndpoint,
+CAResult_t CABLEClientSendData(const CAEndpoint_t *remoteEndpoint,
                                const void *data,
                                uint32_t dataLen)
 {
@@ -1661,7 +1653,7 @@ CAResult_t CABLEClientSendData(const CARemoteEndpoint_t *remoteEndpoint,
 }
 
 
-CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint,
+CAResult_t CABLEServerSendData(const CAEndpoint_t *remoteEndpoint,
                                const void *data,
                                uint32_t dataLen)
 {
@@ -1709,8 +1701,7 @@ CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *servic
                         CA_STATUS_FAILED);
 
     //Add message to data queue
-    CARemoteEndpoint_t *remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_LE, remoteAddress,
-                                         serviceUUID);
+    CAEndpoint_t *remoteEndpoint = CAAdapterCreateEndpoint(0, CA_ADAPTER_GATT_BTLE, remoteAddress, 0);
     if (NULL == remoteEndpoint)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create remote endpoint !");
@@ -1724,11 +1715,11 @@ CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *servic
     if (!bleData)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
-        CAAdapterFreeRemoteEndpoint(remoteEndpoint);
+        CAAdapterFreeEndpoint(remoteEndpoint);
         return CA_MEMORY_ALLOC_FAILED;
     }
 
-    CAAdapterFreeRemoteEndpoint(remoteEndpoint);
+    CAAdapterFreeEndpoint(remoteEndpoint);
     // Add message to send queue
     CAQueueingThreadAddData(g_bleServerReceiverQueue, bleData, sizeof(CALEData_t));
 
@@ -1751,8 +1742,7 @@ CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *servic
                         CA_STATUS_FAILED);
 
     //Add message to data queue
-    CARemoteEndpoint_t *remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_LE, remoteAddress,
-                                         serviceUUID);
+    CAEndpoint_t *remoteEndpoint = CAAdapterCreateEndpoint(0, CA_ADAPTER_GATT_BTLE, remoteAddress, 0);
     if (NULL == remoteEndpoint)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create remote endpoint !");
@@ -1766,11 +1756,11 @@ CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *servic
     if (!bleData)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create bledata!");
-        CAAdapterFreeRemoteEndpoint(remoteEndpoint);
+        CAAdapterFreeEndpoint(remoteEndpoint);
         return CA_MEMORY_ALLOC_FAILED;
     }
 
-    CAAdapterFreeRemoteEndpoint(remoteEndpoint);
+    CAAdapterFreeEndpoint(remoteEndpoint);
     // Add message to send queue
     CAQueueingThreadAddData(g_bleClientReceiverQueue, bleData, sizeof(CALEData_t));
 
index f4b4df2..8bfb50b 100644 (file)
@@ -52,7 +52,7 @@ CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
     handler.stopAdapter = CAStopLE;
     handler.terminate = CATerminateLE;
 
-    registerCallback(handler, CA_LE);
+    registerCallback(handler, CA_ADAPTER_GATT_BTLE);
 
     return CA_STATUS_OK;
 }
@@ -78,21 +78,21 @@ CAResult_t CAStartLEDiscoveryServer()
     return CA_STATUS_OK;
 }
 
-int32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t dataLen)
+int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
 {
     OIC_LOG(DEBUG, TAG, "CASendLEUnicastData");
 
     return -1;
 }
 
-int32_t CASendLEMulticastData(const void *data, uint32_t dataLen)
+int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
 {
     OIC_LOG(DEBUG, TAG, "CASendLEMulticastData");
 
     return -1;
 }
 
-CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size)
+CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
 {
     OIC_LOG(DEBUG, TAG, "CAGetLEInterfaceInformation");
 
index c5dd281..93d6cd7 100644 (file)
@@ -34,6 +34,8 @@
 #include "caadapternetdtls.h"
 #endif
 
+CAGlobals_t caglobals;
+
 #define TAG PCF("CA")
 
 static bool g_isInitialized = false;
@@ -113,8 +115,7 @@ void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHand
 }
 
 #ifdef __WITH_DTLS__
-CAResult_t CARegisterDTLSCredentialsHandler(
-                                             CAGetDTLSCredentialsHandler GetDTLSCredentialsHandler)
+CAResult_t CARegisterDTLSCredentialsHandler(CAGetDTLSCredentialsHandler GetDTLSCredentialsHandler)
 {
     OIC_LOG(DEBUG, TAG, "CARegisterDTLSCredentialsHandler");
 
@@ -128,33 +129,11 @@ CAResult_t CARegisterDTLSCredentialsHandler(
 }
 #endif //__WITH_DTLS__
 
-CAResult_t CACreateRemoteEndpoint(const CAURI_t uri, const CATransportType_t transportType,
-                                  CARemoteEndpoint_t **remoteEndpoint)
+void CADestroyEndpoint(CAEndpoint_t *rep)
 {
-    OIC_LOG(DEBUG, TAG, "CACreateRemoteEndpoint");
-
-    if(!g_isInitialized)
-    {
-        return CA_STATUS_NOT_INITIALIZED;
-    }
-
-    CARemoteEndpoint_t *remote = CACreateRemoteEndpointUriInternal(uri, transportType);
-
-    if (remote == NULL)
-    {
-        OIC_LOG(DEBUG, TAG, "remote is NULL!");
-        return CA_STATUS_FAILED;
-    }
-
-    *remoteEndpoint = remote;
-
-    return CA_STATUS_OK;
-}
+    OIC_LOG(DEBUG, TAG, "CADestroyEndpoint");
 
-void CADestroyRemoteEndpoint(CARemoteEndpoint_t *rep)
-{
-    OIC_LOG(DEBUG, TAG, "CADestroyRemoteEndpoint");
-    CADestroyRemoteEndpointInternal(rep);
+    CADestroyEndpointInternal(rep);
 }
 
 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength)
@@ -174,7 +153,7 @@ void CADestroyToken(CAToken_t token)
     CADestroyTokenInternal(token);
 }
 
-CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size)
+CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size)
 {
     OIC_LOG(DEBUG, TAG, "CAGetNetworkInformation");
 
@@ -186,19 +165,7 @@ CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size)
     return CAGetNetworkInformationInternal(info, size);
 }
 
-CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token, uint8_t tokenLength)
-{
-    OIC_LOG(DEBUG, TAG, "CAFindResource");
-
-    if(!g_isInitialized)
-    {
-        return CA_STATUS_NOT_INITIALIZED;
-    }
-    return CADetachMessageResourceUri(resourceUri, token, tokenLength, NULL, 0);
-
-}
-
-CAResult_t CASendRequest(const CARemoteEndpoint_t *object,const CARequestInfo_t *requestInfo)
+CAResult_t CASendRequest(const CAEndpoint_t *object,const CARequestInfo_t *requestInfo)
 {
     OIC_LOG(DEBUG, TAG, "CASendGetRequest");
 
@@ -210,21 +177,7 @@ CAResult_t CASendRequest(const CARemoteEndpoint_t *object,const CARequestInfo_t
     return CADetachRequestMessage(object, requestInfo);
 }
 
-CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
-                              const CARequestInfo_t *requestInfo)
-{
-    OIC_LOG(DEBUG, TAG, "CASendRequestToAll");
-
-    if(!g_isInitialized)
-    {
-        return CA_STATUS_NOT_INITIALIZED;
-    }
-
-    return CADetachRequestToAllMessage(object, requestInfo);
-}
-
-CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
-    const CAResponseInfo_t *responseInfo)
+CAResult_t CASendNotification(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo)
 {
     OIC_LOG(DEBUG, TAG, "CASendNotification");
 
@@ -237,8 +190,7 @@ CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
 
 }
 
-CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
-    const CAResponseInfo_t *responseInfo)
+CAResult_t CASendResponse(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo)
 {
     OIC_LOG(DEBUG, TAG, "CASendResponse");
 
@@ -251,20 +203,6 @@ CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
 
 }
 
-CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
-                               uint8_t tokenLength, const CAHeaderOption_t *options,
-                               const uint8_t numOptions)
-{
-    OIC_LOG(DEBUG, TAG, "CAAdvertiseResource");
-
-    if(!g_isInitialized)
-    {
-        return CA_STATUS_NOT_INITIALIZED;
-    }
-    return CADetachMessageResourceUri(resourceUri, token, tokenLength, options, numOptions);
-
-}
-
 CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
 {
     OIC_LOG_V(DEBUG, TAG, "Selected network : %d", interestedNetwork);
@@ -274,29 +212,26 @@ CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
         return CA_STATUS_NOT_INITIALIZED;
     }
 
-    if (!(interestedNetwork & 0xf))
-    {
-        return CA_NOT_SUPPORTED;
-    }
-
     CAResult_t res = CA_STATUS_OK;
 
-    if (interestedNetwork & CA_IPV4)
+    if (interestedNetwork & CA_ADAPTER_IP)
     {
-        res = CAAddNetworkType(CA_IPV4);
-        OIC_LOG_V(ERROR, TAG, "CAAddNetworkType(CA_IPV4) function returns error : %d", res);
+        res = CAAddNetworkType(CA_ADAPTER_IP);
+        OIC_LOG_V(ERROR, TAG, "CAAddNetworkType(CA_IP_ADAPTER) function returns error : %d", res);
     }
-
-    if (interestedNetwork & CA_EDR)
+    else if (interestedNetwork & CA_ADAPTER_RFCOMM_BTEDR)
     {
-        res = CAAddNetworkType(CA_EDR);
-        OIC_LOG_V(ERROR, TAG, "CAAddNetworkType(CA_EDR) function returns error : %d", res);
+        res = CAAddNetworkType(CA_ADAPTER_RFCOMM_BTEDR);
+        OIC_LOG_V(ERROR, TAG, "CAAddNetworkType(CA_RFCOMM_ADAPTER) function returns error : %d", res);
     }
-
-    if (interestedNetwork & CA_LE)
+    else if (interestedNetwork & CA_ADAPTER_GATT_BTLE)
+    {
+        res = CAAddNetworkType(CA_ADAPTER_GATT_BTLE);
+        OIC_LOG_V(ERROR, TAG, "CAAddNetworkType(CA_GATT_ADAPTER) function returns error : %d", res);
+    }
+    else
     {
-        res = CAAddNetworkType(CA_LE);
-        OIC_LOG_V(ERROR, TAG, "CAAddNetworkType(CA_LE) function returns error : %d", res);
+        res = CA_NOT_SUPPORTED;
     }
 
     return res;
@@ -311,29 +246,26 @@ CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
         return CA_STATUS_NOT_INITIALIZED;
     }
 
-    if (!(nonInterestedNetwork & 0xf))
-    {
-        return CA_NOT_SUPPORTED;
-    }
-
     CAResult_t res = CA_STATUS_OK;
 
-    if (nonInterestedNetwork & CA_IPV4)
+    if (nonInterestedNetwork & CA_ADAPTER_IP)
     {
-        res = CARemoveNetworkType(CA_IPV4);
-        OIC_LOG_V(ERROR, TAG, "CARemoveNetworkType(CA_IPV4) function returns error : %d", res);
+        res = CARemoveNetworkType(CA_ADAPTER_IP);
+        OIC_LOG_V(ERROR, TAG, "CARemoveNetworkType(CA_IP_ADAPTER) function returns error : %d", res);
     }
-
-    if (nonInterestedNetwork & CA_EDR)
+    else if (nonInterestedNetwork & CA_ADAPTER_RFCOMM_BTEDR)
     {
-        res = CARemoveNetworkType(CA_EDR);
-        OIC_LOG_V(ERROR, TAG, "CARemoveNetworkType(CA_EDR) function returns error : %d", res);
+        res = CARemoveNetworkType(CA_ADAPTER_RFCOMM_BTEDR);
+        OIC_LOG_V(ERROR, TAG, "CARemoveNetworkType(CA_RFCOMM_ADAPTER) function returns error : %d", res);
     }
-
-    if (nonInterestedNetwork & CA_LE)
+    else if (nonInterestedNetwork & CA_ADAPTER_GATT_BTLE)
+    {
+        res = CARemoveNetworkType(CA_ADAPTER_GATT_BTLE);
+        OIC_LOG_V(ERROR, TAG, "CARemoveNetworkType(CA_GATT_ADAPTER) function returns error : %d", res);
+    }
+    else
     {
-        res = CARemoveNetworkType(CA_LE);
-        OIC_LOG_V(ERROR, TAG, "CARemoveNetworkType(CA_LE) function returns error : %d", res);
+        res = CA_STATUS_FAILED;
     }
 
     return res;
@@ -370,8 +302,7 @@ CAResult_t CAEnableAnonECDHCipherSuite(const bool enable)
     return CADtlsEnableAnonECDHCipherSuite(enable);
 }
 
-CAResult_t CAGenerateOwnerPSK(const CAAddress_t* addrInfo,
-                    const CATransportType_t transportType,
+CAResult_t CAGenerateOwnerPSK(const CAEndpoint_t* endpoint,
                     const uint8_t* label, const size_t labelLen,
                     const uint8_t* rsrcServerDeviceID, const size_t rsrcServerDeviceIDLen,
                     const uint8_t* provServerDeviceID, const size_t provServerDeviceIDLen,
@@ -382,16 +313,16 @@ CAResult_t CAGenerateOwnerPSK(const CAAddress_t* addrInfo,
     CAResult_t res = CA_STATUS_OK;
 
     //newOwnerLabel and prevOwnerLabe can be NULL
-    if(!addrInfo || !label || 0 == labelLen || !ownerPSK || 0 == ownerPSKSize)
+    if (!endpoint || !label || 0 == labelLen || !ownerPSK || 0 == ownerPSKSize)
     {
         return CA_STATUS_INVALID_PARAM;
     }
 
-    res = CADtlsGenerateOwnerPSK(addrInfo, transportType, label, labelLen,
+    res = CADtlsGenerateOwnerPSK(endpoint, label, labelLen,
                                   rsrcServerDeviceID, rsrcServerDeviceIDLen,
                                   provServerDeviceID, provServerDeviceIDLen,
                                   ownerPSK, ownerPSKSize);
-    if(CA_STATUS_OK != res)
+    if (CA_STATUS_OK != res)
     {
         OIC_LOG_V(ERROR, TAG, "Failed to CAGenerateOwnerPSK : %d", res);
     }
@@ -401,19 +332,18 @@ CAResult_t CAGenerateOwnerPSK(const CAAddress_t* addrInfo,
     return res;
 }
 
-CAResult_t CAInitiateHandshake(const CAAddress_t* addrInfo,
-                               const CATransportType_t transportType)
+CAResult_t CAInitiateHandshake(const CAEndpoint_t *endpoint)
 {
     OIC_LOG_V(DEBUG, TAG, "IN : CAInitiateHandshake");
     CAResult_t res = CA_STATUS_OK;
 
-    if(!addrInfo)
+    if (!endpoint)
     {
         return CA_STATUS_INVALID_PARAM;
     }
 
-    res = CADtlsInitiateHandshake(addrInfo, transportType);
-    if(CA_STATUS_OK != res)
+    res = CADtlsInitiateHandshake(endpoint);
+    if (CA_STATUS_OK != res)
     {
         OIC_LOG_V(ERROR, TAG, "Failed to CADtlsInitiateHandshake : %d", res);
     }
@@ -423,19 +353,18 @@ CAResult_t CAInitiateHandshake(const CAAddress_t* addrInfo,
     return res;
 }
 
-CAResult_t CACloseDtlsSession(const CAAddress_t* addrInfo,
-                              const CATransportType_t transportType)
+CAResult_t CACloseDtlsSession(const CAEndpoint_t *endpoint)
 {
     OIC_LOG_V(DEBUG, TAG, "IN : CACloseDtlsSession");
     CAResult_t res = CA_STATUS_OK;
 
-    if(!addrInfo)
+    if (!endpoint)
     {
         return CA_STATUS_INVALID_PARAM;
     }
 
-    res = CADtlsClose(addrInfo, transportType);
-    if(CA_STATUS_OK != res)
+    res = CADtlsClose(endpoint);
+    if (CA_STATUS_OK != res)
     {
         OIC_LOG_V(ERROR, TAG, "Failed to CADtlsClose : %d", res);
     }
index bf3e064..91ced23 100644 (file)
@@ -34,6 +34,8 @@
 
 #define TAG "CM_ST"
 
+CAGlobals_t caglobals;
+
 static bool g_isInitialized = false;
 
 CAResult_t CAInitialize()
@@ -106,34 +108,9 @@ void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHand
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-CAResult_t CACreateRemoteEndpoint(const CAURI_t uri, const CATransportType_t transportType,
-                                  CARemoteEndpoint_t **remoteEndpoint)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-
-    if (!g_isInitialized)
-    {
-        OIC_LOG(ERROR, TAG, "not initialized");
-        return CA_STATUS_NOT_INITIALIZED;
-    }
-
-    CARemoteEndpoint_t *remote = CACreateRemoteEndpointUriInternal(uri, transportType);
-
-    if (remote == NULL)
-    {
-        OIC_LOG(ERROR, TAG, "remote endpoint is NULL");
-        return CA_STATUS_FAILED;
-    }
-
-    *remoteEndpoint = remote;
-
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-void CADestroyRemoteEndpoint(CARemoteEndpoint_t *rep)
+void CADestroyEndpoint(CAEndpoint_t *rep)
 {
-    CADestroyRemoteEndpointInternal(rep);
+    CADestroyEndpointInternal(rep);
 }
 
 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength)
@@ -155,7 +132,7 @@ void CADestroyToken(CAToken_t token)
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size)
+CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size)
 {
     if (!g_isInitialized)
     {
@@ -166,80 +143,29 @@ CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size)
     return CAGetNetworkInformationInternal(info, size);
 }
 
-CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token, uint8_t tokenLength)
+CAResult_t CASendRequest(const CAEndpoint_t *object,const CARequestInfo_t *requestInfo)
 {
-    OIC_LOG(DEBUG, TAG, "IN");
-
-    if (!g_isInitialized)
-    {
-        OIC_LOG(ERROR, TAG, "not initialized");
-        return CA_STATUS_NOT_INITIALIZED;
-    }
-
-    return CADetachMessageResourceUri(resourceUri, token, tokenLength, NULL, 0);
-}
-
-CAResult_t CASendRequest(const CARemoteEndpoint_t *object,const CARequestInfo_t *requestInfo)
-{
-    if (!g_isInitialized)
-    {
-        OIC_LOG(ERROR, TAG, "not initialized");
-        return CA_STATUS_NOT_INITIALIZED;
-    }
+    OIC_LOG(DEBUG, TAG, "CASendGetRequest");
 
     return CADetachRequestMessage(object, requestInfo);
 }
 
-CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
-                              const CARequestInfo_t *requestInfo)
-{
-    OIC_LOG(DEBUG, TAG, "CASendRequestToAll");
-
-    if (!g_isInitialized)
-    {
-        OIC_LOG(ERROR, TAG, "not initialized");
-        return CA_STATUS_NOT_INITIALIZED;
-    }
-
-    return CADetachRequestToAllMessage(object, requestInfo);
-}
-
-CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
+CAResult_t CASendNotification(const CAEndpoint_t *object,
     const CAResponseInfo_t *responseInfo)
 {
-    if (!g_isInitialized)
-    {
-        OIC_LOG(ERROR, TAG, "not initialized");
-        return CA_STATUS_NOT_INITIALIZED;
-    }
+    OIC_LOG(DEBUG, TAG, "CASendNotification");
 
     return CADetachResponseMessage(object, responseInfo);
 }
 
-CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
+CAResult_t CASendResponse(const CAEndpoint_t *object,
     const CAResponseInfo_t *responseInfo)
 {
-    if (!g_isInitialized)
-    {
-        OIC_LOG(ERROR, TAG, "not initialized");
-        return CA_STATUS_NOT_INITIALIZED;
-    }
+    OIC_LOG(DEBUG, TAG, "CASendResponse");
 
     return CADetachResponseMessage(object, responseInfo);
 }
 
-CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
-                               uint8_t tokenLength, const CAHeaderOption_t *options,
-                               const uint8_t numOptions)
-{
-    if (!g_isInitialized)
-    {
-        OIC_LOG(ERROR, TAG, "not initialized");
-        return CA_STATUS_NOT_INITIALIZED;
-    }
-    return CADetachMessageResourceUri(resourceUri, token, tokenLength, options, numOptions);
-}
-
 CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
 {
     OIC_LOG_V(DEBUG, TAG, "Selected n/W=%d", interestedNetwork);
@@ -257,9 +183,9 @@ CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
     }
     CAResult_t res = CA_STATUS_OK;
 
-    if (interestedNetwork & CA_IPV4)
+    if (interestedNetwork & CA_ADAPTER_IP)
     {
-        res = CAAddNetworkType(CA_IPV4);
+        res = CAAddNetworkType(CA_ADAPTER_IP);
         if (res != CA_STATUS_OK)
         {
             OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
@@ -267,9 +193,9 @@ CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
         }
     }
 
-    if (interestedNetwork & CA_EDR)
+    if (interestedNetwork & CA_ADAPTER_RFCOMM_BTEDR)
     {
-        res = CAAddNetworkType(CA_EDR);
+        res = CAAddNetworkType(CA_ADAPTER_RFCOMM_BTEDR);
         if (res != CA_STATUS_OK)
         {
             OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
@@ -277,9 +203,9 @@ CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
         }
     }
 
-    if (interestedNetwork & CA_LE)
+    if (interestedNetwork & CA_ADAPTER_GATT_BTLE)
     {
-        res = CAAddNetworkType(CA_LE);
+        res = CAAddNetworkType(CA_ADAPTER_GATT_BTLE);
         if (res != CA_STATUS_OK)
         {
             OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
@@ -308,9 +234,9 @@ CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
 
     CAResult_t res = CA_STATUS_OK;
 
-    if (nonInterestedNetwork & CA_IPV4)
+    if (nonInterestedNetwork & CA_ADAPTER_IP)
     {
-        res = CARemoveNetworkType(CA_IPV4);
+        res = CARemoveNetworkType(CA_ADAPTER_IP);
         if (res != CA_STATUS_OK)
         {
             OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
@@ -318,9 +244,9 @@ CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
         }
     }
 
-    if (nonInterestedNetwork & CA_EDR)
+    if (nonInterestedNetwork & CA_ADAPTER_RFCOMM_BTEDR)
     {
-        res = CARemoveNetworkType(CA_EDR);
+        res = CARemoveNetworkType(CA_ADAPTER_RFCOMM_BTEDR);
         if (res != CA_STATUS_OK)
         {
             OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
@@ -328,9 +254,9 @@ CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
         }
     }
 
-    if (nonInterestedNetwork & CA_LE)
+    if (nonInterestedNetwork & CA_ADAPTER_GATT_BTLE)
     {
-        res = CARemoveNetworkType(CA_LE);
+        res = CARemoveNetworkType(CA_ADAPTER_GATT_BTLE);
         if (res != CA_STATUS_OK)
         {
             OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
index 4f0dd5d..9cf61ae 100644 (file)
@@ -38,7 +38,7 @@
 #define CA_MEMORY_ALLOC_CHECK(arg) {if (arg == NULL) \
     {OIC_LOG(ERROR, TAG, "memory error");goto memory_error_exit;} }
 
-#define CA_TRANSPORT_TYPE_NUM   4
+#define CA_TRANSPORT_TYPE_NUM   3
 
 static CAConnectivityHandler_t g_adapterHandler[CA_TRANSPORT_TYPE_NUM] = {};
 
@@ -48,26 +48,26 @@ static CANetworkChangeCallback g_networkChangeCallback = NULL;
 
 static CAErrorHandleCallback g_errorHandleCallback = NULL;
 
-static int CAGetAdapterIndex(CATransportType_t cType)
+static int CAGetAdapterIndex(CATransportAdapter_t cType)
 {
     switch (cType)
     {
-        case CA_IPV4:
+        case CA_ADAPTER_IP:
             return 0;
-        case CA_IPV6:
+        case CA_ADAPTER_RFCOMM_BTEDR:
             return 1;
-        case CA_EDR:
+        case CA_ADAPTER_GATT_BTLE:
             return 2;
-        case CA_LE:
-            return 3;
+        default:
+            break;
     }
 
-    OIC_LOG(DEBUG, TAG, "CA_TRANSPORT_TYPE_NUM is not 4");
+    OIC_LOG(DEBUG, TAG, "CA_TRANSPORT_TYPE_NUM is not 3");
 
     return -1;
 }
 
-static void CARegisterCallback(CAConnectivityHandler_t handler, CATransportType_t cType)
+static void CARegisterCallback(CAConnectivityHandler_t handler, CATransportAdapter_t cType)
 {
     OIC_LOG(DEBUG, TAG, "CARegisterCallback - Entry");
 
@@ -98,8 +98,7 @@ static void CARegisterCallback(CAConnectivityHandler_t handler, CATransportType_
     OIC_LOG_V(DEBUG, TAG, "%d type adapter, register complete!", cType);
 }
 
-static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data,
-                                     uint32_t dataLen)
+static void CAReceivedPacketCallback(const CAEndpoint_t *endpoint, void *data, uint32_t dataLen)
 {
     OIC_LOG(DEBUG, TAG, "receivedPacketCallback in interface controller");
 
@@ -110,17 +109,13 @@ static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data,
     }
     else
     {
-        OICFree(endpoint);
-        endpoint = NULL;
         OICFree(data);
-        data = NULL;
 
         OIC_LOG(ERROR, TAG, "network packet received callback is NULL!");
     }
 }
 
-static void CANetworkChangedCallback(CALocalConnectivity_t *info,
-                                     CANetworkStatus_t status)
+static void CANetworkChangedCallback(const CAEndpoint_t *info, CANetworkStatus_t status)
 {
     OIC_LOG(DEBUG, TAG, "Network Changed callback");
 
@@ -131,8 +126,9 @@ static void CANetworkChangedCallback(CALocalConnectivity_t *info,
     }
 }
 
-static void CAAdapterErrorHandleCallback(const CARemoteEndpoint_t *endpoint, const void *data,
-                                         uint32_t dataLen, CAResult_t result)
+static void CAAdapterErrorHandleCallback(const CAEndpoint_t *endpoint,
+                                         const void *data, uint32_t dataLen,
+                                         CAResult_t result)
 {
     OIC_LOG(DEBUG, TAG, "received error from adapter in interfacecontroller");
 
@@ -151,18 +147,15 @@ void CAInitializeAdapters(ca_thread_pool_t handle)
 
     // Initialize adapters and register callback.
 #ifdef IP_ADAPTER
-    CAInitializeIP(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
-                         handle);
+    CAInitializeIP(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback, handle);
 #endif /* IP_ADAPTER */
 
 #ifdef EDR_ADAPTER
-    CAInitializeEDR(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
-                    handle);
+    CAInitializeEDR(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback, handle);
 #endif /* EDR_ADAPTER */
 
 #ifdef LE_ADAPTER
-    CAInitializeLE(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
-                   handle);
+    CAInitializeLE(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback, handle);
 #endif /* LE_ADAPTER */
 
 }
@@ -187,7 +180,7 @@ void CASetErrorHandleCallback(CAErrorHandleCallback errorCallback)
     g_errorHandleCallback = errorCallback;
 }
 
-CAResult_t CAStartAdapter(CATransportType_t transportType)
+CAResult_t CAStartAdapter(CATransportAdapter_t transportType)
 {
     OIC_LOG_V(DEBUG, TAG, "Start the adapter of CAConnectivityType[%d]", transportType);
 
@@ -207,7 +200,7 @@ CAResult_t CAStartAdapter(CATransportType_t transportType)
     return CA_STATUS_OK;
 }
 
-void CAStopAdapter(CATransportType_t transportType)
+void CAStopAdapter(CATransportAdapter_t transportType)
 {
     OIC_LOG_V(DEBUG, TAG, "Stop the adapter of CATransportType[%d]", transportType);
 
@@ -225,14 +218,14 @@ void CAStopAdapter(CATransportType_t transportType)
     }
 }
 
-CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size)
+CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size)
 {
     if (info == NULL || size == NULL)
     {
         return CA_STATUS_INVALID_PARAM;
     }
 
-    CALocalConnectivity_t *tempInfo[CA_TRANSPORT_TYPE_NUM] = { 0 };
+    CAEndpoint_t *tempInfo[CA_TRANSPORT_TYPE_NUM] = { 0 };
     uint32_t tempSize[CA_TRANSPORT_TYPE_NUM] = { 0 };
 
     CAResult_t res = CA_STATUS_FAILED;
@@ -273,9 +266,7 @@ CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size)
 
     // #3. add data into result
     // memory allocation
-
-    CALocalConnectivity_t *resInfo = (CALocalConnectivity_t *)
-                                     OICCalloc(resSize, sizeof(CALocalConnectivity_t));
+    CAEndpoint_t *resInfo = (CAEndpoint_t *) OICCalloc(resSize, sizeof (*resInfo));
     CA_MEMORY_ALLOC_CHECK(resInfo);
 
     // #4. save data
@@ -317,7 +308,7 @@ memory_error_exit:
     return CA_MEMORY_ALLOC_FAILED;
 }
 
-CAResult_t CASendUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t length)
+CAResult_t CASendUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length)
 {
     OIC_LOG(DEBUG, TAG, "Send unicast data to enabled interface..");
 
@@ -329,7 +320,7 @@ CAResult_t CASendUnicastData(const CARemoteEndpoint_t *endpoint, const void *dat
         return CA_STATUS_INVALID_PARAM;
     }
 
-    CATransportType_t type = endpoint->transportType;
+    CATransportAdapter_t type = endpoint->adapter;
 
     int index = CAGetAdapterIndex(type);
 
@@ -353,7 +344,7 @@ CAResult_t CASendUnicastData(const CARemoteEndpoint_t *endpoint, const void *dat
     return res;
 }
 
-CAResult_t CASendMulticastData(const void *data, uint32_t length)
+CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length)
 {
     OIC_LOG(DEBUG, TAG, "Send multicast data to enabled interface..");
 
@@ -376,7 +367,7 @@ CAResult_t CASendMulticastData(const void *data, uint32_t length)
             continue;
         }
 
-        CATransportType_t connType = *(CATransportType_t *) ptrType;
+        CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
 
         int index = CAGetAdapterIndex(connType);
 
@@ -397,7 +388,7 @@ CAResult_t CASendMulticastData(const void *data, uint32_t length)
                 return CA_MEMORY_ALLOC_FAILED;
             }
             memcpy(payload, data, length);
-            sentDataLen = g_adapterHandler[index].sendDataToAll(payload, length);
+            sentDataLen = g_adapterHandler[index].sendDataToAll(endpoint, payload, length);
             OICFree(payload);
         }
 
@@ -435,7 +426,7 @@ CAResult_t CAStartListeningServerAdapters()
             continue;
         }
 
-        CATransportType_t connType = *(CATransportType_t *) ptrType;
+        CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
 
         int index = CAGetAdapterIndex(connType);
         if (index == -1)
@@ -475,7 +466,7 @@ CAResult_t CAStartDiscoveryServerAdapters()
             continue;
         }
 
-        CATransportType_t connType = *(CATransportType_t *) ptrType;
+        CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
 
         int index = CAGetAdapterIndex(connType);
 
index a77afe3..3bbb240 100644 (file)
@@ -49,18 +49,16 @@ static CANetworkChangeCallback g_networkChangeCallback = NULL;
 
 static CAErrorHandleCallback g_errorHandleCallback = NULL;
 
-static int CAGetAdapterIndex(CATransportType_t cType)
+static int CAGetAdapterIndex(CATransportAdapter_t cType)
 {
     switch (cType)
     {
-        case CA_IPV4:
+        case CA_ADAPTER_IP:
             return 0;
-        case CA_IPV6:
+        case CA_ADAPTER_RFCOMM_BTEDR:
             return 1;
-        case CA_EDR:
+        case CA_ADAPTER_GATT_BTLE:
             return 2;
-        case CA_LE:
-            return 3;
     }
 
     OIC_LOG(DEBUG, TAG, "CA_CONNECTIVITY_TYPE_NUM is not 4");
@@ -68,7 +66,7 @@ static int CAGetAdapterIndex(CATransportType_t cType)
     return -1;
 }
 
-static void CARegisterCallback(CAConnectivityHandler_t handler, CATransportType_t cType)
+static void CARegisterCallback(CAConnectivityHandler_t handler, CATransportAdapter_t cType)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -100,7 +98,7 @@ static void CARegisterCallback(CAConnectivityHandler_t handler, CATransportType_
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data,
+static void CAReceivedPacketCallback(CAEndpoint_t *endpoint, void *data,
     uint32_t dataLen)
 {
     OIC_LOG(DEBUG, TAG, "IN");
@@ -119,7 +117,7 @@ void CASetErrorHandleCallback(CAErrorHandleCallback errorCallback)
     g_errorHandleCallback = errorCallback;
 }
 
-static void CANetworkChangedCallback(CALocalConnectivity_t *info, CANetworkStatus_t status)
+static void CANetworkChangedCallback(CAEndpoint_t *info, CANetworkStatus_t status)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -169,7 +167,7 @@ void CASetNetworkChangeCallback(CANetworkChangeCallback callback)
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-CAResult_t CAStartAdapter(CATransportType_t transportType)
+CAResult_t CAStartAdapter(CATransportAdapter_t transportType)
 {
     OIC_LOG_V(DEBUG, TAG, "transportType[%d]", transportType);
 
@@ -189,7 +187,7 @@ CAResult_t CAStartAdapter(CATransportType_t transportType)
     return CA_STATUS_OK;
 }
 
-void CAStopAdapter(CATransportType_t transportType)
+void CAStopAdapter(CATransportAdapter_t transportType)
 {
     OIC_LOG_V(DEBUG, TAG, "transportType[%d]", transportType);
 
@@ -208,13 +206,13 @@ void CAStopAdapter(CATransportType_t transportType)
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size)
+CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size)
 {
     OIC_LOG(DEBUG, TAG, "IN");
     VERIFY_NON_NULL(info, TAG, "info");
     VERIFY_NON_NULL(size, TAG, "size");
 
-    CALocalConnectivity_t *tempInfo[CA_CONNECTIVITY_TYPE_NUM] = { 0 };
+    CAEndpoint_t *tempInfo[CA_CONNECTIVITY_TYPE_NUM] = { 0 };
     uint32_t tempSize[CA_CONNECTIVITY_TYPE_NUM] = { 0 };
 
     CAResult_t res = CA_STATUS_FAILED;
@@ -255,8 +253,7 @@ CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size)
 
     // #3. add data into result
     // memory allocation
-    CALocalConnectivity_t *resInfo =
-        (CALocalConnectivity_t *) OICCalloc(resSize, sizeof(CALocalConnectivity_t));
+    CAEndpoint_t *resInfo = (CAEndpoint_t *)OICCalloc(resSize, sizeof(CAEndpoint_t));
     CA_MEMORY_ALLOC_CHECK(resInfo);
 
     uint8_t i = 0;
@@ -268,7 +265,7 @@ CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size)
             continue;
         }
 
-        memcpy(resInfo + i, tempInfo[index], sizeof(CALocalConnectivity_t) * tempSize[index]);
+        memcpy(resInfo + i, tempInfo[index], sizeof(CAEndpoint_t) * tempSize[index]);
 
         i += tempSize[index];
 
@@ -296,7 +293,7 @@ memory_error_exit:
     return CA_MEMORY_ALLOC_FAILED;
 }
 
-CAResult_t CASendUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t length)
+CAResult_t CASendUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -304,11 +301,11 @@ CAResult_t CASendUnicastData(const CARemoteEndpoint_t *endpoint, const void *dat
 
     if (endpoint == NULL)
     {
-        OIC_LOG(DEBUG, TAG, "RemoteEndpoint is NULL");
+        OIC_LOG(DEBUG, TAG, "Endpoint is NULL");
         return CA_STATUS_INVALID_PARAM;
     }
 
-    CATransportType_t type = endpoint->transportType;
+    CATransportAdapter_t type = endpoint->adapter;
 
     int index = CAGetAdapterIndex(type);
 
@@ -333,7 +330,7 @@ CAResult_t CASendUnicastData(const CARemoteEndpoint_t *endpoint, const void *dat
     return res;
 }
 
-CAResult_t CASendMulticastData(const void *data, uint32_t length)
+CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -354,7 +351,7 @@ CAResult_t CASendMulticastData(const void *data, uint32_t length)
             continue;
         }
 
-        CATransportType_t connType = *(CATransportType_t *) ptrType;
+        CATransportAdapter_t connType = *(CATransportAdapter_t *) ptrType;
 
         int index = CAGetAdapterIndex(connType);
 
@@ -367,7 +364,7 @@ CAResult_t CASendMulticastData(const void *data, uint32_t length)
         uint32_t sentDataLen = 0;
         if (g_adapterHandler[index].sendDataToAll != NULL)
         {
-            sentDataLen = g_adapterHandler[index].sendDataToAll(data, length);
+            sentDataLen = g_adapterHandler[index].sendDataToAll(endpoint, data, length);
         }
 
         if (sentDataLen == length)
@@ -400,7 +397,7 @@ CAResult_t CAStartListeningServerAdapters()
             continue;
         }
 
-        CATransportType_t connType = *(CATransportType_t *) ptrType;
+        CATransportAdapter_t connType = *(CATransportAdapter_t *) ptrType;
 
         int index = CAGetAdapterIndex(connType);
 
@@ -439,7 +436,7 @@ CAResult_t CAStartDiscoveryServerAdapters()
             continue;
         }
 
-        CATransportType_t connType = *(CATransportType_t *) ptrType;
+        CATransportAdapter_t connType = *(CATransportAdapter_t *) ptrType;
 
         int index = CAGetAdapterIndex(connType);
 
@@ -498,7 +495,7 @@ CAResult_t CAReadData()
             return CA_STATUS_FAILED;
         }
 
-        CATransportType_t connType = *(CATransportType_t *) ptrType;
+        CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
 
         int index = CAGetAdapterIndex(connType);
 
index b680b81..5fcbad3 100644 (file)
@@ -60,7 +60,7 @@ typedef enum
 typedef struct
 {
     CASendDataType_t type;
-    CARemoteEndpoint_t *remoteEndpoint;
+    CAEndpoint_t *remoteEndpoint;
     CARequestInfo_t *requestInfo;
     CAResponseInfo_t *responseInfo;
     CAErrorInfo_t *errorInfo;
@@ -83,8 +83,9 @@ static CARequestCallback g_requestHandler = NULL;
 static CAResponseCallback g_responseHandler = NULL;
 static CAErrorCallback g_errorHandler = NULL;
 
-static void CAErrorHandler(const CARemoteEndpoint_t *remoteEndpoint,
-                           const void *data, uint32_t dataLen, CAResult_t result);
+static void CAErrorHandler(const CAEndpoint_t *endpoint,
+                           const void *data, uint32_t dataLen,
+                           CAResult_t result);
 
 static bool CAIsSelectedNetworkAvailable()
 {
@@ -98,25 +99,25 @@ static bool CAIsSelectedNetworkAvailable()
     return true;
 }
 
-static void CATimeoutCallback(const CARemoteEndpoint_t *endpoint, const void *pdu, uint32_t size)
+static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uint32_t size)
 {
     OIC_LOG(DEBUG, TAG, "IN");
     VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint");
     VERIFY_NON_NULL_VOID(pdu, TAG, "pdu");
 
-    CARemoteEndpoint_t* ep = CACloneRemoteEndpoint(endpoint);
+    CAEndpoint_t* ep = CACloneEndpoint(endpoint);
     if (NULL == ep)
     {
         OIC_LOG(ERROR, TAG, "clone failed");
         return;
     }
 
-    CAResponseInfo_t* resInfo = (CAResponseInfo_t*) OICCalloc(1, sizeof(CAResponseInfo_t));
+    CAResponseInfo_t* resInfo = (CAResponseInfo_t*)OICCalloc(1, sizeof(CAResponseInfo_t));
 
     if (NULL == resInfo)
     {
         OIC_LOG(ERROR, TAG, "calloc failed");
-        CADestroyRemoteEndpointInternal(ep);
+        CAAdapterFreeEndpoint(ep);
         return;
     }
 
@@ -129,7 +130,7 @@ static void CATimeoutCallback(const CARemoteEndpoint_t *endpoint, const void *pd
         OIC_LOG(ERROR, TAG, "fail to get Token from retransmission list");
         OICFree(resInfo->info.token);
         OICFree(resInfo);
-        CADestroyRemoteEndpointInternal(ep);
+        CAAdapterFreeEndpoint(ep);
         return;
     }
 
@@ -137,7 +138,7 @@ static void CATimeoutCallback(const CARemoteEndpoint_t *endpoint, const void *pd
     if (NULL == cadata)
     {
         OIC_LOG(ERROR, TAG, "memory allocation failed !");
-        CADestroyRemoteEndpointInternal(ep);
+        CAAdapterFreeEndpoint(ep);
         OICFree(resInfo);
         return;
     }
@@ -164,7 +165,7 @@ static void CADataDestroyer(void *data, uint32_t size)
 
     if (NULL != cadata->remoteEndpoint)
     {
-        CADestroyRemoteEndpointInternal((CARemoteEndpoint_t *) cadata->remoteEndpoint);
+        CADestroyEndpointInternal(cadata->remoteEndpoint);
     }
 
     if (NULL != cadata->requestInfo)
@@ -208,7 +209,7 @@ static void CAReceiveThreadProcess(void *threadData)
     // parse the data and call the callbacks.
     // #1 parse the data
     // #2 get endpoint
-    CARemoteEndpoint_t *rep = (CARemoteEndpoint_t *)(data->remoteEndpoint);
+    CAEndpoint_t *rep = (CAEndpoint_t *)(data->remoteEndpoint);
 
     if (NULL == rep)
     {
@@ -245,25 +246,22 @@ static void CASendThreadProcess(void *threadData)
 
     CASendDataType_t type = data->type;
 
+    coap_pdu_t *pdu = NULL;
+
     if (SEND_TYPE_UNICAST == type)
     {
-        coap_pdu_t *pdu = NULL;
 
         if (NULL != data->requestInfo)
         {
             OIC_LOG(DEBUG, TAG, "requestInfo is available..");
 
-            pdu = (coap_pdu_t *) CAGeneratePDU(data->remoteEndpoint->resourceUri,
-                                               data->requestInfo->method,
-                                               data->requestInfo->info);
+            pdu = CAGeneratePDU(data->requestInfo->method, &data->requestInfo->info);
         }
         else if (NULL != data->responseInfo)
         {
             OIC_LOG(DEBUG, TAG, "responseInfo is available..");
 
-            pdu = (coap_pdu_t *) CAGeneratePDU(data->remoteEndpoint->resourceUri,
-                                               data->responseInfo->result,
-                                               data->responseInfo->info);
+            pdu = CAGeneratePDU(data->responseInfo->result, &data->responseInfo->info);
         }
         else
         {
@@ -300,20 +298,18 @@ static void CASendThreadProcess(void *threadData)
     {
         OIC_LOG(DEBUG, TAG, "both requestInfo & responseInfo is not available");
 
-        CAInfo_t info = data->requestInfo->info;
-
-        info.options = data->options;
-        info.numOptions = data->numOptions;
+        CAInfo_t *info = &data->requestInfo->info;
 
-        coap_pdu_t *pdu = (coap_pdu_t *) CAGeneratePDU(data->remoteEndpoint->resourceUri, CA_GET,
-                                                       info);
+        info->options = data->options;
+        info->numOptions = data->numOptions;
 
+        pdu = CAGeneratePDU(CA_GET, info);
         if (NULL != pdu)
         {
             CALogPDUInfo(pdu);
 
-            res = CASendMulticastData(pdu->hdr, pdu->length);
-            if(CA_STATUS_OK != res)
+            res = CASendMulticastData(data->remoteEndpoint, pdu->hdr, pdu->length);
+            if (CA_STATUS_OK != res)
             {
                 OIC_LOG_V(ERROR, TAG, "send failed:%d", res);
                 CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
@@ -328,7 +324,7 @@ static void CASendThreadProcess(void *threadData)
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, uint32_t dataLen)
+static void CAReceivedPacketCallback(const CAEndpoint_t *endpoint, void *data, uint32_t dataLen)
 {
     OIC_LOG(DEBUG, TAG, "IN");
     VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint");
@@ -341,12 +337,9 @@ static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, u
     if (NULL == pdu)
     {
         OIC_LOG(ERROR, TAG, "Parse PDU failed");
-        CAAdapterFreeRemoteEndpoint(endpoint);
         return;
     }
 
-    char uri[CA_MAX_URI_LENGTH] = { };
-
     if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
     {
         CARequestInfo_t *ReqInfo = (CARequestInfo_t *) OICCalloc(1, sizeof(CARequestInfo_t));
@@ -354,17 +347,15 @@ static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, u
         {
             OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, Memory allocation failed!");
             coap_delete_pdu(pdu);
-            CAAdapterFreeRemoteEndpoint(endpoint);
             return;
         }
 
-        CAResult_t res = CAGetRequestInfoFromPDU(pdu, ReqInfo, uri, sizeof(uri));
+        CAResult_t res = CAGetRequestInfoFromPDU(pdu, ReqInfo);
         if (CA_STATUS_OK != res)
         {
             OIC_LOG_V(ERROR, TAG, "CAGetRequestInfoFromPDU failed : %d", res);
             OICFree(ReqInfo);
             coap_delete_pdu(pdu);
-            CAAdapterFreeRemoteEndpoint(endpoint);
             return;
         }
 
@@ -395,35 +386,19 @@ static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, u
         OIC_LOG(DEBUG, TAG, "Request- token");
         OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *) ReqInfo->info.token, CA_MAX_TOKEN_LEN);
         OIC_LOG_V(DEBUG, TAG, "Request- msgID : %d", ReqInfo->info.messageId);
-        if (NULL != endpoint)
-        {
-            endpoint->resourceUri = (char *) OICMalloc(sizeof(uri) + 1);
-            if (NULL == endpoint->resourceUri)
-            {
-                OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, Memory allocation failed!");
-                OICFree(ReqInfo);
-                coap_delete_pdu(pdu);
-                CAAdapterFreeRemoteEndpoint(endpoint);
-                return;
-            }
-            memcpy(endpoint->resourceUri, uri, sizeof(uri));
-            endpoint->resourceUri[sizeof(uri)] = '\0';
-            OIC_LOG_V(DEBUG, TAG, "URI : %s", endpoint->resourceUri);
-        }
         // store the data at queue.
         CAData_t *cadata = NULL;
         cadata = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
         if (NULL == cadata)
         {
             OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
-            OICFree(ReqInfo);
+            CADestroyRequestInfoInternal(ReqInfo);
             coap_delete_pdu(pdu);
-            CAAdapterFreeRemoteEndpoint(endpoint);
             return;
         }
 
         cadata->type = SEND_TYPE_UNICAST;
-        cadata->remoteEndpoint = endpoint;
+        cadata->remoteEndpoint = CAAdapterCloneEndpoint(endpoint);
         cadata->requestInfo = ReqInfo;
         cadata->responseInfo = NULL;
         CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
@@ -435,17 +410,15 @@ static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, u
         {
             OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, Memory allocation failed!");
             coap_delete_pdu(pdu);
-            CAAdapterFreeRemoteEndpoint(endpoint);
             return;
         }
 
-        CAResult_t res = CAGetResponseInfoFromPDU(pdu, ResInfo, uri, sizeof(uri));
+        CAResult_t res = CAGetResponseInfoFromPDU(pdu, ResInfo);
         if (CA_STATUS_OK != res)
         {
             OIC_LOG_V(ERROR, TAG, "CAGetResponseInfoFromPDU failed : %d", res);
             OICFree(ResInfo);
             coap_delete_pdu(pdu);
-            CAAdapterFreeRemoteEndpoint(endpoint);
             return;
         }
 
@@ -468,35 +441,18 @@ static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, u
         OIC_LOG_V(DEBUG, TAG, "Response- token : %s", ResInfo->info.token);
         OIC_LOG_V(DEBUG, TAG, "Response- msgID: %d", ResInfo->info.messageId);
 
-        if (NULL != endpoint)
-        {
-            endpoint->resourceUri = (char *) OICMalloc(sizeof(uri) + 1);
-            if (NULL == endpoint->resourceUri)
-            {
-                OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
-                OICFree(ResInfo);
-                coap_delete_pdu(pdu);
-                CAAdapterFreeRemoteEndpoint(endpoint);
-                return;
-            }
-            memcpy(endpoint->resourceUri, uri, sizeof(uri));
-            endpoint->resourceUri[sizeof(uri)] = '\0';
-            OIC_LOG_V(DEBUG, TAG, "URI : %s", endpoint->resourceUri);
-        }
-
         // store the data at queue.
         CAData_t *cadata = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
         if (NULL == cadata)
         {
             OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
-            OICFree(ResInfo);
+            CADestroyResponseInfoInternal(ResInfo);
             coap_delete_pdu(pdu);
-            CAAdapterFreeRemoteEndpoint(endpoint);
             return;
         }
 
         cadata->type = SEND_TYPE_UNICAST;
-        cadata->remoteEndpoint = endpoint;
+        cadata->remoteEndpoint = CAAdapterCloneEndpoint(endpoint);
         cadata->requestInfo = NULL;
 
         // for retransmission
@@ -528,7 +484,7 @@ static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, u
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-static void CANetworkChangedCallback(CALocalConnectivity_t *info, CANetworkStatus_t status)
+static void CANetworkChangedCallback(const CAEndpoint_t *info, CANetworkStatus_t status)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -565,27 +521,21 @@ void CAHandleRequestResponseCallbacks()
 
     // get endpoint
     CAData_t *td = (CAData_t *) msg;
-    CARemoteEndpoint_t *rep = td->remoteEndpoint;
-
-    if (NULL == rep)
-    {
-        return;
-    }
 
     if (td->requestInfo && g_requestHandler)
     {
         OIC_LOG_V(DEBUG, TAG, "request callback : %d", td->requestInfo->info.numOptions);
-        g_requestHandler(rep, td->requestInfo);
+        g_requestHandler(td->remoteEndpoint, td->requestInfo);
     }
     else if (td->responseInfo && g_responseHandler)
     {
         OIC_LOG_V(DEBUG, TAG, "response callback : %d", td->responseInfo->info.numOptions);
-        g_responseHandler(rep, td->responseInfo);
+        g_responseHandler(td->remoteEndpoint, td->responseInfo);
     }
     else if (td->errorInfo && g_errorHandler)
     {
         OIC_LOG_V(DEBUG, TAG, "error callback error: %d", td->errorInfo->result);
-        g_errorHandler(rep, td->errorInfo);
+        g_errorHandler(td->remoteEndpoint, td->errorInfo);
     }
 
     CADataDestroyer(msg, sizeof(CAData_t));
@@ -594,7 +544,7 @@ void CAHandleRequestResponseCallbacks()
     OIC_LOG(DEBUG, TAG, "CAHandleRequestResponseCallbacks OUT");
 }
 
-CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *object, const CARequestInfo_t *request)
+CAResult_t CADetachRequestMessage(const CAEndpoint_t *object, const CARequestInfo_t *request)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -606,13 +556,13 @@ CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *object, const CARequ
         return CA_STATUS_FAILED;
     }
 
-    CARemoteEndpoint_t *remoteEndpoint = NULL;
+    CAEndpoint_t *remoteEndpoint = NULL;
     CARequestInfo_t *requestInfo = NULL;
     CAData_t *data = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
     CA_MEMORY_ALLOC_CHECK(data);
 
     // clone remote endpoint
-    remoteEndpoint = CACloneRemoteEndpoint(object);
+    remoteEndpoint = CACloneEndpoint(object);
     CA_MEMORY_ALLOC_CHECK(remoteEndpoint);
 
     // clone request info
@@ -620,7 +570,7 @@ CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *object, const CARequ
     CA_MEMORY_ALLOC_CHECK(requestInfo);
 
     // save data
-    data->type = SEND_TYPE_UNICAST;
+    data->type = request->isMulticast ? SEND_TYPE_MULTICAST : SEND_TYPE_UNICAST;
     data->remoteEndpoint = remoteEndpoint;
     data->requestInfo = requestInfo;
     data->responseInfo = NULL;
@@ -632,7 +582,7 @@ CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *object, const CARequ
 
 // memory error label.
 memory_error_exit:
-    CADestroyRemoteEndpointInternal(remoteEndpoint);
+    CAAdapterFreeEndpoint(remoteEndpoint);
     CADestroyRequestInfoInternal(requestInfo);
 
     OICFree(data);
@@ -640,66 +590,7 @@ memory_error_exit:
     return CA_MEMORY_ALLOC_FAILED;
 }
 
-CAResult_t CADetachRequestToAllMessage(const CAGroupEndpoint_t *object,
-                                       const CARequestInfo_t *request)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-
-    if (NULL == object || NULL == request || NULL == object->resourceUri)
-    {
-        return CA_STATUS_INVALID_PARAM;
-    }
-
-    if ((request->method < CA_GET) || (request->method > CA_DELETE))
-    {
-        OIC_LOG(ERROR, TAG, "Invalid method type!");
-
-        return CA_STATUS_INVALID_PARAM;
-    }
-
-    if (false == CAIsSelectedNetworkAvailable())
-    {
-        return CA_STATUS_FAILED;
-    }
-
-    CARemoteEndpoint_t *remoteEndpoint = NULL;
-    CARequestInfo_t *requestInfo = NULL;
-
-    // allocate & initialize
-    CAData_t *data = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
-    CA_MEMORY_ALLOC_CHECK(data);
-
-    CAAddress_t addr = {};
-    remoteEndpoint = CACreateRemoteEndpointInternal(object->resourceUri, addr,
-                                                    object->transportType);
-
-    // clone request info
-    requestInfo = CACloneRequestInfo(request);
-    CA_MEMORY_ALLOC_CHECK(requestInfo);
-
-    // save data
-    data->type = SEND_TYPE_MULTICAST;
-    data->remoteEndpoint = remoteEndpoint;
-    data->requestInfo = requestInfo;
-    data->responseInfo = NULL;
-
-    // add thread
-    CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
-
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-
-// memory error label.
-memory_error_exit:
-
-    CADestroyRequestInfoInternal(requestInfo);
-    CADestroyRemoteEndpointInternal(remoteEndpoint);
-    OICFree(data);
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_MEMORY_ALLOC_FAILED;
-}
-
-CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *object,
+CAResult_t CADetachResponseMessage(const CAEndpoint_t *object,
                                    const CAResponseInfo_t *response)
 {
     OIC_LOG(DEBUG, TAG, "IN");
@@ -711,7 +602,7 @@ CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *object,
         return CA_STATUS_FAILED;
     }
 
-    CARemoteEndpoint_t *remoteEndpoint = NULL;
+    CAEndpoint_t *remoteEndpoint = NULL;
     CAResponseInfo_t *responseInfo = NULL;
 
     // allocate & initialize
@@ -719,7 +610,7 @@ CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *object,
     CA_MEMORY_ALLOC_CHECK(data);
 
     // clone remote endpoint
-    remoteEndpoint = CACloneRemoteEndpoint(object);
+    remoteEndpoint = CACloneEndpoint(object);
     CA_MEMORY_ALLOC_CHECK(remoteEndpoint);
 
     // clone response info
@@ -740,7 +631,7 @@ CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *object,
 
 // memory error label.
 memory_error_exit:
-    CADestroyRemoteEndpointInternal(remoteEndpoint);
+    CAAdapterFreeEndpoint(remoteEndpoint);
     CADestroyResponseInfoInternal(responseInfo);
     OICFree(data);
     OIC_LOG(DEBUG, TAG, "OUT");
@@ -752,83 +643,7 @@ CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t
                                       uint8_t tokenLength, const CAHeaderOption_t *options,
                                       uint8_t numOptions)
 {
-    OIC_LOG(DEBUG, TAG, "IN");
-    VERIFY_NON_NULL(resourceUri, TAG, "resourceUri is NULL");
-    VERIFY_NON_NULL(token, TAG, "Token is NULL");
-
-    if (false == CAIsSelectedNetworkAvailable())
-    {
-        return CA_STATUS_FAILED;
-    }
-
-    CARemoteEndpoint_t *remoteEndpoint = NULL;
-    CARequestInfo_t *reqInfo = NULL;
-    char *tempToken = NULL;
-
-    // allocate & initialize
-    CAData_t *data = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
-    CA_MEMORY_ALLOC_CHECK(data);
-
-    CAAddress_t addr = {};
-    remoteEndpoint = CACreateRemoteEndpointInternal(resourceUri, addr,
-                                                    CA_IPV4 | CA_EDR | CA_LE);
-
-    // create request info
-    reqInfo = (CARequestInfo_t *) OICCalloc(1, sizeof(CARequestInfo_t));
-    CA_MEMORY_ALLOC_CHECK(reqInfo);
-
-    if (tokenLength)
-    {
-        // copy token value
-        tempToken = (char *) OICMalloc(tokenLength);
-        CA_MEMORY_ALLOC_CHECK(tempToken);
-        memcpy(tempToken, token, tokenLength);
-    }
-
-    // save request info data
-    reqInfo->method = CA_GET;
-    reqInfo->info.type = CA_MSG_NONCONFIRM;
-
-    reqInfo->info.token = tempToken;
-    reqInfo->info.tokenLength = tokenLength;
-
-    // save data
-    data->type = SEND_TYPE_MULTICAST;
-    data->remoteEndpoint = remoteEndpoint;
-    data->requestInfo = reqInfo;
-
-    data->responseInfo = NULL;
-    data->options = NULL;
-    data->numOptions = 0;
-    if (NULL != options && 0 < numOptions)
-    {
-        // copy data
-        CAHeaderOption_t *headerOption = (CAHeaderOption_t *) OICMalloc(sizeof(CAHeaderOption_t)
-                                                                        * numOptions);
-        CA_MEMORY_ALLOC_CHECK(headerOption);
-
-        memcpy(headerOption, options, sizeof(CAHeaderOption_t) * numOptions);
-
-        data->options = headerOption;
-        data->numOptions = numOptions;
-    }
-
-    // add thread
-    CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
-
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-
-// memory error label.
-memory_error_exit:
-
-    CADestroyRemoteEndpointInternal(remoteEndpoint);
-
-    OICFree(tempToken);
-    OICFree(reqInfo);
-    OICFree(data);
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_MEMORY_ALLOC_FAILED;
+    return CA_NOT_SUPPORTED;
 }
 
 void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
@@ -918,7 +733,7 @@ CAResult_t CAInitializeMessageHandler()
 void CATerminateMessageHandler()
 {
     OIC_LOG(DEBUG, TAG, "IN");
-    CATransportType_t connType;
+    CATransportAdapter_t connType;
     u_arraylist_t *list = CAGetSelectedNetworkList();
     uint32_t length = u_arraylist_length(list);
 
@@ -932,7 +747,7 @@ void CATerminateMessageHandler()
             continue;
         }
 
-        connType = *(CATransportType_t *) ptrType;
+        connType = *(CATransportAdapter_t *)ptrType;
         CAStopAdapter(connType);
     }
 
@@ -992,26 +807,25 @@ void CALogPDUInfo(coap_pdu_t *pdu)
     OIC_LOG_BUFFER(DEBUG, TAG, pdu->hdr->token, pdu->hdr->token_length);
 }
 
-void CAErrorHandler(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
-                    uint32_t dataLen, CAResult_t result)
+void CAErrorHandler(const CAEndpoint_t *endpoint,
+                    const void *data, uint32_t dataLen,
+                    CAResult_t result)
 {
     OIC_LOG(DEBUG, TAG, "IN");
-    VERIFY_NON_NULL_VOID(remoteEndpoint, TAG, "remoteEndpoint");
+    VERIFY_NON_NULL_VOID(endpoint, TAG, "remoteEndpoint");
     VERIFY_NON_NULL_VOID(data, TAG, "data");
 
     uint32_t code = CA_NOT_FOUND;
     //Do not free remoteEndpoint and data. Currently they will be freed in data thread
     //Get PDU data
-    coap_pdu_t *pdu = (coap_pdu_t *) CAParsePDU((const char *) data, dataLen, &code);
+    coap_pdu_t *pdu = (coap_pdu_t *)CAParsePDU((const char *)data, dataLen, &code);
     if (NULL == pdu)
     {
         OIC_LOG(ERROR, TAG, "Parse PDU failed");
         return;
     }
 
-    char uri[CA_MAX_URI_LENGTH] = { 0, };
-
-    CAErrorInfo_t *errorInfo = (CAErrorInfo_t *) OICCalloc(1, sizeof(CAErrorInfo_t));
+    CAErrorInfo_t *errorInfo = (CAErrorInfo_t *)OICCalloc(1, sizeof (CAErrorInfo_t));
     if (NULL == errorInfo)
     {
         OIC_LOG(ERROR, TAG, "CAErrorHandler, Memory allocation failed!");
@@ -1019,7 +833,7 @@ void CAErrorHandler(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
         return;
     }
 
-    CAResult_t res = CAGetErrorInfoFromPDU(pdu, errorInfo, uri, CA_MAX_URI_LENGTH);
+    CAResult_t res = CAGetErrorInfoFromPDU(pdu, errorInfo);
     if (CA_STATUS_OK != res)
     {
         OIC_LOG_V(ERROR, TAG, "CAGetErrorInfoFromPDU failed : %d", res);
@@ -1040,38 +854,23 @@ void CAErrorHandler(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
                    errorInfo->info.tokenLength);
     OIC_LOG_V(DEBUG, TAG, "CAErrorHandler, msgID : %d", errorInfo->info.messageId);
 
-    CARemoteEndpoint_t *rep = NULL;
-    rep = CACloneRemoteEndpoint(remoteEndpoint);
-    if(!rep)
+    CAEndpoint_t *rep = NULL;
+    rep = CACloneEndpoint(endpoint);
+    if (!rep)
     {
-        OIC_LOG(ERROR, TAG, "CAErrorHandler, CloneRemoteEndpoint Failed");
+        OIC_LOG(ERROR, TAG, "CAErrorHandler, CloneEndpoint Failed");
         OICFree(errorInfo);
         coap_delete_pdu(pdu);
         return;
     }
 
-    if(NULL == rep->resourceUri)
-    {
-        CAURI_t resourceUri = OICStrdup(uri);
-        if (NULL == resourceUri)
-        {
-            OIC_LOG(ERROR, TAG, "CAErrorHandler, Memory allocation failed!");
-            OICFree(errorInfo);
-            coap_delete_pdu(pdu);
-            return;
-        }
-
-        OIC_LOG_V(DEBUG, TAG, "URI : %s", resourceUri);
-        rep->resourceUri = resourceUri;
-    }
-
     // store the data at queue.
     CAData_t *cadata = NULL;
     cadata = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
     if (NULL == cadata)
     {
         OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
-        CADestroyRemoteEndpointInternal(rep);
+        CADestroyEndpointInternal(rep);
         OICFree(errorInfo);
         coap_delete_pdu(pdu);
         return;
@@ -1082,6 +881,7 @@ void CAErrorHandler(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
     cadata->responseInfo = NULL;
     cadata->errorInfo = errorInfo;
     cadata->dataType = CA_ERROR_DATA;
+
     CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
     coap_delete_pdu(pdu);
 
index 655775d..d687d45 100644 (file)
@@ -45,7 +45,7 @@ typedef enum
 typedef struct
 {
     CASendDataType_t type;
-    CARemoteEndpoint_t *remoteEndpoint;
+    CAEndpoint_t *remoteEndpoint;
     CARequestInfo_t *requestInfo;
     CAResponseInfo_t *responseInfo;
     CAHeaderOption_t *options;
@@ -60,10 +60,10 @@ static CARequestCallback g_requestHandler = NULL;
 static CAResponseCallback g_responseHandler = NULL;
 static CAErrorCallback g_errorHandler = NULL;
 
-static void CATimeoutCallback(const CARemoteEndpoint_t *endpoint, const void *pdu, uint32_t size)
+static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uint32_t size)
 {
     OIC_LOG(DEBUG, TAG, "IN");
-    CARemoteEndpoint_t* ep = CACloneRemoteEndpoint(endpoint);
+    CAEndpoint_t* ep = CACloneEndpoint(endpoint);
     if (NULL == ep)
     {
         OIC_LOG(ERROR, TAG, "clone failed");
@@ -75,7 +75,7 @@ static void CATimeoutCallback(const CARemoteEndpoint_t *endpoint, const void *pd
     if (NULL == resInfo)
     {
         OIC_LOG(ERROR, TAG, "calloc failed");
-        CADestroyRemoteEndpointInternal(ep);
+        CADestroyEndpointInternal(ep);
         return;
     }
 
@@ -88,7 +88,7 @@ static void CATimeoutCallback(const CARemoteEndpoint_t *endpoint, const void *pd
         g_responseHandler(ep, resInfo);
     }
 
-    CADestroyRemoteEndpointInternal(ep);
+    CADestroyEndpointInternal(ep);
     OICFree(resInfo);
 
     OIC_LOG(DEBUG, TAG, "OUT");
@@ -111,17 +111,13 @@ static void CAProcessData(const CAData_t *data)
         {
             OIC_LOG(DEBUG, TAG, "reqInfo avlbl");
 
-            pdu = (coap_pdu_t *) CAGeneratePDU(data->remoteEndpoint->resourceUri,
-                                               data->requestInfo->method,
-                                               data->requestInfo->info);
+            pdu = (coap_pdu_t *)CAGeneratePDU(data->requestInfo->method, &data->requestInfo->info);
         }
         else if (NULL != data->responseInfo)
         {
             OIC_LOG(DEBUG, TAG, "resInfo avlbl");
 
-            pdu = (coap_pdu_t *) CAGeneratePDU(data->remoteEndpoint->resourceUri,
-                                               data->responseInfo->result,
-                                               data->responseInfo->info);
+            pdu = (coap_pdu_t *)CAGeneratePDU(data->responseInfo->result, &data->responseInfo->info);
         }
         else
         {
@@ -157,18 +153,17 @@ static void CAProcessData(const CAData_t *data)
     {
         OIC_LOG(DEBUG, TAG, "both requestInfo & responseInfo is not available");
 
-        CAInfo_t info = data->requestInfo->info;
+        CAInfo_t *info = &data->requestInfo->info;
 
-        info.options = data->options;
-        info.numOptions = data->numOptions;
+        info->options = data->options;
+        info->numOptions = data->numOptions;
 
-        coap_pdu_t *pdu = (coap_pdu_t *) CAGeneratePDU(data->remoteEndpoint->resourceUri, CA_GET,
-                                                       info);
+        coap_pdu_t *pdu = (coap_pdu_t *)CAGeneratePDU(CA_GET, info);
 
         if (NULL != pdu)
         {
             CALogPDUInfo(pdu);
-            res = CASendMulticastData(pdu->hdr, pdu->length);
+            res = CASendMulticastData(data->remoteEndpoint, pdu->hdr, pdu->length);
             if(CA_STATUS_OK != res)
             {
                 OIC_LOG_V(ERROR, TAG, "send failed:%d", res);
@@ -182,7 +177,7 @@ static void CAProcessData(const CAData_t *data)
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, uint32_t dataLen)
+static void CAReceivedPacketCallback(CAEndpoint_t *endpoint, void *data, uint32_t dataLen)
 {
     OIC_LOG(DEBUG, TAG, "IN");
     VERIFY_NON_NULL_VOID(data, TAG, "data");
@@ -208,7 +203,7 @@ static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, u
             return;
         }
 
-        CAResult_t res = CAGetRequestInfoFromPDU(pdu, ReqInfo, uri, sizeof(uri));
+        CAResult_t res = CAGetRequestInfoFromPDU(pdu, ReqInfo);
         if (CA_STATUS_OK != res)
         {
             OIC_LOG_V(ERROR, TAG, "CAGetRequestInfoFromPDU failed : %d", res);
@@ -235,20 +230,6 @@ static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, u
         OIC_LOG_V(DEBUG, TAG, "code: %d", ReqInfo->method);
         OIC_LOG(DEBUG, TAG, "token:");
         OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *) ReqInfo->info.token, CA_MAX_TOKEN_LEN);
-        if (NULL != endpoint)
-        {
-            endpoint->resourceUri = (char *) OICMalloc(sizeof(uri) + 1);
-            if (NULL == endpoint->resourceUri)
-            {
-                OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, Memory allocation failed!");
-                OICFree(ReqInfo);
-                coap_delete_pdu(pdu);
-                return;
-            }
-            memcpy(endpoint->resourceUri, uri, sizeof(uri));
-            endpoint->resourceUri[sizeof(uri)] = '\0';
-            OIC_LOG_V(DEBUG, TAG, "URI : %s", endpoint->resourceUri);
-        }
 
         if (ReqInfo)
         {
@@ -270,7 +251,7 @@ static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, u
             return;
         }
 
-        CAResult_t res = CAGetResponseInfoFromPDU(pdu, ResInfo, uri, sizeof(uri));
+        CAResult_t res = CAGetResponseInfoFromPDU(pdu, ResInfo);
         if (CA_STATUS_OK != res)
         {
             OIC_LOG_V(ERROR, TAG, "CAGetResponseInfoFromPDU failed : %d", res);
@@ -295,21 +276,6 @@ static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, u
         }
         OIC_LOG_V(DEBUG, TAG, "code: %d", ResInfo->result);
 
-        if (NULL != endpoint)
-        {
-            endpoint->resourceUri = (char *) OICMalloc(sizeof(uri) + 1);
-            if (NULL == endpoint->resourceUri)
-            {
-                OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
-                OICFree(ResInfo);
-                coap_delete_pdu(pdu);
-                return;
-            }
-            memcpy(endpoint->resourceUri, uri, sizeof(uri));
-            endpoint->resourceUri[sizeof(uri)] = '\0';
-            OIC_LOG_V(DEBUG, TAG, "URI : %s", endpoint->resourceUri);
-        }
-
         // for retransmission
         void *retransmissionPdu = NULL;
         CARetransmissionReceivedData(&g_retransmissionContext, endpoint, pdu->hdr, pdu->length,
@@ -338,11 +304,6 @@ static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, u
         }
     }
 
-    if (endpoint && endpoint->resourceUri)
-    {
-        OICFree(endpoint->resourceUri);
-        endpoint->resourceUri = NULL;
-    }
     if (pdu)
     {
         coap_delete_pdu(pdu);
@@ -350,7 +311,7 @@ static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data, u
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-static void CANetworkChangedCallback(CALocalConnectivity_t *info, CANetworkStatus_t status)
+static void CANetworkChangedCallback(CAEndpoint_t *info, CANetworkStatus_t status)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -363,7 +324,7 @@ void CAHandleRequestResponseCallbacks()
     CARetransmissionBaseRoutine((void *)&g_retransmissionContext);
 }
 
-CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *object, const CARequestInfo_t *request)
+CAResult_t CADetachRequestMessage(const CAEndpoint_t *object, const CARequestInfo_t *request)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -399,53 +360,7 @@ memory_error_exit:
     return CA_MEMORY_ALLOC_FAILED;
 }
 
-CAResult_t CADetachRequestToAllMessage(const CAGroupEndpoint_t *object,
-                                       const CARequestInfo_t *request)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-
-    if (NULL == object || NULL == request || NULL == object->resourceUri)
-    {
-        return CA_STATUS_INVALID_PARAM;
-    }
-
-    if ((request->method < CA_GET) || (request->method > CA_DELETE))
-    {
-        OIC_LOG(ERROR, TAG, "Invalid method type!");
-
-        return CA_STATUS_INVALID_PARAM;
-    }
-
-    // allocate & initialize
-    CAData_t *data = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
-    CA_MEMORY_ALLOC_CHECK(data);
-
-    CAAddress_t addr = {0};
-    CARemoteEndpoint_t *remoteEndpoint = CACreateRemoteEndpointInternal(object->resourceUri, addr,
-                                                                        object->transportType);
-
-    // save data
-    data->type = SEND_TYPE_MULTICAST;
-    data->remoteEndpoint = remoteEndpoint;
-    data->requestInfo = request;
-    data->responseInfo = NULL;
-
-    CAProcessData(data);
-    CADestroyRemoteEndpointInternal(remoteEndpoint);
-
-    OICFree(data);
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-
-// memory error label.
-memory_error_exit:
-
-    OICFree(data);
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_MEMORY_ALLOC_FAILED;
-}
-
-CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *object,
+CAResult_t CADetachResponseMessage(const CAEndpoint_t *object,
                                    const CAResponseInfo_t *response)
 {
     OIC_LOG(DEBUG, TAG, "IN");
@@ -476,75 +391,8 @@ memory_error_exit:
     return CA_MEMORY_ALLOC_FAILED;
 }
 
-CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
-                                      uint8_t tokenLength, const CAHeaderOption_t *options,
-                                      uint8_t numOptions)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    VERIFY_NON_NULL(resourceUri, TAG, "resourceUri is NULL");
-    VERIFY_NON_NULL(token, TAG, "Token is NULL");
-
-    // allocate & initialize
-    CAData_t *data = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
-    CA_MEMORY_ALLOC_CHECK(data);
-
-    CAAddress_t addr = {0};
-    CARemoteEndpoint_t *remoteEndpoint =
-            CACreateRemoteEndpointInternal(resourceUri, addr, CA_IPV4 | CA_EDR | CA_LE);
-
-    // create request info
-    CARequestInfo_t *reqInfo = (CARequestInfo_t *) OICCalloc(1, sizeof(CARequestInfo_t));
-    CA_MEMORY_ALLOC_CHECK(reqInfo);
-
-    // save request info data
-    reqInfo->method = CA_GET;
-    reqInfo->info.type = CA_MSG_NONCONFIRM;
-
-    reqInfo->info.token = token;
-    reqInfo->info.tokenLength = tokenLength;
-
-    // save data
-    data->type = SEND_TYPE_MULTICAST;
-    data->remoteEndpoint = remoteEndpoint;
-    data->requestInfo = reqInfo;
-
-    data->responseInfo = NULL;
-    data->options = NULL;
-    data->numOptions = 0;
-    CAHeaderOption_t *headerOption = NULL;
-    if (NULL != options && numOptions > 0)
-    {
-        // copy data
-        headerOption = (CAHeaderOption_t *) OICMalloc(sizeof(CAHeaderOption_t) * numOptions);
-        CA_MEMORY_ALLOC_CHECK(headerOption);
-        memcpy(headerOption, options, sizeof(CAHeaderOption_t) * numOptions);
-
-        data->options = headerOption;
-        data->numOptions = numOptions;
-    }
-
-    CAProcessData(data);
-
-    CADestroyRemoteEndpoint(remoteEndpoint);
-    OICFree(headerOption);
-    OICFree(data);
-    OICFree(reqInfo);
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-
-// memory error label.
-memory_error_exit:
-
-    CADestroyRemoteEndpointInternal(remoteEndpoint);
-
-    OICFree(reqInfo);
-    OICFree(data);
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_MEMORY_ALLOC_FAILED;
-}
-
-void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
-                             CAErrorCallback errorHandler)
+void CASetInterfaceCallbacks(CARequestCallback ReqHandler,
+                CAResponseCallback RespHandler, CAErrorCallback errorHandler)
 {
     OIC_LOG(DEBUG, TAG, "IN");
     g_requestHandler = ReqHandler;
index c5a89bc..d9c8797 100644 (file)
 #include <stdlib.h>
 
 #include "canetworkconfigurator.h"
-#include "cainterfacecontroller_singlethread.h"
+#include "cainterfacecontroller.h"
 #include "uarraylist.h"
 #include "logger.h"
 
 #define TAG "CANW"
 
 static u_arraylist_t *g_selectedNetworkList = NULL;
-static uint32_t NETWORK_IP = CA_IPV4;
-static uint32_t NETWORK_EDR = CA_EDR;
-static uint32_t NETWORK_LE = CA_LE;
+static uint32_t NETWORK_IP = CA_ADAPTER_IP;
+static uint32_t NETWORK_RFCOMM = CA_ADAPTER_RFCOMM_BTEDR;
+static uint32_t NETWORK_GATT = CA_ADAPTER_GATT_BTLE;
 
-
-CAResult_t CAAddNetworkType(CATransportType_t transportType)
+CAResult_t CAAddNetworkType(CATransportAdapter_t transportType)
 {
     OIC_LOG(DEBUG, TAG, "IN");
     if (NULL == g_selectedNetworkList)
@@ -50,9 +49,7 @@ CAResult_t CAAddNetworkType(CATransportType_t transportType)
     CAResult_t res = CA_STATUS_OK;
     switch (transportType)
     {
-        case CA_IPV4:
-        {
-
+        case CA_ADAPTER_IP:
 #ifndef IP_ADAPTER
             OIC_LOG(DEBUG, TAG, "Add network type(IP) - Not Supported");
             return CA_NOT_SUPPORTED;
@@ -64,48 +61,37 @@ CAResult_t CAAddNetworkType(CATransportType_t transportType)
                 goto exit;
             }
             res = u_arraylist_add(g_selectedNetworkList, &NETWORK_IP);
-        }
-        break;
-        case CA_IPV6:
-        {
-            OIC_LOG(ERROR, TAG, "Currently IPV6 is not supported");
-            return CA_NOT_SUPPORTED;
-        }
-
-        case CA_EDR:
-        {
+            break;
 
+        case CA_ADAPTER_RFCOMM_BTEDR:
 #ifndef EDR_ADAPTER
             OIC_LOG(DEBUG, TAG, "Add network type(EDR) - Not Supported");
             return CA_NOT_SUPPORTED;
 #endif /* EDR_ADAPTER */
 
             OIC_LOG(DEBUG, TAG, "Add network type(EDR)");
-            if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_EDR))
+            if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_RFCOMM))
             {
                 goto exit;
             }
-            res = u_arraylist_add(g_selectedNetworkList, &NETWORK_EDR);
-        }
-        break;
-
-        case CA_LE:
-        {
+            res = u_arraylist_add(g_selectedNetworkList, &NETWORK_RFCOMM);
+            break;
 
+        case CA_ADAPTER_GATT_BTLE:
 #ifndef LE_ADAPTER
             OIC_LOG(DEBUG, TAG, "Add network type(LE) - Not Supported");
             return CA_NOT_SUPPORTED;
 #endif /* LE_ADAPTER */
 
             OIC_LOG(DEBUG, TAG, "Add network type(LE)");
-            if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_LE))
+            if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_GATT))
             {
                 goto exit;
             }
-            res = u_arraylist_add(g_selectedNetworkList, &NETWORK_LE);
-        }
-        break;
-
+            res = u_arraylist_add(g_selectedNetworkList, &NETWORK_GATT);
+            break;
+        default:
+            break;
     }
 
     if (CA_STATUS_OK != res)
@@ -114,7 +100,7 @@ CAResult_t CAAddNetworkType(CATransportType_t transportType)
         return res;
     }
     // start selected interface adapter
-    res = CAStartAdapter((CATransportType_t)transportType);
+    res = CAStartAdapter(transportType);
     OIC_LOG(DEBUG, TAG, "OUT");
     return res;
 
@@ -123,7 +109,7 @@ exit:
     return CA_STATUS_OK;
 }
 
-CAResult_t CARemoveNetworkType(CATransportType_t transportType)
+CAResult_t CARemoveNetworkType(CATransportAdapter_t transportType)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -143,14 +129,13 @@ CAResult_t CARemoveNetworkType(CATransportType_t transportType)
             continue;
         }
 
-        CATransportType_t connType = *(CATransportType_t *) ptrType;
+        CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
 
         if (transportType == connType)
         {
             switch (transportType)
             {
-                case CA_IPV4:
-
+                case CA_ADAPTER_IP:
 #ifndef IP_ADAPTER
                     OIC_LOG(DEBUG, TAG, "Remove network type(IP) - Not Supported");
                     return CA_NOT_SUPPORTED;
@@ -161,14 +146,7 @@ CAResult_t CARemoveNetworkType(CATransportType_t transportType)
 #endif /* IP_ADAPTER */
                     break;
 
-                case CA_IPV6:
-                {
-                    OIC_LOG(ERROR, TAG, "Currently IPV6 is not supported");
-                    return CA_NOT_SUPPORTED;
-                }
-
-                case CA_EDR:
-
+                case CA_ADAPTER_RFCOMM_BTEDR:
 #ifndef EDR_ADAPTER
                     OIC_LOG(DEBUG, TAG, "Remove network type(EDR) - Not Supported");
                     return CA_NOT_SUPPORTED;
@@ -176,11 +154,9 @@ CAResult_t CARemoveNetworkType(CATransportType_t transportType)
                     OIC_LOG(DEBUG, TAG, "Remove network type(EDR)");
                     u_arraylist_remove(g_selectedNetworkList, index);
 #endif /* EDR_ADAPTER */
-
                     break;
 
-                case CA_LE:
-
+                case CA_ADAPTER_GATT_BTLE:
 #ifndef LE_ADAPTER
                     OIC_LOG(DEBUG, TAG, "Remove network type(LE) - Not Supported");
                     return CA_NOT_SUPPORTED;
@@ -188,7 +164,9 @@ CAResult_t CARemoveNetworkType(CATransportType_t transportType)
                     OIC_LOG(DEBUG, TAG, "Remove network type(LE)");
                     u_arraylist_remove(g_selectedNetworkList, index);
 #endif /* LE_ADAPTER */
+                    break;
 
+                default:
                     break;
             }
 
@@ -206,7 +184,7 @@ u_arraylist_t *CAGetSelectedNetworkList()
     return g_selectedNetworkList;
 }
 
-CAResult_t CAGetNetworkInformationInternal(CALocalConnectivity_t **info, uint32_t *size)
+CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, uint32_t *size)
 {
     OIC_LOG(DEBUG, TAG, "get network information.");
 
index fedc0de..4510963 100644 (file)
 
 #define TAG "CA"
 
+/**
+ * @def VERIFY_NON_NULL_RET
+ * @brief Macro to verify the validity of input argument
+ */
+#define VERIFY_NON_NULL_RET(arg, log_tag, log_message,ret) \
+    if (NULL == arg ){ \
+        OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
+        return ret; \
+    }
+
 #define CA_BUFSIZE (128)
 #define CA_PDU_MIN_SIZE (4)
 #define CA_PORT_BUFFER_SIZE (4)
@@ -66,62 +76,59 @@ static const char COAP_URI_HEADER[] = "coap://[::]/";
 
 static uint32_t SEED = 0;
 
-CAResult_t CAGetRequestInfoFromPDU(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo,
-                                   char *outUri, uint32_t buflen)
+CAResult_t CAGetRequestInfoFromPDU(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
-    if (NULL == pdu || NULL == outReqInfo || NULL == outUri)
+    if (NULL == pdu || NULL == outReqInfo)
     {
         OIC_LOG(ERROR, TAG, "parameter is null");
         return CA_STATUS_INVALID_PARAM;
     }
 
     uint32_t code = CA_NOT_FOUND;
-
-    OIC_LOG_V(DEBUG, TAG, "buffer length : %d", buflen);
-    CAResult_t ret = CAGetInfoFromPDU(pdu, &code, &(outReqInfo->info), outUri, buflen);
+    CAResult_t ret = CAGetInfoFromPDU(pdu, &code, &(outReqInfo->info));
     outReqInfo->method = code;
+
     OIC_LOG(DEBUG, TAG, "OUT");
     return ret;
 }
 
-CAResult_t CAGetResponseInfoFromPDU(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo,
-                                    char *outUri, uint32_t buflen)
+CAResult_t CAGetResponseInfoFromPDU(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
-    if (NULL == pdu || NULL == outResInfo || NULL == outUri)
+    if (NULL == pdu || NULL == outResInfo)
     {
         OIC_LOG(ERROR, TAG, "parameter is null");
         return CA_STATUS_INVALID_PARAM;
     }
 
     uint32_t code = CA_NOT_FOUND;
-    CAResult_t ret = CAGetInfoFromPDU(pdu, &code, &(outResInfo->info), outUri, buflen);
+    CAResult_t ret = CAGetInfoFromPDU(pdu, &code, &(outResInfo->info));
     outResInfo->result = code;
+
     OIC_LOG(DEBUG, TAG, "OUT");
     return ret;
 }
 
-CAResult_t CAGetErrorInfoFromPDU(const coap_pdu_t *pdu, CAErrorInfo_t *errorInfo,
-                                 char *uri, uint32_t buflen)
+CAResult_t CAGetErrorInfoFromPDU(const coap_pdu_t *pdu, CAErrorInfo_t *errorInfo)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
-    if (!pdu || !errorInfo || !uri)
+    if (!pdu)
     {
         OIC_LOG(ERROR, TAG, "parameter is null");
         return CA_STATUS_INVALID_PARAM;
     }
 
     uint32_t code = 0;
-    CAResult_t ret = CAGetInfoFromPDU(pdu, &code, &errorInfo->info, uri, buflen);
+    CAResult_t ret = CAGetInfoFromPDU(pdu, &code, &errorInfo->info);
     OIC_LOG(DEBUG, TAG, "OUT");
     return ret;
 }
 
-coap_pdu_t *CAGeneratePDU(const char *uri, uint32_t code, const CAInfo_t info)
+coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -129,7 +136,7 @@ coap_pdu_t *CAGeneratePDU(const char *uri, uint32_t code, const CAInfo_t info)
 
     // RESET have to use only 4byte (empty message)
     // and ACKNOWLEDGE can use empty message when code is empty.
-    if (CA_MSG_RESET == info.type || (CA_EMPTY == code && CA_MSG_ACKNOWLEDGE == info.type))
+    if (CA_MSG_RESET == info->type || (CA_EMPTY == code && CA_MSG_ACKNOWLEDGE == info->type))
     {
         OIC_LOG(DEBUG, TAG, "code is empty");
         if (!(pdu = CAGeneratePDUImpl((code_t) code, NULL, info, NULL, 0)))
@@ -142,8 +149,9 @@ coap_pdu_t *CAGeneratePDU(const char *uri, uint32_t code, const CAInfo_t info)
     {
         coap_list_t *optlist = NULL;
 
-        if (CA_MSG_ACKNOWLEDGE != info.type)
+        if (CA_MSG_ACKNOWLEDGE != info->type)
         {
+            const char *uri = info->resourceUri;
             if (NULL == uri)
             {
                 OIC_LOG(ERROR, TAG, "uri NULL");
@@ -188,8 +196,8 @@ coap_pdu_t *CAGeneratePDU(const char *uri, uint32_t code, const CAInfo_t info)
             coap_delete_list(optlist);
             return NULL;
         }
-        size_t lenPayload = info.payload ? strlen(info.payload) : 0;
-        pdu = CAGeneratePDUImpl((code_t) code, optlist, info, info.payload, lenPayload);
+        size_t lenPayload = info->payload ? strlen(info->payload) : 0;
+        pdu = CAGeneratePDUImpl((code_t)code, optlist, info, info->payload, lenPayload);
         if (NULL == pdu)
         {
             OIC_LOG(ERROR, TAG, "pdu NULL");
@@ -239,10 +247,11 @@ coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode)
     return outpdu;
 }
 
-coap_pdu_t *CAGeneratePDUImpl(code_t code, coap_list_t *options, const CAInfo_t info,
+coap_pdu_t *CAGeneratePDUImpl(code_t code, coap_list_t *options, const CAInfo_t *info,
                               const char *payload, size_t payloadSize)
 {
     OIC_LOG(DEBUG, TAG, "IN");
+    VERIFY_NON_NULL_RET(info, TAG, "info is NULL", NULL);
 
     coap_pdu_t *pdu = coap_new_pdu();
 
@@ -252,9 +261,9 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, coap_list_t *options, const CAInfo_t
         return NULL;
     }
 
-    OIC_LOG_V(DEBUG, TAG, "msgID is %d", info.messageId);
+    OIC_LOG_V(DEBUG, TAG, "msgID is %d", info->messageId);
     uint16_t message_id;
-    if (0 == info.messageId)
+    if (0 == info->messageId)
     {
         /* initialize message id */
         prng((uint8_t * ) &message_id, sizeof(message_id));
@@ -264,21 +273,21 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, coap_list_t *options, const CAInfo_t
     else
     {
         /* use saved message id */
-        message_id = info.messageId;
+        message_id = info->messageId;
     }
     pdu->hdr->id = message_id;
     OIC_LOG_V(DEBUG, TAG, "messageId in pdu is %d, %d", message_id, pdu->hdr->id);
 
-    pdu->hdr->type = info.type;
+    pdu->hdr->type = info->type;
     pdu->hdr->code = COAP_RESPONSE_CODE(code);
 
-    if (info.token && CA_EMPTY != code)
+    if (info->token && CA_EMPTY != code)
     {
-        uint32_t tokenLength = info.tokenLength;
+        uint32_t tokenLength = info->tokenLength;
         OIC_LOG_V(DEBUG, TAG, "token info token length: %d, token :", tokenLength);
-        OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *)info.token, tokenLength);
+        OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *)info->token, tokenLength);
 
-        int32_t ret = coap_add_token(pdu, tokenLength, (unsigned char *) info.token);
+        int32_t ret = coap_add_token(pdu, tokenLength, (unsigned char *)info->token);
         if (0 == ret)
         {
             OIC_LOG(ERROR, TAG, "can't add token");
@@ -335,7 +344,7 @@ CAResult_t CAParseURI(const char *uriInfo, coap_list_t **optlist)
         int ret = coap_insert(optlist,
                               CACreateNewOptionNode(COAP_OPTION_URI_PORT,
                                                     coap_encode_var_bytes(portbuf, uri.port),
-                                                    portbuf),
+                                                    (char *)portbuf),
                               CAOrderOpts);
         if (ret <= 0)
         {
@@ -345,8 +354,8 @@ CAResult_t CAParseURI(const char *uriInfo, coap_list_t **optlist)
 
     if (uri.path.s && uri.path.length)
     {
-        CAResult_t ret = CAParseUriPartial(uri.path.s, uri.path.length, COAP_OPTION_URI_PATH,
-                                           optlist);
+        CAResult_t ret = CAParseUriPartial(uri.path.s, uri.path.length,
+                                           COAP_OPTION_URI_PATH, optlist);
         if (CA_STATUS_OK != ret)
         {
             OIC_LOG(ERROR, TAG, "CAParseUriPartial failed(uri path)");
@@ -399,7 +408,7 @@ CAResult_t CAParseUriPartial(const unsigned char *str, size_t length, int target
             {
                 int ret = coap_insert(optlist,
                                       CACreateNewOptionNode(target, COAP_OPT_LENGTH(pBuf),
-                                                            COAP_OPT_VALUE(pBuf)),
+                                                            (char *)COAP_OPT_VALUE(pBuf)),
                                       CAOrderOpts);
                 if (ret <= 0)
                 {
@@ -429,11 +438,12 @@ CAResult_t CAParseUriPartial(const unsigned char *str, size_t length, int target
     return CA_STATUS_OK;
 }
 
-CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t info, coap_list_t **optlist)
+CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t *info, coap_list_t **optlist)
 {
     OIC_LOG(DEBUG, TAG, "IN");
+    VERIFY_NON_NULL_RET(info, TAG, "info is NULL", CA_STATUS_INVALID_PARAM);
 
-    OIC_LOG_V(DEBUG, TAG, "parse Head Opt: %d", info.numOptions);
+    OIC_LOG_V(DEBUG, TAG, "parse Head Opt: %d", info->numOptions);
 
     if (!optlist)
     {
@@ -441,29 +451,29 @@ CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t info, coap_list_t **o
         return CA_STATUS_INVALID_PARAM;
     }
 
-    for (uint32_t i = 0; i < info.numOptions; i++)
+    for (uint32_t i = 0; i < info->numOptions; i++)
     {
-        if(!(info.options + i))
+        if(!(info->options + i))
         {
             OIC_LOG(ERROR, TAG, "options is not available");
             return CA_STATUS_FAILED;
         }
 
-        uint32_t id = (info.options + i)->optionID;
+        uint32_t id = (info->options + i)->optionID;
         if (COAP_OPTION_URI_PATH == id || COAP_OPTION_URI_QUERY == id)
         {
             OIC_LOG_V(DEBUG, TAG, "not Header Opt: %d", id);
         }
         else
         {
-            if ((info.options + i)->optionData && (info.options + i)->optionLength > 0)
+            if ((info->options + i)->optionData && (info->options + i)->optionLength > 0)
             {
                 OIC_LOG_V(DEBUG, TAG, "Head opt ID: %d", id);
-                OIC_LOG_V(DEBUG, TAG, "Head opt data: %s", (info.options + i)->optionData);
-                OIC_LOG_V(DEBUG, TAG, "Head opt length: %d", (info.options + i)->optionLength);
+                OIC_LOG_V(DEBUG, TAG, "Head opt data: %s", (info->options + i)->optionData);
+                OIC_LOG_V(DEBUG, TAG, "Head opt length: %d", (info->options + i)->optionLength);
                 int ret = coap_insert(optlist,
-                                      CACreateNewOptionNode(id, (info.options + i)->optionLength,
-                                                            (info.options + i)->optionData),
+                                      CACreateNewOptionNode(id, (info->options + i)->optionLength,
+                                                            (info->options + i)->optionData),
                                       CAOrderOpts);
                 if (ret <= 0)
                 {
@@ -477,7 +487,7 @@ CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t info, coap_list_t **o
     return CA_STATUS_OK;
 }
 
-coap_list_t *CACreateNewOptionNode(uint16_t key, uint32_t length, const uint8_t *data)
+coap_list_t *CACreateNewOptionNode(uint16_t key, uint32_t length, const char *data)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -548,12 +558,11 @@ uint32_t CAGetOptionCount(coap_opt_iterator_t opt_iter)
     return count;
 }
 
-CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo,
-                            char *outUri, uint32_t buflen)
+CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
-    if (!pdu || !outCode || !outInfo || !outUri)
+    if (!pdu || !outCode || !outInfo)
     {
         OIC_LOG(ERROR, TAG, "NULL pointer param");
         return CA_STATUS_INVALID_PARAM;
@@ -732,16 +741,20 @@ CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *
     }
 
     uint32_t length = strlen(optionResult);
-    OIC_LOG_V(DEBUG, TAG, "URL length:%d,%d,%d", length, buflen, strlen(outUri));
-    if (buflen >= length)
+    OIC_LOG_V(DEBUG, TAG, "URL length:%d", length);
+
+    outInfo->resourceUri = OICMalloc(length + 1);
+    if (!outInfo->resourceUri)
     {
-        memcpy(outUri, optionResult, length);
-#ifdef ARDUINO
-        OIC_LOG_V(DEBUG, TAG, "made URL:%s\n", optionResult);
-#else
-        OIC_LOG_V(DEBUG, TAG, "made URL : %s, %s", optionResult, outUri);
-#endif
+        OIC_LOG(ERROR, TAG, "Out of memory");
+        OICFree(outInfo->options);
+        OICFree(outInfo->token);
+        return CA_MEMORY_ALLOC_FAILED;
     }
+    memcpy(outInfo->resourceUri, optionResult, length);
+    outInfo->resourceUri[length] = '\0';
+    OIC_LOG_V(DEBUG, TAG, "made URL : %s, %s", optionResult, outInfo->resourceUri);
+
     OIC_LOG(DEBUG, TAG, "OUT");
     return CA_STATUS_OK;
 
index 08f003f..73de3f1 100644 (file)
@@ -27,7 +27,7 @@
 
 #define TAG "CA"
 
-CARemoteEndpoint_t *CACloneRemoteEndpoint(const CARemoteEndpoint_t *rep)
+CAEndpoint_t *CACloneEndpoint(const CAEndpoint_t *rep)
 {
     if (NULL == rep)
     {
@@ -36,7 +36,7 @@ CARemoteEndpoint_t *CACloneRemoteEndpoint(const CARemoteEndpoint_t *rep)
     }
 
     // allocate the remote end point structure.
-    CARemoteEndpoint_t *clone = (CARemoteEndpoint_t *) OICMalloc(sizeof(CARemoteEndpoint_t));
+    CAEndpoint_t *clone = (CAEndpoint_t *)OICMalloc(sizeof (CAEndpoint_t));
     if (NULL == clone)
     {
         OIC_LOG(ERROR, TAG, "CACloneRemoteEndpoint Out of memory");
@@ -44,251 +44,9 @@ CARemoteEndpoint_t *CACloneRemoteEndpoint(const CARemoteEndpoint_t *rep)
     }
     *clone = *rep;
 
-    if (NULL != rep->resourceUri)
-    {
-        // allocate reference uri field
-        char *temp = OICStrdup(rep->resourceUri);
-        if (NULL == temp)
-        {
-            OIC_LOG(ERROR, TAG, "CACloneRemoteEndpoint Out of memory");
-
-            CADestroyRemoteEndpointInternal(clone);
-
-            return NULL;
-        }
-
-        // save the uri
-        clone->resourceUri = temp;
-    }
-
     return clone;
 }
 
-#define COAP_PREFIX         "coap://"
-#define COAP_PREFIX_LEN     7
-#define COAPS_PREFIX         "coaps://"
-#define COAPS_PREFIX_LEN     8
-
-
-// return 1 : ip
-// return 0 : mac
-static int32_t getCAAddress(const char *pAddress, CAAddress_t *outAddress)
-{
-    if (NULL == pAddress || NULL == outAddress)
-    {
-        OIC_LOG(ERROR, TAG, "parameter is null");
-        return -1;
-    }
-
-    // simple parse, it will be change.
-    // 10.11.12.13:4545 (ip)
-    // 10:11:12:13:45:45 (mac)
-
-    int32_t len = strlen(pAddress);
-
-    int32_t isIp = 0;
-    int32_t ipLen = 0;
-
-    int i = 0;
-    for (i = 0; i < len; i++)
-    {
-        if (pAddress[i] == '.')
-        {
-            isIp = 1;
-        }
-
-        // found port number start index
-        if (isIp && pAddress[i] == ':')
-        {
-            ipLen = i;
-            break;
-        }
-    }
-
-    if (isIp)
-    {
-        if(ipLen && ipLen < sizeof(outAddress->IP.ipAddress))
-        {
-            OICStrcpyPartial(outAddress->IP.ipAddress, sizeof(outAddress->IP.ipAddress),
-                    pAddress, ipLen);
-        }
-        else if (!ipLen && len < sizeof(outAddress->IP.ipAddress))
-        {
-            OICStrcpy(outAddress->IP.ipAddress, sizeof(outAddress->IP.ipAddress),
-                    pAddress);
-        }
-        else
-        {
-            OIC_LOG_V(ERROR, TAG, "IP Address too long: %d", ipLen==0 ? len : ipLen);
-            return -1;
-        }
-
-
-        if (ipLen > 0)
-        {
-            outAddress->IP.port = atoi(pAddress + ipLen + 1);
-        }
-
-        OIC_LOG_V(DEBUG, TAG, "ip: %s, port: %d", outAddress->IP.ipAddress, outAddress->IP.port);
-    }
-    else
-    {
-        OICStrcpy(outAddress->BT.btMacAddress, sizeof(outAddress->BT.btMacAddress),
-                    pAddress);
-
-        OIC_LOG_V(DEBUG, TAG, "mac address : %s", outAddress->BT.btMacAddress);
-    }
-
-    return isIp;
-}
-
-CARemoteEndpoint_t *CACreateRemoteEndpointUriInternal(const CAURI_t uri,
-                                                      const CATransportType_t transportType)
-{
-    // support URI type
-    // coap://10.11.12.13:4545/resource_uri
-    // coap://10:11:12:13:45:45/resource_uri
-
-    if (NULL == uri)
-    {
-        OIC_LOG(ERROR, TAG, "parameter is null");
-        return NULL;
-    }
-
-    // parse uri
-    // #1. check prefix
-    int startIndex = 0;
-    bool secured = false;
-    if (strncmp(COAP_PREFIX, uri, COAP_PREFIX_LEN) == 0)
-    {
-        OIC_LOG_V(DEBUG, TAG, "uri has '%s' prefix.", COAP_PREFIX);
-        startIndex = COAP_PREFIX_LEN;
-    }
-
-    if (strncmp(COAPS_PREFIX, uri, COAPS_PREFIX_LEN) == 0)
-    {
-        OIC_LOG_V(DEBUG, TAG, "uri has '%s' prefix.", COAPS_PREFIX);
-        startIndex = COAPS_PREFIX_LEN;
-        secured = true;
-    }
-
-    // #2. copy uri for parse
-    int32_t len = strlen(uri) - startIndex;
-
-    if (len <= 0)
-    {
-        OIC_LOG(ERROR, TAG, "uri length is 0!");
-        return NULL;
-    }
-
-    char *cloneUri = (char *) OICCalloc(len + 1, sizeof(char));
-    if (NULL == cloneUri)
-    {
-        OIC_LOG(ERROR, TAG, "CACreateRemoteEndpointUriInternal Out of memory");
-        return NULL;
-    }
-
-    memcpy(cloneUri, &uri[startIndex], sizeof(char) * len);
-    cloneUri[len] = '\0';
-
-    // #3. parse address
-    // #4. parse resource uri
-    char *pAddress = cloneUri;
-    char *pResourceUri = NULL;
-
-    int32_t i = 0;
-    for (i = 0; i < len; i++)
-    {
-        if (cloneUri[i] == '/')
-        {
-            // separate
-            cloneUri[i] = 0;
-
-            pResourceUri = &cloneUri[i + 1];
-
-            break;
-        }
-
-    }
-
-    OIC_LOG_V(DEBUG, TAG, "pAddress : %s", pAddress);
-
-    OIC_LOG_V(DEBUG, TAG, "pResourceUri : %s", pResourceUri == NULL ? "" : pResourceUri);
-
-    // address
-    CAAddress_t address = {};
-
-    int resType = getCAAddress(pAddress, &address);
-    if (resType == -1)
-    {
-        OIC_LOG(DEBUG, TAG, "address parse error");
-
-        OICFree(cloneUri);
-        return NULL;
-    }
-
-    // resource uri
-    CAURI_t resourceUri = pResourceUri;
-
-    CARemoteEndpoint_t *remoteEndpoint = CACreateRemoteEndpointInternal(resourceUri, address,
-                                                                        transportType);
-    if (NULL == remoteEndpoint)
-    {
-        OIC_LOG(ERROR, TAG, "create remote endpoint fail");
-
-        OICFree(cloneUri);
-        return NULL;
-    }
-    remoteEndpoint->isSecured = secured;
-
-    OICFree(cloneUri);
-
-    OIC_LOG_V(DEBUG, TAG, "Remote endpoint successfully created [%d]!", remoteEndpoint->isSecured);
-    return remoteEndpoint;
-}
-
-CARemoteEndpoint_t *CACreateRemoteEndpointInternal(const CAURI_t resourceUri,
-                                                   const CAAddress_t addr,
-                                                   const CATransportType_t type)
-{
-    if (NULL == resourceUri)
-    {
-        OIC_LOG(ERROR, TAG, "uri is null value");
-        return NULL;
-    }
-
-    // allocate the remote end point structure.
-    CARemoteEndpoint_t *rep = (CARemoteEndpoint_t *) OICCalloc(1, sizeof(CARemoteEndpoint_t));
-
-    if (NULL == rep)
-    {
-        OIC_LOG(ERROR, TAG, "CACreateRemoteEndpointInternal of memory");
-        return NULL;
-    }
-
-    // allocate reference uri field
-    char *temp = OICStrdup(resourceUri);
-    if (NULL == temp)
-    {
-        OIC_LOG(ERROR, TAG, "CACreateRemoteEndpointInternal Out of memory");
-
-        CADestroyRemoteEndpointInternal(rep);
-
-        return NULL;
-    }
-
-    // save the uri
-    rep->resourceUri = temp;
-
-    // save the addressInfo
-    rep->addressInfo = addr;
-
-    // save the type
-    rep->transportType = type;
-
-    return rep;
-}
-
 CARequestInfo_t *CACloneRequestInfo(const CARequestInfo_t *rep)
 {
     if (NULL == rep)
@@ -478,18 +236,8 @@ CAResponseInfo_t *CACloneResponseInfo(const CAResponseInfo_t *rep)
     return clone;
 }
 
-void CADestroyRemoteEndpointInternal(CARemoteEndpoint_t *rep)
+void CADestroyEndpointInternal(CAEndpoint_t *rep)
 {
-    if (NULL == rep)
-    {
-        OIC_LOG(ERROR, TAG, "parameter is null");
-        return;
-    }
-
-    // free uri field
-    OICFree((char *) rep->resourceUri);
-
-    // free remote end point structure.
     OICFree(rep);
 }
 
index aeb2b5d..37b97fb 100644 (file)
@@ -67,7 +67,7 @@ typedef struct
     uint64_t timeout;                   /**< timeout value. microseconds */
     uint8_t triedCount;                 /**< retransmission count */
     uint16_t messageId;                 /**< coap PDU message id */
-    CARemoteEndpoint_t *endpoint;       /**< remote endpoint */
+    CAEndpoint_t *endpoint;             /**< remote endpoint */
     void *pdu;                          /**< coap PDU */
     uint32_t size;                      /**< coap PDU size */
 } CARetransmissionData_t;
@@ -97,7 +97,7 @@ static bool CACheckTimeout(uint64_t currentTime, uint64_t timeStamp, uint64_t ti
 
     if (currentTime >= timeStamp + timeout)
     {
-        OIC_LOG_V(DEBUG, TAG, "%d microseconds time out!!, tried count(%d)", timeout, triedCount);
+        OIC_LOG_V(DEBUG, TAG, "%d microseconds time out!!, tried count(%ld)", timeout, triedCount);
         return true;
     }
 
@@ -174,7 +174,7 @@ static void CACheckRetransmissionList(CARetransmission_t *context)
                                              removedData->size);
                 }
 
-                CADestroyRemoteEndpointInternal(removedData->endpoint);
+                CADestroyEndpointInternal(removedData->endpoint);
                 OICFree(removedData->pdu);
 
                 OICFree(removedData);
@@ -227,7 +227,7 @@ static void CARetransmissionBaseRoutine(void *threadValue)
         else if (!context->isStop)
         {
             // check each RETRANSMISSION_CHECK_PERIOD_SEC time.
-            OIC_LOG_V(DEBUG, TAG, "wait..(%d)microseconds",
+            OIC_LOG_V(DEBUG, TAG, "wait..(%ld)microseconds",
                       RETRANSMISSION_CHECK_PERIOD_SEC * (uint64_t) USECS_PER_SEC);
 
             // wait
@@ -333,8 +333,8 @@ CAResult_t CARetransmissionStart(CARetransmission_t *context)
 }
 
 CAResult_t CARetransmissionSentData(CARetransmission_t *context,
-                                    const CARemoteEndpoint_t* endpoint, const void* pdu,
-                                    uint32_t size)
+                                    const CAEndpoint_t *endpoint,
+                                    const void *pdu, uint32_t size)
 {
     if (NULL == context || NULL == endpoint || NULL == pdu)
     {
@@ -343,10 +343,10 @@ CAResult_t CARetransmissionSentData(CARetransmission_t *context,
     }
 
     // #0. check support transport type
-    if (!(context->config.supportType & endpoint->transportType))
+    if (!(context->config.supportType & endpoint->adapter))
     {
         OIC_LOG_V(DEBUG, TAG, "not supported transport type for retransmission..(%d)",
-                  endpoint->transportType);
+                  endpoint->adapter);
         return CA_NOT_SUPPORTED;
     }
 
@@ -383,7 +383,7 @@ CAResult_t CARetransmissionSentData(CARetransmission_t *context,
     memcpy(pduData, pdu, size);
 
     // clone remote endpoint
-    CARemoteEndpoint_t *remoteEndpoint = CACloneRemoteEndpoint(endpoint);
+    CAEndpoint_t *remoteEndpoint = CACloneEndpoint(endpoint);
     if (NULL == remoteEndpoint)
     {
         OICFree(retData);
@@ -419,7 +419,7 @@ CAResult_t CARetransmissionSentData(CARetransmission_t *context,
 
         // found index
         if (NULL != currData->endpoint && currData->messageId == messageId
-            && (currData->endpoint->transportType == endpoint->transportType))
+            && (currData->endpoint->adapter == endpoint->adapter))
         {
             OIC_LOG(ERROR, TAG, "Duplicate message ID");
 
@@ -445,7 +445,7 @@ CAResult_t CARetransmissionSentData(CARetransmission_t *context,
 }
 
 CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
-                                        const CARemoteEndpoint_t *endpoint, const void *pdu,
+                                        const CAEndpoint_t *endpoint, const void *pdu,
                                         uint32_t size, void **retransmissionPdu)
 {
     OIC_LOG(DEBUG, TAG, "IN - CARetransmissionReceivedData");
@@ -456,10 +456,10 @@ CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
     }
 
     // #0. check support transport type
-    if (!(context->config.supportType & endpoint->transportType))
+    if (!(context->config.supportType & endpoint->adapter))
     {
         OIC_LOG_V(DEBUG, TAG, "not supported transport type for retransmission..(%d)",
-                  endpoint->transportType);
+                  endpoint->adapter);
         return CA_STATUS_OK;
     }
 
@@ -493,7 +493,7 @@ CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
 
         // found index
         if (NULL != retData->endpoint && retData->messageId == messageId
-            && (retData->endpoint->transportType == endpoint->transportType))
+            && (retData->endpoint->adapter == endpoint->adapter))
         {
             // get pdu data for getting token when CA_EMPTY(RST/ACK) is received from remote device
             // if retransmission was finish..token will be unavailable.
@@ -541,7 +541,7 @@ CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
             OIC_LOG_V(DEBUG, TAG, "remove retransmission CON data!!, message id(%d)",
                       messageId);
 
-            CADestroyRemoteEndpointInternal(removedData->endpoint);
+            CADestroyEndpointInternal(removedData->endpoint);
             OICFree(removedData->pdu);
             OICFree(removedData);
 
@@ -612,7 +612,7 @@ uint64_t getCurrentTimeInMicroSeconds()
     clock_gettime(CLOCK_MONOTONIC, &getTs);
 
     currentTime = (getTs.tv_sec * (uint64_t)1000000000 + getTs.tv_nsec)/1000;
-    OIC_LOG_V(DEBUG, TAG, "current time = %d", currentTime);
+    OIC_LOG_V(DEBUG, TAG, "current time = %ld", currentTime);
 #else
 #if _POSIX_TIMERS > 0
     struct timespec ts;
index d7d9dba..2665b2c 100644 (file)
@@ -46,7 +46,7 @@ typedef struct
     uint16_t messageId;
 
     /** remote endpoint **/
-    CARemoteEndpoint_t *endpoint;
+    CAEndpoint_t *endpoint;
 
     /** coap PDU **/
     void *pdu;
@@ -145,7 +145,7 @@ void CACheckRetransmissionList()
                                                      removedData->size);
             }
 
-            CADestroyRemoteEndpointInternal(removedData->endpoint);
+            CADestroyEndpointInternal(removedData->endpoint);
             OICFree(removedData->pdu);
 
             OICFree(removedData);
@@ -195,7 +195,7 @@ CAResult_t CARetransmissionInitialize(CARetransmission_t *context,
     if (NULL == config)
     {
         // setDefault
-        cfg.supportType = (CATransportType_t) DEFAULT_RETRANSMISSION_TYPE;
+        cfg.supportType = (CATransportAdapter_t) DEFAULT_RETRANSMISSION_TYPE;
         cfg.tryingCount = DEFAULT_RETRANSMISSION_COUNT;
     }
     else
@@ -216,7 +216,7 @@ CAResult_t CARetransmissionInitialize(CARetransmission_t *context,
     return CA_STATUS_OK;
 }
 
-CAResult_t CARetransmissionSentData(CARetransmission_t *context, const CARemoteEndpoint_t *endpoint,
+CAResult_t CARetransmissionSentData(CARetransmission_t *context, const CAEndpoint_t *endpoint,
                                     const void *pdu, uint32_t size)
 {
     OIC_LOG(DEBUG, TAG, "IN");
@@ -227,7 +227,7 @@ CAResult_t CARetransmissionSentData(CARetransmission_t *context, const CARemoteE
     }
 
     // #0. check support connectivity type
-    if (!(context->config.supportType & endpoint->transportType))
+    if (!(context->config.supportType & endpoint->adapter))
     {
         OIC_LOG(ERROR, TAG, "error");
         OIC_LOG_V(ERROR, TAG, "not supported conntype=%d", endpoint->transportType);
@@ -267,7 +267,7 @@ CAResult_t CARetransmissionSentData(CARetransmission_t *context, const CARemoteE
     memcpy(pduData, pdu, size);
 
     // clone remote endpoint
-    CARemoteEndpoint_t *remoteEndpoint = CACloneRemoteEndpoint(endpoint);
+    CAEndpoint_t *remoteEndpoint = CACloneEndpoint(endpoint);
     if (NULL == remoteEndpoint)
     {
         OICFree(retData);
@@ -295,7 +295,7 @@ CAResult_t CARetransmissionSentData(CARetransmission_t *context, const CARemoteE
 }
 
 CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
-                                        const CARemoteEndpoint_t *endpoint, const void *pdu,
+                                        const CAEndpoint_t *endpoint, const void *pdu,
                                         uint32_t size, void **retransmissionPdu)
 {
     OIC_LOG(DEBUG, TAG, "IN");
@@ -306,9 +306,9 @@ CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
     }
 
     // #0. check support connectivity type
-    if (!(context->config.supportType & endpoint->transportType))
+    if (!(context->config.supportType & endpoint->adapter))
     {
-        OIC_LOG_V(DEBUG, TAG, "not supp conntype=%d", endpoint->transportType);
+        OIC_LOG_V(DEBUG, TAG, "not supp conntype=%d", endpoint->adapter);
         return CA_STATUS_OK;
     }
 
@@ -339,7 +339,7 @@ CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
 
         // found index
         if (NULL != retData->endpoint && retData->messageId == messageId
-            && (retData->endpoint->transportType == endpoint->transportType))
+            && (retData->endpoint->adapter == endpoint->adapter))
         {
             // get pdu data for getting token when CA_EMPTY(RST/ACK) is received from remote device
             // if retransmission was finish..token will be unavailable.
@@ -376,7 +376,7 @@ CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
 
             OIC_LOG_V(DEBUG, TAG, "remove RTCON data, msgid=%d", messageId);
 
-            CADestroyRemoteEndpointInternal(removedData->endpoint);
+            CADestroyEndpointInternal(removedData->endpoint);
             OICFree(removedData->pdu);
 
             OICFree(removedData);
index f000980..cc5bb9e 100644 (file)
@@ -8,6 +8,7 @@ print "Reading IP adapter script"
 
 target_os = env.get('TARGET_OS')
 inc_files = env.get('CPPPATH')
+secured = env.get('SECURED')
 src_dir = './ip_adapter/'
 
 if target_os == 'tizen':
@@ -18,9 +19,9 @@ if target_os == 'arduino':
        env.AppendUnique(CA_SRC=[src_dir+'caipadapter_singlethread.c'])
        env.AppendUnique(CPPPATH=[src_dir+'arduino/'])
 else:
-      env.AppendUnique(CA_SRC=[src_dir+'caipadapter.c'])
-      env.AppendUnique(CA_SRC=[src_dir+'caipclient.c'])
-      env.AppendUnique(CA_SRC=[src_dir+'caipserver.c'])
+       env.AppendUnique(CA_SRC=[src_dir+'caipadapter.c'])
+       env.AppendUnique(CA_SRC=[src_dir+'caipclient.c'])
+       env.AppendUnique(CA_SRC=[src_dir+'caipserver.c'])
 
 #Source files to build in Linux platform
 if target_os in ['linux','darwin','ios']:
index efa6e67..cbb1a41 100644 (file)
  */
 typedef struct
 {
-    CARemoteEndpoint_t *remoteEndpoint;
+    CAEndpoint_t *remoteEndpoint;
     void *data;
     uint32_t dataLen;
+    bool isMulticast;
 } CAIPData;
 
 /**
@@ -110,20 +111,20 @@ static void CAIPNotifyNetworkChange(const char *address, uint16_t port,
 
 static void CAIPConnectionStateCB(const char *ipAddress, CANetworkStatus_t status);
 
-static void CAIPPacketReceivedCB(const char *ipAddress, uint16_t port, const void *data,
-                                       uint32_t dataLength, bool isSecured,
-                                       const CARemoteId_t *identity);
+static void CAIPPacketReceivedCB(const CAEndpoint_t *endpoint,
+                                        const void *data, uint32_t dataLength);
 #ifdef __WITH_DTLS__
-static uint32_t CAIPPacketSendCB(const char *ipAddress, uint16_t port,
-                                       const void *data, uint32_t dataLength);
+static uint32_t CAIPPacketSendCB(const CAEndpoint_t *endpoint,
+                                        const void *data, uint32_t dataLength);
 #endif
 
 static CAResult_t CAIPStopServers();
 
 static void CAIPSendDataThread(void *threadData);
 
-static CAIPData *CACreateIPData(const CARemoteEndpoint_t *remoteEndpoint,
-                                            const void *data, uint32_t dataLength);
+static CAIPData *CACreateIPData(const CAEndpoint_t *remoteEndpoint,
+                                         const void *data, uint32_t dataLength,
+                                         bool isMulticast);
 void CAFreeIPData(CAIPData *ipData);
 
 static void CADataDestroyer(void *data, uint32_t size);
@@ -177,15 +178,13 @@ void CAIPNotifyNetworkChange(const char *address, uint16_t port, CANetworkStatus
 
     VERIFY_NON_NULL_VOID(address, IP_ADAPTER_TAG, "address is NULL");
 
-    CALocalConnectivity_t *localEndpoint = CAAdapterCreateLocalEndpoint(CA_IPV4, address);
+    CAEndpoint_t *localEndpoint = CAAdapterCreateEndpoint(0, CA_ADAPTER_IP, address, port);
     if (!localEndpoint)
     {
         OIC_LOG(ERROR, IP_ADAPTER_TAG, "localEndpoint creation failed!");
         return;
     }
 
-    localEndpoint->addressInfo.IP.port = port;
-
     if (g_networkChangeCallback)
     {
         g_networkChangeCallback(localEndpoint, status);
@@ -195,7 +194,7 @@ void CAIPNotifyNetworkChange(const char *address, uint16_t port, CANetworkStatus
         OIC_LOG(ERROR, IP_ADAPTER_TAG, "g_networkChangeCallback is NULL");
     }
 
-    CAAdapterFreeLocalEndpoint(localEndpoint);
+    CAAdapterFreeEndpoint(localEndpoint);
 
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
 }
@@ -259,16 +258,14 @@ void CAIPConnectionStateCB(const char *ipAddress, CANetworkStatus_t status)
 }
 
 #ifdef __WITH_DTLS__
-uint32_t CAIPPacketSendCB(const char *ipAddress, uint16_t port,
-        const void *data, uint32_t dataLength)
+uint32_t CAIPPacketSendCB(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLength)
 {
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
 
-    VERIFY_NON_NULL_RET(ipAddress, IP_ADAPTER_TAG, "ipAddress is NULL", 0);
-
+    VERIFY_NON_NULL_RET(endpoint, IP_ADAPTER_TAG, "endpoint is NULL", 0);
     VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "data is NULL", 0);
 
-    uint32_t sentLength = CAIPSendData(ipAddress, port, data, dataLength, false, true);
+    uint32_t sentLength = CAIPSendData(endpoint, data, dataLength, false);
 
     OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Successfully sent %d of encrypted data!", sentLength);
 
@@ -278,57 +275,39 @@ uint32_t CAIPPacketSendCB(const char *ipAddress, uint16_t port,
 }
 #endif
 
-void CAIPPacketReceivedCB(const char *ipAddress, uint16_t port, const void *data,
-                                uint32_t dataLength, bool isSecured,
-                                const CARemoteId_t *identity)
+void CAIPPacketReceivedCB(const CAEndpoint_t *endpoint, const void *data,
+                                uint32_t dataLength)
 {
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
 
-    VERIFY_NON_NULL_VOID(ipAddress, IP_ADAPTER_TAG, "ipAddress is NULL");
-
+    VERIFY_NON_NULL_VOID(endpoint, IP_ADAPTER_TAG, "ipAddress is NULL");
     VERIFY_NON_NULL_VOID(data, IP_ADAPTER_TAG, "data is NULL");
 
-    OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Address: %s, port:%d", ipAddress, port);
+    OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Address: %s, port:%d", endpoint->addr, endpoint->port);
 
-    // CA is freeing this memory
-    CARemoteEndpoint_t *endPoint = CAAdapterCreateRemoteEndpoint(CA_IPV4, ipAddress, NULL );
-    if (!endPoint)
-    {
-        OIC_LOG(ERROR, IP_ADAPTER_TAG, "EndPoint creation failed!");
-        return;
-    }
-    endPoint->addressInfo.IP.port = port;
-    endPoint->isSecured = isSecured;
-    if (identity)
-    {
-        endPoint->identity = *identity;
-    }
-
-
-    void *buf = OICCalloc(dataLength + 1, sizeof(char));
+    void *buf = OICCalloc(dataLength + 1, sizeof (char));
     if (!buf)
     {
         OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory Allocation failed!");
-        CAAdapterFreeRemoteEndpoint(endPoint);
         return;
     }
     memcpy(buf, data, dataLength);
+
     if (g_networkPacketCallback)
     {
-        g_networkPacketCallback(endPoint, buf, dataLength);
+        g_networkPacketCallback(endpoint, buf, dataLength);
     }
     else
     {
         OICFree(buf);
-        CAAdapterFreeRemoteEndpoint(endPoint);
     }
 
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
 }
 
 CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
-                                CANetworkPacketReceivedCallback networkPacketCallback,
-                                CANetworkChangeCallback netCallback, ca_thread_pool_t handle)
+                          CANetworkPacketReceivedCallback networkPacketCallback,
+                          CANetworkChangeCallback netCallback, ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
     VERIFY_NON_NULL(registerCallback, IP_ADAPTER_TAG, "registerCallback");
@@ -360,7 +339,7 @@ CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
 #ifdef __WITH_DTLS__
     CAAdapterNetDtlsInit();
 
-    CADTLSSetAdapterCallbacks(CAIPPacketReceivedCB, CAIPPacketSendCB, CA_IPV4);
+    CADTLSSetAdapterCallbacks(CAIPPacketReceivedCB, CAIPPacketSendCB, 0);
 #endif
 
     CAConnectivityHandler_t ipHandler;
@@ -373,7 +352,7 @@ CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
     ipHandler.readData = CAReadIPData;
     ipHandler.stopAdapter = CAStopIP;
     ipHandler.terminate = CATerminateIP;
-    registerCallback(ipHandler, CA_IPV4);
+    registerCallback(ipHandler, CA_ADAPTER_IP);
 
     if (CA_STATUS_OK != CAIPInitializeQueueHandles())
     {
@@ -512,8 +491,8 @@ CAResult_t CAStartIPDiscoveryServer()
     return CAStartIPListeningServer();
 }
 
-int32_t CASendIPUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
-                                  uint32_t dataLength)
+int32_t CASendIPUnicastData(const CAEndpoint_t *remoteEndpoint,
+                            const void *data, uint32_t dataLength)
 {
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
 
@@ -528,7 +507,7 @@ int32_t CASendIPUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void
     }
 
     // Create IPData to add to queue
-    CAIPData *ipData = CACreateIPData(remoteEndpoint, data, dataLength);
+    CAIPData *ipData = CACreateIPData(remoteEndpoint, data, dataLength, false);
     if (!ipData)
     {
         OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to create ipData!");
@@ -544,7 +523,7 @@ int32_t CASendIPUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void
     }
 }
 
-int32_t CASendIPMulticastData(const void *data, uint32_t dataLength)
+int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLength)
 {
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
 
@@ -558,7 +537,7 @@ int32_t CASendIPMulticastData(const void *data, uint32_t dataLength)
     }
 
     // Create IPData to add to queue
-    CAIPData *ipData = CACreateIPData(NULL, data, dataLength);
+    CAIPData *ipData = CACreateIPData(endpoint, data, dataLength, true);
     if (!ipData)
     {
         OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to create ipData!");
@@ -574,7 +553,7 @@ int32_t CASendIPMulticastData(const void *data, uint32_t dataLength)
     }
 }
 
-CAResult_t CAGetIPInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size)
+CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
 {
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
 
@@ -611,8 +590,7 @@ CAResult_t CAGetIPInterfaceInformation(CALocalConnectivity_t **info, uint32_t *s
     }
 #endif
 
-    CALocalConnectivity_t *conInfo = (CALocalConnectivity_t *) OICCalloc(
-                                      netInfoSize, sizeof(CALocalConnectivity_t));
+    CAEndpoint_t *conInfo = (CAEndpoint_t *)OICCalloc(netInfoSize, sizeof (CAEndpoint_t));
     if (!conInfo)
     {
         OIC_LOG(ERROR, IP_ADAPTER_TAG, "Malloc Failed");
@@ -630,23 +608,23 @@ CAResult_t CAGetIPInterfaceInformation(CALocalConnectivity_t **info, uint32_t *s
             continue;
         }
 
-        conInfo[count].type = CA_IPV4;
-        conInfo[count].isSecured = false;
-        conInfo[count].addressInfo.IP.port = CAGetServerPortNum(netInfo->ipAddress, false);
-        OICStrcpy(conInfo[count].addressInfo.IP.ipAddress,
-                  sizeof(conInfo[count].addressInfo.IP.ipAddress),
+        conInfo[count].adapter = CA_ADAPTER_IP;
+        conInfo[count].flags = 0;
+        conInfo[count].port = CAGetServerPortNum(netInfo->ipAddress, false);
+        OICStrcpy(conInfo[count].addr,
+                  sizeof(conInfo[count].addr),
                   netInfo->ipAddress);
 
 #ifdef __WITH_DTLS__
         // copy secure unicast server information
         {
             count ++;
-            conInfo[count].type = CA_IPV4;
-            conInfo[count].isSecured = true;
-            conInfo[count].addressInfo.IP.port = CAGetServerPortNum(netInfo->ipAddress, true);
-            OICStrcpy(conInfo[count].addressInfo.IP.ipAddress,
-                      sizeof(conInfo[count].addressInfo.IP.ipAddress),
-                      netInfo->ipAddress);
+            conInfo[count].adapter = CA_ADAPTER_IP;
+            conInfo[count].flags = CA_SECURE;
+            conInfo[count].port = CAGetServerPortNum(netInfo->ipAddress, true);
+            OICStrcpy(conInfo[count].addr,
+                  sizeof(conInfo[count].addr),
+                  netInfo->ipAddress);
         }
 #endif
         count ++;
@@ -713,7 +691,7 @@ void CATerminateIP()
     CAStopIP();
 
 #ifdef __WITH_DTLS__
-    CADTLSSetAdapterCallbacks(NULL, NULL, CA_IPV4);
+    CADTLSSetAdapterCallbacks(NULL, NULL, 0);
 #endif
 
     CAIPSetPacketReceiveCallback(NULL);
@@ -742,26 +720,23 @@ void CAIPSendDataThread(void *threadData)
         return;
     }
 
-    //If remoteEndpoint is NULL, its Multicast, else its Unicast.
-    if (ipData->remoteEndpoint)
+    if (ipData->isMulticast)
+    {
+        //Processing for sending multicast
+        OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Multicast Data is called");
+        strncpy(ipData->remoteEndpoint->addr, CA_MULTICAST_IP, MAX_ADDR_STR_SIZE_CA);
+        ipData->remoteEndpoint->port = CA_MCAST_PORT;
+        CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, true);
+    }
+    else
     {
         //Processing for sending unicast
-        char *address = ipData->remoteEndpoint->addressInfo.IP.ipAddress;
-        uint16_t port = ipData->remoteEndpoint->addressInfo.IP.port;
-
 #ifdef __WITH_DTLS__
-        if (!ipData->remoteEndpoint->isSecured)
-        {
-            OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Unicast Data is called");
-            CAIPSendData(address, port, ipData->data, ipData->dataLen, false,
-                               ipData->remoteEndpoint->isSecured);
-        }
-        else
+        if (ipData->remoteEndpoint->flags & CA_SECURE)
         {
             OIC_LOG(DEBUG, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt called!");
-            CAResult_t result = CAAdapterNetDtlsEncrypt(address, port, ipData->data,
-                                                        ipData->dataLen, CA_IPV4);
-
+            CAResult_t result = CAAdapterNetDtlsEncrypt(ipData->remoteEndpoint,
+                                               ipData->data, ipData->dataLen);
             if (CA_STATUS_OK != result)
             {
                 OIC_LOG(ERROR, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt failed!");
@@ -769,24 +744,21 @@ void CAIPSendDataThread(void *threadData)
             OIC_LOG_V(DEBUG, IP_ADAPTER_TAG,
                       "CAAdapterNetDtlsEncrypt returned with result[%d]", result);
         }
+        else
+        {
+            OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Unicast Data is called");
+            CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, false);
+        }
 #else
-        CAIPSendData(address, port, ipData->data, ipData->dataLen, false,
-                           ipData->remoteEndpoint->isSecured);
+        CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, false);
 #endif
     }
-    else
-    {
-        //Processing for sending multicast
-        OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Multicast Data is called");
-        CAIPSendData(CA_MULTICAST_IP, CA_MCAST_PORT, ipData->data,
-                           ipData->dataLen, true, false);
-    }
 
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
 }
 
-CAIPData *CACreateIPData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
-                                     uint32_t dataLength)
+CAIPData *CACreateIPData(const CAEndpoint_t *remoteEndpoint, const void *data,
+                                     uint32_t dataLength, bool isMulticast)
 {
     VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "IPData is NULL", NULL);
 
@@ -797,7 +769,7 @@ CAIPData *CACreateIPData(const CARemoteEndpoint_t *remoteEndpoint, const void *d
         return NULL;
     }
 
-    ipData->remoteEndpoint = CAAdapterCopyRemoteEndpoint(remoteEndpoint);
+    ipData->remoteEndpoint = CAAdapterCloneEndpoint(remoteEndpoint);
     ipData->data = (void *) OICMalloc(dataLength);
     if (!ipData->data)
     {
@@ -809,6 +781,8 @@ CAIPData *CACreateIPData(const CARemoteEndpoint_t *remoteEndpoint, const void *d
     memcpy(ipData->data, data, dataLength);
     ipData->dataLen = dataLength;
 
+    ipData->isMulticast = isMulticast;
+
     return ipData;
 }
 
@@ -816,7 +790,7 @@ void CAFreeIPData(CAIPData *ipData)
 {
     VERIFY_NON_NULL_VOID(ipData, IP_ADAPTER_TAG, "ipData is NULL");
 
-    CAAdapterFreeRemoteEndpoint(ipData->remoteEndpoint);
+    CAAdapterFreeEndpoint(ipData->remoteEndpoint);
     OICFree(ipData->data);
     OICFree(ipData);
 }
index 9a36455..0a8b6b7 100644 (file)
@@ -109,20 +109,20 @@ static CAResult_t CAIPStopServers();
 
 void CAIPNotifyNetworkChange(const char *address, uint16_t port, CANetworkStatus_t status)
 {
-    CALocalConnectivity_t *localEndpoint = CAAdapterCreateLocalEndpoint(CA_IPV4, address);
+    CAEndpoint_t *localEndpoint = CAAdapterCreateLocalEndpoint(CA_IPV4, address);
     if (!localEndpoint)
     {
         OIC_LOG(ERROR, TAG, "Out of memory!");
         return;
     }
-    localEndpoint->addressInfo.IP.port = port;
+    localEndpoint->port = port;
 
     if (NULL != g_networkChangeCallback)
     {
         g_networkChangeCallback(localEndpoint, status);
     }
 
-    CAAdapterFreeLocalEndpoint(localEndpoint);
+    CAAdapterFreeEndpoint(localEndpoint);
 }
 
 void CAIPConnectionStateCB(const char *ipAddr,
@@ -209,19 +209,18 @@ void CAIPPacketReceivedCB(const char *ipAddress, uint16_t port,
     OIC_LOG_V(DEBUG, TAG, "data:%s", data);
 
     /* CA is freeing this memory */
-    CARemoteEndpoint_t *endPoint = CAAdapterCreateRemoteEndpoint(CA_IPV4, ipAddress, NULL);
+    CAEndpoint_t *endPoint = CAAdapterCreateEndpoint(CA_DEFAULT_FLAGS, CA_IPV4, ipAddress, port);
     if (NULL == endPoint)
     {
         OIC_LOG(ERROR, TAG, "Out of memory!");
         return;
     }
-    endPoint->addressInfo.IP.port = port;
 
     if (g_networkPacketCallback)
     {
         g_networkPacketCallback(endPoint, data, dataLength);
     }
-    CAAdapterFreeRemoteEndpoint(endPoint);
+    CAAdapterFreeEndpoint(endPoint);
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
@@ -346,12 +345,11 @@ CAResult_t CAStartIPDiscoveryServer()
     return CAStartIPListeningServer();
 }
 
-int32_t CASendIPUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
-                                  uint32_t dataLength)
+int32_t CASendIPUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLength)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
-    VERIFY_NON_NULL_RET(remoteEndpoint, TAG, "remoteEndpoint", -1);
+    VERIFY_NON_NULL_RET(endpoint, TAG, "remoteEndpoint", -1);
     VERIFY_NON_NULL_RET(data, TAG, "data", -1);
     if (dataLength == 0)
     {
@@ -359,13 +357,12 @@ int32_t CASendIPUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void
         return -1;
     }
 
-    CAIPSendData(remoteEndpoint->addressInfo.IP.ipAddress,
-                       remoteEndpoint->addressInfo.IP.port, data, dataLength, false);
+    CAIPSendData(endpoint->addr, endpoint->port, data, dataLength, false);
     OIC_LOG(DEBUG, TAG, "OUT");
     return dataLength;
 }
 
-int32_t CASendIPMulticastData(const void *data, uint32_t dataLength)
+int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLength)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -381,7 +378,7 @@ int32_t CASendIPMulticastData(const void *data, uint32_t dataLength)
     return dataLength;
 }
 
-CAResult_t CAGetIPInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size)
+CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
 {
     OIC_LOG(DEBUG, TAG, "IN");
     VERIFY_NON_NULL(info, TAG, "info");
@@ -415,7 +412,7 @@ CAResult_t CAGetIPInterfaceInformation(CALocalConnectivity_t **info, uint32_t *s
         return CA_MEMORY_ALLOC_FAILED;
     }
 
-    (*info)->addressInfo.IP.port = g_unicastServerport;
+    (*info)->port = g_unicastServerport;
     (*size) = 1;
 
     OICFree(ipAddress);
index 2f9cfd0..ac902db 100644 (file)
 #define IP_CLIENT_TAG "IP_CLIENT"
 #define OC_MULTICAST_IP "224.0.1.187"
 
-static uint32_t CASendData(const char *remoteAddress, uint16_t port, const void *data,
+static uint32_t CASendData(const CAEndpoint_t *endpoint, const void *data,
                            uint32_t dataLength, int sockfd)
 {
     OIC_LOG(DEBUG, IP_CLIENT_TAG, "IN");
 
-    VERIFY_NON_NULL_RET(remoteAddress, IP_CLIENT_TAG, "IP address is NULL", 0);
+    VERIFY_NON_NULL_RET(endpoint, IP_CLIENT_TAG, "IP address is NULL", 0);
     VERIFY_NON_NULL_RET(data, IP_CLIENT_TAG, "data is NULL", 0);
 
     if (0 == dataLength)
@@ -56,9 +56,9 @@ static uint32_t CASendData(const char *remoteAddress, uint16_t port, const void
 
     struct sockaddr_in destAddr = { 0 };
     destAddr.sin_family = AF_INET;
-    destAddr.sin_port = htons(port);
+    destAddr.sin_port = htons(endpoint->port);
 
-    int ret = inet_pton(AF_INET, remoteAddress, &(destAddr.sin_addr));
+    int ret = inet_pton(AF_INET, endpoint->addr, &(destAddr.sin_addr));
     if (1 != ret)
     {
         OIC_LOG(ERROR, IP_CLIENT_TAG, "inet_pton failed!");
@@ -75,13 +75,13 @@ static uint32_t CASendData(const char *remoteAddress, uint16_t port, const void
     }
 
     OIC_LOG_V(INFO, IP_CLIENT_TAG, "Sending data is successful, sent bytes[%d] to ip[%s:%d]",
-              sendDataLength, remoteAddress, port);
+              sendDataLength, endpoint->addr, endpoint->port);
     OIC_LOG(DEBUG, IP_CLIENT_TAG, "OUT");
     return sendDataLength;
 }
 
-uint32_t CAIPSendData(const char *remoteAddress, uint16_t remotePort, const void *data,
-                            uint32_t dataLength, bool isMulticast, bool isSecured)
+uint32_t CAIPSendData(const CAEndpoint_t *endpoint, const void *data,
+                            uint32_t dataLength, bool isMulticast)
 {
     u_arraylist_t *tempServerInfoList = u_arraylist_create();
     if (!tempServerInfoList)
@@ -99,7 +99,7 @@ uint32_t CAIPSendData(const char *remoteAddress, uint16_t remotePort, const void
     }
 
     uint32_t len = 0;
-    if (isMulticast || strcmp(remoteAddress, OC_MULTICAST_IP) == 0)
+    if (isMulticast || strcmp(endpoint->addr, OC_MULTICAST_IP) == 0)
     {
         uint32_t listIndex = 0;
         uint32_t listLength = u_arraylist_length(tempServerInfoList);
@@ -107,7 +107,7 @@ uint32_t CAIPSendData(const char *remoteAddress, uint16_t remotePort, const void
         {
             CAServerInfo_t *info = (CAServerInfo_t *) u_arraylist_get(tempServerInfoList,
                                                                       listIndex);
-            if (!info || info->isMulticastServer || info->isSecured)
+            if (!info || info->isMulticastServer || (info->endpoint.flags & CA_SECURE))
             {
                 continue;
             }
@@ -119,16 +119,14 @@ uint32_t CAIPSendData(const char *remoteAddress, uint16_t remotePort, const void
             }
 
             OIC_LOG_V(DEBUG, IP_CLIENT_TAG,
-                      "CA IP Multicast SendData with src ip %s port %d sockFd %d",
-                      info->ipAddress, info->port, info->socketFd);
-            len = CASendData(remoteAddress, remotePort, data, dataLength, info->socketFd);
+                    "CA IP Multicast SendData with src ip %s port %d sockFd %d",
+                    info->endpoint.addr, info->endpoint.port, info->socketFd);
+            len = CASendData(endpoint, data, dataLength, info->socketFd);
         }
     }
     else
     {
-        int sockFd = CAGetSocketFdForUnicastServer(tempServerInfoList, remoteAddress, isSecured,
-                                                   isMulticast, CA_IPV4);
-
+        int sockFd = CAGetSocketFdForUnicastServer(tempServerInfoList, isMulticast, endpoint);
         if (sockFd < 0)
         {
             OIC_LOG(ERROR, IP_CLIENT_TAG, "Invalid Socket Fd");
@@ -138,7 +136,7 @@ uint32_t CAIPSendData(const char *remoteAddress, uint16_t remotePort, const void
 
         OIC_LOG_V(DEBUG, IP_CLIENT_TAG, "IP unicast SendData sockFd %d", sockFd);
 
-        len = CASendData(remoteAddress, remotePort, data, dataLength, sockFd);
+        len = CASendData(endpoint, data, dataLength, sockFd);
 
     }
     CAClearServerInfoList(tempServerInfoList);
index 35e4c77..75364fa 100644 (file)
@@ -205,7 +205,7 @@ static void CAReceiveHandler(void *data)
             {
                 OIC_LOG_V(ERROR, IP_SERVER_TAG,
                           "data Received server information ip %s, port %d socket %d",
-                          info->ipAddress, info->port, sd);
+                          info->endpoint.addr, info->endpoint.port, sd);
                 memset(recvBuffer, 0, sizeof(recvBuffer));
 
                 struct sockaddr_in srcSockAddress = { 0 };
@@ -262,12 +262,17 @@ static void CAReceiveHandler(void *data)
                 }
                 OICFree(netMask);
 
-                if (info->isSecured)
+                CAEndpoint_t ep;
+                strncpy(ep.addr, srcIPAddress, MAX_ADDR_STR_SIZE_CA);
+                ep.port = srcPort;
+                ep.flags = CA_IPV4;
+                ep.adapter = CA_ADAPTER_IP;
+
+                if (info->endpoint.flags & CA_SECURE)
                 {
 #ifdef __WITH_DTLS__
-                    CAResult_t ret = CAAdapterNetDtlsDecrypt(srcIPAddress, srcPort,
-                                                             (uint8_t *)recvBuffer, recvLen,
-                                                             CA_IPV4);
+                    ep.flags |= CA_SECURE;
+                    (void)CAAdapterNetDtlsDecrypt(&ep, (uint8_t *)recvBuffer, recvLen);
                     OIC_LOG_V(DEBUG, IP_SERVER_TAG,
                               "CAAdapterNetDtlsDecrypt returns [%d]", ret);
 #endif
@@ -278,9 +283,8 @@ static void CAReceiveHandler(void *data)
 
                     if (g_adapterEthServerContext->packetReceivedCallback)
                     {
-                        g_adapterEthServerContext->packetReceivedCallback(srcIPAddress, srcPort,
-                                                                          recvBuffer, recvLen,
-                                                                          false, NULL);
+                        g_adapterEthServerContext->packetReceivedCallback(&ep,
+                                                          recvBuffer, recvLen);
                     }
 
                     ca_mutex_unlock(g_mutexAdapterServerContext);
@@ -627,10 +631,11 @@ CAResult_t CAIPStartUnicastServer(const char *localAddress, uint16_t *port,
             OICStrcpy(info->subNetMask, sizeof(info->subNetMask), netMask);
             OICFree(netMask);
         }
-        OICStrcpy(info->ipAddress, sizeof(info->ipAddress), localAddress);
-        info->port = *port;
+        OICStrcpy(info->endpoint.addr, sizeof(info->endpoint.addr), localAddress);
+        info->endpoint.port = *port;
+        info->endpoint.flags = isSecured ? CA_SECURE : 0;
+        info->endpoint.adapter = CA_ADAPTER_IP;
         info->socketFd = unicastServerFd;
-        info->isSecured = isSecured;
         info->isServerStarted = true;
         info->isMulticastServer = false;
         OICStrcpy(info->ifAddr, sizeof(info->ifAddr), localAddress);
@@ -727,10 +732,10 @@ CAResult_t CAIPStartMulticastServer(const char *localAddress, const char *multic
             OICFree(netMask);
         }
 
-        OICStrcpy(info->ipAddress, sizeof(info->ipAddress), multicastAddress);
-        info->port = multicastPort;
+        OICStrcpy(info->endpoint.addr, sizeof(info->endpoint.addr), multicastAddress);
+        info->endpoint.port = multicastPort;
+        info->endpoint.flags = 0;
         info->socketFd = mulicastServerFd;
-        info->isSecured = false;
         info->isServerStarted = true;
         info->isMulticastServer = true;
         OICStrcpy(info->ifAddr, sizeof(info->ifAddr), localAddress);
@@ -792,7 +797,7 @@ CAResult_t CAIPStopServer(const char *interfaceAddress)
                 struct ip_mreq multicastMemberReq = { { 0 }, { 0 } };
 
                 multicastMemberReq.imr_interface.s_addr = inet_addr(info->ifAddr);
-                inet_aton(info->ipAddress, &multicastMemberReq.imr_multiaddr);
+                inet_aton(info->endpoint.addr, &multicastMemberReq.imr_multiaddr);
                 if (-1 == setsockopt(info->socketFd, IPPROTO_IP, IP_DROP_MEMBERSHIP,
                                      (char *) &multicastMemberReq, sizeof(struct ip_mreq)))
                 {
@@ -812,7 +817,7 @@ CAResult_t CAIPStopServer(const char *interfaceAddress)
                 return CA_STATUS_FAILED;
             }
         }
-        else if (strncmp(interfaceAddress, info->ipAddress, strlen(info->ipAddress)) == 0)
+        else if (strncmp(interfaceAddress, info->endpoint.addr, strlen(info->endpoint.addr)) == 0)
         {
             if (u_arraylist_remove(g_serverInfoList, listIndex))
             {
@@ -865,7 +870,7 @@ CAResult_t CAIPStopAllServers()
                 struct ip_mreq multicastMemberReq = { { 0 }, { 0 } };
 
                 multicastMemberReq.imr_interface.s_addr = inet_addr(info->ifAddr);
-                inet_aton(info->ipAddress, &multicastMemberReq.imr_multiaddr);
+                inet_aton(info->endpoint.addr, &multicastMemberReq.imr_multiaddr);
                 if (-1 == setsockopt(info->socketFd, IPPROTO_IP, IP_DROP_MEMBERSHIP,
                                      (char *) &multicastMemberReq, sizeof(struct ip_mreq)))
                 {
index bfc8bbd..cb566a8 100644 (file)
@@ -35,26 +35,23 @@ class CATests : public testing::Test {
     }
 };
 
-void request_handler(CARemoteEndpoint_t* object, CARequestInfo_t* requestInfo);
-void response_handler(CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo);
-void error_handler(const CARemoteEndpoint_t *object, const CAErrorInfo_t* errorInfo);
-
+void request_handler(CAEndpoint_t* object, CARequestInfo_t* requestInfo);
+void response_handler(CAEndpoint_t* object, CAResponseInfo_t* responseInfo);
+void error_handler(const CAEndpoint_t *object, const CAErrorInfo_t* errorInfo);
 CAResult_t checkGetNetworkInfo();
 CAResult_t checkSelectNetwork();
 
-
-
-void request_handler(const CARemoteEndpoint_t *object, const CARequestInfo_t *requestInfo)
+void request_handler(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo)
 {
 
 }
 
-void response_handler(const CARemoteEndpoint_t *object, const CAResponseInfo_t *responseInfo)
+void response_handler(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo)
 {
 
 }
 
-void error_handler(const CARemoteEndpoint_t *object, const CAErrorInfo_t* errorInfo)
+void error_handler(const CAEndpoint_t *object, const CAErrorInfo_t* errorInfo)
 {
     if(!object || !errorInfo)
     {
@@ -66,7 +63,7 @@ void error_handler(const CARemoteEndpoint_t *object, const CAErrorInfo_t* errorI
 }
 
 static char* uri = NULL;
-static CARemoteEndpoint_t* tempRep = NULL;
+static CAEndpoint_t* tempRep = NULL;
 static CARequestInfo_t requestInfo;
 static CAInfo_t requestData;
 static CAInfo_t responseData;
@@ -78,10 +75,10 @@ static const char RESOURCE_URI[] = "/a/light";
 
 static const char SECURE_INFO_DATA[] =
                                     "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
-                                     "\"if\":[\"oic.if.baseline\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}";
+                                     "\"if\":[\"oc.mi.def\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}";
 static const char NORMAL_INFO_DATA[] =
                                     "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
-                                     "\"if\":[\"oic.if.baseline\"],\"obs\":1}}]}";
+                                     "\"if\":[\"oc.mi.def\"],\"obs\":1}}]}";
 
 #ifdef __WITH_DTLS__
 
@@ -200,11 +197,11 @@ TEST_F(CATests, CreateRemoteEndpointTestGood)
 {
     uri = (char *) URI;
 
-    EXPECT_EQ(CA_STATUS_OK, CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep));
+    EXPECT_EQ(CA_STATUS_OK, CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, uri, 0, &tempRep));
 
     if (tempRep != NULL)
     {
-        CADestroyRemoteEndpoint(tempRep);
+        CADestroyEndpoint(tempRep);
         tempRep = NULL;
     }
 }
@@ -214,18 +211,13 @@ TEST_F(CATests, CreateRemoteEndpointTestValues)
 {
     uri = (char *) URI;
 
-    CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
+    CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, uri, 0, &tempRep);
 
     EXPECT_TRUE(tempRep != NULL);
 
     if (tempRep != NULL)
     {
-        EXPECT_STRNE(NULL, tempRep->resourceUri);
-    }
-
-    if (tempRep != NULL)
-    {
-        CADestroyRemoteEndpoint(tempRep);
+        CADestroyEndpoint(tempRep);
         tempRep = NULL;
     }
 }
@@ -235,48 +227,15 @@ TEST_F(CATests, CreateRemoteEndpointTestBad)
 {
     uri = NULL;
 
-    EXPECT_EQ(CA_STATUS_FAILED, CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep));
+    EXPECT_EQ(CA_STATUS_FAILED, CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, uri, 0, &tempRep));
 
     if (tempRep != NULL)
     {
-        CADestroyRemoteEndpoint(tempRep);
+        CADestroyEndpoint(tempRep);
         tempRep = NULL;
     }
 }
 
-// check values of remoteEndpoint when uri is NULL
-TEST_F(CATests, CreateRemoteEndpointTestWithNullUri)
-{
-    uri = NULL;
-    CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
-
-    if (tempRep != NULL)
-    {
-        EXPECT_STREQ(NULL, tempRep->resourceUri);
-
-    }
-
-    if (tempRep != NULL)
-    {
-        CADestroyRemoteEndpoint(tempRep);
-        tempRep = NULL;
-    }
-}
-
-// CADestroyRemoteEndpoint TC
-// check destroyed remoteEndpoint
-TEST_F(CATests, DestroyRemoteEndpointTest)
-{
-    uri = (char *) URI;
-    CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
-
-    CADestroyRemoteEndpoint(tempRep);
-    tempRep = NULL;
-
-    char * check = (char *) "destroy success";
-    EXPECT_STREQ(check, "destroy success");
-}
-
 // CAGerateToken TC
 // check return value
 TEST_F(CATests, GenerateTokenTestGood)
@@ -303,32 +262,12 @@ TEST_F(CATests, DestroyTokenTest)
     EXPECT_STREQ(check, "destroy success");
 }
 
-// CAFindResource TC
-// check return value
-TEST(FindResourceTest, DISABLED_TC_14_Positive_01)
-{
-    uri = (char *) RESOURCE_URI;
-
-    CAGenerateToken(&tempToken, tokenLength);
-    EXPECT_EQ(CA_STATUS_OK, CAFindResource(uri, tempToken, tokenLength));
-    CADestroyToken(tempToken);
-}
-
-// check return value when uri is NULL
-TEST_F(CATests, FindResourceTest)
-{
-    uri = NULL;
-    CAGenerateToken(&tempToken, tokenLength);
-    EXPECT_EQ(CA_STATUS_INVALID_PARAM, CAFindResource(uri, tempToken, tokenLength));
-    CADestroyToken(tempToken);
-}
-
 // CASendRequest TC
 // check return value
 TEST(SendRequestTest, DISABLED_TC_16_Positive_01)
 {
     uri = (char *) URI;
-    CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
+    CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, uri, 0, &tempRep);
 
     memset(&requestData, 0, sizeof(CAInfo_t));
     CAGenerateToken(&tempToken, tokenLength);
@@ -337,13 +276,11 @@ TEST(SendRequestTest, DISABLED_TC_16_Positive_01)
 
     int length = strlen(NORMAL_INFO_DATA) + strlen("a/light");
     requestData.payload = (CAPayload_t) calloc(length, sizeof(char));
-
     if(!requestData.payload)
     {
         CADestroyToken(tempToken);
         FAIL() << "requestData.payload allocation failed";
     }
-
     snprintf(requestData.payload, length, NORMAL_INFO_DATA, "a/light");
     requestData.type = CA_MSG_NONCONFIRM;
 
@@ -357,7 +294,7 @@ TEST(SendRequestTest, DISABLED_TC_16_Positive_01)
 
     free(requestData.payload);
 
-    CADestroyRemoteEndpoint(tempRep);
+    CADestroyEndpoint(tempRep);
     tempRep = NULL;
 
 }
@@ -366,7 +303,7 @@ TEST(SendRequestTest, DISABLED_TC_16_Positive_01)
 TEST_F(CATests, SendRequestTestWithNullURI)
 {
     uri = NULL;
-    CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
+    CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, uri, 0, &tempRep);
 
     memset(&requestData, 0, sizeof(CAInfo_t));
     CAGenerateToken(&tempToken, tokenLength);
@@ -375,13 +312,11 @@ TEST_F(CATests, SendRequestTestWithNullURI)
 
     int length = strlen(NORMAL_INFO_DATA) + strlen("a/light");
     requestData.payload = (CAPayload_t) calloc(length, sizeof(char));
-
     if(!requestData.payload)
     {
         CADestroyToken(tempToken);
         FAIL() << "requestData.payload allocation failed";
     }
-
     snprintf(requestData.payload, length, NORMAL_INFO_DATA, "a/light");
     requestData.type = CA_MSG_NONCONFIRM;
 
@@ -397,7 +332,7 @@ TEST_F(CATests, SendRequestTestWithNullURI)
 
     if (tempRep != NULL)
     {
-        CADestroyRemoteEndpoint(tempRep);
+        CADestroyEndpoint(tempRep);
         tempRep = NULL;
     }
 }
@@ -406,13 +341,13 @@ TEST_F(CATests, SendRequestTestWithNullURI)
 TEST_F(CATests, SendRequestTestWithNullAddr)
 {
     uri = (char *) URI;
-    CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
+    CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, uri, 0, &tempRep);
 
     EXPECT_EQ(CA_STATUS_INVALID_PARAM, CASendRequest(tempRep, NULL));
 
     if (tempRep != NULL)
     {
-        CADestroyRemoteEndpoint(tempRep);
+        CADestroyEndpoint(tempRep);
         tempRep = NULL;
     }
 }
@@ -422,7 +357,7 @@ TEST_F(CATests, SendRequestTestWithNullAddr)
 TEST(SendResponseTest, DISABLED_TC_19_Positive_01)
 {
     uri = (char *) URI;
-    CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
+    CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, uri, 0, &tempRep);
 
     memset(&responseData, 0, sizeof(CAInfo_t));
     responseData.type = CA_MSG_NONCONFIRM;
@@ -440,7 +375,7 @@ TEST(SendResponseTest, DISABLED_TC_19_Positive_01)
     EXPECT_EQ(CA_STATUS_OK, CASendResponse(tempRep, &responseInfo));
 
     CADestroyToken(tempToken);
-    CADestroyRemoteEndpoint(tempRep);
+    CADestroyEndpoint(tempRep);
     tempRep = NULL;
 }
 
@@ -448,7 +383,7 @@ TEST(SendResponseTest, DISABLED_TC_19_Positive_01)
 TEST(SendResponseTest, DISABLED_TC_20_Negative_01)
 {
     uri = NULL;
-    CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
+    CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, uri, 0, &tempRep);
 
     memset(&responseData, 0, sizeof(CAInfo_t));
     responseData.type = CA_MSG_NONCONFIRM;
@@ -468,7 +403,7 @@ TEST(SendResponseTest, DISABLED_TC_20_Negative_01)
     CADestroyToken(tempToken);
     if (tempRep != NULL)
     {
-        CADestroyRemoteEndpoint(tempRep);
+        CADestroyEndpoint(tempRep);
         tempRep = NULL;
     }
 }
@@ -477,13 +412,13 @@ TEST(SendResponseTest, DISABLED_TC_20_Negative_01)
 TEST_F(CATests, SendResponseTest)
 {
     uri = (char *) URI;
-    CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
+    CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, uri, 0, &tempRep);
 
     EXPECT_EQ(CA_STATUS_INVALID_PARAM, CASendResponse(tempRep, NULL));
 
     if (tempRep != NULL)
     {
-        CADestroyRemoteEndpoint(tempRep);
+        CADestroyEndpoint(tempRep);
         tempRep = NULL;
     }
 }
@@ -493,7 +428,7 @@ TEST_F(CATests, SendResponseTest)
 TEST(SendNotificationTest, DISABLED_TC_22_Positive_01)
 {
     uri = (char *) URI;
-    CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
+    CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, uri, 0, &tempRep);
 
     memset(&responseData, 0, sizeof(CAInfo_t));
     responseData.type = CA_MSG_NONCONFIRM;
@@ -512,7 +447,7 @@ TEST(SendNotificationTest, DISABLED_TC_22_Positive_01)
     CADestroyToken(tempToken);
     if (tempRep != NULL)
     {
-        CADestroyRemoteEndpoint(tempRep);
+        CADestroyEndpoint(tempRep);
         tempRep = NULL;
     }
 }
@@ -521,7 +456,7 @@ TEST(SendNotificationTest, DISABLED_TC_22_Positive_01)
 TEST_F(CATests, SendNotificationTest)
 {
     uri = NULL;
-    CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
+    CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, uri, 0, &tempRep);
 
     memset(&responseData, 0, sizeof(CAInfo_t));
     responseData.type = CA_MSG_NONCONFIRM;
@@ -540,88 +475,11 @@ TEST_F(CATests, SendNotificationTest)
     CADestroyToken(tempToken);
     if (tempRep != NULL)
     {
-        CADestroyRemoteEndpoint(tempRep);
+        CADestroyEndpoint(tempRep);
         tempRep = NULL;
     }
 }
 
-// CAAdvertiseResource TC
-// check return value
-TEST(AdvertiseResourceTest, DISABLED_TC_24_Positive_01)
-{
-    uri = (char *) RESOURCE_URI;
-    int optionNum = 2;
-
-    CAHeaderOption_t* headerOpt;
-    headerOpt = (CAHeaderOption_t *) calloc(1, optionNum * sizeof(CAHeaderOption_t));
-
-    if(!headerOpt)
-    {
-        FAIL() <<"Allocation for headerOpt failed";
-    }
-
-    char* tmpOptionData1 = (char *) "Hello";
-    size_t tmpOptionDataLen = (strlen(tmpOptionData1) < CA_MAX_HEADER_OPTION_DATA_LENGTH) ?
-            strlen(tmpOptionData1) : CA_MAX_HEADER_OPTION_DATA_LENGTH - 1;
-    headerOpt[0].optionID = 3000;
-    memcpy(headerOpt[0].optionData, tmpOptionData1, tmpOptionDataLen);
-    headerOpt[0].optionLength = (uint16_t) tmpOptionDataLen;
-
-    char* tmpOptionData2 = (char *) "World";
-    tmpOptionDataLen = (strlen(tmpOptionData2) < CA_MAX_HEADER_OPTION_DATA_LENGTH) ?
-                strlen(tmpOptionData2) : CA_MAX_HEADER_OPTION_DATA_LENGTH - 1;
-    headerOpt[1].optionID = 3001;
-    memcpy(headerOpt[1].optionData, tmpOptionData2, tmpOptionDataLen);
-    headerOpt[1].optionLength = (uint16_t) tmpOptionDataLen;
-
-    CAGenerateToken(&tempToken, tokenLength);
-
-    EXPECT_EQ(CA_STATUS_OK, CAAdvertiseResource(uri, tempToken, tokenLength,
-                                                headerOpt, (uint8_t )optionNum));
-
-    CADestroyToken(tempToken);
-
-    free(headerOpt);
-}
-
-// check return value when uri is NULL
-TEST_F(CATests, AdvertiseResourceTest)
-{
-    uri = NULL;
-    int optionNum = 2;
-
-    CAHeaderOption_t* headerOpt;
-    headerOpt = (CAHeaderOption_t *) calloc(1, optionNum * sizeof(CAHeaderOption_t));
-
-    if(!headerOpt)
-    {
-        FAIL() << "Allocation for headerOpt failed";
-    }
-
-    char* tmpOptionData1 = (char *) "Hello";
-    size_t tmpOptionDataLen = (strlen(tmpOptionData1) < CA_MAX_HEADER_OPTION_DATA_LENGTH) ?
-            strlen(tmpOptionData1) : CA_MAX_HEADER_OPTION_DATA_LENGTH - 1;
-    headerOpt[0].optionID = 3000;
-    memcpy(headerOpt[0].optionData, tmpOptionData1, tmpOptionDataLen);
-    headerOpt[0].optionLength = (uint16_t) tmpOptionDataLen;
-
-    char* tmpOptionData2 = (char *) "World";
-    tmpOptionDataLen = (strlen(tmpOptionData2) < CA_MAX_HEADER_OPTION_DATA_LENGTH) ?
-                strlen(tmpOptionData2) : CA_MAX_HEADER_OPTION_DATA_LENGTH - 1;
-    headerOpt[1].optionID = 3001;
-    memcpy(headerOpt[1].optionData, tmpOptionData2, tmpOptionDataLen);
-    headerOpt[1].optionLength = (uint16_t) tmpOptionDataLen;
-
-    CAGenerateToken(&tempToken, tokenLength);
-
-    EXPECT_EQ(CA_STATUS_INVALID_PARAM, CAAdvertiseResource(uri, tempToken, tokenLength,
-                                                           headerOpt, (uint8_t )optionNum));
-
-    CADestroyToken(tempToken);
-
-    free(headerOpt);
-}
-
 // CASelectNewwork TC
 // check return value
 TEST_F(CATests, SelectNetworkTestGood)
@@ -632,16 +490,16 @@ TEST_F(CATests, SelectNetworkTestGood)
 
 CAResult_t checkSelectNetwork()
 {
-    CAResult_t res = CASelectNetwork(CA_IPV4);
+    CAResult_t res = CASelectNetwork(CA_ADAPTER_IP);
 
     if (CA_STATUS_OK == res)
     {
-        EXPECT_EQ(CA_STATUS_OK, CAUnSelectNetwork(CA_IPV4));
+        EXPECT_EQ(CA_STATUS_OK, CAUnSelectNetwork(CA_ADAPTER_IP));
         return CA_STATUS_OK;
     }
     if (CA_NOT_SUPPORTED == res)
     {
-        EXPECT_EQ(CA_STATUS_FAILED, CAUnSelectNetwork(CA_IPV4));
+        EXPECT_EQ(CA_STATUS_FAILED, CAUnSelectNetwork(CA_ADAPTER_IP));
         return CA_STATUS_OK;
     }
 
@@ -669,67 +527,6 @@ TEST_F(CATests, HandlerRequestResponseTest)
     EXPECT_EQ(CA_STATUS_OK, CAHandleRequestResponse());
 }
 
-// CASendRequestToAll TC
-// check return value
-TEST(SendRequestToAllTest, DISABLED_TC_31_Positive_01)
-{
-    CASelectNetwork(CA_IPV4);
-
-    uri = (char *) RESOURCE_URI;
-    CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
-    CAGroupEndpoint_t *group = NULL;
-    group = (CAGroupEndpoint_t *) malloc(sizeof(CAGroupEndpoint_t));
-    if(!group)
-    {
-        FAIL() << "Allocation for group failed";
-    }
-
-    group->transportType = tempRep->transportType;
-    group->resourceUri = tempRep->resourceUri;
-
-    memset(&requestData, 0, sizeof(CAInfo_t));
-    CAGenerateToken(&tempToken, tokenLength);
-    requestData.token = tempToken;
-    requestData.tokenLength = tokenLength;
-
-    requestData.payload = (char *) "Temp Json Payload";
-    requestData.type = CA_MSG_NONCONFIRM;
-    memset(&requestInfo, 0, sizeof(CARequestInfo_t));
-    requestInfo.method = CA_GET;
-    requestInfo.info = requestData;
-
-    EXPECT_EQ(CA_STATUS_OK, CASendRequestToAll(group, &requestInfo));
-
-    CADestroyToken(tempToken);
-
-    CADestroyRemoteEndpoint(tempRep);
-    tempRep = NULL;
-
-    free(group);
-}
-
-// check return value when group->resourceUri is NULL
-TEST(SendRequestToAllTest, DISABLED_TC_32_Negative_01)
-{
-    uri = (char *) RESOURCE_URI;
-    CAGroupEndpoint_t *group = NULL;
-
-    memset(&requestData, 0, sizeof(CAInfo_t));
-    CAGenerateToken(&tempToken, tokenLength);
-    requestData.token = tempToken;
-    requestData.tokenLength = tokenLength;
-
-    requestData.payload = (char *) "Temp Json Payload";
-    requestData.type = CA_MSG_NONCONFIRM;
-    memset(&requestInfo, 0, sizeof(CARequestInfo_t));
-    requestInfo.method = CA_GET;
-    requestInfo.info = requestData;
-
-    EXPECT_EQ(CA_STATUS_INVALID_PARAM, CASendRequestToAll(group, &requestInfo));
-
-    CADestroyToken(tempToken);
-}
-
 // CAGetNetworkInformation TC
 // check return value
 TEST_F (CATests, GetNetworkInformationTestGood)
@@ -751,7 +548,7 @@ TEST_F(CATests, RegisterDTLSCredentialsHandlerTest)
 
 CAResult_t checkGetNetworkInfo()
 {
-    CALocalConnectivity_t *tempInfo = NULL;
+    CAEndpoint_t *tempInfo = NULL;
     uint32_t tempSize = 0;
 
     CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize);
index ccf85fa..2f9ebff 100644 (file)
@@ -55,17 +55,6 @@ typedef enum
 
 } SPResult;
 
-/**
- * Connectivity types.
- */
-typedef enum
-{
-    SP_IPV4         = (1 << 0),
-    SP_IPV6         = (1 << 1),
-    SP_CONN_EDR     = (1 << 2),
-    SP_CONN_LE      = (1 << 3)
-} SPConnectivityType;
-
 typedef struct SPTargetDeviceInfo SPTargetDeviceInfo_t;
 typedef struct SPDevInfo SPDevInfo_t;
 
@@ -74,12 +63,10 @@ typedef struct SPDevInfo SPDevInfo_t;
  */
 struct SPTargetDeviceInfo
 {
-    char ip[DEV_ADDR_SIZE_MAX];            /**< IP address in IPv4 dot-decimal notation. **/
-    int port;                              /**< Remote endpoint port. **/
-    SPConnectivityType connType;           /**< Connectivity type. **/
-    OicSecPstat_t *pstat;                  /**< Pointer to target's pstat resource. **/
-    OicSecDoxm_t *doxm;                    /**< Pointer to target's doxm resource. **/
-    SPTargetDeviceInfo_t *next;            /**< Next pointer. **/
+    OCDevAddr endpoint;             /**< target address **/
+    OicSecPstat_t *pstat;           /**< Pointer to target's pstat resource. **/
+    OicSecDoxm_t *doxm;             /**< Pointer to target's doxm resource. **/
+    SPTargetDeviceInfo_t *next;     /**< Next pointer. **/
 };
 
 /**
@@ -87,14 +74,11 @@ struct SPTargetDeviceInfo
  */
 struct SPDevInfo
 {
-    OicUuid_t deviceId;                    /**< Device ID. **/
-    char ip[DEV_ADDR_SIZE_MAX];            /**< IP address in IPv4 dot-decimal notation. **/
-    int port;                              /**< Remote endpoint port. **/
-    SPConnectivityType connType;           /**< Connectivity type. **/
-    SPDevInfo_t *next;                     /**< Next pointer. **/
+    OCDevAddr endpoint;             /**< target address **/
+    OicUuid_t deviceId;             /**< Device ID. **/
+    SPDevInfo_t *next;              /**< Next pointer. **/
 };
 
-
 /**
  * The function is responsible for discovery of device is current subnet. It will list
  * all the device in subnet which are not yet owned. Please call OCInit with OC_CLIENT_SERVER as
index 5a15297..ecf647b 100644 (file)
@@ -88,7 +88,7 @@ typedef enum
 #define COAPS_QUERY "coaps://%s:%d%s"
 #define CA_SECURE_PORT   5684
 
-void (*handler)(const CARemoteEndpoint_t *, const CAResponseInfo_t *);
+void (*handler)(const CAEndpoint_t *, const CAResponseInfo_t *);
 
 /**
  * CA token to keep track of response.
@@ -217,74 +217,6 @@ static SPResult convertCAResultToSPResult(CAResult_t caResult)
 }
 
 /**
- * Convert SP network types to CA network types,
- *
- * @param[in]  connType   connection type.
- * @return  CA connectivity type corresponding to SP connectivity type.
- */
-static CATransportType_t getConnectivity(SPConnectivityType connType)
-{
-    switch (connType)
-    {
-        case SP_IPV4:
-            {
-                return CA_IPV4;
-            }
-        case SP_IPV6:
-            {
-                return CA_IPV6;
-            }
-        case SP_CONN_EDR:
-            {
-                return CA_EDR;
-            }
-        case SP_CONN_LE:
-            {
-                return CA_LE;
-            }
-        default:
-            {
-                return CA_IPV4;
-            }
-    }
-    return CA_IPV4;
-}
-
-/**
- * Convert CA network types to SP network types,
- *
- * @param[in]  connType   connection type.
- * @return  SPConnectitivty type corresponding to CATransportType_t.
- */
-static SPConnectivityType getConnectivitySP(CATransportType_t connType)
-{
-    switch (connType)
-    {
-        case CA_IPV4:
-            {
-                return SP_IPV4;
-            }
-        case CA_IPV6:
-            {
-                return SP_IPV6;
-            }
-        case CA_EDR:
-            {
-                return SP_CONN_EDR;
-            }
-        case CA_LE:
-            {
-                return SP_CONN_LE;
-            }
-        default:
-            {
-                return SP_IPV4;
-            }
-    }
-    return SP_IPV4;
-}
-
-/**
  * Function to delete memory allocated to linked list.
  *
  */
@@ -361,34 +293,44 @@ static SPResult SPTimeout(unsigned short timeout, uint32_t mask)
 
 /**
  * Function to send request to resource server.
- * @param[in] uri             Request URI.
+ * @param[in] method          method to be used for sending rquest.
+ * @param[in] endpoint        endpoint address
+ * @param[in] secure          use secure connection
+ * @param[in] resourceUri     resourceUri token.
  * @param[in] payload         Payload to be sent with data. NULL is case message
  *                            doesn't have payload.
  * @param[in] payloadLen      Size of data to be sent.
- * @param[in] token           CA token.
- * @param[in] method          method to be used for sending rquest.
- * @param[in] conntype        Connectivity type.
  * @return  CA_STATUS_OK on success, otherwise error code.
  */
-static CAResult_t sendCARequest(CAURI_t uri, char *payload, int payloadLen,
-                                CAToken_t token, CAMethod_t method, SPConnectivityType conntype)
+static CAResult_t sendCARequest(CAMethod_t method,
+                                const OCDevAddr *devAddr,
+                                OCTransportFlags secure,
+                                const char *resourceUri,
+                                char *payload, int payloadLen)
 {
-    CARemoteEndpoint_t *endpoint = NULL;
-    CATransportType_t caConnType = getConnectivity(conntype);
-    if (CA_STATUS_OK != CACreateRemoteEndpoint(uri, caConnType, &endpoint) || !endpoint)
+    if (CA_STATUS_OK != CAGenerateToken(&gToken, CA_MAX_TOKEN_LEN))
+    {
+        OC_LOG(ERROR, TAG, "Error while generating token");
+        return CA_MEMORY_ALLOC_FAILED;
+    }
+
+    CAEndpoint_t *endpoint = NULL;
+    if (CA_STATUS_OK != CACreateEndpoint((CATransportFlags_t)secure,
+                                         devAddr->adapter, devAddr->addr,
+                                         devAddr->port, &endpoint))
     {
         OC_LOG(ERROR, TAG, "Failed to create remote endpoint");
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
         return CA_STATUS_FAILED;
     }
     CAMessageType_t msgType = CA_MSG_CONFIRM;
     CAInfo_t requestData = { 0 };
-    requestData.token = token;
+    requestData.token = gToken;
     requestData.tokenLength  = CA_MAX_TOKEN_LEN;
     if (payload && '\0' != (*(payload + payloadLen)))
     {
         OC_LOG(ERROR, TAG, "Payload not properly terminated.");
-        CADestroyRemoteEndpoint(endpoint);
+        CADestroyEndpoint(endpoint);
         return CA_STATUS_INVALID_PARAM;
     }
     requestData.payload = payload;
@@ -396,13 +338,14 @@ static CAResult_t sendCARequest(CAURI_t uri, char *payload, int payloadLen,
     CARequestInfo_t requestInfo = { 0 };
     requestInfo.method = method;
     requestInfo.info = requestData;
+    requestInfo.isMulticast = false;
     CAResult_t caResult = CA_STATUS_OK;
     caResult = CASendRequest(endpoint, &requestInfo);
     if (CA_STATUS_OK != caResult)
     {
         OC_LOG(ERROR, TAG, "Send Request Error !!");
     }
-    CADestroyRemoteEndpoint(endpoint);
+    CADestroyEndpoint(endpoint);
     return caResult;
 }
 
@@ -411,26 +354,26 @@ static CAResult_t sendCARequest(CAURI_t uri, char *payload, int payloadLen,
  *
  * @param[in] ip                    IP of target device.
  * @param[in] port                  port of remote server.
- * @param[in] connType              connectivity type of endpoint.
+ * @param[in] adapter              adapter type of endpoint.
  * @param[in] doxm                  pointer to doxm instance.
  * @return SP_RESULT_SUCCESS for success and errorcode otherwise.
  */
-static SPResult addDevice(const char *ip, int port, SPConnectivityType connType, OicSecDoxm_t *doxm)
+static SPResult addDevice(const char *ip, int port, OCTransportAdapter adapter, OicSecDoxm_t *doxm)
 {
     if (NULL == ip || 0 >= port)
     {
         return SP_RESULT_INVALID_PARAM;
     }
-    SPTargetDeviceInfo_t *ptr = (SPTargetDeviceInfo_t *) OICCalloc(1, sizeof(SPTargetDeviceInfo_t));
+    SPTargetDeviceInfo_t *ptr = (SPTargetDeviceInfo_t *)OICCalloc(1, sizeof (SPTargetDeviceInfo_t));
     if (NULL == ptr)
     {
         OC_LOG(ERROR, TAG, "Error while allocating memory for linkedlist node !!");
         return SP_RESULT_MEM_ALLOCATION_FAIL;
     }
 
-    SPStringCopy(ptr->ip, ip, sizeof(ptr->ip));
-    ptr->port = port;
-    ptr->connType = connType;
+    SPStringCopy(ptr->endpoint.addr, ip, MAX_ADDR_STR_SIZE);
+    ptr->endpoint.port = port;
+    ptr->endpoint.adapter = adapter;
 
     ptr->doxm = doxm;
 
@@ -484,7 +427,7 @@ static SPResult selectProvisioningMethod(OicSecOxm_t *supportedMethods, size_t n
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
  */
-static void ProvisionDiscoveryHandler(const CARemoteEndpoint_t *object,
+static void ProvisionDiscoveryHandler(const CAEndpoint_t *object,
                                       const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_DISCOVERY_STARTED) && gToken)
@@ -523,9 +466,7 @@ static void ProvisionDiscoveryHandler(const CARemoteEndpoint_t *object,
             OC_LOG(DEBUG, TAG, "Successfully converted pstat json to bin.");
             OICFree(pTempPayload);
 
-            SPConnectivityType connType = getConnectivitySP(object->transportType);
-            SPResult res = addDevice(object->addressInfo.IP.ipAddress, object->addressInfo.IP.port,
-                                     connType, ptrDoxm);
+            SPResult res = addDevice(object->addr, object->port, object->adapter, ptrDoxm);
             if (SP_RESULT_SUCCESS != res)
             {
                 OC_LOG(ERROR, TAG, "Error while adding data to linkedlist.");
@@ -545,7 +486,7 @@ static void ProvisionDiscoveryHandler(const CARemoteEndpoint_t *object,
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
  */
-static void OwnerShipTransferModeHandler(const CARemoteEndpoint_t *object,
+static void OwnerShipTransferModeHandler(const CAEndpoint_t *object,
         const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_UP_OWN_TR_METH_STARTED) && gToken)
@@ -575,7 +516,7 @@ static void OwnerShipTransferModeHandler(const CARemoteEndpoint_t *object,
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
  */
-static void ListMethodsHandler(const CARemoteEndpoint_t *object,
+static void ListMethodsHandler(const CAEndpoint_t *object,
                                const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_LIST_METHODS_STARTED) && gToken)
@@ -633,7 +574,7 @@ static void ListMethodsHandler(const CARemoteEndpoint_t *object,
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
  */
-static void OperationModeUpdateHandler(const CARemoteEndpoint_t *object,
+static void OperationModeUpdateHandler(const CAEndpoint_t *object,
                                        const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_UPDATE_OP_MODE_STARTED) && gToken)
@@ -662,7 +603,7 @@ static void OperationModeUpdateHandler(const CARemoteEndpoint_t *object,
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
  */
-static void OwnerShipUpdateHandler(const CARemoteEndpoint_t *object,
+static void OwnerShipUpdateHandler(const CAEndpoint_t *object,
                                    const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_UPDATE_OWNER_STARTED) && gToken)
@@ -692,7 +633,7 @@ static void OwnerShipUpdateHandler(const CARemoteEndpoint_t *object,
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
  */
-static void ACLProvisioningHandler(const CARemoteEndpoint_t *object,
+static void ACLProvisioningHandler(const CAEndpoint_t *object,
                                    const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_PROV_ACL_STARTED) && gToken)
@@ -723,7 +664,7 @@ static void ACLProvisioningHandler(const CARemoteEndpoint_t *object,
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
  */
-static void FinalizeProvisioningHandler(const CARemoteEndpoint_t *object,
+static void FinalizeProvisioningHandler(const CAEndpoint_t *object,
                                         const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_UP_HASH_STARTED) && gToken)
@@ -753,7 +694,7 @@ static void FinalizeProvisioningHandler(const CARemoteEndpoint_t *object,
  * @param[in] object        Remote endpoint object
  * @param[in] requestInfo   Datastructure containing request information.
  */
-static void CredProvisioningHandler(const CARemoteEndpoint_t *object,
+static void CredProvisioningHandler(const CAEndpoint_t *object,
                                     const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_PROV_CRED_STARTED) && gToken)
@@ -783,7 +724,7 @@ static void CredProvisioningHandler(const CARemoteEndpoint_t *object,
  * @param[in] object        Remote endpoint object
  * @param[in] responseInfo  Datastructure containing response information.
  */
-static void SPResponseHandler(const CARemoteEndpoint_t *object,
+static void SPResponseHandler(const CAEndpoint_t *object,
                               const CAResponseInfo_t *responseInfo)
 {
     if ((NULL != responseInfo) && (NULL != responseInfo->info.token))
@@ -798,7 +739,7 @@ static void SPResponseHandler(const CARemoteEndpoint_t *object,
  * @param[in] object     Remote endpoint object
  * @param[in] errorInfo  Datastructure containing error information.
  */
-static void SPErrorHandler(const CARemoteEndpoint_t *object,
+static void SPErrorHandler(const CAEndpoint_t *object,
                            const CAErrorInfo_t *errorInfo)
 {
     OC_LOG(INFO, TAG, "Error Handler.");
@@ -810,7 +751,7 @@ static void SPErrorHandler(const CARemoteEndpoint_t *object,
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
  */
-static void SPRequestHandler(const CARemoteEndpoint_t *object, const CARequestInfo_t *requestInfo)
+static void SPRequestHandler(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo)
 {
     OC_LOG(INFO, TAG, "Request Handler.");
 }
@@ -830,7 +771,22 @@ static SPResult findResource(unsigned short timeout)
         OC_LOG(ERROR, TAG, "Error while generating token.");
         return SP_RESULT_INTERNAL_ERROR;
     }
-    res = CAFindResource(DOXM_OWNED_FALSE_MULTICAST_QUERY, gToken, CA_MAX_TOKEN_LEN);
+
+    CAEndpoint_t endpoint = { CA_DEFAULT_FLAGS };
+
+    CAMessageType_t msgType = CA_MSG_NONCONFIRM;
+    CAInfo_t requestData = { 0 };
+    requestData.token = gToken;
+    requestData.tokenLength  = CA_MAX_TOKEN_LEN;
+    requestData.payload = NULL;
+    requestData.type = msgType;
+    requestData.resourceUri = DOXM_OWNED_FALSE_MULTICAST_QUERY;
+    CARequestInfo_t requestInfo = { 0 };
+    requestInfo.method = CA_GET;
+    requestInfo.info = requestData;
+    requestInfo.isMulticast = true;
+    res = CASendRequest(&endpoint, &requestInfo);
+
     handler = &ProvisionDiscoveryHandler;
     gStateManager |= SP_DISCOVERY_STARTED;
     if (CA_STATUS_OK != res)
@@ -857,11 +813,6 @@ static SPResult updateOwnerTransferModeToResource(unsigned short timeout,
         SPTargetDeviceInfo_t *deviceInfo, OicSecOxm_t selectedMethod)
 {
     SPResult res = SP_RESULT_INTERNAL_ERROR;
-    char uri[CA_MAX_URI_LENGTH] = {0};
-    size_t uriLen = sizeof(uri);
-    snprintf(uri, uriLen - 1, COAP_QUERY, deviceInfo->ip,
-             deviceInfo->port, OIC_RSRC_DOXM_URI);
-    uri[uriLen - 1] = '\0';
 
     deviceInfo->doxm->oxmSel = selectedMethod;
     char *payload = BinToDoxmJSON(deviceInfo->doxm);
@@ -873,18 +824,14 @@ static SPResult updateOwnerTransferModeToResource(unsigned short timeout,
     OC_LOG_V(DEBUG, TAG, "Payload: %s", payload);
     int payloadLen = strlen(payload);
 
-    CAMethod_t method = CA_PUT;
-    if (CA_STATUS_OK != CAGenerateToken(&gToken, CA_MAX_TOKEN_LEN))
-    {
-        OC_LOG(ERROR, TAG, "Error while generating token");
-        OICFree(payload);
-        return SP_RESULT_INTERNAL_ERROR;
-    }
     handler = &OwnerShipTransferModeHandler;
     gStateManager |= SP_UP_OWN_TR_METH_STARTED;
 
-    CAResult_t result = sendCARequest(uri, payload, payloadLen, gToken, method,
-                                      deviceInfo->connType);
+    CAResult_t result = sendCARequest(CA_PUT,
+                                      &deviceInfo->endpoint,
+                                      OC_DEFAULT_FLAGS,
+                                      OIC_RSRC_DOXM_URI,
+                                      payload, payloadLen);
     OICFree(payload);
     if (CA_STATUS_OK != result)
     {
@@ -911,22 +858,16 @@ static SPResult updateOwnerTransferModeToResource(unsigned short timeout,
  * @return  SP_SUCCESS on success
  */
 static SPResult getProvisioningStatusResource(unsigned short timeout,
-        SPTargetDeviceInfo_t *deviceInfo)
+                                              SPTargetDeviceInfo_t *deviceInfo)
 {
-    char uri[CA_MAX_URI_LENGTH] = {0};
-    size_t uriLen = sizeof(uri);
-    snprintf(uri, uriLen - 1, COAP_QUERY, deviceInfo->ip,
-             deviceInfo->port, OIC_RSRC_PSTAT_URI);
-    uri[uriLen - 1] = '\0';
-    CAMethod_t method = CA_GET;
-    if (CA_STATUS_OK != CAGenerateToken(&gToken, CA_MAX_TOKEN_LEN))
-    {
-        OC_LOG(ERROR, TAG, "Error while generating token");
-        return SP_RESULT_INTERNAL_ERROR;
-    }
     handler = &ListMethodsHandler;
     gStateManager |= SP_LIST_METHODS_STARTED;
-    CAResult_t result = sendCARequest(uri, NULL, 0, gToken, method, deviceInfo->connType);
+
+    CAResult_t result = sendCARequest(CA_GET,
+                                      &deviceInfo->endpoint,
+                                      OC_DEFAULT_FLAGS,
+                                      OIC_RSRC_PSTAT_URI,
+                                      NULL, 0);
     if (CA_STATUS_OK != result)
     {
         OC_LOG(ERROR, TAG, "Failure while sending request.");
@@ -959,19 +900,13 @@ static SPResult getProvisioningStatusResource(unsigned short timeout,
  * @param[in]  deviceInfo  Device Info.
  * @return  SP_SUCCESS on success
  */
-static SPResult updateOperationMode(unsigned short timeout, SPTargetDeviceInfo_t *deviceInfo,
+static SPResult updateOperationMode(unsigned short timeout,
+                                    SPTargetDeviceInfo_t *deviceInfo,
                                     OicSecDpom_t selectedOperationMode)
 {
 
     SPResult res = SP_RESULT_INTERNAL_ERROR;
 
-    char uri[CA_MAX_URI_LENGTH] = {0};
-    size_t uriLen = sizeof(uri);
-    snprintf(uri, uriLen - 1, COAP_QUERY, deviceInfo->ip,
-             deviceInfo->port , OIC_RSRC_PSTAT_URI);
-    uri[uriLen - 1] = '\0';
-
-
     deviceInfo->pstat->om = selectedOperationMode;
 
     char *payloadBuffer = BinToPstatJSON(deviceInfo->pstat);
@@ -982,21 +917,14 @@ static SPResult updateOperationMode(unsigned short timeout, SPTargetDeviceInfo_t
     }
 
     size_t payloadLen = strlen(payloadBuffer);
-
-    CAMethod_t method = CA_PUT;
-    if (CA_STATUS_OK != CAGenerateToken(&gToken, CA_MAX_TOKEN_LEN))
-    {
-        OC_LOG(ERROR, TAG, "Error while generating token");
-        if (payloadBuffer)
-        {
-            OICFree(payloadBuffer);
-        }
-        return SP_RESULT_INTERNAL_ERROR;
-    }
     handler = &OperationModeUpdateHandler;
     gStateManager |= SP_UPDATE_OP_MODE_STARTED;
-    CAResult_t result = sendCARequest(uri, payloadBuffer, payloadLen, gToken, method,
-                                      deviceInfo->connType);
+
+    CAResult_t result = sendCARequest(CA_PUT,
+                                      &deviceInfo->endpoint,
+                                      OC_DEFAULT_FLAGS,
+                                      OIC_RSRC_PSTAT_URI,
+                                      payloadBuffer, payloadLen);
     if (CA_STATUS_OK != result)
     {
         OC_LOG(ERROR, TAG, "Error while sending request.");
@@ -1046,12 +974,7 @@ static SPResult initiateDtlsHandshake(const SPTargetDeviceInfo_t *deviceInfo)
     }
     OC_LOG(INFO, TAG, "Anonymous cipher suite Enabled.");
 
-    CAAddress_t address = {};
-    strncpy(address.IP.ipAddress, deviceInfo->ip, DEV_ADDR_SIZE_MAX);
-    address.IP.ipAddress[DEV_ADDR_SIZE_MAX - 1] = '\0';
-    address.IP.port = CA_SECURE_PORT;
-
-    caresult = CAInitiateHandshake(&address, deviceInfo->connType);
+    caresult = CAInitiateHandshake((CAEndpoint_t *)&deviceInfo->endpoint);
     if (CA_STATUS_OK != caresult)
     {
         OC_LOG_V(ERROR, TAG, "DTLS handshake failure.");
@@ -1071,13 +994,8 @@ static SPResult initiateDtlsHandshake(const SPTargetDeviceInfo_t *deviceInfo)
 static SPResult sendOwnershipInfo(unsigned short timeout,
                                   SPTargetDeviceInfo_t *selectedDeviceInfo)
 {
-    char uri[CA_MAX_URI_LENGTH] = {0};
-    size_t uriLen = sizeof(uri);
-    snprintf(uri, uriLen - 1, COAPS_QUERY, selectedDeviceInfo->ip,
-             CA_SECURE_PORT, OIC_RSRC_DOXM_URI);
-    uri[uriLen - 1] = '\0';
-
     OicUuid_t provTooldeviceID = {};
+
     if (OC_STACK_OK != GetDoxmDeviceID(&provTooldeviceID))
     {
         OC_LOG(ERROR, TAG, "Error while retrieving provisioning tool's device ID");
@@ -1085,7 +1003,6 @@ static SPResult sendOwnershipInfo(unsigned short timeout,
     }
     memcpy(selectedDeviceInfo->doxm->owner.id, provTooldeviceID.id , UUID_LENGTH);
 
-
     selectedDeviceInfo->doxm->owned = true;
 
     char *payloadBuffer =  BinToDoxmJSON(selectedDeviceInfo->doxm);
@@ -1096,19 +1013,14 @@ static SPResult sendOwnershipInfo(unsigned short timeout,
     }
     int payloadLen = strlen(payloadBuffer);
 
-    CAMethod_t method = CA_PUT;
-    if (CA_STATUS_OK != CAGenerateToken(&gToken, CA_MAX_TOKEN_LEN))
-    {
-        OC_LOG(ERROR, TAG, "Error while generating token");
-        OICFree(payloadBuffer);
-        return SP_RESULT_INTERNAL_ERROR;
-
-    }
     handler = &OwnerShipUpdateHandler;
     gStateManager |= SP_UPDATE_OWNER_STARTED;
 
-    CAResult_t result = sendCARequest(uri, payloadBuffer, payloadLen, gToken, method,
-                                      selectedDeviceInfo->connType);
+    CAResult_t result = sendCARequest(CA_PUT,
+                                      &selectedDeviceInfo->endpoint,
+                                      OC_SECURE,
+                                      OIC_RSRC_DOXM_URI,
+                                      payloadBuffer, payloadLen);
     if (CA_STATUS_OK != result)
     {
         OC_LOG(ERROR, TAG, "Error while sending request.");
@@ -1137,10 +1049,11 @@ static SPResult sendOwnershipInfo(unsigned short timeout,
 static SPResult saveOwnerPSK(SPTargetDeviceInfo_t *selectedDeviceInfo)
 {
     SPResult result = SP_RESULT_INTERNAL_ERROR;
-    CAAddress_t address = {};
-    strncpy(address.IP.ipAddress, selectedDeviceInfo->ip, DEV_ADDR_SIZE_MAX);
-    address.IP.ipAddress[DEV_ADDR_SIZE_MAX - 1] = '\0';
-    address.IP.port = CA_SECURE_PORT;
+
+    CAEndpoint_t endpoint = {0};
+    strncpy(endpoint.addr, selectedDeviceInfo->endpoint.addr, MAX_ADDR_STR_SIZE_CA);
+    endpoint.addr[MAX_ADDR_STR_SIZE_CA - 1] = '\0';
+    endpoint.port = CA_SECURE_PORT;
 
     OicUuid_t provTooldeviceID = {};
     if (OC_STACK_OK != GetDoxmDeviceID(&provTooldeviceID))
@@ -1152,8 +1065,8 @@ static SPResult saveOwnerPSK(SPTargetDeviceInfo_t *selectedDeviceInfo)
     uint8_t ownerPSK[OWNER_PSK_LENGTH_128] = {};
 
     //Generating OwnerPSK
-    CAResult_t pskRet = CAGenerateOwnerPSK(&address, selectedDeviceInfo->connType,
-            (uint8_t*) OXM_JUST_WORKS, strlen(OXM_JUST_WORKS), provTooldeviceID.id,
+    CAResult_t pskRet = CAGenerateOwnerPSK(&endpoint,
+            (uint8_t *)OXM_JUST_WORKS, strlen(OXM_JUST_WORKS), provTooldeviceID.id,
             sizeof(provTooldeviceID.id), selectedDeviceInfo->doxm->deviceID.id,
             sizeof(selectedDeviceInfo->doxm->deviceID.id), ownerPSK,
             OWNER_PSK_LENGTH_128);
@@ -1295,23 +1208,15 @@ SPResult provisionCredentials(unsigned short timeout, const OicSecCred_t *cred,
         return SP_RESULT_MEM_ALLOCATION_FAIL;
     }
 
-    char uri[CA_MAX_URI_LENGTH] = {0};
-    size_t uriLen = sizeof(uri);
-    snprintf(uri, uriLen - 1, COAPS_QUERY, deviceInfo->ip,
-             CA_SECURE_PORT, OIC_RSRC_CRED_URI);
-    uri[uriLen - 1] = '\0';
-
     int payloadLen = strlen(credJson);
-    CAMethod_t method = CA_POST;
-    if (CA_STATUS_OK != CAGenerateToken(&gToken, CA_MAX_TOKEN_LEN))
-    {
-        OC_LOG(ERROR, TAG, "Error while generating token");
-        return SP_RESULT_INTERNAL_ERROR;
-    }
     handler = &CredProvisioningHandler;
     gStateManager |= SP_PROV_CRED_STARTED;
-    CAResult_t result = sendCARequest(uri, credJson, payloadLen, gToken, method,
-                                      deviceInfo->connType);
+
+    CAResult_t result = sendCARequest(CA_POST,
+                                      &deviceInfo->endpoint,
+                                      OC_SECURE,
+                                      OIC_RSRC_CRED_URI,
+                                      credJson, payloadLen);
     OICFree(credJson);
     if (CA_STATUS_OK != result)
     {
@@ -1408,26 +1313,15 @@ SPResult SPProvisionACL(unsigned short timeout, const SPTargetDeviceInfo_t *sele
         return SP_RESULT_MEM_ALLOCATION_FAIL;
     }
 
-    char uri[CA_MAX_URI_LENGTH] = {0};
-    size_t uriLen = sizeof(uri);
-    snprintf(uri, uriLen - 1, COAPS_QUERY, selectedDeviceInfo->ip,
-             CA_SECURE_PORT, OIC_RSRC_ACL_URI);
-    uri[uriLen - 1] = '\0';
-
     int payloadLen = strlen(aclString);
-    CAMethod_t method = CA_POST;
-    if (CA_STATUS_OK != CAGenerateToken(&gToken, CA_MAX_TOKEN_LEN))
-    {
-        OC_LOG(ERROR, TAG, "Error while generating token");
-        OICFree(aclString);
-        return SP_RESULT_INTERNAL_ERROR;
-
-    }
     handler = &ACLProvisioningHandler;
     gStateManager |= SP_PROV_ACL_STARTED;
 
-    CAResult_t result = sendCARequest(uri, aclString, payloadLen, gToken, method,
-                                      selectedDeviceInfo->connType);
+    CAResult_t result = sendCARequest(CA_POST,
+                                      &selectedDeviceInfo->endpoint,
+                                      OC_SECURE,
+                                      OIC_RSRC_DOXM_URI,
+                                      aclString, payloadLen);
     OICFree(aclString);
     if (CA_STATUS_OK != result)
     {
@@ -1524,11 +1418,6 @@ SPResult SPFinalizeProvisioning(unsigned short timeout,
         OC_LOG(ERROR, TAG, "Target device Info is NULL.");
         return SP_RESULT_INVALID_PARAM;
     }
-    char uri[CA_MAX_URI_LENGTH] = {0};
-    size_t uriLen = sizeof(uri);
-    snprintf(uri, uriLen - 1, COAPS_QUERY, selectedDeviceInfo->ip,
-             CA_SECURE_PORT, OIC_RSRC_PSTAT_URI);
-    uri[uriLen - 1] = '\0';
 
     uint16_t aclHash = 0; // value for beachhead version.
     selectedDeviceInfo->pstat->commitHash = aclHash;
@@ -1541,17 +1430,14 @@ SPResult SPFinalizeProvisioning(unsigned short timeout,
     }
     int payloadLen = strlen(payloadBuffer);
 
-    CAMethod_t method = CA_PUT;
-    if (CA_STATUS_OK != CAGenerateToken(&gToken, CA_MAX_TOKEN_LEN))
-    {
-        OC_LOG(ERROR, TAG, "Error while generating token");
-        OICFree(payloadBuffer);
-        return SP_RESULT_INTERNAL_ERROR;
-    }
     handler = &FinalizeProvisioningHandler;
     gStateManager |= SP_UP_HASH_STARTED;
-    CAResult_t result = sendCARequest(uri, payloadBuffer, payloadLen, gToken, method,
-                                      selectedDeviceInfo->connType);
+
+    CAResult_t result = sendCARequest(CA_PUT,
+                                      &selectedDeviceInfo->endpoint,
+                                      OC_SECURE,
+                                      OIC_RSRC_PSTAT_URI,
+                                      payloadBuffer, payloadLen);
     OICFree(payloadBuffer);
     if (CA_STATUS_OK != result)
     {
@@ -1568,12 +1454,12 @@ SPResult SPFinalizeProvisioning(unsigned short timeout,
         return SP_RESULT_TIMEOUT;
     }
 
-    CAAddress_t address = {};
-    strncpy(address.IP.ipAddress, selectedDeviceInfo->ip, DEV_ADDR_SIZE_MAX);
-    address.IP.ipAddress[DEV_ADDR_SIZE_MAX - 1] = '\0';
-    address.IP.port = CA_SECURE_PORT;
+    CAEndpoint_t endpoint = {0};
+    strncpy(endpoint.addr, selectedDeviceInfo->endpoint.addr, MAX_ADDR_STR_SIZE_CA);
+    endpoint.addr[DEV_ADDR_SIZE_MAX - 1] = '\0';
+    endpoint.port = CA_SECURE_PORT;
 
-    result = CACloseDtlsSession(&address, selectedDeviceInfo->connType);
+    result = CACloseDtlsSession(&endpoint);
     if (CA_STATUS_OK != result)
     {
         OC_LOG_V(ERROR, TAG, "DTLS handshake failure.");
index 99f420c..814d5bd 100755 (executable)
@@ -449,13 +449,12 @@ static OCEntityHandlerResult HandleDoxmPutRequest (const OCEntityHandlerRequest
 #ifdef __WITH_DTLS__
                 CAResult_t pskRet;
 
-                OCServerRequest * request = (OCServerRequest *)ehRequest->requestHandle;
+                OCServerRequest *request = (OCServerRequest *)ehRequest->requestHandle;
                 uint8_t ownerPSK[OWNER_PSK_LENGTH_128] = {};
 
                 //Generating OwnerPSK
                 OC_LOG (INFO, TAG, PCF("Doxm EntityHandle  generating OwnerPSK"));
-                pskRet = CAGenerateOwnerPSK(&request->addressInfo,
-                        request->connectivityType,
+                pskRet = CAGenerateOwnerPSK((CAEndpoint_t *)&request->devAddr,
                         (uint8_t*) OXM_JUST_WORKS, strlen(OXM_JUST_WORKS),
                         newDoxm->owner.id, sizeof(newDoxm->owner.id),
                         gDoxm->deviceID.id, sizeof(gDoxm->deviceID.id),
index e3fd498..f83481d 100644 (file)
@@ -50,7 +50,7 @@ PEContext_t g_policyEngineContext;
  * @param   requestInfo    [IN] Information for the request.
  * @return  NONE
  */
-void SRMRequestHandler(const CARemoteEndpoint_t *endPoint, const CARequestInfo_t *requestInfo)
+void SRMRequestHandler(const CAEndpoint_t *endPoint, const CARequestInfo_t *requestInfo)
 {
     OC_LOG(INFO, TAG, PCF("Received request from remote device"));
 
@@ -65,11 +65,11 @@ void SRMRequestHandler(const CARemoteEndpoint_t *endPoint, const CARequestInfo_t
     memcpy(subjectId.id, endPoint->identity.id, sizeof(subjectId.id));
 
     //Check the URI has the query and skip it before checking the permission
-    char *uri = strstr(endPoint->resourceUri, "?");
+    char *uri = strstr(requestInfo->info.resourceUri, "?");
     int position = 0;
     if (uri)
     {
-        position = uri - endPoint->resourceUri;
+        position = uri - requestInfo->info.resourceUri;
     }
     if (position > MAX_URI_LENGTH)
     {
@@ -80,18 +80,19 @@ void SRMRequestHandler(const CARemoteEndpoint_t *endPoint, const CARequestInfo_t
     if (position > 0)
     {
         char newUri[MAX_URI_LENGTH + 1];
-        strncpy(newUri, endPoint->resourceUri, (position));
+        strncpy(newUri, requestInfo->info.resourceUri, (position));
         newUri[position] = '\0';
         //Skip query and pass the newUri.
-        response = CheckPermission(&g_policyEngineContext, &subjectId, newUri,
-                GetPermissionFromCAMethod_t(requestInfo->method));
-
+        response = CheckPermission(&g_policyEngineContext, &subjectId,
+                              newUri,
+                              GetPermissionFromCAMethod_t(requestInfo->method));
     }
     else
     {
-        //Pass endPoint->resourceUri if there is no query info.
-        response = CheckPermission(&g_policyEngineContext, &subjectId, endPoint->resourceUri,
-                GetPermissionFromCAMethod_t(requestInfo->method));
+        //Pass resourceUri if there is no query info.
+        response = CheckPermission(&g_policyEngineContext, &subjectId,
+                              requestInfo->info.resourceUri,
+                              GetPermissionFromCAMethod_t(requestInfo->method));
     }
     if (IsAccessGranted(response) && gRequestHandler)
     {
@@ -128,7 +129,7 @@ void SRMRequestHandler(const CARemoteEndpoint_t *endPoint, const CARequestInfo_t
  * @param   responseInfo [IN] Response information from the endpoint.
  * @return  NONE
  */
-void SRMResponseHandler(const CARemoteEndpoint_t *endPoint, const CAResponseInfo_t *responseInfo)
+void SRMResponseHandler(const CAEndpoint_t *endPoint, const CAResponseInfo_t *responseInfo)
 {
     OC_LOG(INFO, TAG, PCF("Received response from remote device"));
     if (gResponseHandler)
@@ -144,7 +145,7 @@ void SRMResponseHandler(const CARemoteEndpoint_t *endPoint, const CAResponseInfo
  * @param   errorInfo [IN] Error information from the endpoint.
  * @return  NONE
  */
-void SRMErrorHandler(const CARemoteEndpoint_t *endPoint, const CAErrorInfo_t *errorInfo)
+void SRMErrorHandler(const CAEndpoint_t *endPoint, const CAErrorInfo_t *errorInfo)
 {
     OC_LOG(INFO, TAG, PCF("Received error from remote device"));
     if (gErrorHandler)
index 2259e41..1a3f0d2 100644 (file)
 using namespace std;
 
 // Helper Methods
-void UTRequestHandler(const CARemoteEndpoint_t *endPoint, const CARequestInfo_t *requestInfo)
+void UTRequestHandler(const CAEndpoint_t *endPoint, const CARequestInfo_t *requestInfo)
 {
     EXPECT_TRUE(true) << "UTRequestHandler\n";
 }
 
-void UTResponseHandler(const CARemoteEndpoint_t *endPoint, const CAResponseInfo_t *responseInfo)
+void UTResponseHandler(const CAEndpoint_t *endPoint, const CAResponseInfo_t *responseInfo)
 {
      EXPECT_TRUE(true) << "UTResponseHandler\n";
 }
 
-void UTErrorHandler(const CARemoteEndpoint_t *endPoint, const CAErrorInfo_t *errorInfo)
+void UTErrorHandler(const CAEndpoint_t *endPoint, const CAErrorInfo_t *errorInfo)
 {
      EXPECT_TRUE(true) << "UTErrorHandler\n";
 }
index 15a7862..727a78d 100644 (file)
@@ -62,8 +62,10 @@ typedef struct ClientCB {
     OCMethod method;
     // This is the sequence identifier the server applies to the invocation tied to 'handle'.
     uint32_t sequenceNumber;
-    // This is the request uri associated with the call back
+    // The canonical form of the request uri associated with the call back
     char * requestUri;
+    // Remote address complete
+    OCDevAddr * devAddr;
     // Struct to hold TTL info for presence
     #ifdef WITH_PRESENCE
     OCPresence * presence;
@@ -112,7 +114,8 @@ OCStackResult
 AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
              CAToken_t token, uint8_t tokenLength,
              OCDoHandle *handle, OCMethod method,
-             char * requestUri, char * resourceTypeName, OCConnectivityType conType, uint32_t ttl);
+             OCDevAddr *devAddr, char * requestUri,
+             char * resourceTypeName, uint32_t ttl);
 
 /** @ingroup ocstack
  *
index 08f72c9..7a5749a 100644 (file)
@@ -45,11 +45,8 @@ typedef struct ResourceObserver
     uint8_t tokenLength;
     // Resource handle
     OCResource *resource;
-    //TODO bundle it in Endpoint structure(address, uri, type, secured)
-    /** Remote Endpoint address **/
-    CAAddress_t addressInfo;
-    /** Connectivity of the endpoint**/
-    CATransportType_t connectivityType;
+    /** Remote Endpoint **/
+    OCDevAddr devAddr;
     // Quality of service of the request
     OCQualityOfService qos;
     // number of times the server failed to reach the observer
@@ -128,8 +125,7 @@ OCStackResult GenerateObserverId (OCObservationId *observationId);
  * @param tokenLength Length of token.
  * @param resHandle Resource handle.
  * @param qos Quality of service of observation.
- * @param addressInfo Address of observer.
- * @param connectivityType Connection type.
+ * @param observer address
  * @return ::OC_STACK_OK on success, some other value upon failure.
  */
 OCStackResult AddObserver (const char         *resUri,
@@ -139,8 +135,7 @@ OCStackResult AddObserver (const char         *resUri,
                            uint8_t            tokenLength,
                            OCResource         *resHandle,
                            OCQualityOfService qos,
-                           const CAAddress_t  *addressInfo,
-                           CATransportType_t connectivityType);
+                           const OCDevAddr    *devAddr);
 
 /**
  * Delete observer with specified token from list of observers.
index 557eedf..e068231 100644 (file)
@@ -141,7 +141,7 @@ OCStackResult BuildVirtualResourceResponse(const OCResource *resourcePtr,
                                            const char *filterValue,
                                            char * out,
                                            uint16_t *remaining,
-                                           CATransportType_t connType);
+                                           CATransportAdapter_t adapter);
 
 /**
  * A helper function that Maps an @ref OCEntityHandlerResult type to an
index 7909399..fce897a 100644 (file)
@@ -45,10 +45,8 @@ typedef struct OCServerRequest
     OCStackResult observeResult;
     uint8_t numResponses;
     OCEHResponseHandler ehResponseHandler;
-    /** Remote Endpoint address **/
-    CAAddress_t addressInfo;
-    /** Connectivity of the endpoint**/
-    CATransportType_t connectivityType;
+    /** Remote endpoint address **/
+    OCDevAddr devAddr;
     // token for the request
     CAToken_t requestToken;
     // token length the request
@@ -56,7 +54,6 @@ typedef struct OCServerRequest
     // The ID of CoAP pdu                                   //Kept in
     uint16_t coapID;                                        //CoAP
     uint8_t delayedResNeeded;
-    uint8_t secured;
     //////////////////////////////////////////////////////////
     // An array of the received vendor specific header options
     uint8_t numRcvdVendorSpecificHeaderOptions;
@@ -152,21 +149,20 @@ OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle)
  * @param tokenLength - request token length
  * @param resourceUrl - URL of resource
  * @param reqTotalSize - total size of the request
- * @param addressInfo - CA Address
- * @param connectivityType - connection type
+ * @param devAddr - OCDevAddr
  *
  * @return
  *     OCStackResult
  */
 OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
-        uint8_t delayedResNeeded, uint8_t secured, uint8_t notificationFlag, OCMethod method,
+        uint8_t delayedResNeeded, uint8_t notificationFlag, OCMethod method,
         uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption,
         OCQualityOfService qos, char * query,
         OCHeaderOption * rcvdVendorSpecificHeaderOptions,
         char * reqJSONPayload, CAToken_t requestToken,
         uint8_t tokenLength,
         char * resourceUrl, size_t reqTotalSize,
-        CAAddress_t *addressInfo, CATransportType_t connectivityType);
+        const OCDevAddr *devAddr);
 
 /**
  * Form the OCEntityHandlerRequest struct that is passed to a resource's entity handler
index dd53780..1fd936b 100644 (file)
@@ -76,12 +76,8 @@ typedef struct
     uint8_t numRcvdVendorSpecificHeaderOptions;
     OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
 
-    /** Remote Endpoint address **/
-    //////////////////////////////////////////////////////////
-    // TODO: bundle this up as endpoint
-    CAAddress_t addressInfo;
-    /** Connectivity of the endpoint**/
-    CATransportType_t connectivityType;
+    /** Remote endpoint address **/
+    OCDevAddr devAddr;
 
     //token for the observe request
     CAToken_t requestToken;
@@ -89,8 +85,6 @@ typedef struct
     // The ID of CoAP pdu
     uint16_t coapID;
     uint8_t delayedResNeeded;
-    uint8_t secured;
-    //////////////////////////////////////////////////////////
     uint8_t reqMorePacket;
     uint32_t reqPacketNum;
     uint16_t reqPacketSize;
@@ -136,7 +130,7 @@ OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t stat
 
 OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
 
-OCStackResult SendDirectStackResponse(const CARemoteEndpoint_t* endPoint, const uint16_t coapID,
+OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16_t coapID,
         const CAResponseResult_t responseResult, const CAMessageType_t type,
         const uint8_t numOptions, const CAHeaderOption_t *options,
         CAToken_t token, uint8_t tokenLength);
@@ -265,6 +259,10 @@ const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
 
 OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
 
+void CopyEndpointToDevAddr(const CAEndpoint_t *in, OCDevAddr *out);
+
+void CopyDevAddrToEndpoint(const OCDevAddr *in, CAEndpoint_t *out);
+
 #ifdef __cplusplus
 }
 #endif // __cplusplus
index 91ff8f4..fa10079 100644 (file)
@@ -37,6 +37,20 @@ extern "C" {
 /**
  * Initialize the OC Stack.  Must be called prior to starting the stack.
  *
+ * @param mode
+ *     Host device is client, server, or client-server.
+ * @param serverFlags
+ *     Default server transport flags.
+ * @param clientFlags
+ *     Default client transport flags.
+ *
+ * @return ::OC_STACK_OK on success, some other value upon failure.
+ */
+OCStackResult OCInit1(OCMode mode, OCTransportFlags serverFlags, OCTransportFlags clientFlags);
+
+/**
+ * Initialize the OC Stack.  Must be called prior to starting the stack.
+ *
  * @param ipAddr
  *     IP Address of host device. Deprecated parameter.
  * @param port
@@ -79,11 +93,11 @@ OCStackResult OCProcess();
  *                           should not be free'd by the consumer.  A NULL handle is permitted
  *                           in the event where the caller has no use for the return value.
  * @param method             @ref OCMethod to perform on the resource.
- * @param requiredUri        URI of the resource to interact with.
- * @param referenceUri       URI of the reference resource.
+ * @param requiredUri        URI of the resource to interact with. (Address prefix
+ *                           is deprecated in favor of destination.)
+ * @param destination        Complete description of destination.
  * @param request            JSON encoded request.
- * @param conType            @ref OCConnectivityType type of connectivity indicating the
- *                           interface. Example: ::OC_WIFI, ::OC_ETHERNET, ::OC_ALL.
+ * @param connectivityType   Modifier flags when destination is not given.
  * @param qos                Quality of service. Note that if this API is called on a uri with
  *                           the well-known multicast IP address, the qos will be forced to
  *                           ::OC_LOW_QOS
@@ -100,11 +114,16 @@ OCStackResult OCProcess();
  *
  * @return ::OC_STACK_OK on success, some other value upon failure.
  */
-OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requiredUri,
-            const char *referenceUri, const char *request, OCConnectivityType conType,
-            OCQualityOfService qos, OCCallbackData *cbData,
-            OCHeaderOption * options, uint8_t numOptions);
-
+OCStackResult OCDoResource(OCDoHandle *handle,
+                            OCMethod method,
+                            const char *requestUri,
+                            const OCDevAddr *destination,
+                            const char *request,
+                            OCConnectivityType connectivityType,
+                            OCQualityOfService qos,
+                            OCCallbackData *cbData,
+                            OCHeaderOption *options,
+                            uint8_t numOptions);
 /**
  * Cancel a request associated with a specific @ref OCDoResource invocation.
  *
@@ -446,37 +465,8 @@ OCNotifyListOfObservers (OCResourceHandle handle,
  */
 OCStackResult OCDoResponse(OCEntityHandlerResponse *response);
 
-
-//Utility methods
-
-/**
- * This method is used to retrieved the IPv4 address from OCDev address
- * data structure.
- *
- * @param ipAddr OCDevAddr address.
- * @param a first byte of IPv4 address.
- * @param b second byte of IPv4 address.
- * @param c third byte of IPv4 address.
- * @param d fourth byte of IPv4 address.
- * @return ::OC_STACK_OK on success, some other value upon failure.
- */
-int32_t OCDevAddrToIPv4Addr(OCDevAddr *ipAddr, uint8_t *a, uint8_t *b,
-            uint8_t *c, uint8_t *d );
-
-/**
- * This method is used to retrieve the port number from OCDev address
- * data structure.
- *
- * @param ipAddr OCDevAddr address.
- * @param port Port number.
- * @return ::OC_STACK_OK on success, some other value upon failure.
- */
-int32_t OCDevAddrToPort(OCDevAddr *ipAddr, uint16_t *port);
-
 #ifdef __cplusplus
 }
 #endif // __cplusplus
 
 #endif /* OCSTACK_H_ */
-
-
index 8864231..48782aa 100644 (file)
@@ -32,20 +32,8 @@ extern "C" {
 //-----------------------------------------------------------------------------
 // Defines
 //-----------------------------------------------------------------------------
-
-//TODO: May want to refactor this in upcoming sprints.
-//Don't want to expose to application layer that lower level stack is using CoAP.
-
-/// Authority + URI string to prefix well known queries
-#define OC_WELL_KNOWN_QUERY                  "224.0.1.187:5683/oic/res"
+#define OC_WELL_KNOWN_QUERY                  "/oic/res"
 #define OC_MULTICAST_DISCOVERY_URI           "/oic/res"
-#define OC_EXPLICIT_DEVICE_DISCOVERY_URI     "224.0.1.187:5683/oic/d?rt=core.led"
-/// Multicast address and port string to prefix multicast queries
-#define OC_MULTICAST_PREFIX                  "224.0.1.187:5683"
-/// IP Multicast address to use for multicast requests
-#define OC_MULTICAST_IP                      "224.0.1.187"
-/// IP Multicast port to use for multicast requests
-#define OC_MULTICAST_PORT                    5683
 
 #ifdef WITH_PRESENCE
 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
@@ -119,20 +107,134 @@ extern "C" {
 #define OC_DATA_MODEL_VERSION          "sec.0.95"
 //*******************
 
+// These provide backward compatibility - their use is deprecated
+#ifndef GOING_AWAY
+#define OC_MULTICAST_PREFIX                  "224.0.1.187:5683"
+#define OC_MULTICAST_IP                      "224.0.1.187:5683"
+#define OC_MULTICAST_PORT                    5683
+#endif // GOING_AWAY
 
 //-----------------------------------------------------------------------------
 // Typedefs
 //-----------------------------------------------------------------------------
 
+#define MAX_ADDR_STR_SIZE (40)
+#define MAX_IDENTITY_SIZE (32)
+
+/*
+ * These enums (OCTransportAdapter and OCTransportFlags) must
+ * be kept synchronized with OCConnectivityType (below) as well as
+ * CATransportAdapter and CATransportFlags (in CACommon.h).
+ */
+
+typedef enum
+{
+    OC_DEFAULT_ADAPTER = 0,
+
+    // value zero indicates discovery
+    OC_ADAPTER_IP           = (1 << 0),   // IPv4 and IPv6, including 6LoWPAN
+    OC_ADAPTER_GATT_BTLE    = (1 << 1),   // GATT over Bluetooth LE
+    OC_ADAPTER_RFCOMM_BTEDR = (1 << 2),   // RFCOMM over Bluetooth EDR
+} OCTransportAdapter;
+
+// enum layout assumes some targets have 16-bit integer (e.g., Arduino)
+typedef enum
+{
+    OC_DEFAULT_FLAGS = 0,
+
+    // Insecure transport is the default (subject to change)
+    OC_FLAG_SECURE     = (1 << 4),   // secure the transport path
+
+    // IPv4 & IPv6 autoselection is the default
+    OC_IP_USE_V6       = (1 << 5),   // IP adapter only
+    OC_IP_USE_V4       = (1 << 6),   // IP adapter only
+
+    // Link-Local multicast is the default multicast scope for IPv6.
+    // These are placed here to correspond to the IPv6 multicast address bits.
+    OC_SCOPE_INTERFACE = 0x1, // IPv6 Interface-Local scope (loopback)
+    OC_SCOPE_LINK      = 0x2, // IPv6 Link-Local scope (default)
+    OC_SCOPE_REALM     = 0x3, // IPv6 Realm-Local scope
+    OC_SCOPE_ADMIN     = 0x4, // IPv6 Admin-Local scope
+    OC_SCOPE_SITE      = 0x5, // IPv6 Site-Local scope
+    OC_SCOPE_ORG       = 0x8, // IPv6 Organization-Local scope
+    OC_SCOPE_GLOBAL    = 0xE, // IPv6 Global scope
+} OCTransportFlags;
+
+#define OC_MASK_SCOPE    (0x000F)
+#define OC_MASK_MODS     (0x0FF0)
+
+/*
+ * endpoint identity
+ */
+typedef struct
+{
+    uint16_t id_length;
+    unsigned char id[MAX_IDENTITY_SIZE];
+} OCIdentity;
+
 /**
  * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
+ *
+ * OCDevAddr must be the same as CAEndpoint (in CACommon.h).
  */
-typedef struct OCDevAddr
+typedef struct
 {
-    uint32_t     size;                    ///< length of the address stored in addr field.
-    uint8_t      addr[DEV_ADDR_SIZE_MAX]; ///< device address.
+    OCTransportAdapter      adapter;    // adapter type
+    OCTransportFlags        flags;      // transport modifiers
+    char                    addr[MAX_ADDR_STR_SIZE]; // address for all adapters
+    uint32_t                interface;  // usually zero for default interface
+    uint16_t                port;       // for IP
+    OCIdentity              identity;   // secure node identity
 } OCDevAddr;
 
+/*
+ * OCConnectivityType includes elements of both OCTransportAdapter
+ * and OCTransportFlags. It is defined conditionally because the
+ * smaller definition limits expandability on 32/64 bit integer machines,
+ * and the larger definition won't fit into an enum on 16-bit integer
+ * machines like Arduino.
+ *
+ * This structure must directly correspond to OCTransportAdapter
+ * and OCTransportFlags.
+ */
+typedef enum
+{
+    CT_DEFAULT = 0,                // use when defaults are ok
+
+    #if defined (__UINT32_MAX__) && (__UINT32_MAX__ == 65535) // 16-bit int
+    CT_ADAPTER_IP           = (1 << 10),  // IPv4 and IPv6, including 6LoWPAN
+    CT_ADAPTER_GATT_BTLE    = (1 << 11),  // GATT over Bluetooth LE
+    CT_ADAPTER_RFCOMM_BTEDR = (1 << 12),  // RFCOMM over Bluetooth EDR
+    #define CT_ADAPTER_SHIFT 10
+    #define CT_MASK_FLAGS 0x03FF
+    #define CT_MASK_ADAPTER 0xFC00
+    #else   // assume 32-bit int
+    CT_ADAPTER_IP           = (1 << 16),  // IPv4 and IPv6, including 6LoWPAN
+    CT_ADAPTER_GATT_BTLE    = (1 << 17),  // GATT over Bluetooth LE
+    CT_ADAPTER_RFCOMM_BTEDR = (1 << 18),  // RFCOMM over Bluetooth EDR
+    #define CT_ADAPTER_SHIFT 16
+    #define CT_MASK_FLAGS 0xFFFF
+    #define CT_MASK_ADAPTER 0xFFFF0000
+    #endif
+
+    // Insecure transport is the default (subject to change)
+    CT_FLAG_SECURE     = (1 << 4), // secure the transport path
+
+    // IPv4 & IPv6 autoselection is the default
+    CT_IP_USE_V6       = (1 << 5), // IP adapter only
+    CT_IP_USE_V4       = (1 << 6), // IP adapter only
+
+    // Link-Local multicast is the default multicast scope for IPv6.
+    // These are placed here to correspond to the IPv6 address bits.
+    CT_SCOPE_INTERFACE = 0x1, // IPv6 Interface-Local scope (loopback)
+    CT_SCOPE_LINK      = 0x2, // IPv6 Link-Local scope (default)
+    CT_SCOPE_REALM     = 0x3, // IPv6 Realm-Local scope
+    CT_SCOPE_ADMIN     = 0x4, // IPv6 Admin-Local scope
+    CT_SCOPE_SITE      = 0x5, // IPv6 Site-Local scope
+    CT_SCOPE_ORG       = 0x8, // IPv6 Organization-Local scope
+    CT_SCOPE_GLOBAL    = 0xE, // IPv6 Global scope
+} OCConnectivityType;
+
 /**
  * OC Virtual resources supported by every OC device.
  */
@@ -149,25 +251,27 @@ typedef enum
 } OCVirtualResources;
 
 /**
- * Standard RESTful HTTP Methods.
+ *  OCDoResource methods
  */
 typedef enum
 {
-    OC_REST_NOMETHOD    = 0,
-    OC_REST_GET         = (1 << 0),     ///< Read
-    OC_REST_PUT         = (1 << 1),     ///< Write
-    OC_REST_POST        = (1 << 2),     ///< Update
-    OC_REST_DELETE      = (1 << 3),     ///< Delete
+    OC_REST_NOMETHOD       = 0,
+    OC_REST_GET            = (1 << 0),     ///< Read
+    OC_REST_PUT            = (1 << 1),     ///< Write
+    OC_REST_POST           = (1 << 2),     ///< Update
+    OC_REST_DELETE         = (1 << 3),     ///< Delete
     /// Register observe request for most up date notifications ONLY.
-    OC_REST_OBSERVE     = (1 << 4),
+    OC_REST_OBSERVE        = (1 << 4),
     /// Register observe request for all notifications, including stale notifications.
-    OC_REST_OBSERVE_ALL = (1 << 5),
+    OC_REST_OBSERVE_ALL    = (1 << 5),
     /// Deregister observation, intended for internal use
     OC_REST_CANCEL_OBSERVE = (1 << 6),
     #ifdef WITH_PRESENCE
     /// Subscribe for all presence notifications of a particular resource.
-    OC_REST_PRESENCE    = (1 << 7)
+    OC_REST_PRESENCE       = (1 << 7),
     #endif
+    /// Allows OCDoResource caller to do discovery.
+    OC_REST_DISCOVER       = (1 << 8)
 } OCMethod;
 
 /**
@@ -238,18 +342,6 @@ typedef enum
 } OCTransportProtocolID;
 
 /**
- * Adaptor types.
- */
-typedef enum
-{
-    OC_IPV4 = 0,
-    OC_IPV6,
-    OC_EDR,
-    OC_LE,
-    OC_ALL // Multicast message: send over all the interfaces.
-} OCConnectivityType;
-
-/**
  * Declares Stack Results & Errors.
  */
 typedef enum
@@ -436,13 +528,15 @@ typedef struct
 typedef struct
 {
     /// Address of remote server
-    OCDevAddr * addr;
-    /// Indicates adaptor type on which the response was received
-    OCConnectivityType connType;
+    OCDevAddr devAddr;
+    OCDevAddr *addr;            // backward compatibility (points to devAddr)
+    OCConnectivityType connType;  // backward compatibility
     /// the is the result of our stack, OCStackResult should contain coap/other error codes;
     OCStackResult result;
     /// If associated with observe, this will represent the sequence of notifications from server.
     uint32_t sequenceNumber;
+    /// resourceURI
+    const char * resourceUri;
     /// resJSONPayload is retrieved from the payload of the received request PDU
     const char * resJSONPayload;
     /// An array of the received vendor specific header options
index 48718ee..93689fb 100644 (file)
@@ -33,17 +33,15 @@ static int UNICAST_DISCOVERY = 0;
 static int TEST_CASE = 0;
 
 static const char * UNICAST_DEVICE_DISCOVERY_QUERY = "coap://%s:6298/oic/d";
-static const char * UNICAST_PLATFORM_DISCOVERY_QUERY = "coap://%s:6298/oic/p";
-
 static const char * MULTICAST_DEVICE_DISCOVERY_QUERY = "/oic/d";
+static const char * UNICAST_PLATFORM_DISCOVERY_QUERY = "coap://%s:6298/oic/p";
 static const char * MULTICAST_PLATFORM_DISCOVERY_QUERY = "/oic/p";
 
 static const char * UNICAST_RESOURCE_DISCOVERY_QUERY = "coap://%s:6298/oic/res";
 static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oic/res";
 //The following variable determines the interface protocol (IPv4, IPv6, etc)
 //to be used for sending unicast messages. Default set to IPv4.
-static OCConnectivityType OC_CONNTYPE = OC_IPV4;
-
+static OCConnectivityType OC_CONNTYPE = CT_ADAPTER_IP;
 static std::string putPayload = "{\"oic\":[{\"rep\":{\"power\":15,\"state\":true}}]}";
 static std::string coapServerIP = "255.255.255.255";
 static std::string coapServerPort = "5683";
@@ -343,9 +341,6 @@ OCStackApplicationResult presenceCB(void* ctx, OCDoHandle handle, OCClientRespon
 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
         OCClientResponse * clientResponse)
 {
-    uint8_t remoteIpAddr[4];
-    uint16_t remotePortNu;
-
     if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
     {
         OC_LOG(INFO, TAG, "Callback Context for DISCOVER query recvd successfully");
@@ -355,16 +350,11 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
     {
         OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
 
-        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
-                remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
-        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
-
         std::string connectionType = getConnectivityType (clientResponse->connType);
         OC_LOG_V(INFO, TAG, "Discovered on %s", connectionType.c_str());
         OC_LOG_V(INFO, TAG,
-                "Device =============> Discovered %s @ %d.%d.%d.%d:%d",
-                clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
-                remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
+                "Device =============> Discovered %s @ %s:%d",
+                clientResponse->resJSONPayload, clientResponse->devAddr.addr, clientResponse->devAddr.port);
 
         parseClientResponse(clientResponse);
 
@@ -711,7 +701,7 @@ int InitPlatformDiscovery(OCQualityOfService qos)
     }
     else
     {
-        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
+        ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, CT_DEFAULT,
                 (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0);
     }
 
@@ -752,7 +742,7 @@ int InitDeviceDiscovery(OCQualityOfService qos)
     }
     else
     {
-        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
+        ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, CT_DEFAULT,
                 (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0);
     }
 
@@ -790,7 +780,7 @@ int InitDiscovery(OCQualityOfService qos)
     }
     else
     {
-        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
+        ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, CT_DEFAULT,
                 (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0);
     }
     if (ret != OC_STACK_OK)
@@ -815,10 +805,7 @@ int main(int argc, char* argv[])
                 TEST_CASE = atoi(optarg);
                 break;
             case 'c':
-                // TODO: re-enable IPv4/IPv6 command line selection when IPv6 is supported
-                // OC_CONNTYPE = OCConnectivityType(atoi(optarg));
-                OC_CONNTYPE = OC_IPV4;
-                OC_LOG(INFO, TAG, "IPv6 not currently supported, using IPv4.");
+                OC_CONNTYPE = CT_ADAPTER_IP;
                 break;
             default:
                 PrintUsage();
@@ -901,16 +888,8 @@ std::string getIPAddrTBServer(OCClientResponse * clientResponse)
     {
         return "";
     }
-    uint8_t a, b, c, d = 0;
-    if (0 != OCDevAddrToIPv4Addr(clientResponse->addr, &a, &b, &c, &d))
-    {
-        return "";
-    }
 
-    char ipaddr[16] = {'\0'};
-    // ostringstream not working correctly here, hence snprintf
-    snprintf(ipaddr,  sizeof(ipaddr), "%d.%d.%d.%d", a,b,c,d);
-    return std::string (ipaddr);
+    return std::string(clientResponse->devAddr.addr);
 }
 
 std::string getPortTBServer(OCClientResponse * clientResponse)
@@ -923,31 +902,23 @@ std::string getPortTBServer(OCClientResponse * clientResponse)
     {
         return "";
     }
-    uint16_t p = 0;
-    if (0 != OCDevAddrToPort(clientResponse->addr, &p))
-    {
-        return "";
-    }
     std::ostringstream ss;
-    ss << p;
+    ss << clientResponse->devAddr.port;
     return ss.str();
 }
 
 std::string getConnectivityType (OCConnectivityType connType)
 {
-    switch (connType)
+    switch (connType & CT_MASK_ADAPTER)
     {
-        case OC_IPV4:
-            return "IPv4";
-
-        case OC_IPV6:
-            return "IPv6";
+        case CT_ADAPTER_IP:
+            return "IP";
 
-        case OC_LE:
-            return "BLE";
+        case CT_ADAPTER_GATT_BTLE:
+            return "GATT";
 
-        case OC_EDR:
-            return "BT";
+        case CT_ADAPTER_RFCOMM_BTEDR:
+            return "RFCOMM";
 
         default:
             return "Incorrect connectivity";
index 365c8f6..45af118 100644 (file)
@@ -42,9 +42,9 @@ static int TEST_CASE = 0;
 static const char UNICAST_DISCOVERY_QUERY[] = "coap://%s:6298/oic/res";
 static std::string putPayload = "{\"oic\":[{\"rep\":{\"power\":15,\"state\":true}}]}";
 
-//The following variable determines the interface protocol (IPv4, IPv6, etc)
-//to be used for sending unicast messages. Default set to IPv4.
-static OCConnectivityType OC_CONNTYPE = OC_IPV4;
+//The following variable determines the interface protocol (IP, etc)
+//to be used for sending unicast messages. Default set to IP.
+static OCConnectivityType OC_CONNTYPE = CT_ADAPTER_IP;
 static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oic/res";
 
 int gQuitFlag = 0;
@@ -109,9 +109,6 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, OCMethod method,
 OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle,
                                 OCClientResponse * clientResponse)
 {
-    uint8_t remoteIpAddr[4];
-    uint16_t remotePortNu;
-
     if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
     {
         OC_LOG(INFO, TAG, "<====Callback Context for PUT received successfully====>");
@@ -123,13 +120,8 @@ OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle,
 
     if(clientResponse)
     {
-        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
-                            remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
-        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
-
-        OC_LOG_V(INFO, TAG,"PUT Response: %s \nFrom %d.%d.%d.%d:%d\n",
-                 clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
-                remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
+        OC_LOG_V(INFO, TAG,"PUT Response: %s \nFrom %s:%d\n",
+                 clientResponse->resJSONPayload, clientResponse->devAddr.addr, clientResponse->devAddr.port);
     }
     else
     {
@@ -141,9 +133,6 @@ OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle,
 OCStackApplicationResult postReqCB(void *ctx, OCDoHandle handle,
                           OCClientResponse *clientResponse)
 {
-    uint8_t remoteIpAddr[4];
-    uint16_t remotePortNu;
-
     if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
     {
         OC_LOG(INFO, TAG, "<====Callback Context for POST received successfully====>");
@@ -155,13 +144,8 @@ OCStackApplicationResult postReqCB(void *ctx, OCDoHandle handle,
 
     if(clientResponse)
     {
-        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
-                            remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
-        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
-
-        OC_LOG_V(INFO, TAG,"POST Response: %s \nFrom %d.%d.%d.%d:%d\n",
-                    clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
-                    remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
+        OC_LOG_V(INFO, TAG,"POST Response: %s \nFrom %s:%d\n",
+                    clientResponse->resJSONPayload, clientResponse->devAddr.addr, clientResponse->devAddr.port);
     }
     else
     {
@@ -174,9 +158,6 @@ OCStackApplicationResult postReqCB(void *ctx, OCDoHandle handle,
 OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle,
                            OCClientResponse * clientResponse)
 {
-    uint8_t remoteIpAddr[4];
-    uint16_t remotePortNu;
-
     if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
     {
         OC_LOG(INFO, TAG, "<====Callback Context for GET received successfully====>");
@@ -188,13 +169,8 @@ OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle,
 
     if (clientResponse)
     {
-        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr, remoteIpAddr + 1,
-                remoteIpAddr + 2, remoteIpAddr + 3);
-        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
-
-        OC_LOG_V(INFO, TAG,"Get Response: %s \nFrom %d.%d.%d.%d:%d\n",
-                clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
-                remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
+        OC_LOG_V(INFO, TAG,"Get Response: %s \nFrom %s:%d\n",
+                clientResponse->resJSONPayload, clientResponse->devAddr.addr, clientResponse->devAddr.port);
 
         if (clientResponse->rcvdVendorSpecificHeaderOptions
                 && clientResponse->numRcvdVendorSpecificHeaderOptions)
@@ -228,8 +204,6 @@ OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle,
 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
         OCClientResponse * clientResponse)
 {
-    uint8_t remoteIpAddr[4];
-    uint16_t remotePortNu;
     if (ctx == (void*)DEFAULT_CONTEXT_VALUE)
     {
         OC_LOG(INFO, TAG, "\n<====Callback Context for DISCOVERY query "
@@ -242,14 +216,9 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
 
     if (clientResponse)
     {
-        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
-                remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
-        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
-
         OC_LOG_V(INFO, TAG,
-                "Device Discovered %s \n @ %d.%d.%d.%d:%d\n",
-                clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
-                remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
+                "Device Discovered %s \n @ %s:%d\n",
+                clientResponse->resJSONPayload, clientResponse->devAddr.addr, clientResponse->devAddr.port);
 
         collectUniqueResource(clientResponse);
     }
@@ -376,7 +345,7 @@ int InitDiscovery()
     }
     else
     {
-        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
+        ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, CT_DEFAULT,
                 OC_LOW_QOS, &cbData, NULL, 0);
     }
 
@@ -387,20 +356,18 @@ int InitDiscovery()
     return ret;
 }
 
-
-
-const char * getIPAddr(const OCClientResponse * clientResponse)
+const char *getIPAddr(const OCClientResponse *clientResponse)
 {
-    uint8_t a, b, c, d;
-   if(!clientResponse || 0 != OCDevAddrToIPv4Addr(clientResponse->addr, &a, &b, &c, &d))
+    if (!clientResponse)
     {
         return "";
     }
 
-    char * ipaddr = NULL;
-    if((ipaddr = (char *) OICCalloc(1, MAX_IP_ADDR_ST_SZ)))
+    const OCDevAddr *devAddr = &clientResponse->devAddr;
+    char *ipaddr = (char *) OICCalloc(1, strlen(devAddr->addr));
+    if (ipaddr)
     {
-        snprintf(ipaddr, MAX_IP_ADDR_ST_SZ, "%d.%d.%d.%d", a,b,c,d);
+        snprintf(ipaddr, MAX_IP_ADDR_ST_SZ, "%s", devAddr->addr);
     }
     else
     {
@@ -409,18 +376,17 @@ const char * getIPAddr(const OCClientResponse * clientResponse)
     return ipaddr;
 }
 
-const char * getPort(const OCClientResponse * clientResponse)
+const char *getPort(const OCClientResponse *clientResponse)
 {
-    uint16_t p = 0;
-    if(!clientResponse || 0 != OCDevAddrToPort(clientResponse->addr, &p) )
+    if(!clientResponse)
     {
         return "";
     }
 
-    char * port = NULL;
-    if((port = (char *) OICCalloc(1, MAX_PORT_ST_SZ)))
+    char *port = NULL;
+    if((port = (char *)OICCalloc(1, MAX_PORT_ST_SZ)))
     {
-        snprintf(port, MAX_PORT_ST_SZ, "%d", p);
+        snprintf(port, MAX_PORT_ST_SZ, "%d", clientResponse->devAddr.port);
     }
     else
     {
@@ -660,24 +626,17 @@ void printResourceList()
         printf("uri = %s\n", iter->uri);
         printf("ip = %s\n", iter->ip);
         printf("port = %s\n", iter->port);
-        switch (iter->connType)
+        switch (iter->connType & CT_MASK_ADAPTER)
         {
-            case OC_IPV4:
-                printf("connType = %s\n","IPv4");
-                break;
-            case OC_IPV6:
-                // TODO: Allow IPv6 when support is added
-                printf("IPv6 not currently supported, default to IPv4\n");
-                //printf("connType = %s\n","IPv6");
+            case CT_ADAPTER_IP:
                 printf("connType = %s\n","IPv4");
                 break;
-            case OC_LE:
+            case OC_ADAPTER_GATT_BTLE:
                 printf("connType = %s\n","BLE");
                 break;
-            case OC_EDR:
+            case OC_ADAPTER_RFCOMM_BTEDR:
                 printf("connType = %s\n","BT");
                 break;
-            case OC_ALL:
             default:
                 printf("connType = %s\n","Invalid connType");
                 break;
@@ -719,10 +678,7 @@ int main(int argc, char* argv[])
                 TEST_CASE = atoi(optarg);
                 break;
             case 'c':
-                // TODO: re-enable IPv4/IPv6 command line selection when IPv6 is supported
-                // OC_CONNTYPE = OCConnectivityType(atoi(optarg));
-                OC_CONNTYPE = OC_IPV4;
-                OC_LOG(INFO, TAG, "Using default IPv4, IPv6 not currently supported.");
+                OC_CONNTYPE = CT_ADAPTER_IP;
                 break;
             default:
                 PrintUsage();
index a8875d4..0f9c40a 100644 (file)
@@ -76,9 +76,9 @@ testToTextMap queryInterface[] = {
 
 static std::string putPayload = "{\"state\":\"off\",\"power\":\"0\"}";
 
-//The following variable determines the interface protocol (IPv4, IPv6, etc)
-//to be used for sending unicast messages. Default set to IPv4.
-static OCConnectivityType OC_CONNTYPE = OC_IPV4;
+//The following variable determines the interface protocol (IP, etc)
+//to be used for sending unicast messages. Default set to IP.
+static OCConnectivityType OC_CONNTYPE = CT_ADAPTER_IP;
 static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oic/res";
 
 // The handle for the observe registration
@@ -183,9 +183,6 @@ OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse
 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
         OCClientResponse * clientResponse)
 {
-    uint8_t remoteIpAddr[4];
-    uint16_t remotePortNu;
-
     OC_LOG(INFO, TAG,
             "Entering discoveryReqCB (Application Layer CB)");
     OC_LOG_V(INFO, TAG, "StackResult: %s",
@@ -196,14 +193,9 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
         OC_LOG_V(INFO, TAG, "Callback Context recvd successfully");
     }
 
-    OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
-            remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
-    OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
-
     OC_LOG_V(INFO, TAG,
             "Device =============> Discovered %s @ %d.%d.%d.%d:%d",
-            clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
-            remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
+            clientResponse->resJSONPayload, clientResponse->devAddr.addr, clientResponse->devAddr.port);
 
     if(TEST == TEST_UNKNOWN_RESOURCE_GET_DEFAULT || TEST == TEST_UNKNOWN_RESOURCE_GET_BATCH ||\
             TEST == TEST_UNKNOWN_RESOURCE_GET_LINK_LIST)
@@ -223,8 +215,8 @@ int InitGetRequestToUnavailableResource(OCClientResponse * clientResponse)
     OCStackResult ret;
     OCCallbackData cbData;
     std::ostringstream getQuery;
-    getQuery << "coap://" << getIPAddrTBServer(clientResponse) << ":" <<
-            getPortTBServer(clientResponse) << "/SomeUnknownResource";
+    getQuery << "coap://" << clientResponse->devAddr.addr << ":" <<
+            clientResponse->devAddr.port << "/SomeUnknownResource";
     cbData.cb = getReqCB;
     cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
     cbData.cd = NULL;
@@ -245,8 +237,8 @@ int InitObserveRequest(OCClientResponse * clientResponse)
     OCCallbackData cbData;
     OCDoHandle handle;
     std::ostringstream obsReg;
-    obsReg << "coap://" << getIPAddrTBServer(clientResponse) << ":" <<
-            getPortTBServer(clientResponse) <<
+    obsReg << "coap://" << clientResponse->devAddr.addr << ":" <<
+            clientResponse->devAddr.addr <<
             getQueryStrForGetPut(clientResponse->resJSONPayload);
     cbData.cb = getReqCB;
     cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
@@ -273,8 +265,8 @@ int InitPutRequest(OCClientResponse * clientResponse)
     OCCallbackData cbData;
     //* Make a PUT query*/
     std::ostringstream getQuery;
-    getQuery << "coap://" << getIPAddrTBServer(clientResponse) << ":" <<
-            getPortTBServer(clientResponse) <<
+    getQuery << "coap://" << clientResponse->devAddr.addr << ":" <<
+            clientResponse->devAddr.port <<
             "/a/room" << queryInterface[TEST].text;
     cbData.cb = putReqCB;
     cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
@@ -296,17 +288,10 @@ int InitGetRequest(OCClientResponse * clientResponse)
     OCStackResult ret;
     OCCallbackData cbData;
 
-    uint8_t remoteIpAddr[4];
-    uint16_t remotePortNu;
-
-    OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
-            remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
-    OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
-
     //* Make a GET query*/
     std::ostringstream getQuery;
-    getQuery << "coap://" << getIPAddrTBServer(clientResponse) << ":" <<
-            getPortTBServer(clientResponse) <<
+    getQuery << "coap://" << clientResponse->devAddr.addr << ":" <<
+            clientResponse->devAddr.port <<
             "/a/room" << queryInterface[TEST].text;
 
     std::cout << "Get Query: " << getQuery.str() << std::endl;
@@ -336,7 +321,7 @@ int InitDiscovery()
     cbData.cb = discoveryReqCB;
     cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
     cbData.cd = NULL;
-    ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_ALL,
+    ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, CT_DEFAULT,
                         OC_LOW_QOS,
             &cbData, NULL, 0);
     if (ret != OC_STACK_OK)
@@ -358,9 +343,7 @@ int main(int argc, char* argv[])
                 TEST = atoi(optarg);
                 break;
             case 'c':
-                // TODO: re-enable IPv4/IPv6 command line selection when IPv6 is supported
-                // OC_CONNTYPE = OCConnectivityType(atoi(optarg));
-                OC_CONNTYPE = OC_IPV4;
+                OC_CONNTYPE = CT_ADAPTER_IP;
                 break;
             default:
                 PrintUsage();
@@ -405,48 +388,6 @@ int main(int argc, char* argv[])
     return 0;
 }
 
-std::string getIPAddrTBServer(OCClientResponse * clientResponse)
-{
-    if (!clientResponse)
-    {
-        return "";
-    }
-    if (!clientResponse->addr)
-    {
-        return "";
-    }
-    uint8_t a, b, c, d = 0;
-    if (0 != OCDevAddrToIPv4Addr(clientResponse->addr, &a, &b, &c, &d))
-    {
-        return "";
-    }
-
-    char ipaddr[16] = {'\0'};
-    // ostringstream not working correctly here, hence snprintf
-    snprintf(ipaddr,  sizeof(ipaddr), "%d.%d.%d.%d", a,b,c,d);
-    return std::string (ipaddr);
-}
-
-std::string getPortTBServer(OCClientResponse * clientResponse)
-{
-    if (!clientResponse)
-    {
-        return "";
-    }
-    if (!clientResponse->addr)
-    {
-        return "";
-    }
-    uint16_t p = 0;
-    if (0 != OCDevAddrToPort(clientResponse->addr, &p))
-    {
-        return "";
-    }
-    std::ostringstream ss;
-    ss << p;
-    return ss.str();
-}
-
 std::string getQueryStrForGetPut(const char * responsePayload)
 {
 
index 9b6ce98..0e07d81 100644 (file)
@@ -37,11 +37,10 @@ static std::string coapServerIP = "255.255.255.255";
 static std::string coapServerPort = "5683";
 static std::string coapServerResource = "/a/led";
 
-//The following variable determines the interface protocol (IPv4, IPv6, etc)
-//to be used for sending unicast messages. Default set to IPv4.
-static OCConnectivityType OC_CONNTYPE = OC_IPV4;
+//The following variable determines the interface protocol (IP, etc)
+//to be used for sending unicast messages. Default set to IP.
+static OCConnectivityType OC_CONNTYPE = CT_ADAPTER_IP;
 static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oic/res";
-
 static int IPV4_ADDR_SIZE = 16;
 void StripNewLineChar(char* str);
 
@@ -130,9 +129,6 @@ OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse
 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
         OCClientResponse * clientResponse)
 {
-    uint8_t remoteIpAddr[4];
-    uint16_t remotePortNu;
-
     if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
     {
         OC_LOG(INFO, TAG, "Callback Context for DISCOVER query recvd successfully");
@@ -142,14 +138,9 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
     {
         OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
 
-        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
-                remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
-        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
-
         OC_LOG_V(INFO, TAG,
-                "Device =============> Discovered %s @ %d.%d.%d.%d:%d",
-                clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
-                remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
+                "Device =============> Discovered %s @ %s:%d",
+                clientResponse->resJSONPayload, clientResponse->devAddr.addr, clientResponse->devAddr.port);
 
         parseClientResponse(clientResponse);
 
@@ -217,7 +208,7 @@ int InitDiscovery()
     }
     else
     {
-        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_ALL,
+        ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, CT_DEFAULT,
                 OC_LOW_QOS, &cbData, NULL, 0);
     }
     if (ret != OC_STACK_OK)
@@ -242,9 +233,7 @@ int main(int argc, char* argv[])
                 TEST_CASE = atoi(optarg);
                 break;
             case 'c':
-                // TODO: re-enable IPv4/IPv6 command line selection when IPv6 is supported
-                // OC_CONNTYPE = OCConnectivityType(atoi(optarg));
-                OC_CONNTYPE = OC_IPV4;
+                OC_CONNTYPE = CT_ADAPTER_IP;
                 break;
             default:
                 PrintUsage();
@@ -291,30 +280,6 @@ int main(int argc, char* argv[])
     return 0;
 }
 
-std::string getIPAddrTBServer(OCClientResponse * clientResponse)
-{
-    if(!clientResponse) return "";
-    if(!clientResponse->addr) return "";
-    uint8_t a, b, c, d = 0;
-    if(0 != OCDevAddrToIPv4Addr(clientResponse->addr, &a, &b, &c, &d) ) return "";
-
-    char ipaddr[16] = {'\0'};
-    // ostringstream not working correctly here, hence snprintf
-    snprintf(ipaddr,  sizeof(ipaddr), "%d.%d.%d.%d", a,b,c,d);
-    return std::string (ipaddr);
-}
-
-std::string getPortTBServer(OCClientResponse * clientResponse)
-{
-    if(!clientResponse) return "";
-    if(!clientResponse->addr) return "";
-    uint16_t p = 0;
-    if(0 != OCDevAddrToPort(clientResponse->addr, &p) ) return "";
-    std::ostringstream ss;
-    ss << p;
-    return ss.str();
-}
-
 std::string getQueryStrForGetPut(OCClientResponse * clientResponse)
 {
     return "/a/led";
@@ -322,8 +287,8 @@ std::string getQueryStrForGetPut(OCClientResponse * clientResponse)
 
 void parseClientResponse(OCClientResponse * clientResponse)
 {
-    coapServerIP = getIPAddrTBServer(clientResponse);
-    coapServerPort = getPortTBServer(clientResponse);
+    coapServerIP = clientResponse->devAddr.addr;
+    coapServerPort = clientResponse->devAddr.port;
     coapServerResource = getQueryStrForGetPut(clientResponse);
 }
 
index b3f1a42..ebc65a7 100644 (file)
@@ -140,23 +140,14 @@ OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse
 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
         OCClientResponse * clientResponse)
 {
-    uint8_t remoteIpAddr[4];
-    uint16_t remotePortNu;
-
     OC_LOG(INFO, TAG, "Callback Context for DISCOVER query recvd successfully");
 
     if (clientResponse)
     {
         OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
-
-        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
-                remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
-        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
-
         OC_LOG_V(INFO, TAG,
-                "Device =============> Discovered %s @ %d.%d.%d.%d:%d",
-                clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
-                remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
+                "Device =============> Discovered %s @ %s:%d",
+                clientResponse->resJSONPayload, clientResponse->devAddr.addr, clientResponse->devAddr.port);
 
         ocConnType = clientResponse->connType;
 
@@ -239,6 +230,7 @@ int InitGetRequest(OCQualityOfService qos)
 int InitDiscovery()
 {
     OCStackResult ret;
+    OCMethod method;
     OCCallbackData cbData;
     char szQueryUri[MAX_URI_LENGTH] = { 0 };
     OCConnectivityType discoveryReqConnType;
@@ -258,13 +250,15 @@ int InitDiscovery()
             OC_LOG(ERROR, TAG, "!! Bad input for IPV4 address. !!");
             return OC_STACK_INVALID_PARAM;
         }
-        discoveryReqConnType = OC_IPV4;
+        discoveryReqConnType = CT_ADAPTER_IP;
+        method = OC_REST_GET;
     }
     else
     {
         //Send discovery request on Wifi and Ethernet interface
-        discoveryReqConnType = OC_ALL;
+        discoveryReqConnType = CT_DEFAULT;
         strcpy(szQueryUri, MULTICAST_DISCOVERY_QUERY);
+        method = OC_REST_DISCOVER;
     }
 
     cbData.cb = discoveryReqCB;
@@ -276,7 +270,7 @@ int InitDiscovery()
         (UNICAST_DISCOVERY) ? "Unicast" : "Multicast",
         szQueryUri);
 
-    ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0,
+    ret = OCDoResource(NULL, method, szQueryUri, 0, 0,
             discoveryReqConnType, OC_LOW_QOS,
             &cbData, NULL, 0);
     if (ret != OC_STACK_OK)
@@ -364,28 +358,11 @@ int main(int argc, char* argv[])
     return 0;
 }
 
-std::string getIPAddrTBServer(OCClientResponse * clientResponse)
-{
-    if(!clientResponse) return "";
-    if(!clientResponse->addr) return "";
-    uint8_t a, b, c, d = 0;
-    if(0 != OCDevAddrToIPv4Addr(clientResponse->addr, &a, &b, &c, &d) ) return "";
-
-    char ipaddr[16] = {'\0'};
-    // ostringstream not working correctly here, hence snprintf
-    snprintf(ipaddr,  sizeof(ipaddr), "%d.%d.%d.%d", a,b,c,d);
-    return std::string (ipaddr);
-}
-
-
 std::string getPortTBServer(OCClientResponse * clientResponse)
 {
     if(!clientResponse) return "";
-    if(!clientResponse->addr) return "";
-    uint16_t p = 0;
-    if(0 != OCDevAddrToPort(clientResponse->addr, &p) ) return "";
     std::ostringstream ss;
-    ss << p;
+    ss << clientResponse->devAddr.port;
     return ss.str();
 }
 
@@ -466,7 +443,7 @@ int parseClientResponse(OCClientResponse * clientResponse)
     }
     cJSON_Delete(root);
 
-    coapServerIP = getIPAddrTBServer(clientResponse);
+    coapServerIP = clientResponse->devAddr.addr;
     if (port == -1)
     {
         coapServerPort = getPortTBServer(clientResponse);
index 39022c1..6e52718 100644 (file)
@@ -45,7 +45,8 @@ OCStackResult
 AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
              CAToken_t token, uint8_t tokenLength,
              OCDoHandle *handle, OCMethod method,
-             char * requestUri, char * resourceTypeName, OCConnectivityType conType, uint32_t ttl)
+             OCDevAddr *devAddr, char * requestUri,
+             char * resourceTypeName, uint32_t ttl)
 {
     if(!clientCB || !cbData || !handle || !requestUri || tokenLength > CA_MAX_TOKEN_LEN)
     {
@@ -96,8 +97,8 @@ AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
             {
                 cbNode->TTL = ttl;
             }
-            cbNode->requestUri = requestUri;
-            cbNode->conType = conType;
+            cbNode->requestUri = requestUri;    // I own it now
+            cbNode->devAddr = devAddr;          // I own it now
             LL_APPEND(cbList, cbNode);
             *clientCB = cbNode;
         }
@@ -116,6 +117,7 @@ AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
         OICFree(token);
         OICFree(*handle);
         OICFree(requestUri);
+        OICFree(devAddr);
         *handle = cbNode->handle;
     }
 
@@ -124,6 +126,7 @@ AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
     {
         // Amend the found or created node by adding a new resourceType to it.
         return InsertResourceTypeFilter(cbNode,(char *)resourceTypeName);
+        // I own resourceTypName now.
     }
     else
     {
index 2df74d9..d680a0f 100644 (file)
@@ -268,8 +268,7 @@ static OCStackResult BuildRootResourceJSON(OCResource *resource,
 
 
 static OCStackResult
-HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest,
-                       uint8_t filterOn, char *filterValue)
+HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest, uint8_t filterOn, char *filterValue)
 {
     if(!ehRequest)
     {
@@ -280,15 +279,15 @@ HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest,
     char jsonbuffer[MAX_RESPONSE_LENGTH] = {};
     size_t jsonbufferLength = 0;
     uint16_t remaining = 0;
-    char * ptr = NULL;
-    OCResource * collResource = (OCResource *) ehRequest->resource;
+    char *ptr = NULL;
+    OCResource *collResource = (OCResource *)ehRequest->resource;
 
     ptr = jsonbuffer;
     remaining = MAX_RESPONSE_LENGTH;
 
     ret = BuildRootResourceJSON(collResource, ptr, &remaining);
 
-    if (ret == OC_STACK_OK && remaining >= (sizeof(OC_JSON_SEPARATOR) + 1))
+    if (ret == OC_STACK_OK && remaining >= (sizeof (OC_JSON_SEPARATOR) + 1))
     {
         ptr += strlen((char*)ptr);
         *ptr = OC_JSON_SEPARATOR;
@@ -312,7 +311,7 @@ HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest,
 
                 // Function will return error if not enough space in buffer.
                 ret = BuildVirtualResourceResponse(temp, filterOn, filterValue,
-                         (char*)ptr, &remaining, CA_IPV4 );
+                                         (char*)ptr, &remaining, CA_ADAPTER_IP);
                 if (ret != OC_STACK_OK)
                 {
                     break;
index 555db9b..6ab5c58 100644 (file)
@@ -33,6 +33,7 @@
 #include "utlist.h"
 #include "pdu.h"
 
+
 // Module Name
 #define MOD_NAME PCF("ocobserve")
 
@@ -200,12 +201,12 @@ OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr,
             #endif
                 qos = DetermineObserverQoS(method, resourceObserver, qos);
 
-                result = AddServerRequest(&request, 0, 0, 0, 1, OC_REST_GET,
+                result = AddServerRequest(&request, 0, 0, 1, OC_REST_GET,
                         0, resPtr->sequenceNum, qos, resourceObserver->query,
                         NULL, NULL,
                         resourceObserver->token, resourceObserver->tokenLength,
                         resourceObserver->resUri, 0,
-                        &(resourceObserver->addressInfo), resourceObserver->connectivityType);
+                        &resourceObserver->devAddr);
 
                 if(request)
                 {
@@ -238,13 +239,12 @@ OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr,
 
                 //This is effectively the implementation for the presence entity handler.
                 OC_LOG(DEBUG, TAG, PCF("This notification is for Presence"));
-
-                result = AddServerRequest(&request, 0, 0, 0, 1, OC_REST_GET,
+                result = AddServerRequest(&request, 0, 0, 1, OC_REST_GET,
                         0, resPtr->sequenceNum, qos, resourceObserver->query,
                         NULL, NULL,
                         resourceObserver->token, resourceObserver->tokenLength,
                         resourceObserver->resUri, 0,
-                        &(resourceObserver->addressInfo), resourceObserver->connectivityType);
+                        &resourceObserver->devAddr);
 
                 if(result == OC_STACK_OK)
                 {
@@ -321,11 +321,11 @@ OCStackResult SendListObserverNotification (OCResource * resource,
                 qos = DetermineObserverQoS(OC_REST_GET, observer, qos);
 
 
-                result = AddServerRequest(&request, 0, 0, 0, 1, OC_REST_GET,
+                result = AddServerRequest(&request, 0, 0, 1, OC_REST_GET,
                         0, resource->sequenceNum, qos, observer->query,
                         NULL, NULL, observer->token, observer->tokenLength,
                         observer->resUri, 0,
-                        &(observer->addressInfo), observer->connectivityType);
+                        &observer->devAddr);
 
                 if(request)
                 {
@@ -422,8 +422,7 @@ OCStackResult AddObserver (const char         *resUri,
                            uint8_t            tokenLength,
                            OCResource         *resHandle,
                            OCQualityOfService qos,
-                           const CAAddress_t  *addressInfo,
-                           CATransportType_t connectivityType)
+                           const OCDevAddr    *devAddr)
 {
     // Check if resource exists and is observable.
     if (!resHandle)
@@ -464,10 +463,12 @@ OCStackResult AddObserver (const char         *resUri,
             memcpy(obsNode->token, token, tokenLength);
         }
         obsNode->tokenLength = tokenLength;
-        obsNode->addressInfo = *addressInfo;
-        obsNode->connectivityType = connectivityType;
+
+        obsNode->devAddr = *devAddr;
         obsNode->resource = resHandle;
+
         LL_APPEND (serverObsList, obsNode);
+
         return OC_STACK_OK;
     }
 
index 0e358df..2314461 100644 (file)
@@ -77,9 +77,9 @@ OCEntityHandlerResult defaultResourceEHandler(OCEntityHandlerFlag flag,
 }
 
 /* This method will retrieve the port at which the secure resource is hosted */
-static OCStackResult GetSecurePortInfo(CATransportType_t connType, uint16_t *port)
+static OCStackResult GetSecurePortInfo(CATransportAdapter_t connType, uint16_t *port)
 {
-    CALocalConnectivity_t* info = NULL;
+    CAEndpoint_t* info = NULL;
     uint32_t size = 0;
     OCStackResult ret = OC_STACK_ERROR;
 
@@ -88,11 +88,11 @@ static OCStackResult GetSecurePortInfo(CATransportType_t connType, uint16_t *por
     {
         while (size--)
         {
-            if (info[size].isSecured && info[size].type == connType)
+            if ((info[size].flags & CA_SECURE) && info[size].adapter == connType)
             {
-                if (info[size].type == CA_IPV4)
+                if (info[size].adapter == CA_ADAPTER_IP)
                 {
-                    *port = info[size].addressInfo.IP.port;
+                    *port = info[size].port;
                     ret = OC_STACK_OK;
                     break;
                 }
@@ -299,7 +299,7 @@ static OCStackResult ValidateUrlQuery (char *url, char *query,
 OCStackResult
 BuildVirtualResourceResponse(const OCResource *resourcePtr, uint8_t filterOn,
                        const char *filterValue, char *out, uint16_t *remaining,
-                       CATransportType_t connType )
+                       CATransportAdapter_t adapter)
 {
     if(!resourcePtr || !out  || !remaining)
     {
@@ -362,53 +362,53 @@ BuildVirtualResourceResponse(const OCResource *resourcePtr, uint8_t filterOn,
         if (encodeRes)
         {
             // Add URIs
-            cJSON_AddItemToObject (resObj, OC_RSRVD_HREF, cJSON_CreateString(resourcePtr->uri));
+            cJSON_AddItemToObject(resObj, OC_RSRVD_HREF, cJSON_CreateString(resourcePtr->uri));
 
             // Add server instance id
-            cJSON_AddItemToObject (resObj,
+            cJSON_AddItemToObject(resObj,
                                    OC_RSRVD_SERVER_INSTANCE_ID,
                                    cJSON_CreateString(OCGetServerInstanceIDString()));
 
 
             cJSON_AddItemToObject (resObj, OC_RSRVD_PROPERTY, propObj = cJSON_CreateObject());
             // Add resource types
-            cJSON_AddItemToObject (propObj, OC_RSRVD_RESOURCE_TYPE, rtArray = cJSON_CreateArray());
+            cJSON_AddItemToObject(propObj, OC_RSRVD_RESOURCE_TYPE, rtArray = cJSON_CreateArray());
             resourceTypePtr = resourcePtr->rsrcType;
             while (resourceTypePtr)
             {
-                cJSON_AddItemToArray (rtArray,
+                cJSON_AddItemToArray(rtArray,
                                       cJSON_CreateString(resourceTypePtr->resourcetypename));
                 resourceTypePtr = resourceTypePtr->next;
             }
             // Add interface types
-            cJSON_AddItemToObject (propObj, OC_RSRVD_INTERFACE, rtArray = cJSON_CreateArray());
+            cJSON_AddItemToObject(propObj, OC_RSRVD_INTERFACE, rtArray = cJSON_CreateArray());
             interfacePtr = resourcePtr->rsrcInterface;
             while (interfacePtr)
             {
-                cJSON_AddItemToArray (rtArray, cJSON_CreateString(interfacePtr->name));
+                cJSON_AddItemToArray(rtArray, cJSON_CreateString(interfacePtr->name));
                 interfacePtr = interfacePtr->next;
             }
 
             //Add Policy
-            cJSON_AddItemToObject (propObj, OC_RSRVD_POLICY, policyObj = cJSON_CreateObject());
+            cJSON_AddItemToObject(propObj, OC_RSRVD_POLICY, policyObj = cJSON_CreateObject());
 
             if (policyObj)
             {
                 // Policy Property Bitmap
                 // If resource is discoverable, set discoverability flag.
                 // Resources that are not discoverable will not have the flag.
-                cJSON_AddNumberToObject (policyObj, OC_RSRVD_BITMAP,
+                cJSON_AddNumberToObject(policyObj, OC_RSRVD_BITMAP,
                                  resourcePtr->resourceProperties & (OC_OBSERVABLE|OC_DISCOVERABLE));
 
                 // Set secure flag for secure resources
                 if (resourcePtr->resourceProperties & OC_SECURE)
                 {
-                    cJSON_AddNumberToObject (policyObj, OC_RSRVD_SECURE, OC_RESOURCE_SECURE);
+                    cJSON_AddNumberToObject(policyObj, OC_RSRVD_SECURE, OC_RESOURCE_SECURE);
                     //Set the IP port also as secure resources are hosted on a different port
                     uint16_t port = 0;
-                    if (GetSecurePortInfo (connType, &port) == OC_STACK_OK)
+                    if (GetSecurePortInfo(adapter, &port) == OC_STACK_OK)
                     {
-                        cJSON_AddNumberToObject (policyObj, OC_RSRVD_HOSTING_PORT, port);
+                        cJSON_AddNumberToObject(policyObj, OC_RSRVD_HOSTING_PORT, port);
                     }
                 }
             }
@@ -592,6 +592,8 @@ OCStackResult DetermineResourceHandling (const OCServerRequest *request,
 
     OC_LOG(INFO, TAG, PCF("Entering DetermineResourceHandling"));
 
+    const OCDevAddr *devAddr = &request->devAddr;
+
     // Check if virtual resource
     if (IsVirtualResource((const char*)request->resourceUrl))
     {
@@ -599,7 +601,7 @@ OCStackResult DetermineResourceHandling (const OCServerRequest *request,
         *resource = headResource;
         return OC_STACK_OK;
     }
-    if (NULL == request->resourceUrl || (strlen((const char*)(request->resourceUrl)) == 0))
+    if (strlen((const char*)(request->resourceUrl)) == 0)
     {
         // Resource URL not specified
         *handling = OC_RESOURCE_NOT_SPECIFIED;
@@ -625,7 +627,7 @@ OCStackResult DetermineResourceHandling (const OCServerRequest *request,
         }
 
         // secure resource will entertain only authorized requests
-        if ((resourcePtr->resourceProperties & OC_SECURE) && (request->secured == 0))
+        if ((resourcePtr->resourceProperties & OC_SECURE) && ((devAddr->flags & OC_FLAG_SECURE) == 0))
         {
             OC_LOG(ERROR, TAG, PCF("Un-authorized request. Ignoring"));
             return OC_STACK_RESOURCE_ERROR;
@@ -697,9 +699,9 @@ OCStackResult EntityHandlerCodeToOCStackCode(OCEntityHandlerResult ehResult)
 }
 
 static OCStackResult
-HandleVirtualResource (OCServerRequest *request, OCResource* resource)
+HandleVirtualResource(OCServerRequest *request, OCResource *resource)
 {
-    if(!request || !resource)
+    if (!request || !resource)
     {
         return OC_STACK_INVALID_PARAM;
     }
@@ -742,8 +744,9 @@ HandleVirtualResource (OCServerRequest *request, OCResource* resource)
                         remaining--;
                     }
                     firstLoopDone = 1;
-                    result = BuildVirtualResourceResponse(resource, filterOn, filterValue,
-                            (char*)ptr, &remaining, request->connectivityType );
+                    result = BuildVirtualResourceResponse(resource, filterOn,
+                                filterValue, (char*)ptr, &remaining,
+                                (CATransportAdapter_t)request->devAddr.adapter);
 
                     if (result != OC_STACK_OK)
                     {
@@ -919,7 +922,7 @@ HandleResourceWithEntityHandler (OCServerRequest *request,
                 (const char *)(request->query),
                 ehRequest.obsInfo.obsId, request->requestToken, request->tokenLength,
                 resource, request->qos,
-                &request->addressInfo, request->connectivityType);
+                &request->devAddr);
 
         if(result == OC_STACK_OK)
         {
index 2abade8..e4aac79 100644 (file)
@@ -239,14 +239,12 @@ OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle)
  *     OCStackResult
  */
 OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
-        uint8_t delayedResNeeded, uint8_t secured, uint8_t notificationFlag, OCMethod method,
+        uint8_t delayedResNeeded, uint8_t notificationFlag, OCMethod method,
         uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption,
         OCQualityOfService qos, char * query,
         OCHeaderOption * rcvdVendorSpecificHeaderOptions,
-        char * reqJSONPayload, CAToken_t requestToken,
-        uint8_t tokenLength,
-        char * resourceUrl, size_t reqTotalSize,
-        CAAddress_t *addressInfo, CATransportType_t connectivityType)
+        char * reqJSONPayload, CAToken_t requestToken, uint8_t tokenLength,
+        char * resourceUrl, size_t reqTotalSize, const OCDevAddr *devAddr)
 {
     OCServerRequest * serverRequest = NULL;
 
@@ -255,11 +253,11 @@ OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
     //null terminator as well.
     serverRequest = (OCServerRequest *) OICCalloc(1, sizeof(OCServerRequest) +
         (reqTotalSize ? reqTotalSize : 1) - 1);
+    VERIFY_NON_NULL(devAddr);
     VERIFY_NON_NULL(serverRequest);
 
     serverRequest->coapID = coapID;
     serverRequest->delayedResNeeded = delayedResNeeded;
-    serverRequest->secured = secured;
     serverRequest->notificationFlag = notificationFlag;
 
     serverRequest->method = method;
@@ -305,11 +303,7 @@ OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
             resourceUrl);
     }
 
-    if (addressInfo)
-    {
-        serverRequest->addressInfo = *addressInfo;
-    }
-    serverRequest->connectivityType = connectivityType;
+    serverRequest->devAddr = *devAddr;
 
     *request = serverRequest;
     OC_LOG(INFO, TAG, PCF("Server Request Added!!"));
@@ -442,7 +436,7 @@ CAResponseResult_t ConvertEHResultToCAResult (OCEntityHandlerResult result)
 OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse)
 {
     OCStackResult result = OC_STACK_ERROR;
-    CARemoteEndpoint_t responseEndpoint = {};
+    CAEndpoint_t responseEndpoint = {};
     CAResponseInfo_t responseInfo = {};
     CAHeaderOption_t* optionsPointer = NULL;
 
@@ -462,12 +456,9 @@ OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse)
 
     OCServerRequest *serverRequest = (OCServerRequest *)ehResponse->requestHandle;
 
-    // Copy the address
-    responseEndpoint.resourceUri      = (CAURI_t) serverRequest->resourceUrl;
-    responseEndpoint.addressInfo      = serverRequest->addressInfo;
-    responseEndpoint.transportType    = serverRequest->connectivityType;
-    responseEndpoint.isSecured        = serverRequest->secured;
+    CopyDevAddrToEndpoint(&serverRequest->devAddr, &responseEndpoint);
 
+    responseInfo.info.resourceUri = serverRequest->resourceUrl;
     responseInfo.result = ConvertEHResultToCAResult(ehResponse->ehResult);
 
     if(serverRequest->notificationFlag && serverRequest->qos == OC_HIGH_QOS)
@@ -570,18 +561,18 @@ OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse)
 
     #ifdef WITH_PRESENCE
     //TODO: Add other connectivity types to CAConnTypes[] when enabled
-    CATransportType_t CAConnTypes[] = {CA_IPV4};
+    CATransportAdapter_t CAConnTypes[] = {CA_ADAPTER_IP};
     const char * connTypes[] = {"ip transport"};
-    int size = sizeof(CAConnTypes)/ sizeof(CATransportType_t);
-    CATransportType_t connType = responseEndpoint.transportType;
+    int size = sizeof(CAConnTypes)/ sizeof(CATransportAdapter_t);
+    CATransportAdapter_t adapter = responseEndpoint.adapter;
     CAResult_t caResult = CA_STATUS_FAILED;
     result = OC_STACK_OK;
 
     //Sending response on all n/w interfaces
     for(int i = 0; i < size; i++ )
     {
-        responseEndpoint.transportType = (CATransportType_t)(connType & CAConnTypes[i]);
-        if(responseEndpoint.transportType)
+        responseEndpoint.adapter = (CATransportAdapter_t)(adapter & CAConnTypes[i]);
+        if(responseEndpoint.adapter)
         {
             //The result is set to OC_STACK_OK only if CASendResponse succeeds in sending the
             //response on all the n/w interfaces else it is set to OC_STACK_ERROR
index cc0342c..415e8fb 100644 (file)
@@ -108,6 +108,8 @@ void* defaultDeviceHandlerCallbackParameter = NULL;
             {OC_LOG_V(FATAL, TAG, "%s failed!!", #op); goto exit;} }
 #define VERIFY_NON_NULL(arg, logLevel, retVal) { if (!(arg)) { OC_LOG((logLevel), \
              TAG, PCF(#arg " is NULL")); return (retVal); } }
+#define VERIFY_NON_NULL_NR(arg, logLevel) { if (!(arg)) { OC_LOG((logLevel), \
+             TAG, PCF(#arg " is NULL")); return; } }
 #define VERIFY_NON_NULL_V(arg) { if (!arg) {OC_LOG_V(FATAL, TAG, "%s is NULL", #arg);\
     goto exit;} }
 
@@ -277,20 +279,6 @@ static OCStackResult verifyUriQueryLength(const char * inputUri,
  */
 static bool OCIsPacketTransferRequired(const char *request, const char *response, size_t size);
 
-/**
- * Retrieves a resource type based upon a query contains only just one
- * resource attribute (and that has to be of type "rt").
- *
- * @remark This API malloc's memory for the resource type. Do not malloc resourceType
- * before passing in.
- *
- * @param query The query part of the URI.
- * @param resourceType The resource type to be populated; pass by reference.
- *
- * @return ::OC_STACK_OK on success, some other value upon failure.
- */
-static OCStackResult getResourceType(const char * query, char** resourceType);
-
 /*
  * Attempts to initialize every network interface that the CA Layer might have compiled in.
  *
@@ -311,22 +299,6 @@ static CAResult_t OCSelectNetwork();
 static uint32_t GetTicks(uint32_t afterMilliSeconds);
 
 /**
- * This method is used to create the IPv4 dev_addr structure.
- * Builds a socket interface address using IP address and port number.
- * TODO: Remove in future. Temporary helper function.
- *
- * @param a IPv4 octet 0.
- * @param b IPv4 octet 1.
- * @param c IPv4 octet 2.
- * @param d IPv4 octet 3.
- * @param port Port number.
- * @param ipAddr - IPv4 address.
- * @return ::OC_STACK_OK on success, some other value upon failure.
- */
-static OCStackResult OCBuildIPv4Address(uint8_t a, uint8_t b, uint8_t c, uint8_t d,
-        uint16_t port, OCDevAddr *ipAddr);
-
-/**
  * Convert CAResponseResult_t to OCStackResult.
  *
  * @param caCode CAResponseResult_t code.
@@ -343,33 +315,20 @@ static OCStackResult CAToOCStackResult(CAResponseResult_t caCode);
 static CAResponseResult_t OCToCAStackResult(OCStackResult ocCode);
 
 /**
- * Convert OCConnectivityType to CATransportType_t.
+ * Convert OCTransportFlags_t to CATransportModifiers_t.
  *
- * @param ocConType OCConnectivityType input.
- * @param caConType CATransportType_t output.
- * @return  ::OC_STACK_OK on success, some other value upon failure.
+ * @param ocConType OCTransportFlags_t input.
+ * @return CATransportFlags
  */
-static OCStackResult OCToCATransportType(OCConnectivityType ocConType,
-        CATransportType_t* caConType);
+static CATransportFlags_t OCToCATransportFlags(OCTransportFlags ocConType);
 
 /**
- * Convert CATransportType_t to OCConnectivityType.
+ * Convert CATransportFlags_t to OCTransportModifiers_t.
  *
- * @param caConType CATransportType_t input.
- * @param ocConType OCConnectivityType output.
- * @return ::OC_STACK_OK on success, some other value upon failure.
+ * @param caConType CATransportFlags_t input.
+ * @return OCTransportFlags
  */
-static OCStackResult CAToOCConnectivityType(CATransportType_t caConType,
-        OCConnectivityType *ocConType);
-
-/**
- * Update response.addr appropriately from endPoint.addressInfo.
- *
- * @param address OCDevAddr output.
- * @param endPoint CARemoteEndpoint_t input.
- * @return ::OC_STACK_OK on success, some other value upon failure.
- */
-static OCStackResult UpdateResponseAddr(OCDevAddr *address, const CARemoteEndpoint_t* endPoint);
+static OCTransportFlags CAToOCTransportFlags(CATransportFlags_t caConType);
 
 /**
  * Handle response from presence request.
@@ -378,8 +337,8 @@ static OCStackResult UpdateResponseAddr(OCDevAddr *address, const CARemoteEndpoi
  * @param responseInfo CA response info.
  * @return ::OC_STACK_OK on success, some other value upon failure.
  */
-static OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint,
-        const CAResponseInfo_tresponseInfo);
+static OCStackResult HandlePresenceResponse(const CAEndpoint_t *endPoint,
+        const CAResponseInfo_t *responseInfo);
 
 /**
  * This function will be called back by CA layer when a response is received.
@@ -387,7 +346,7 @@ static OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint,
  * @param endPoint CA remote endpoint.
  * @param responseInfo CA response info.
  */
-static void HandleCAResponses(const CARemoteEndpoint_t* endPoint,
+static void HandleCAResponses(const CAEndpoint_t* endPoint,
         const CAResponseInfo_t* responseInfo);
 
 /**
@@ -396,7 +355,7 @@ static void HandleCAResponses(const CARemoteEndpoint_t* endPoint,
  * @param endPoint CA remote endpoint.
  * @param requestInfo CA request info.
  */
-static void HandleCARequests(const CARemoteEndpoint_t* endPoint,
+static void HandleCARequests(const CAEndpoint_t* endPoint,
         const CARequestInfo_t* requestInfo);
 
 /**
@@ -453,25 +412,64 @@ uint32_t GetTicks(uint32_t afterMilliSeconds)
     }
 }
 
-OCStackResult OCBuildIPv4Address(uint8_t a, uint8_t b, uint8_t c, uint8_t d,
-        uint16_t port, OCDevAddr *ipAddr)
+void CopyEndpointToDevAddr(const CAEndpoint_t *in, OCDevAddr *out)
 {
-    if (!ipAddr )
+    VERIFY_NON_NULL_NR(in, FATAL);
+    VERIFY_NON_NULL_NR(out, FATAL);
+
+    out->adapter = (OCTransportAdapter)in->adapter;
+    out->flags = CAToOCTransportFlags(in->flags);
+    strncpy(out->addr, in->addr, MAX_ADDR_STR_SIZE);
+    out->addr[MAX_ADDR_STR_SIZE - 1] = '\0';
+    out->port = in->port;
+}
+
+void CopyDevAddrToEndpoint(const OCDevAddr *in, CAEndpoint_t *out)
+{
+    VERIFY_NON_NULL_NR(in, FATAL);
+    VERIFY_NON_NULL_NR(out, FATAL);
+
+    out->adapter = (CATransportAdapter_t)in->adapter;
+    out->flags = OCToCATransportFlags(in->flags);
+    strncpy(out->addr, in->addr, MAX_ADDR_STR_SIZE);
+    out->port = in->port;
+}
+
+static OCStackResult OCCreateEndpoint(OCDevAddr *devAddr, CAEndpoint_t **endpoint)
+{
+    VERIFY_NON_NULL(devAddr, FATAL, OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL(endpoint, FATAL, OC_STACK_INVALID_PARAM);
+
+    CAEndpoint_t *ep = (CAEndpoint_t *)OICMalloc(sizeof (CAEndpoint_t));
+    if (!ep)
     {
-        OC_LOG(FATAL, TAG, PCF("Invalid argument"));
-        return OC_STACK_INVALID_PARAM;
+        return OC_STACK_NO_MEMORY;
     }
 
-    ipAddr->addr[0] = a;
-    ipAddr->addr[1] = b;
-    ipAddr->addr[2] = c;
-    ipAddr->addr[3] = d;
-    ipAddr->addr[4] = (uint8_t)port;
-    ipAddr->addr[5] = (uint8_t)(port >> 8);
+    ep->adapter = (CATransportAdapter_t)devAddr->adapter;
+    ep->flags = OCToCATransportFlags(devAddr->flags);
+    strncpy(ep->addr, devAddr->addr, MAX_ADDR_STR_SIZE_CA);
+    ep->port = devAddr->port;
+
+    *endpoint = ep;
 
     return OC_STACK_OK;
 }
 
+static void OCDestroyEndpoint(CAEndpoint_t *endpoint)
+{
+    free(endpoint);
+}
+
+void FixUpClientResponse(OCClientResponse *cr)
+{
+    VERIFY_NON_NULL_NR(cr, FATAL);
+
+    cr->addr = &cr->devAddr;
+    cr->connType = (OCConnectivityType)
+        ((cr->devAddr.adapter << CT_ADAPTER_SHIFT) | (cr->devAddr.flags & CT_MASK_FLAGS));
+}
+
 //-----------------------------------------------------------------------------
 // Internal API function
 //-----------------------------------------------------------------------------
@@ -640,93 +638,25 @@ CAResponseResult_t OCToCAStackResult(OCStackResult ocCode)
     return ret;
 }
 
-OCStackResult OCToCATransportType(OCConnectivityType ocConType, CATransportType_t* caConType)
+CATransportFlags_t OCToCATransportFlags(OCTransportFlags ocFlags)
 {
-    OCStackResult ret = OC_STACK_OK;
+    CATransportFlags_t caFlags = (CATransportFlags_t)ocFlags;
 
-    switch(ocConType)
+    // supply default behavior
+    if ((caFlags & (CA_IPV6|CA_IPV4)) == 0)
     {
-        case OC_IPV4:
-            *caConType = CA_IPV4;
-            break;
-        case OC_IPV6:
-            *caConType = CA_IPV6;
-            break;
-        case OC_EDR:
-            *caConType = CA_EDR;
-            break;
-        case OC_LE:
-            *caConType = CA_LE;
-            break;
-        case OC_ALL:
-            // Currently OC_ALL represents IPv4
-            // Add other connectivity types as they are enabled in future
-            *caConType = (CATransportType_t) (CA_IPV4);
-            break;
-        default:
-            ret = OC_STACK_INVALID_PARAM;
-            break;
+        caFlags = (CATransportFlags_t)(caFlags|CA_IPV6|CA_IPV4);
     }
-    return ret;
-}
-
-OCStackResult CAToOCConnectivityType(CATransportType_t caConType, OCConnectivityType *ocConType)
-{
-    OCStackResult ret = OC_STACK_OK;
-
-    switch(caConType)
+    if ((caFlags & OC_MASK_SCOPE) == 0)
     {
-        case CA_IPV4:
-            *ocConType = OC_IPV4;
-            break;
-        case CA_IPV6:
-            *ocConType = OC_IPV6;
-            break;
-        case CA_EDR:
-            *ocConType = OC_EDR;
-            break;
-        case CA_LE:
-            *ocConType = OC_LE;
-            break;
-        default:
-            ret = OC_STACK_INVALID_PARAM;
-            break;
+        caFlags = (CATransportFlags_t)(caFlags|OC_SCOPE_LINK);
     }
-    return ret;
+    return caFlags;
 }
 
-OCStackResult UpdateResponseAddr(OCDevAddr *address, const CARemoteEndpoint_t* endPoint)
+OCTransportFlags CAToOCTransportFlags(CATransportFlags_t caFlags)
 {
-    OCStackResult ret = OC_STACK_ERROR;
-    char * tok = NULL;
-    char * savePtr = NULL;
-    char* cpAddress = OICStrdup(endPoint->addressInfo.IP.ipAddress);
-    if(!cpAddress)
-    {
-        ret = OC_STACK_NO_MEMORY;
-        goto exit;
-    }
-
-    // Grabs the first three numbers from the IPv4 address and replaces dots
-    for(int i=0; i<4; i++)
-    {
-        tok = strtok_r(i==0 ? cpAddress : NULL, ".", &savePtr);
-
-        if(!tok)
-        {
-            ret = OC_STACK_ERROR;
-            goto exit;
-        }
-        address->addr[i] = atoi(tok);
-    }
-
-    address->addr[4] = (uint8_t)endPoint->addressInfo.IP.port;
-    address->addr[5] = (uint8_t)(endPoint->addressInfo.IP.port >> 8);
-    ret = OC_STACK_OK;
-
-exit:
-    OICFree(cpAddress);
-    return ret;
+    return (OCTransportFlags)caFlags;
 }
 
 static OCStackResult ResetPresenceTTL(ClientCB *cbNode, uint32_t maxAgeSeconds)
@@ -785,11 +715,11 @@ static OCStackResult ResetPresenceTTL(ClientCB *cbNode, uint32_t maxAgeSeconds)
 
 const char *convertTriggerEnumToString(OCPresenceTrigger trigger)
 {
-    if(trigger == OC_PRESENCE_TRIGGER_CREATE)
+    if (trigger == OC_PRESENCE_TRIGGER_CREATE)
     {
         return OC_RSRVD_TRIGGER_CREATE;
     }
-    else if(trigger == OC_PRESENCE_TRIGGER_CHANGE)
+    else if (trigger == OC_PRESENCE_TRIGGER_CHANGE)
     {
         return OC_RSRVD_TRIGGER_CHANGE;
     }
@@ -815,6 +745,32 @@ OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr)
     }
 }
 
+/**
+ * The cononical presence allows constructed URIs to be string compared.
+ *
+ * requestUri must be a char array of size CA_MAX_URI_LENGTH
+ */
+static int FormCanonicalPresenceUri(const CAEndpoint_t *endpoint, char *resourceUri, char *presenceUri)
+{
+    VERIFY_NON_NULL(endpoint, FATAL, OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL(resourceUri, FATAL, OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL(presenceUri, FATAL, OC_STACK_INVALID_PARAM);
+
+    const char *format;
+
+    if (endpoint->flags & CA_IPV6)
+    {
+        format = "coap://[%s]:%u%s";
+    }
+    else
+    {
+        format = "coap://%s:%u%s";
+    }
+
+    return snprintf(presenceUri, CA_MAX_URI_LENGTH, format, endpoint->addr,
+                                               endpoint->port, OC_PRESENCE_URI);
+}
+
 void parsePresencePayload(char* payload, uint32_t* seqNum, uint32_t* maxAge,
         OCPresenceTrigger *presenceTrigger, char** resType)
 {
@@ -920,19 +876,22 @@ exit:
     cJSON_Delete(repObj);
 }
 
-static OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint,
-                            const CAResponseInfo_tresponseInfo)
+OCStackResult HandlePresenceResponse(const CAEndpoint_t *endpoint,
+                            const CAResponseInfo_t *responseInfo)
 {
+    VERIFY_NON_NULL(endpoint, FATAL, OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL(responseInfo, FATAL, OC_STACK_INVALID_PARAM);
+
     OCStackApplicationResult cbResult = OC_STACK_DELETE_TRANSACTION;
     ClientCB * cbNode = NULL;
     char *resourceTypeName = NULL;
-    OCClientResponse response = {};
-    OCDevAddr address = {};
+    OCClientResponse response;
     OCStackResult result = OC_STACK_ERROR;
     uint32_t maxAge = 0;
     OCPresenceTrigger presenceTrigger = OC_PRESENCE_TRIGGER_CHANGE;
-    char *fullUri = NULL;
-    char *ipAddress = NULL;
+    int uriLen;
+    char presenceUri[CA_MAX_URI_LENGTH];
+
     int presenceSubscribe = 0;
     int multicastPresenceSubscribe = 0;
 
@@ -942,70 +901,40 @@ static OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint,
         return OC_STACK_ERROR;
     }
 
-    fullUri = (char *) OICMalloc(MAX_URI_LENGTH);
-
-    if(!fullUri)
-    {
-        OC_LOG(ERROR, TAG, PCF("Memory could not be allocated for fullUri"));
-        result = OC_STACK_NO_MEMORY;
-        goto exit;
-    }
-
-    ipAddress = OICStrdup(endPoint->addressInfo.IP.ipAddress);
-
-    if(!ipAddress)
+    uriLen = FormCanonicalPresenceUri(endpoint, OC_PRESENCE_URI, presenceUri);
+    if (uriLen < 0 || uriLen >= sizeof (presenceUri))
     {
-        OC_LOG(ERROR, TAG, PCF("Memory could not be allocated for ipAddress"));
-        result = OC_STACK_NO_MEMORY;
-        goto exit;
+        return OC_STACK_INVALID_URI;
     }
 
-
-    snprintf(fullUri, MAX_URI_LENGTH, "coap://%s:%u%s", ipAddress, endPoint->addressInfo.IP.port,
-                OC_PRESENCE_URI);
-
-    cbNode = GetClientCB(NULL, 0, NULL, fullUri);
-
-    if(cbNode)
+    cbNode = GetClientCB(NULL, 0, NULL, presenceUri);
+    if (cbNode)
     {
         presenceSubscribe = 1;
     }
     else
     {
-        snprintf(fullUri, MAX_URI_LENGTH, "coap://%s:%u%s", OC_MULTICAST_IP, OC_MULTICAST_PORT,
-                                                endPoint->resourceUri);
-        cbNode = GetClientCB(NULL, 0, NULL, fullUri);
-        if(cbNode)
+        strncpy(presenceUri, responseInfo->info.resourceUri, CA_MAX_URI_LENGTH);
+        cbNode = GetClientCB(NULL, 0, NULL, presenceUri);
+        if (cbNode)
         {
             multicastPresenceSubscribe = 1;
         }
     }
 
-    if(!presenceSubscribe && !multicastPresenceSubscribe)
+    if (!presenceSubscribe && !multicastPresenceSubscribe)
     {
-        OC_LOG(ERROR, TAG, PCF("Received a presence notification, but no callback, ignoring"));
+         OC_LOG(ERROR, TAG, PCF("Received a presence notification, but no callback, ignoring"));
         goto exit;
     }
 
     response.resJSONPayload = responseInfo->info.payload;
     response.result = OC_STACK_OK;
 
-    result = UpdateResponseAddr(&address, endPoint);
-    if(result != OC_STACK_OK)
-    {
-        goto exit;
-    }
-
-    response.addr = &address;
-
-    result = CAToOCConnectivityType(endPoint->transportType, &(response.connType));
-    if(result != OC_STACK_OK)
-    {
-        OC_LOG(ERROR, TAG, PCF("Invalid connectivity type in endpoint"));
-        goto exit;
-    }
+    CopyEndpointToDevAddr(endpoint, &response.devAddr);
+    FixUpClientResponse(&response);
 
-    if(responseInfo->info.payload)
+    if (responseInfo->info.payload)
     {
         parsePresencePayload(responseInfo->info.payload,
                                 &(response.sequenceNumber),
@@ -1014,28 +943,14 @@ static OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint,
                                 &resourceTypeName);
     }
 
-    if(presenceSubscribe)
+    if (presenceSubscribe)
     {
         if(cbNode->sequenceNumber == response.sequenceNumber)
         {
-            if (cbNode->presence)
-            {
-                OC_LOG(INFO, TAG, PCF("No presence change. Updating TTL."));
-
-                result = ResetPresenceTTL(cbNode, maxAge);
-
-                if (result != OC_STACK_OK)
-                {
-                    OC_LOG_V(ERROR, TAG, "ResetPresenceTTL failed with error: %u", result);
-                }
-            }
-            else
-            {
-                OC_LOG(INFO, TAG, PCF("Not subscribed to presence."));
-            }
-
+            OC_LOG(INFO, TAG, PCF("No presence change"));
             goto exit;
         }
+
         if(maxAge == 0)
         {
             OC_LOG(INFO, TAG, PCF("Stopping presence"));
@@ -1051,7 +966,8 @@ static OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint,
         {
             if(!cbNode->presence)
             {
-                cbNode->presence = (OCPresence *) OICMalloc(sizeof(OCPresence));
+                cbNode->presence = (OCPresence *)OICMalloc(sizeof (OCPresence));
+
                 if(!(cbNode->presence))
                 {
                     OC_LOG(ERROR, TAG, PCF("Could not allocate memory for cbNode->presence"));
@@ -1089,9 +1005,8 @@ static OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint,
     else
     {
         // This is the multicast case
-
         OCMulticastNode* mcNode = NULL;
-        mcNode = GetMCPresenceNode(fullUri);
+        mcNode = GetMCPresenceNode(presenceUri);
 
         if(mcNode != NULL)
         {
@@ -1110,22 +1025,24 @@ static OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint,
         }
         else
         {
-            char* uri = OICStrdup(fullUri);
-            if(!uri)
+            char* uri = OICStrdup(presenceUri);
+            if (!uri)
             {
-                OC_LOG(ERROR, TAG,
+                OC_LOG(INFO, TAG,
                     PCF("No Memory for URI to store in the presence node"));
                 result = OC_STACK_NO_MEMORY;
                 goto exit;
             }
+
             result = AddMCPresenceNode(&mcNode, uri, response.sequenceNumber);
-            if(result != OC_STACK_OK)
+            if(result == OC_STACK_NO_MEMORY)
             {
-                OC_LOG(ERROR, TAG,
-                    PCF("Unable to add Multicast Presence Node"));
+                OC_LOG(INFO, TAG,
+                    PCF("No Memory for Multicast Presence Node"));
                 OICFree(uri);
                 goto exit;
             }
+            // presence node now owns uri
         }
 
         // Ensure that a filter is actually applied.
@@ -1146,29 +1063,17 @@ static OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint,
     }
 
 exit:
-OICFree(fullUri);
-OICFree(ipAddress);
-OICFree(resourceTypeName);
-return result;
+    OICFree(resourceTypeName);
+    return result;
 }
 
-void HandleCAResponses(const CARemoteEndpoint_t* endPoint, const CAResponseInfo_t* responseInfo)
+void HandleCAResponses(const CAEndpoint_t* endPoint, const CAResponseInfo_t* responseInfo)
 {
-    OC_LOG(INFO, TAG, PCF("Enter HandleCAResponses"));
-
-    if(NULL == endPoint)
-    {
-        OC_LOG(ERROR, TAG, PCF("endPoint is NULL"));
-        return;
-    }
-
-    if(NULL == responseInfo)
-    {
-        OC_LOG(ERROR, TAG, PCF("responseInfo is NULL"));
-        return;
-    }
+    VERIFY_NON_NULL_NR(endPoint, FATAL);
+    VERIFY_NON_NULL_NR(responseInfo, FATAL);
+    VERIFY_NON_NULL_NR(responseInfo->info.resourceUri, FATAL);
 
-    if(strcmp(endPoint->resourceUri, OC_PRESENCE_URI) == 0)
+    if(strcmp(responseInfo->info.resourceUri, OC_PRESENCE_URI) == 0)
     {
         HandlePresenceResponse(endPoint, responseInfo);
         return;
@@ -1199,22 +1104,11 @@ void HandleCAResponses(const CARemoteEndpoint_t* endPoint, const CAResponseInfo_
         {
             OC_LOG(INFO, TAG, PCF("Receiving A Timeout for this token"));
             OC_LOG(INFO, TAG, PCF("Calling into application address space"));
-            OCClientResponse response = {};
-            OCDevAddr address = {};
-            OCStackResult result = UpdateResponseAddr(&address, endPoint);
-            if(result != OC_STACK_OK)
-            {
-                OC_LOG(ERROR, TAG, PCF("Error parsing IP address in UpdateResponseAddr"));
-                return;
-            }
 
-            result = UpdateResponseAddr(&address, endPoint);
-            if(result != OC_STACK_OK)
-            {
-                OC_LOG(ERROR, TAG, PCF("Invalid connectivity type in endpoint"));
-                return;
-            }
-            response.addr = &address;
+            OCClientResponse response = {};
+            CopyEndpointToDevAddr(endPoint, &response.devAddr);
+            FixUpClientResponse(&response);
+            response.resourceUri = responseInfo->info.resourceUri;
 
             response.result = CAToOCStackResult(responseInfo->result);
             cbNode->callBack(cbNode->context,
@@ -1225,26 +1119,11 @@ void HandleCAResponses(const CARemoteEndpoint_t* endPoint, const CAResponseInfo_
         {
             OC_LOG(INFO, TAG, PCF("This is a regular response, A client call back is found"));
             OC_LOG(INFO, TAG, PCF("Calling into application address space"));
-            OCClientResponse response = {};
-            OCDevAddr address = {};
 
-            OCStackResult result = UpdateResponseAddr(&address, endPoint);
-            if(result != OC_STACK_OK)
-            {
-                OC_LOG(ERROR, TAG, PCF("Error parsing IP address in UpdateResponseAddr"));
-                return;
-            }
-            response.addr = &address;
-            // Populate the connectivity type. If this is a discovery response,
-            // the resource that will be constructed from this response will make
-            // further API calls from this interface.
-            result = CAToOCConnectivityType(endPoint->transportType,
-                                    &(response.connType));
-            if(result != OC_STACK_OK)
-            {
-                OC_LOG(ERROR, TAG, PCF("Invalid connectivity type in endpoint"));
-                return;
-            }
+            OCClientResponse response = {};
+            CopyEndpointToDevAddr(endPoint, &response.devAddr);
+            FixUpClientResponse(&response);
+            response.resourceUri = responseInfo->info.resourceUri;
 
             response.result = CAToOCStackResult(responseInfo->result);
             response.resJSONPayload = (const char*)responseInfo->info.payload;
@@ -1385,7 +1264,7 @@ void HandleCAResponses(const CARemoteEndpoint_t* endPoint, const CAResponseInfo_
  * This function handles error response from CA
  * code shall be added to handle the errors
  */
-void HandleCAErrorResponse(const CARemoteEndpoint_t* endPoint, const CAErrorInfo_t* errrorInfo)
+void HandleCAErrorResponse(const CAEndpoint_t *endPoint, const CAErrorInfo_t *errrorInfo)
 {
     OC_LOG(INFO, TAG, PCF("Enter HandleCAErrorResponse"));
 
@@ -1408,7 +1287,7 @@ void HandleCAErrorResponse(const CARemoteEndpoint_t* endPoint, const CAErrorInfo
  * from the application entity handler. These responses have no payload and are usually ACKs,
  * RESETs or some error conditions that were caught by the stack.
  */
-OCStackResult SendDirectStackResponse(const CARemoteEndpoint_t* endPoint, const uint16_t coapID,
+OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16_t coapID,
         const CAResponseResult_t responseResult, const CAMessageType_t type,
         const uint8_t numOptions, const CAHeaderOption_t *options,
         CAToken_t token, uint8_t tokenLength)
@@ -1433,7 +1312,7 @@ OCStackResult SendDirectStackResponse(const CARemoteEndpoint_t* endPoint, const
 }
 
 //This function will be called back by CA layer when a request is received
-void HandleCARequests(const CARemoteEndpoint_t* endPoint, const CARequestInfo_t* requestInfo)
+void HandleCARequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* requestInfo)
 {
     OC_LOG(INFO, TAG, PCF("Enter HandleCARequests"));
     if(!endPoint)
@@ -1458,12 +1337,12 @@ void HandleCARequests(const CARemoteEndpoint_t* endPoint, const CARequestInfo_t*
 
     OCServerProtocolRequest serverRequest = {};
 
-    OC_LOG_V(INFO, TAG, PCF("Endpoint URI : %s\n"), (char*)endPoint->resourceUri);
+    OC_LOG_V(INFO, TAG, PCF("Endpoint URI : %s\n"), requestInfo->info.resourceUri);
 
     char * newUri = NULL;
     char * query  = NULL;
 
-    requestResult = getQueryFromUri(endPoint->resourceUri, &query, &newUri);
+    requestResult = getQueryFromUri(requestInfo->info.resourceUri, &query, &newUri);
 
     if (requestResult != OC_STACK_OK)
     {
@@ -1519,34 +1398,24 @@ void HandleCARequests(const CARemoteEndpoint_t* endPoint, const CARequestInfo_t*
     switch (requestInfo->method)
     {
         case CA_GET:
-            {
-                serverRequest.method = OC_REST_GET;
-                break;
-            }
+            serverRequest.method = OC_REST_GET;
+            break;
         case CA_PUT:
-            {
-                serverRequest.method = OC_REST_PUT;
-                break;
-            }
+            serverRequest.method = OC_REST_PUT;
+            break;
         case CA_POST:
-            {
-                serverRequest.method = OC_REST_POST;
-                break;
-            }
+            serverRequest.method = OC_REST_POST;
+            break;
         case CA_DELETE:
-            {
-                serverRequest.method = OC_REST_DELETE;
-                break;
-            }
+            serverRequest.method = OC_REST_DELETE;
+            break;
         default:
-            {
-                OC_LOG(ERROR, TAG, PCF("Received CA method %d not supported"));
-                SendDirectStackResponse(endPoint, requestInfo->info.messageId, CA_BAD_REQ,
+            OC_LOG(ERROR, TAG, PCF("Received CA method %d not supported"));
+            SendDirectStackResponse(endPoint, requestInfo->info.messageId, CA_BAD_REQ,
                         requestInfo->info.type, requestInfo->info.numOptions,
                         requestInfo->info.options, requestInfo->info.token,
                         requestInfo->info.tokenLength);
-                return;
-            }
+            return;
     }
 
     OC_LOG_V(INFO, TAG, "HandleCARequests: CA token length = %d",
@@ -1575,16 +1444,14 @@ void HandleCARequests(const CARemoteEndpoint_t* endPoint, const CARequestInfo_t*
     {
         serverRequest.qos = OC_LOW_QOS;
     }
-    // CA does not need the following 2 fields
+    // CA does not need the following field
     // Are we sure CA does not need them? how is it responding to multicast
     serverRequest.delayedResNeeded = 0;
-    serverRequest.secured = endPoint->isSecured;
 
     serverRequest.coapID = requestInfo->info.messageId;
 
     // copy the address
-    serverRequest.addressInfo      = endPoint->addressInfo;
-    serverRequest.connectivityType = endPoint->transportType;
+    CopyEndpointToDevAddr(endPoint, &serverRequest.devAddr);
 
     // copy vendor specific header options
     uint8_t tempNum = (requestInfo->info.numOptions);
@@ -1650,14 +1517,14 @@ OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest)
     {
         OC_LOG(INFO, TAG, PCF("This is a new Server Request"));
         result = AddServerRequest(&request, protocolRequest->coapID,
-                protocolRequest->delayedResNeeded, protocolRequest->secured, 0,
+                protocolRequest->delayedResNeeded, 0,
                 protocolRequest->method, protocolRequest->numRcvdVendorSpecificHeaderOptions,
                 protocolRequest->observationOption, protocolRequest->qos,
                 protocolRequest->query, protocolRequest->rcvdVendorSpecificHeaderOptions,
                 protocolRequest->reqJSONPayload, protocolRequest->requestToken,
                 protocolRequest->tokenLength,
-                protocolRequest->resourceUrl,protocolRequest->reqTotalSize,
-                &protocolRequest->addressInfo, protocolRequest->connectivityType);
+                protocolRequest->resourceUrl, protocolRequest->reqTotalSize,
+                &protocolRequest->devAddr);
         if (OC_STACK_OK != result)
         {
             OC_LOG(ERROR, TAG, PCF("Error adding server request"));
@@ -1698,66 +1565,6 @@ OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest)
     return result;
 }
 
-bool ParseIPv4Address(char * ipAddrStr, uint8_t * ipAddr, uint16_t * port)
-{
-    size_t index = 0;
-     char *itr, *coap;
-     uint8_t dotCount = 0;
-
-     ipAddr[index] = 0;
-     *port = 0;
-     /* search for scheme */
-     itr = ipAddrStr;
-    if (!isdigit((char) *ipAddrStr))
-    {
-        coap = OC_COAP_SCHEME;
-        while (*coap && tolower(*itr) == *coap)
-        {
-            coap++;
-            itr++;
-        }
-    }
-    ipAddrStr = itr;
-
-    while (*ipAddrStr)
-    {
-        if (isdigit(*ipAddrStr))
-        {
-            ipAddr[index] *= 10;
-            ipAddr[index] += *ipAddrStr - '0';
-        }
-        else if (*ipAddrStr == '.')
-        {
-            index++;
-            dotCount++;
-            ipAddr[index] = 0;
-        }
-        else
-        {
-            break;
-        }
-        ipAddrStr++;
-    }
-    if(*ipAddrStr == ':')
-    {
-        ipAddrStr++;
-        while (*ipAddrStr){
-            if (isdigit(*ipAddrStr))
-            {
-                *port *= 10;
-                *port += *ipAddrStr - '0';
-            }
-            else
-            {
-                break;
-            }
-            ipAddrStr++;
-        }
-    }
-
-    return (3 == dotCount);
-}
-
 bool validatePlatformInfo(OCPlatformInfo info)
 {
 
@@ -1793,12 +1600,21 @@ bool validatePlatformInfo(OCPlatformInfo info)
     }
     return true;
 }
+
 //-----------------------------------------------------------------------------
 // Public APIs
 //-----------------------------------------------------------------------------
 
 OCStackResult OCInit(const char *ipAddr, uint16_t port, OCMode mode)
 {
+    (void) ipAddr;
+    (void) port;
+
+    return OCInit1(mode, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS);
+}
+
+OCStackResult OCInit1(OCMode mode, OCTransportFlags serverFlags, OCTransportFlags clientFlags)
+{
     if(stackState == OC_STACK_INITIALIZED)
     {
         OC_LOG(INFO, TAG, PCF("Subsequent calls to OCInit() without calling \
@@ -1806,8 +1622,6 @@ OCStackResult OCInit(const char *ipAddr, uint16_t port, OCMode mode)
         return OC_STACK_OK;
     }
 
-    (void) ipAddr;
-    (void) port;
     OCStackResult result = OC_STACK_ERROR;
     OC_LOG(INFO, TAG, PCF("Entering OCInit"));
 
@@ -1819,6 +1633,9 @@ OCStackResult OCInit(const char *ipAddr, uint16_t port, OCMode mode)
     }
     myStackMode = mode;
 
+    caglobals.serverFlags = (CATransportFlags_t)serverFlags;
+    caglobals.clientFlags = (CATransportFlags_t)clientFlags;
+
     defaultDeviceHandler = NULL;
     defaultDeviceHandlerCallbackParameter = NULL;
     OCSeedRandom();
@@ -1909,7 +1726,6 @@ OCStackResult OCStop()
     // Free memory dynamically allocated for resources
     deleteAllResources();
     DeleteDeviceInfo();
-    DeletePlatformInfo();
     CATerminate();
     // Remove all observers
     DeleteObserverList();
@@ -1963,259 +1779,424 @@ OCStackResult verifyUriQueryLength(const char *inputUri, uint16_t uriLen)
     return OC_STACK_OK;
 }
 
-OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requiredUri,
-            const char *referenceUri, const char *request, OCConnectivityType conType,
-            OCQualityOfService qos, OCCallbackData *cbData,
-            OCHeaderOption * options, uint8_t numOptions)
+/**
+ *  A request uri consists of the following components in order:
+ *                              example
+ *  optional prefix             "coap://"
+ *  optionally one of
+ *      IPv6 address            "[1234::5678]"
+ *      IPv4 address            "192.168.1.1"
+ *  optional port               ":5683"
+ *  resource uri                "/oc/core..."
+ *
+ *  for PRESENCE requests, extract resource type.
+ */
+static OCStackResult ParseRequestUri(const char *fullUri,
+                                        OCTransportAdapter adapter,
+                                        OCTransportFlags flags,
+                                        OCDevAddr **devAddr,
+                                        char **resourceUri,
+                                        char **resourceType)
 {
-    OCStackResult result = OC_STACK_ERROR;
-    ClientCB *clientCB = NULL;
-    char * requestUri = NULL;
-    char * resourceType = NULL;
-    char * query = NULL;
-    char * newUri = (char *)requiredUri;
-    (void) referenceUri;
-    CARemoteEndpoint_t* endpoint = NULL;
-    CAResult_t caResult;
-    CAToken_t token = NULL;
-    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
-    OCDoHandle resHandle = NULL;
-    CAInfo_t requestData ={};
-    CARequestInfo_t requestInfo ={};
-    CAGroupEndpoint_t grpEnd = {};
+    VERIFY_NON_NULL(fullUri, FATAL, OC_STACK_INVALID_CALLBACK);
 
-    OC_LOG(INFO, TAG, PCF("Entering OCDoResource"));
+    OCStackResult result = OC_STACK_OK;
+    OCDevAddr *da = NULL;
+    char *colon = NULL;
+    char *end;
 
-    // Validate input parameters
-    VERIFY_NON_NULL(cbData, FATAL, OC_STACK_INVALID_CALLBACK);
-    VERIFY_NON_NULL(cbData->cb, FATAL, OC_STACK_INVALID_CALLBACK);
+    // provide defaults for all returned values
+    if (devAddr)
+    {
+        *devAddr = NULL;
+    }
+    if (resourceUri)
+    {
+        *resourceUri = NULL;
+    }
+    if (resourceType)
+    {
+        *resourceType = NULL;
+    }
 
-    //TODO ("Need to form the final query by concatenating require and reference URI's");
-    VERIFY_NON_NULL(requiredUri, FATAL, OC_STACK_INVALID_URI);
+    // delimit url prefix, if any
+    const char *start = fullUri;
+    char *slash2 = strstr(start, "//");
+    if (slash2)
+    {
+        start = slash2 + 2;
+    }
+    char *slash = strchr(start, '/');
+    if (!slash)
+    {
+        return OC_STACK_INVALID_URI;
+    }
 
-    uint16_t uriLen = strlen(requiredUri);
+    // processs url prefix, if any
+    size_t urlLen = slash - start;
+    if (urlLen && devAddr)
+    {   // construct OCDevAddr
+        if (start[0] == '[')
+        {   // ipv6 address
+            char *close = strchr(++start, ']');
+            if (!close || close > slash)
+            {
+                return OC_STACK_INVALID_URI;
+            }
+            end = close;
+            if (close[1] == ':')
+            {
+                colon = close + 1;
+            }
+        }
+        else
+        {   // ipv4 address
+            end = slash;
+            colon = strchr(start, ':');
+            end = (colon && colon < slash) ? colon : slash;
+        }
+        size_t len = end - start;
+        if (len > MAX_ADDR_STR_SIZE)
+        {
+            return OC_STACK_INVALID_URI;
+        }
 
-    // ToDo: We should also check if the requiredUri has a mutlicast address,
-    // then qos has to be OC_Low_QOS
-    switch (method)
-    {
-        case OC_REST_GET:
-        case OC_REST_OBSERVE:
-        case OC_REST_OBSERVE_ALL:
-        case OC_REST_CANCEL_OBSERVE:
-            requestInfo.method = CA_GET;
-            break;
+        // port
+        uint16_t port = 0;      // use standard multicast port
+        if (colon && colon < slash)
+        {
+            for (colon++; colon < slash; colon++)
+            {
+                char c = colon[0];
+                if (c < '0' || c > '9')
+                {
+                    return OC_STACK_INVALID_URI;
+                }
+                port = 10 * port + c - '0';
+            }
+        }
 
-        case OC_REST_PUT:
-            requestInfo.method = CA_PUT;
-            break;
+        da = (OCDevAddr *)OICMalloc(sizeof (OCDevAddr));
+        if (!da)
+        {
+            return OC_STACK_NO_MEMORY;
+        }
+        strncpy(da->addr, start, len);
+        da->port = port;
+        da->adapter = adapter;
+        da->flags = flags;
+        if (!strncmp(fullUri, "coaps:", 6))
+        {
+            da->flags = (OCTransportFlags)(da->flags|CA_SECURE);
+        }
+        *devAddr = da;
+    }
 
-        case OC_REST_POST:
-            requestInfo.method = CA_POST;
-            break;
+    // process resource uri, if any
+    if (slash)
+    {   // request uri and query
+        size_t ulen = strlen(slash); // resource uri length
+        size_t tlen = 0;      // resource type length
+        char *type = NULL;
 
-        case OC_REST_DELETE:
-            requestInfo.method = CA_DELETE;
-            break;
+        static const char *strPresence = "/oc/presence?rt=";
+        static const size_t lenPresence = 15; // = strlen(presence);
+        if (!strncmp(slash, strPresence, lenPresence))
+        {
+            type = slash + lenPresence;
+            tlen = ulen - lenPresence;
+        }
+        // resource uri
+        if (resourceUri)
+        {
+            *resourceUri = (char *)OICMalloc(ulen + 1);
+            if (!*resourceUri)
+            {
+                result = OC_STACK_NO_MEMORY;
+                goto error;
+            }
+            strcpy(*resourceUri, slash);
+        }
+        // resource type
+        if (type && resourceType)
+        {
+            *resourceType = (char *)OICMalloc(tlen + 1);
+            if (!*resourceType)
+            {
+                result = OC_STACK_NO_MEMORY;
+                goto error;
+            }
+            strncpy(*resourceType, type, tlen);
+        }
+    }
+
+    return OC_STACK_OK;
+
+error:
+    // free all returned values
+    if (devAddr)
+    {
+        OICFree(*devAddr);
+    }
+    if (resourceUri)
+    {
+        OICFree(*resourceUri);
+    }
+    if (resourceType)
+    {
+        OICFree(*resourceType);
+    }
+    return result;
+}
+
+static OCStackResult OCPreparePresence(CAEndpoint_t *endpoint,
+                                        char *resourceUri, char **requestUri)
+{
+    char uri[CA_MAX_URI_LENGTH];
 
-        #ifdef WITH_PRESENCE
-        case OC_REST_PRESENCE:
-            // Replacing method type with GET because "presence"
-            // is a stack layer only implementation.
-            requestInfo.method = CA_GET;
-            break;
-        #endif
+    FormCanonicalPresenceUri(endpoint, resourceUri, uri);
 
-        default:
-            result = OC_STACK_INVALID_METHOD;
-            goto exit;
+    *requestUri = (char *)OICMalloc(strlen(uri) + 1);
+    if (!*requestUri)
+    {
+        return OC_STACK_NO_MEMORY;
     }
 
-    if((result = verifyUriQueryLength(requiredUri, uriLen)) != OC_STACK_OK)
+    strcpy(*requestUri, uri);
+    return OC_STACK_OK;
+}
+
+/**
+ * Discover or Perform requests on a specified resource
+ */
+OCStackResult OCDoResource(OCDoHandle *handle,
+                            OCMethod method,
+                            const char *requestUri,
+                            const OCDevAddr *destination,
+                            const char *request,
+                            OCConnectivityType connectivityType,
+                            OCQualityOfService qos,
+                            OCCallbackData *cbData,
+                            OCHeaderOption *options,
+                            uint8_t numOptions)
+{
+    OC_LOG(INFO, TAG, PCF("Entering OCDoResource"));
+
+    // Validate input parameters
+    VERIFY_NON_NULL(cbData, FATAL, OC_STACK_INVALID_CALLBACK);
+    VERIFY_NON_NULL(cbData->cb, FATAL, OC_STACK_INVALID_CALLBACK);
+    VERIFY_NON_NULL(requestUri , FATAL, OC_STACK_INVALID_URI);
+
+    OCStackResult result = OC_STACK_ERROR;
+    CAResult_t caResult;
+    CAToken_t token = NULL;
+    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
+    ClientCB *clientCB = NULL;
+    OCDoHandle resHandle = NULL;
+    CAEndpoint_t *endpoint = NULL;
+    OCDevAddr tmpDevAddr = { OC_DEFAULT_ADAPTER };
+    uint32_t ttl = 0;
+    OCTransportAdapter adapter;
+    OCTransportFlags flags;
+    // the request contents are put here
+    CARequestInfo_t requestInfo = { CA_GET };
+    // requestUri  will be parsed into the following three variables
+    OCDevAddr *devAddr = NULL;
+    char *resourceUri = NULL;
+    char *resourceType = NULL;
+
+    // To track if memory is allocated for additional header options
+    uint8_t hdrOptionMemAlloc = 0;
+
+    // This validation is broken, but doesn't cause harm
+    size_t uriLen = strlen(requestUri );
+    if ((result = verifyUriQueryLength(requestUri , uriLen)) != OC_STACK_OK)
     {
         goto exit;
     }
 
-    if((request) && (strlen(request) > MAX_REQUEST_LENGTH))
+    if ((request) && (strlen(request) > MAX_REQUEST_LENGTH))
     {
         result = OC_STACK_INVALID_PARAM;
         goto exit;
     }
 
-#ifdef WITH_PRESENCE
-    if(method == OC_REST_PRESENCE)
-    {
-        result = getQueryFromUri(requiredUri, &query, &newUri);
+    /*
+     * Support original behavior with address on resourceUri argument.
+     */
+    adapter = (OCTransportAdapter)(connectivityType >> CT_ADAPTER_SHIFT);
+    flags = (OCTransportFlags)(connectivityType & CT_MASK_FLAGS);
 
-        if(result != OC_STACK_OK)
-        {
-            OC_LOG_V(ERROR, TAG, "Invalid Param from getQueryFromUri: %d, URI is %s",
-                    result, requiredUri);
-            goto exit;
-        }
+    result = ParseRequestUri(requestUri, adapter, flags, &devAddr, &resourceUri, &resourceType);
+    if (result != OC_STACK_OK)
+    {
+        OC_LOG_V(DEBUG, TAG, "Unable to parse uri: %s", requestUri);
+        goto exit;
+    }
 
-        if(query)
-        {
-            result = getResourceType((char *) query, &resourceType);
-            OICFree(query);
-            if(resourceType)
-            {
-                OC_LOG_V(DEBUG, TAG, "Got Resource Type: %s", resourceType);
-            }
-            else
-            {
-                OC_LOG(DEBUG, TAG, PCF("Resource type is NULL."));
-            }
-        }
-        else
-        {
-            OC_LOG(DEBUG, TAG, PCF("Query string is NULL."));
-        }
-        if(result != OC_STACK_OK)
+    switch (method)
+    {
+    case OC_REST_GET:
+    case OC_REST_OBSERVE:
+    case OC_REST_OBSERVE_ALL:
+    case OC_REST_CANCEL_OBSERVE:
+        requestInfo.method = CA_GET;
+        break;
+    case OC_REST_PUT:
+        requestInfo.method = CA_PUT;
+        break;
+    case OC_REST_POST:
+        requestInfo.method = CA_POST;
+        break;
+    case OC_REST_DELETE:
+        requestInfo.method = CA_DELETE;
+        break;
+    case OC_REST_DISCOVER:
+        qos = OC_LOW_QOS;
+        if (!destination && !devAddr)
         {
-            goto exit;
+            destination = &tmpDevAddr;
         }
+        // CA_DISCOVER will become GET and isMulticast
+        requestInfo.method = CA_GET;
+        requestInfo.isMulticast = true;
+        break;
+    #ifdef WITH_PRESENCE
+    case OC_REST_PRESENCE:
+        // Replacing method type with GET because "presence"
+        // is a stack layer only implementation.
+        requestInfo.method = CA_GET;
+        break;
+    #endif
+    default:
+        result = OC_STACK_INVALID_METHOD;
+        goto exit;
     }
-#endif // WITH_PRESENCE
 
-    requestUri = (char *) OICMalloc(uriLen + 1);
-    if(requestUri)
+    if (!devAddr && !destination)
     {
-        OICStrcpy(requestUri, uriLen + 1, newUri);
+        OC_LOG_V(DEBUG, TAG, "no devAddr and no destination");
+        result = OC_STACK_INVALID_PARAM;
+        goto exit;
     }
-    else
+
+    /* If not original behavior, use destination argument */
+    if (destination && !devAddr)
     {
-        result = OC_STACK_NO_MEMORY;
-        goto exit;
+        devAddr = (OCDevAddr *)OICMalloc(sizeof (OCDevAddr));
+        if (!devAddr)
+        {
+            result = OC_STACK_NO_MEMORY;
+            goto exit;
+        }
+        *devAddr = *destination;
     }
 
     resHandle = GenerateInvocationHandle();
-    if(!resHandle)
+    if (!resHandle)
     {
         result = OC_STACK_NO_MEMORY;
         goto exit;
     }
 
-    // create token
     caResult = CAGenerateToken(&token, tokenLength);
     if (caResult != CA_STATUS_OK)
     {
         OC_LOG(ERROR, TAG, PCF("CAGenerateToken error"));
-        CADestroyToken(token);
-        result = CAResultToOCResult (caResult);
         goto exit;
     }
 
-    requestData.type = qualityOfServiceToMessageType(qos);
-
-    requestData.token = token;
-    requestData.tokenLength = tokenLength;
-
+    // fill in request data
+    requestInfo.info.type = qualityOfServiceToMessageType(qos);
+    requestInfo.info.token = token;
+    requestInfo.info.tokenLength = tokenLength;
+    requestInfo.info.resourceUri = resourceUri;
+    requestInfo.info.payload = (char *)request;
     if ((method == OC_REST_OBSERVE) || (method == OC_REST_OBSERVE_ALL))
     {
-        result = CreateObserveHeaderOption (&(requestData.options), options,
-                                    numOptions, OC_OBSERVE_REGISTER);
+        result = CreateObserveHeaderOption (&(requestInfo.info.options),
+                                    options, numOptions, OC_OBSERVE_REGISTER);
         if (result != OC_STACK_OK)
         {
-            CADestroyToken(token);
             goto exit;
         }
-        requestData.numOptions = numOptions + 1;
+        hdrOptionMemAlloc = 1;
+        requestInfo.info.numOptions = numOptions + 1;
     }
     else
     {
-        requestData.options = (CAHeaderOption_t*)options;
-        requestData.numOptions = numOptions;
+        requestInfo.info.options = (CAHeaderOption_t*)options;
+        requestInfo.info.numOptions = numOptions;
     }
 
-    requestData.payload = (char *)request;
-
-    requestInfo.info = requestData;
-
-    CATransportType_t caConType;
-
-    result = OCToCATransportType((OCConnectivityType) conType, &caConType);
+    // create remote endpoint
+    result = OCCreateEndpoint(devAddr, &endpoint);
     if (result != OC_STACK_OK)
     {
-        OC_LOG(ERROR, TAG, PCF("Invalid Connectivity Type"));
+        OC_LOG(ERROR, TAG, PCF("CACreateEndpoint error"));
         goto exit;
     }
 
-    // send request
-    if(conType == OC_ALL)
-    {
-        grpEnd.transportType = caConType;
-
-        grpEnd.resourceUri = (CAURI_t) OICMalloc(uriLen + 1);
-        if(!grpEnd.resourceUri)
-        {
-            result = OC_STACK_NO_MEMORY;
-            CADestroyToken(token);
-            goto exit;
-        }
-        OICStrcpy(grpEnd.resourceUri, uriLen +1, requiredUri);
-
-        caResult = CASendRequestToAll(&grpEnd, &requestInfo);
-    }
-    else
+    // prepare for response
+    #ifdef WITH_PRESENCE
+    if (method == OC_REST_PRESENCE)
     {
-        caResult = CACreateRemoteEndpoint(newUri, caConType, &endpoint);
-
-        if (caResult != CA_STATUS_OK)
+        char *presenceUri = NULL;
+        result = OCPreparePresence(endpoint, resourceUri, &presenceUri);
+        if (OC_STACK_OK != result)
         {
-            OC_LOG(ERROR, TAG, PCF("CACreateRemoteEndpoint error"));
-            result = CAResultToOCResult (caResult);
-            CADestroyToken(token);
             goto exit;
         }
-
-        caResult = CASendRequest(endpoint, &requestInfo);
+        OICFree(resourceUri);
+        resourceUri = presenceUri;
     }
+    #endif
 
-    if (caResult != CA_STATUS_OK)
+    ttl = GetTicks(MAX_CB_TIMEOUT_SECONDS * MILLISECONDS_PER_SECOND);
+    result = AddClientCB(&clientCB, cbData, token, tokenLength, &resHandle,
+                            method, devAddr, resourceUri, resourceType, ttl);
+    if (OC_STACK_OK != result)
     {
-        OC_LOG(ERROR, TAG, PCF("CASendRequest"));
-        result = CAResultToOCResult (caResult);
-        CADestroyToken(token);
         goto exit;
     }
 
-    result = AddClientCB(&clientCB, cbData, token, tokenLength, &resHandle, method,
-                             requestUri, resourceType, conType,
-                             GetTicks(MAX_CB_TIMEOUT_SECONDS * MILLISECONDS_PER_SECOND));
-    if(result != OC_STACK_OK)
+    devAddr = NULL;       // Client CB list entry now owns it
+    resourceUri = NULL;   // Client CB list entry now owns it
+    resourceType = NULL;  // Client CB list entry now owns it
+
+    // send request
+    caResult = CASendRequest(endpoint, &requestInfo);
+    if (caResult != CA_STATUS_OK)
     {
-        result = OC_STACK_NO_MEMORY;
+        OC_LOG(ERROR, TAG, PCF("CASendRequest"));
+        result = OC_STACK_COMM_ERROR;
         goto exit;
     }
 
-    if(handle)
+    if (handle)
     {
         *handle = resHandle;
     }
 
 exit:
-    if(newUri != requiredUri)
-    {
-        OICFree(newUri);
-    }
     if (result != OC_STACK_OK)
     {
-        OC_LOG_V(ERROR, TAG, PCF("OCDoResource error no %d"), result);
+        OC_LOG(ERROR, TAG, PCF("OCDoResource error"));
         FindAndDeleteClientCB(clientCB);
+        CADestroyToken(token);
+        if (handle)
+        {
+            *handle = NULL;
+        }
         OICFree(resHandle);
-        OICFree(requestUri);
-        OICFree(resourceType);
     }
-    CADestroyRemoteEndpoint(endpoint);
-    OICFree(grpEnd.resourceUri);
-
-    if (requestData.options  && requestData.numOptions > 0)
+    OICFree(devAddr);
+    OICFree(resourceUri);
+    OICFree(resourceType);
+    OICFree(endpoint);
+    if (hdrOptionMemAlloc)
     {
-        if ((method == OC_REST_OBSERVE) || (method == OC_REST_OBSERVE_ALL))
-        {
-            OICFree(requestData.options);
-        }
+        OICFree(requestInfo.info.options);
     }
     return result;
 }
@@ -2241,7 +2222,7 @@ OCStackResult OCCancel(OCDoHandle handle, OCQualityOfService qos, OCHeaderOption
      *      Remove the callback associated on client side.
      */
     OCStackResult ret = OC_STACK_OK;
-    CARemoteEndpoint_t* endpoint = NULL;
+    CAEndpoint_t* endpoint = NULL;
     CAResult_t caResult;
     CAInfo_t requestData = {};
     CARequestInfo_t requestInfo = {};
@@ -2254,76 +2235,65 @@ OCStackResult OCCancel(OCDoHandle handle, OCQualityOfService qos, OCHeaderOption
     OC_LOG(INFO, TAG, PCF("Entering OCCancel"));
 
     ClientCB *clientCB = GetClientCB(NULL, 0, handle, NULL);
+    if (!clientCB)
+    {
+        OC_LOG(ERROR, TAG, PCF("Client callback not found. Called OCCancel twice?"));
+        goto Error;
+    }
 
-    if(clientCB)
+    switch (clientCB->method)
     {
-        switch (clientCB->method)
-        {
-            case OC_REST_OBSERVE:
-            case OC_REST_OBSERVE_ALL:
-                if(qos == OC_HIGH_QOS)
-                {
-                    requestData.type =  qualityOfServiceToMessageType(qos);
-                    requestData.token = clientCB->token;
-                    requestData.tokenLength = clientCB->tokenLength;
+        case OC_REST_OBSERVE:
+        case OC_REST_OBSERVE_ALL:
+            OC_LOG(INFO, TAG, PCF("Canceling observation"));
+            if (qos != OC_HIGH_QOS)
+            {
+                FindAndDeleteClientCB(clientCB);
+                break;
+            }
 
-                    if (CreateObserveHeaderOption (&(requestData.options),
-                            options, numOptions, OC_OBSERVE_DEREGISTER) != OC_STACK_OK)
-                    {
-                        return OC_STACK_ERROR;
-                    }
-                    requestData.numOptions = numOptions + 1;
-                    requestInfo.method = CA_GET;
-                    requestInfo.info = requestData;
+            requestData.type = qualityOfServiceToMessageType(qos);
+            requestData.token = clientCB->token;
+            requestData.tokenLength = clientCB->tokenLength;
+            if (CreateObserveHeaderOption (&(requestData.options),
+                    options, numOptions, OC_OBSERVE_DEREGISTER) != OC_STACK_OK)
+            {
+                return OC_STACK_ERROR;
+            }
+            requestData.numOptions = numOptions + 1;
+            requestInfo.method = CA_GET;
+            requestInfo.info = requestData;
 
-                    CATransportType_t caConType;
-                    ret = OCToCATransportType(clientCB->conType, &caConType);
-                    if(ret != OC_STACK_OK)
-                    {
-                        goto Error;
-                    }
+            ret = OCCreateEndpoint(clientCB->devAddr, &endpoint);
+            if (ret != OC_STACK_OK)
+            {
+                OC_LOG(ERROR, TAG, PCF("CACreateEndpoint error"));
+                goto Error;
+            }
 
-                    caResult = CACreateRemoteEndpoint((char *)clientCB->requestUri,
-                            caConType, &endpoint);
-                    if (caResult != CA_STATUS_OK)
-                    {
-                        OC_LOG(ERROR, TAG, PCF("CACreateRemoteEndpoint error"));
-                        ret = OC_STACK_ERROR;
-                        goto Error;
-                    }
+            // send request
+            caResult = CASendRequest(endpoint, &requestInfo);
+            if (caResult != CA_STATUS_OK)
+            {
+                OC_LOG(ERROR, TAG, PCF("CASendRequest error"));
+                ret = OC_STACK_ERROR;
+            }
+            ret = CAResultToOCResult (caResult);
+            break;
 
-                    // send request
-                    caResult = CASendRequest(endpoint, &requestInfo);
-                    if (caResult != CA_STATUS_OK)
-                    {
-                        OC_LOG(ERROR, TAG, PCF("CASendRequest error"));
-                        ret = OC_STACK_ERROR;
-                    }
-                    ret = CAResultToOCResult (caResult);
-                }
-                else
-                {
-                    FindAndDeleteClientCB(clientCB);
-                }
-                break;
+        #ifdef WITH_PRESENCE
+        case OC_REST_PRESENCE:
+            FindAndDeleteClientCB(clientCB);
+            break;
+        #endif
 
-            #ifdef WITH_PRESENCE
-            case OC_REST_PRESENCE:
-                FindAndDeleteClientCB(clientCB);
-                break;
-            #endif
-            default:
-                ret = OC_STACK_INVALID_METHOD;
-                break;
-        }
-    }
-    else
-    {
-        OC_LOG(ERROR, TAG, PCF("Client callback not found. Called OCCancel twice?"));
+        default:
+            ret = OC_STACK_INVALID_METHOD;
+            break;
     }
 
-    Error:
-    CADestroyRemoteEndpoint(endpoint);
+Error:
+    OCDestroyEndpoint(endpoint);
     if (requestData.numOptions > 0)
     {
         OICFree(requestData.options);
@@ -2363,119 +2333,105 @@ OCStackResult OCRegisterPersistentStorageHandler(OCPersistentStorage* persistent
 }
 
 #ifdef WITH_PRESENCE
+
 OCStackResult OCProcessPresence()
 {
     OCStackResult result = OC_STACK_OK;
-    uint8_t ipAddr[4] = { 0 };
-    uint16_t port = 0;
 
-    OC_LOG(INFO, TAG, PCF("Entering RequestPresence"));
+    // the following line floods the log with messages that are irrelevant
+    // to most purposes.  Uncomment as needed.
+    //OC_LOG(INFO, TAG, PCF("Entering RequestPresence"));
     ClientCB* cbNode = NULL;
-    OCDevAddr dst = {};
-    OCClientResponse clientResponse ={};
+    OCClientResponse clientResponse;
     OCStackApplicationResult cbResult = OC_STACK_DELETE_TRANSACTION;
 
     LL_FOREACH(cbList, cbNode)
     {
-        if(OC_REST_PRESENCE == cbNode->method)
+        if (OC_REST_PRESENCE != cbNode->method || !cbNode->presence)
         {
-            if(cbNode->presence)
-            {
-                uint32_t now = GetTicks(0);
-                OC_LOG_V(DEBUG, TAG, "this TTL level %d",
-                                                        cbNode->presence->TTLlevel);
-                OC_LOG_V(DEBUG, TAG, "current ticks %d", now);
+            continue;
+        }
 
+        uint32_t now = GetTicks(0);
+        OC_LOG_V(DEBUG, TAG, "this TTL level %d",
+                                                cbNode->presence->TTLlevel);
+        OC_LOG_V(DEBUG, TAG, "current ticks %d", now);
 
-                if(cbNode->presence->TTLlevel >= (PresenceTimeOutSize + 1))
-                {
-                    goto exit;
-                }
+        if(cbNode->presence->TTLlevel >= (PresenceTimeOutSize + 1))
+        {
+            goto exit;
+        }
 
-                if(cbNode->presence->TTLlevel < PresenceTimeOutSize)
-                {
-                    OC_LOG_V(DEBUG, TAG, "timeout ticks %d",
-                            cbNode->presence->timeOut[cbNode->presence->TTLlevel]);
-                }
+        if (cbNode->presence->TTLlevel < PresenceTimeOutSize)
+        {
+            OC_LOG_V(DEBUG, TAG, "timeout ticks %d",
+                    cbNode->presence->timeOut[cbNode->presence->TTLlevel]);
+        }
 
-                if(cbNode->presence->TTLlevel >= PresenceTimeOutSize)
-                {
-                    OC_LOG(DEBUG, TAG, PCF("No more timeout ticks"));
-                    if (ParseIPv4Address(cbNode->requestUri, ipAddr, &port))
-                    {
-                        OCBuildIPv4Address(ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3], port,
-                                &dst);
-
-                        clientResponse.sequenceNumber = 0;
-                        clientResponse.result = OC_STACK_PRESENCE_TIMEOUT;
-                        clientResponse.addr = (OCDevAddr *) &dst;
-                        clientResponse.resJSONPayload = NULL;
-
-                        // Increment the TTLLevel (going to a next state), so we don't keep
-                        // sending presence notification to client.
-                        cbNode->presence->TTLlevel++;
-                        OC_LOG_V(DEBUG, TAG, "moving to TTL level %d",
-                                                cbNode->presence->TTLlevel);
-                    }
-                    else
-                    {
-                        result = OC_STACK_INVALID_IP;
-                        goto exit;
-                    }
+        if (cbNode->presence->TTLlevel >= PresenceTimeOutSize)
+        {
+            OC_LOG(DEBUG, TAG, PCF("No more timeout ticks"));
 
-                    cbResult = cbNode->callBack(cbNode->context, cbNode->handle, &clientResponse);
-                    if (cbResult == OC_STACK_DELETE_TRANSACTION)
-                    {
-                        FindAndDeleteClientCB(cbNode);
-                    }
-                }
+            clientResponse.sequenceNumber = 0;
+            clientResponse.result = OC_STACK_PRESENCE_TIMEOUT;
+            clientResponse.devAddr = *cbNode->devAddr;
+            FixUpClientResponse(&clientResponse);
+            clientResponse.resJSONPayload = NULL;
 
-                if(now >= cbNode->presence->timeOut[cbNode->presence->TTLlevel])
-                {
-                    CAResult_t caResult = CA_STATUS_OK;
-                    CARemoteEndpoint_t* endpoint = NULL;
-                    CAInfo_t requestData ={};
-                    CARequestInfo_t requestInfo = {};
+            // Increment the TTLLevel (going to a next state), so we don't keep
+            // sending presence notification to client.
+            cbNode->presence->TTLlevel++;
+            OC_LOG_V(DEBUG, TAG, "moving to TTL level %d",
+                                        cbNode->presence->TTLlevel);
+
+            cbResult = cbNode->callBack(cbNode->context, cbNode->handle, &clientResponse);
+            if (cbResult == OC_STACK_DELETE_TRANSACTION)
+            {
+                FindAndDeleteClientCB(cbNode);
+            }
+        }
 
-                    OC_LOG(DEBUG, TAG, PCF("time to test server presence"));
+        if (now < cbNode->presence->timeOut[cbNode->presence->TTLlevel])
+        {
+            continue;
+        }
 
+        CAResult_t caResult = CA_STATUS_OK;
+        CAEndpoint_t* endpoint = NULL;
+        CAInfo_t requestData ={};
+        CARequestInfo_t requestInfo = {};
 
-                    CATransportType_t caConType;
-                    result = OCToCATransportType(cbNode->conType, &caConType);
-                    caResult = CACreateRemoteEndpoint((char *)cbNode->requestUri, caConType,
-                                                        &endpoint);
-                    if (caResult != CA_STATUS_OK || result != OC_STACK_OK)
-                    {
-                        OC_LOG(ERROR, TAG, PCF("CACreateRemoteEndpoint error"));
-                        goto exit;
-                    }
+        OC_LOG(DEBUG, TAG, PCF("time to test server presence"));
 
-                    requestData.type = CA_MSG_NONCONFIRM;
-                    requestData.token = cbNode->token;
-                    requestData.tokenLength = cbNode->tokenLength;
-                    requestInfo.method = CA_GET;
-                    requestInfo.info = requestData;
+        result = OCCreateEndpoint(cbNode->devAddr, &endpoint);
+        if (result != OC_STACK_OK)
+        {
+            OC_LOG(ERROR, TAG, PCF("CACreateEndpoint error"));
+            goto exit;
+        }
 
-                    caResult = CASendRequest(endpoint, &requestInfo);
-                    CADestroyRemoteEndpoint(endpoint);
+        requestData.type = CA_MSG_NONCONFIRM;
+        requestData.token = cbNode->token;
+        requestData.tokenLength = cbNode->tokenLength;
+        requestInfo.method = CA_GET;
+        requestInfo.info = requestData;
 
-                    if (caResult != CA_STATUS_OK)
-                    {
-                        OC_LOG(ERROR, TAG, PCF("CASendRequest error"));
-                        goto exit;
-                    }
+        caResult = CASendRequest(endpoint, &requestInfo);
+        OCDestroyEndpoint(endpoint);
 
-                    cbNode->presence->TTLlevel++;
-                    OC_LOG_V(DEBUG, TAG, "moving to TTL level %d",
-                                                            cbNode->presence->TTLlevel);
-                }
-            }
+        if (caResult != CA_STATUS_OK)
+        {
+            OC_LOG(ERROR, TAG, PCF("CASendRequest error"));
+            goto exit;
         }
+
+        cbNode->presence->TTLlevel++;
+        OC_LOG_V(DEBUG, TAG, "moving to TTL level %d", cbNode->presence->TTLlevel);
     }
 exit:
     if (result != OC_STACK_OK)
     {
-        OC_LOG_V(ERROR, TAG, PCF("OCProcessPresence error no %d"), result);
+        OC_LOG(ERROR, TAG, PCF("OCProcessPresence error"));
     }
     return result;
 }
@@ -2519,10 +2475,9 @@ OCStackResult OCStartPresence(const uint32_t ttl)
     {
         presenceState = OC_PRESENCE_INITIALIZED;
 
-        CAAddress_t addressInfo;
-        OICStrcpy(addressInfo.IP.ipAddress, sizeof(addressInfo.IP.ipAddress),
-                OC_MULTICAST_IP);
-        addressInfo.IP.port = OC_MULTICAST_PORT;
+        OCDevAddr devAddr = { OC_DEFAULT_ADAPTER };
+        OICStrcpy(devAddr.addr, sizeof(devAddr.addr), OC_MULTICAST_IP);
+        devAddr.port = OC_MULTICAST_PORT;
 
         CAToken_t caToken = NULL;
         CAResult_t caResult = CAGenerateToken(&caToken, tokenLength);
@@ -2533,11 +2488,8 @@ OCStackResult OCStartPresence(const uint32_t ttl)
             return OC_STACK_ERROR;
         }
 
-        CATransportType_t connType;
-        OCToCATransportType(OC_ALL, &connType );
         AddObserver(OC_PRESENCE_URI, NULL, 0, caToken, tokenLength,
-                (OCResource *)presenceResource.handle, OC_LOW_QOS,
-                &addressInfo, connType);
+                (OCResource *)presenceResource.handle, OC_LOW_QOS, &devAddr);
         CADestroyToken(caToken);
     }
 
@@ -3831,31 +3783,6 @@ bool OCIsPacketTransferRequired(const char *request, const char *response, size_
     return result;
 }
 
-OCStackResult getResourceType(const char * query, char** resourceType)
-{
-    if(!query)
-    {
-        return OC_STACK_INVALID_PARAM;
-    }
-
-    OCStackResult result = OC_STACK_ERROR;
-
-    if(strncmp(query, "rt=", 3) == 0)
-    {
-        *resourceType = OICStrdup(&query[3]);
-        if(!*resourceType)
-        {
-            result = OC_STACK_NO_MEMORY;
-        }
-        else
-        {
-            result = OC_STACK_OK;
-        }
-    }
-
-    return result;
-}
-
 /*
  * This function splits the uri using the '?' delimiter.
  * "uriWithoutQuery" is the block of characters between the beginning
@@ -3901,11 +3828,6 @@ OCStackResult getQueryFromUri(const char * uri, char** query, char ** uriWithout
         }
         OICStrcpy(*uriWithoutQuery, uriWithoutQueryLen +1, uri);
     }
-    else
-    {
-        return OC_STACK_INVALID_PARAM;
-    }
-
     if (queryLen)
     {
         *query = (char *) OICCalloc(queryLen + 1, 1);
@@ -3964,45 +3886,15 @@ const char* OCGetServerInstanceIDString(void)
     return sidStr;
 }
 
-int32_t OCDevAddrToIPv4Addr(OCDevAddr *ipAddr, uint8_t *a, uint8_t *b,
-        uint8_t *c, uint8_t *d )
-{
-    if ( !ipAddr || !a || !b || !c || !d )
-    {
-        OC_LOG(FATAL, TAG, PCF("Invalid argument"));
-        return OC_STACK_INVALID_PARAM;
-    }
-
-    *a = ipAddr->addr[0];
-    *b = ipAddr->addr[1];
-    *c = ipAddr->addr[2];
-    *d = ipAddr->addr[3];
-
-    return OC_STACK_OK;
-}
-
-int32_t OCDevAddrToPort(OCDevAddr *ipAddr, uint16_t *port)
-{
-    if ( !ipAddr || !port )
-    {
-        OC_LOG(FATAL, TAG, PCF("Invalid argument"));
-        return OC_STACK_INVALID_PARAM;
-    }
-
-    *port = (ipAddr->addr[5]<< 8) | ipAddr->addr[4];
-
-    return OC_STACK_OK;
-}
-
 CAResult_t OCSelectNetwork()
 {
     CAResult_t retResult = CA_STATUS_FAILED;
     CAResult_t caResult = CA_STATUS_OK;
 
-    CATransportType_t connTypes[] = {
-            CA_IPV4,
-            CA_EDR,
-            CA_LE};
+    CATransportAdapter_t connTypes[] = {
+            CA_ADAPTER_IP,
+            CA_ADAPTER_RFCOMM_BTEDR,
+            CA_ADAPTER_GATT_BTLE};
     int numConnTypes = sizeof(connTypes)/sizeof(connTypes[0]);
 
     for(int i = 0; i<numConnTypes; i++)
index 65f4ff4..36b2733 100644 (file)
@@ -905,12 +905,8 @@ OCStackResult SendAction(OCDoHandle *handle, const char *targetUri,
     cbdata.cd = NULL;
     cbdata.context = (void*)DEFAULT_CONTEXT_VALUE;
 
-// TODO: Selecting OC_IPV4.
-// It is temporary change as OC_ALL is not working currently. Remove this code and use OC_ALL
-// once it is functioning.
-
     return OCDoResource(handle, OC_REST_PUT, targetUri,
-    NULL, (char *) action, OC_IPV4, OC_NA_QOS, &cbdata, NULL, 0);
+            NULL, (char *) action, CT_ADAPTER_IP, OC_NA_QOS, &cbdata, NULL, 0);
 }
 
 OCStackResult DoAction(OCResource* resource, OCActionSet* actionset,
index 322b487..823adf5 100644 (file)
@@ -41,13 +41,11 @@ void handleSigInt(int signum) {
 // This is a function called back when a device is discovered
 OCStackApplicationResult applicationDiscoverCB(
         OCClientResponse * clientResponse) {
-    uint8_t remoteIpAddr[4];
-    uint16_t remotePortNu;
     OC_LOG(INFO, TAG, "Entering applicationDiscoverCB (Application Layer CB)");
-    OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
-            remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
-    OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
-    OC_LOG_V(INFO, TAG, "Device =============> Discovered %s @ %d.%d.%d.%d:%d",clientResponse->resJSONPayload,remoteIpAddr[0], remoteIpAddr[1], remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
+    OC_LOG_V(INFO, TAG, "Device =============> Discovered %s @ %s:%d",
+                                    clientResponse->resJSONPayload,
+                                    clientResponse->devAddr.addr,
+                                    clientResponse->devAddr.port);
     //return OC_STACK_DELETE_TRANSACTION;
     return OC_STACK_KEEP_TRANSACTION;
 }
index aa750a5..5d893ce 100644 (file)
@@ -280,7 +280,7 @@ TEST(StackDiscovery, DISABLED_DoResourceDeviceDiscovery)
                                         szQueryUri,
                                         0,
                                         0,
-                                        OC_IPV4,
+                                        CT_ADAPTER_IP,
                                         OC_LOW_QOS,
                                         &cbData,
                                         NULL,
@@ -322,7 +322,7 @@ TEST(StackResource, DISABLED_UpdateResourceNullURI)
                                         szQueryUri,
                                         0,
                                         0,
-                                        OC_IPV4,
+                                        CT_ADAPTER_IP,
                                         OC_LOW_QOS,
                                         &cbData,
                                         NULL,
index ffc5ab2..e5982f1 100644 (file)
@@ -90,7 +90,7 @@ int main(int argc, char* argv[]) {
     std::string platformDiscoveryURI = "/oic/p";
     std::string deviceDiscoveryURI   = "/oic/d";
 
-    OCConnectivityType connectivityType = OC_IPV4;
+    OCConnectivityType connectivityType = CT_ADAPTER_IP;
 
     if(argc == 2)
     {
@@ -103,37 +103,29 @@ int main(int argc, char* argv[]) {
             {
                 if(optionSelected == 0)
                 {
-                    connectivityType = OC_IPV4;
-                }
-                else if(optionSelected == 1)
-                {
-                    // TODO: re-enable IPv4/IPv6 command line selection when IPv6 is supported
-                    //connectivityType = OC_IPV6;
-                    connectivityType = OC_IPV4;
-                    std::cout << "IPv6 not currently supported. Using default IPv4" << std::endl;
+                    connectivityType = CT_ADAPTER_IP;
                 }
                 else
                 {
-                    std::cout << "Invalid connectivity type selected. Using default IPv4"
+                    std::cout << "Invalid connectivity type selected. Using default IP"
                     << std::endl;
                 }
             }
             else
             {
-                std::cout << "Invalid connectivity type selected. Using default IPv4" << std::endl;
+                std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
             }
         }
         catch(std::exception&)
         {
-            std::cout << "Invalid input argument. Using IPv4 as connectivity type" << std::endl;
+            std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl;
         }
     }
     else
     {
-        std::cout << "Usage devicediscoveryclient <connectivityType(0|1)>" << std::endl;
-        std::cout << "connectivityType: Default IPv4" << std::endl;
-        std::cout << "connectivityType 0: IPv4" << std::endl;
-        std::cout << "connectivityType 1: IPv6 (not currently supported)" << std::endl;
+        std::cout << "Usage devicediscoveryclient 0" << std::endl;
+        std::cout << "connectivityType: Default IP" << std::endl;
+        std::cout << "connectivityType 0: IP" << std::endl;
     }
     // Create PlatformConfig object
     PlatformConfig cfg {
index 501ad75..c082a61 100644 (file)
@@ -49,7 +49,7 @@ class ClientFridge
         std::cout << "Fridge Client has started " <<std::endl;
         FindCallback f (std::bind(&ClientFridge::foundDevice, this, PH::_1));
         OCStackResult result = OCPlatform::findResource(
-                "", requestURI.str(), OC_ALL, f);
+                "", requestURI.str(), CT_DEFAULT, f);
 
         if(OC_STACK_OK != result)
         {
@@ -267,7 +267,7 @@ class ClientFridge
 
 int main(int argc, char* argv[])
 {
-    OCConnectivityType connectivityType = OC_IPV4;
+    OCConnectivityType connectivityType = CT_ADAPTER_IP;
     if(argc == 2)
     {
         try
@@ -279,37 +279,29 @@ int main(int argc, char* argv[])
             {
                 if(optionSelected == 0)
                 {
-                    connectivityType = OC_IPV4;
-                }
-                else if(optionSelected == 1)
-                {
-                    // TODO: re-enable IPv4/IPv6 command line selection when IPv6 is supported
-                    //connectivityType = OC_IPV6;
-                    connectivityType = OC_IPV4;
-                    std::cout << "IPv6 not currently supported. Using default IPv4" << std::endl;
+                    connectivityType = CT_ADAPTER_IP;
                 }
                 else
                 {
-                    std::cout << "Invalid connectivity type selected. Using default IPv4"
+                    std::cout << "Invalid connectivity type selected. Using default IP"
                         << std::endl;
                 }
             }
             else
             {
-                std::cout << "Invalid connectivity type selected. Using default IPv4" << std::endl;
+                std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
             }
         }
         catch(std::exception&)
         {
-            std::cout << "Invalid input argument. Using IPv4 as connectivity type" << std::endl;
+            std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl;
         }
     }
     else
     {
-        std::cout << "Usage: fridgeclient <ConnectivityType(0|1)>\n";
-        std::cout << "connectivityType: Default IPv4" << std::endl;
-        std::cout << "connectivityType 0: IPv4" << std::endl;
-        std::cout << "connectivityType 1: IPv6 (not currently supported)" << std::endl;
+        std::cout << "Usage: fridgeclient 0\n";
+        std::cout << "connectivityType: Default IP" << std::endl;
+        std::cout << "connectivityType 0: IP" << std::endl;
     }
 
     PlatformConfig cfg
index c64528d..cb146f6 100644 (file)
@@ -288,6 +288,44 @@ int main(int argc, char* argv[]) {
 
     std::ostringstream requestURI;
 
+    OCConnectivityType connectivityType = CT_DEFAULT;
+
+    if(argc == 2)
+    {
+        try
+        {
+            std::size_t inputValLen;
+            int optionSelected = std::stoi(argv[1], &inputValLen);
+
+            if(inputValLen == strlen(argv[1]))
+            {
+                if(optionSelected == 0)
+                {
+                    connectivityType = CT_ADAPTER_IP;
+                }
+                else
+                {
+                    std::cout << "Invalid connectivity type selected. Using default IP"
+                        << std::endl;
+                }
+            }
+            else
+            {
+                std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
+            }
+        }
+        catch(std::exception& e)
+        {
+            std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl;
+        }
+    }
+    else
+    {
+        std::cout<<"Usage: garageclient 0\n";
+        std::cout<<"ConnectivityType: Default IP\n";
+        std::cout<<"ConnectivityType 0: IP\n";
+    }
+
     // Create PlatformConfig object
     PlatformConfig cfg {
         OC::ServiceType::InProc,
@@ -304,7 +342,7 @@ int main(int argc, char* argv[]) {
         requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.garage";
 
         OCPlatform::findResource("", requestURI.str(),
-                OC_ALL, &foundResource);
+                connectivityType, &foundResource);
 
         std::cout<< "Finding Resource... " <<std::endl;
 
index 89c5a61..1055d12 100644 (file)
@@ -185,7 +185,7 @@ int main(int argc, char* argv[])
         string resourceTypeName = "a.collection";
 
         OCPlatform::findResource("", requestURI.str(),
-                                 OC_ALL, &foundResource);
+                                 CT_DEFAULT, &foundResource);
 
         //Non-intensive block until foundResource callback is called by OCPlatform
         //and onGet gets resource.
index c4b069d..0211113 100644 (file)
@@ -80,6 +80,43 @@ int main(int argc, char* argv[])
 {
     ostringstream requestURI;
 
+    OCConnectivityType connectivityType = CT_DEFAULT;
+
+    if(argc == 2)
+    {
+        try
+        {
+            std::size_t inputValLen;
+            int optionSelected = stoi(argv[1], &inputValLen);
+
+            if(inputValLen == strlen(argv[1]))
+            {
+                if(optionSelected == 0)
+                {
+                    connectivityType = CT_ADAPTER_IP;
+                }
+                else
+                {
+                    std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
+                }
+            }
+            else
+            {
+                std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
+            }
+        }
+        catch(exception& e)
+        {
+            std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl;
+        }
+    }
+    else
+    {
+        std::cout<<"Usage: groupclient 0\n";
+        std::cout<<"ConnectivityType: Default \n";
+        std::cout<<"ConnectivityType 0: IP\n";
+    }
+
     PlatformConfig config
     { OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
 
@@ -103,7 +140,7 @@ int main(int argc, char* argv[])
         requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.light";
 
         OCPlatform::findResource("", requestURI.str(),
-                                 OC_ALL, &foundResource);
+                                 connectivityType, &foundResource);
 
         OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
         OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);
index 305bfe5..9111ba8 100644 (file)
@@ -35,7 +35,7 @@ std::shared_ptr<OCResource> curResource;
 std::mutex resourceLock;
 static int TEST_CASE = 0;
 
-static OCConnectivityType connectivityType = OC_IPV4;
+static OCConnectivityType connectivityType = CT_ADAPTER_IP;
 
 /**
  * List of methods that can be inititated from the client
@@ -221,26 +221,17 @@ int main(int argc, char* argv[]) {
                     {
                         if(optionSelected == 0)
                         {
-                            connectivityType = OC_IPV4;
-                        }
-                        else if(optionSelected == 1)
-                        {
-                            // TODO: re-enable IPv4/IPv6 command line selection when IPv6
-                            // is supported
-                            //connectivityType = OC_IPV6;
-                            connectivityType = OC_IPV4;
-                            std::cout << "IPv6 not currently supported. Using default IPv4"
-                                    << std::endl;
+                            connectivityType = CT_ADAPTER_IP;
                         }
                         else
                         {
-                            std::cout << "Invalid connectivity type selected. Using default IPv4"
+                            std::cout << "Invalid connectivity type selected. Using default IP"
                                 << std::endl;
                         }
                     }
                     else
                     {
-                        std::cout << "Invalid connectivity type selected. Using default IPv4"
+                        std::cout << "Invalid connectivity type selected. Using default IP"
                             << std::endl;
                     }
                     break;
@@ -252,7 +243,7 @@ int main(int argc, char* argv[]) {
     }
     catch(std::exception& )
     {
-        std::cout << "Invalid input argument. Using IPv4 as connectivity type"
+        std::cout << "Invalid input argument. Using IP as connectivity type"
             << std::endl;
     }
 
@@ -343,7 +334,7 @@ int main(int argc, char* argv[]) {
             requestURI << OC_MULTICAST_DISCOVERY_URI;
 
             result = OCPlatform::findResource("", requestURI.str(),
-                    OC_ALL, &foundResource);
+                    CT_DEFAULT, &foundResource);
             if(result == OC_STACK_OK)
             {
                 std::cout << "Finding Resource... " << std::endl;
index fdba60d..1f4ef16 100644 (file)
@@ -215,7 +215,6 @@ void foundResource(std::shared_ptr<OCResource> resource)
     }
     catch(std::exception& e)
     {
-        std::cerr << "Exception in foundResource: "<< e.what() <<std::endl;
         //log(e.what());
     }
 }
@@ -224,6 +223,41 @@ int main(int argc, char* argv[]) {
 
     std::ostringstream requestURI;
 
+    OCConnectivityType connectivityType = CT_DEFAULT;
+    if(argc == 2)
+    {
+        try
+        {
+            std::size_t inputValLen;
+            int optionSelected = std::stoi(argv[1], &inputValLen);
+
+            if(inputValLen == strlen(argv[1]))
+            {
+                if(optionSelected == 0)
+                {
+                    connectivityType = CT_ADAPTER_IP;
+                }
+                else
+                {
+                    std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
+                }
+            }
+            else
+            {
+                std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
+            }
+        }
+        catch(std::exception& e)
+        {
+            std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl;
+        }
+    }
+    else
+    {
+        std::cout << "Usage roomclient 0" << std::endl;
+        std::cout<<"connectivityType: Default" << std::endl;
+        std::cout << "connectivityType 0: IP" << std::endl;
+    }
 
     // Create PlatformConfig object
     PlatformConfig cfg {
@@ -241,7 +275,7 @@ int main(int argc, char* argv[]) {
         // Find all resources
         requestURI << OC_MULTICAST_DISCOVERY_URI;
 
-        OCPlatform::findResource("", requestURI.str(), OC_ALL, &foundResource);
+        OCPlatform::findResource("", requestURI.str(), connectivityType, &foundResource);
         std::cout<< "Finding Resource... " <<std::endl;
 
         // A condition variable will free the mutex it is given, then do a non-
index e06d731..e606908 100644 (file)
@@ -421,7 +421,7 @@ int main(int argc, char* argv[]) {
         printUsage();
         if (argc == 1)
         {
-            std::cout << "<===Setting ObserveType to Observe and ConnectivityType to IPv4===>\n\n";
+            std::cout << "<===Setting ObserveType to Observe and ConnectivityType to IP===>\n\n";
         }
         else if (argc == 2)
         {
@@ -457,14 +457,14 @@ int main(int argc, char* argv[]) {
         requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.light";
 
         OCPlatform::findResource("", requestURI.str(),
-                OC_ALL, &foundResource);
+                CT_DEFAULT, &foundResource);
         std::cout<< "Finding Resource... " <<std::endl;
 
         // Find resource is done twice so that we discover the original resources a second time.
         // These resources will have the same uniqueidentifier (yet be different objects), so that
         // we can verify/show the duplicate-checking code in foundResource(above);
         OCPlatform::findResource("", requestURI.str(),
-                OC_ALL, &foundResource);
+                CT_DEFAULT, &foundResource);
         std::cout<< "Finding Resource for second time..." << std::endl;
 
         // A condition variable will free the mutex it is given, then do a non-
index af0bea4..da84d5d 100644 (file)
@@ -370,35 +370,56 @@ void foundResource(std::shared_ptr<OCResource> resource)
 void PrintUsage()
 {
     std::cout << std::endl;
-    std::cout << "Usage : simpleclientHQ <ObserveType>" << std::endl;
+    std::cout << "Usage : simpleclientHQ <ObserveType> <ConnectivityType>" << std::endl;
     std::cout << "   ObserveType : 1 - Observe" << std::endl;
     std::cout << "   ObserveType : 2 - ObserveAll" << std::endl;
+    std::cout << "   ConnectivityType: Default IP" << std::endl;
+    std::cout << "   ConnectivityType : 0 - IP"<< std::endl;
 }
 
 int main(int argc, char* argv[]) {
 
     std::ostringstream requestURI;
 
+    OCConnectivityType connectivityType = CT_DEFAULT;
     try
     {
         if (argc == 1)
         {
             OBSERVE_TYPE_TO_USE = ObserveType::Observe;
         }
-        else if (argc == 2)
+        else if (argc ==2 || argc==3)
         {
             int value = std::stoi(argv[1]);
             if (value == 1)
-            {
                 OBSERVE_TYPE_TO_USE = ObserveType::Observe;
-            }
             else if (value == 2)
-            {
                 OBSERVE_TYPE_TO_USE = ObserveType::ObserveAll;
-            }
             else
-            {
                 OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+
+            if(argc == 3)
+            {
+                std::size_t inputValLen;
+                int optionSelected = std::stoi(argv[2], &inputValLen);
+
+                if(inputValLen == strlen(argv[2]))
+                {
+                    if(optionSelected == 0)
+                    {
+                        connectivityType = CT_ADAPTER_IP;
+                    }
+                    else
+                    {
+                        std::cout << "Invalid connectivity type selected. Using default IP"
+                            << std::endl;
+                    }
+                }
+                else
+                {
+                    std::cout << "Invalid connectivity type selected. Using default IP"
+                            << std::endl;
+                }
             }
         }
         else
@@ -407,11 +428,12 @@ int main(int argc, char* argv[]) {
             return -1;
         }
     }
-    catch(std::exception&)
+    catch(std::exception& e)
     {
-        std::cout << "Invalid input argument. Using Observe as observe type" << std::endl;
+        std::cout << "Invalid input argument." << std::endl;
     }
 
+
     // Create PlatformConfig object
     PlatformConfig cfg {
         OC::ServiceType::InProc,
@@ -429,14 +451,14 @@ int main(int argc, char* argv[]) {
         requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.light";
 
         OCPlatform::findResource("", requestURI.str(),
-                OC_ALL, &foundResource, OC::QualityOfService::LowQos);
+                connectivityType, &foundResource, OC::QualityOfService::LowQos);
         std::cout<< "Finding Resource... " <<std::endl;
 
         // Find resource is done twice so that we discover the original resources a second time.
         // These resources will have the same uniqueidentifier (yet be different objects), so that
         // we can verify/show the duplicate-checking code in foundResource(above);
         OCPlatform::findResource("", requestURI.str(),
-                OC_ALL, &foundResource, OC::QualityOfService::LowQos);
+                connectivityType, &foundResource, OC::QualityOfService::LowQos);
         std::cout<< "Finding Resource for second time... " <<std::endl;
 
         // A condition variable will free the mutex it is given, then do a non-
index f4282a3..90b7682 100644 (file)
@@ -152,7 +152,7 @@ public:
         std::cout<<"Starting Client find:"<<std::endl;
         FindCallback f (std::bind(&ClientWorker::foundResource, this, std::placeholders::_1));
         std::cout<<"result:" <<
-        OCPlatform::findResource("", requestURI.str(), OC_ALL, f)
+        OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, f)
         << std::endl;
 
         std::cout<<"Finding Resource..."<<std::endl;
@@ -296,7 +296,7 @@ struct FooResource
 
 int main(int argc, char* argv[])
 {
-    OCConnectivityType connectivityType = OC_IPV4;
+    OCConnectivityType connectivityType = CT_ADAPTER_IP;
 
     if(argc == 2)
     {
@@ -309,37 +309,28 @@ int main(int argc, char* argv[])
             {
                 if(optionSelected == 0)
                 {
-                    connectivityType = OC_IPV4;
-                }
-                else if(optionSelected == 1)
-                {
-                    // TODO: re-enable IPv4/IPv6 command line selection when IPv6 is supported
-                    // connectivityType = OC_IPV6;
-                    connectivityType = OC_IPV4;
-                    std::cout << "IPv6 not currently supported. Using default IPv4" << std::endl;
+                    connectivityType = CT_ADAPTER_IP;
                 }
                 else
                 {
-                    std::cout << "Invalid connectivity type selected. Using default IPv4"
-                    << std::endl;
+                    std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
                 }
             }
             else
             {
-                std::cout << "Invalid connectivity type selected. Using default IPv4" << std::endl;
+                std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
             }
         }
         catch(std::exception& )
         {
-            std::cout << "Invalid input argument. Using IPv4 as connectivity type" << std::endl;
+            std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl;
         }
     }
     else
     {
-        std::cout<< "Usage simpleclientserver <ConnectivityType(0|1)>" << std::endl;
-        std::cout<< "    ConnectivityType: Default IPv4" << std::endl;
-        std::cout << "   ConnectivityType : 0 - IPv4" << std::endl;
-        std::cout << "   ConnectivityType : 1 - IPv6 (not currently supported)" << std::endl;
+        std::cout<< "Usage simpleclientserver 0>" << std::endl;
+        std::cout<< "    ConnectivityType: Default IP" << std::endl;
+        std::cout << "   ConnectivityType : 0 - IP" << std::endl;
     }
 
     PlatformConfig cfg {
index e1332c8..d416859 100644 (file)
@@ -279,7 +279,7 @@ void client1()
 {
     std::cout << "in client1\n";
     std::cout<<"result1:" << OCPlatform::findResource("", requestURI.str(),
-            OC_ALL, foundResource1)<< std::endl;
+            CT_DEFAULT, foundResource1)<< std::endl;
 
     // A condition variable will free the mutex it is given, then do a non-
     // intensive block until 'notify' is called on it.  In this case, since we
@@ -296,7 +296,7 @@ void client2()
     std::cout << "in client2\n";
     std::cout<<"result2:" << OCPlatform::findResource("",
                 requestURI.str(),
-                OC_ALL, foundResource2)<< std::endl;
+                CT_DEFAULT, foundResource2)<< std::endl;
 
     // A condition variable will free the mutex it is given, then do a non-
     // intensive block until 'notify' is called on it.  In this case, since we
index 7c31bde..272cd44 100644 (file)
@@ -41,48 +41,63 @@ namespace OC
         {}
 
         virtual OCStackResult ListenForResource(const std::string& serviceUrl,
-                        const std::string& resourceType, OCConnectivityType connectivityType,
+                        const std::string& resourceType,
+                        OCConnectivityType connectivityType,
                         FindCallback& callback,
                         QualityOfService QoS) = 0;
 
         virtual OCStackResult ListenForDevice(const std::string& serviceUrl,
-                        const std::string& deviceURI, OCConnectivityType connectivityType,
+                        const std::string& deviceURI,
+                        OCConnectivityType connectivityType,
                         FindDeviceCallback& callback,
                         QualityOfService QoS) = 0;
 
-        virtual OCStackResult GetResourceRepresentation(const std::string& host,
-                        const std::string& uri, OCConnectivityType connectivityType,
+        virtual OCStackResult GetResourceRepresentation(
+                        const OCDevAddr& devAddr,
+                        const std::string& uri,
                         const QueryParamsMap& queryParams,
                         const HeaderOptions& headerOptions,
                         GetCallback& callback, QualityOfService QoS)=0;
 
-        virtual OCStackResult PutResourceRepresentation(const std::string& host,
-                        const std::string& uri, OCConnectivityType connectivityType,
+        virtual OCStackResult PutResourceRepresentation(
+                        const OCDevAddr& devAddr,
+                        const std::string& uri,
                         const OCRepresentation& rep, const QueryParamsMap& queryParams,
                         const HeaderOptions& headerOptions,
                         PutCallback& callback, QualityOfService QoS) = 0;
 
-        virtual OCStackResult PostResourceRepresentation(const std::string& host,
-                        const std::string& uri, OCConnectivityType connectivityType,
+        virtual OCStackResult PostResourceRepresentation(
+                        const OCDevAddr& devAddr,
+                        const std::string& uri,
                         const OCRepresentation& rep, const QueryParamsMap& queryParams,
                         const HeaderOptions& headerOptions,
                         PostCallback& callback, QualityOfService QoS) = 0;
 
-        virtual OCStackResult DeleteResource(const std::string& host, const std::string& uri,
-                        OCConnectivityType connectivityType, const HeaderOptions& headerOptions,
+        virtual OCStackResult DeleteResource(
+                        const OCDevAddr& devAddr,
+                        const std::string& uri,
+                        const HeaderOptions& headerOptions,
                         DeleteCallback& callback, QualityOfService QoS) = 0;
 
-        virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
-                        const std::string& host, const std::string& uri,
-                        OCConnectivityType connectivityType, const QueryParamsMap& queryParams,
+        virtual OCStackResult ObserveResource(
+                        ObserveType observeType, OCDoHandle* handle,
+                        const OCDevAddr& devAddr,
+                        const std::string& uri,
+                        const QueryParamsMap& queryParams,
                         const HeaderOptions& headerOptions, ObserveCallback& callback,
                         QualityOfService QoS)=0;
 
-        virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host,
-            const std::string& uri, const HeaderOptions& headerOptions, QualityOfService QoS)=0;
+        virtual OCStackResult CancelObserveResource(
+                        OCDoHandle handle,
+                        const std::string& host,
+                        const std::string& uri,
+                        const HeaderOptions& headerOptions,
+                        QualityOfService QoS)=0;
 
-        virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
-                        const std::string& resourceType, OCConnectivityType connectivityType,
+        virtual OCStackResult SubscribePresence(OCDoHandle* handle,
+                        const std::string& host,
+                        const std::string& resourceType,
+                        OCConnectivityType connectivityType,
                         SubscribeCallback& presenceHandler)=0;
 
         virtual OCStackResult UnsubscribePresence(OCDoHandle handle) =0;
index ca67b1b..98206d4 100644 (file)
@@ -94,42 +94,55 @@ namespace OC
         virtual ~InProcClientWrapper();
 
         virtual OCStackResult ListenForResource(const std::string& serviceUrl,
-            const std::string& resourceType, OCConnectivityType connectivityType,
+            const std::string& resourceType, OCConnectivityType transportFlags,
             FindCallback& callback, QualityOfService QoS);
 
         virtual OCStackResult ListenForDevice(const std::string& serviceUrl,
-            const std::string& deviceURI, OCConnectivityType connectivityType,
+            const std::string& deviceURI, OCConnectivityType transportFlags,
             FindDeviceCallback& callback, QualityOfService QoS);
 
-        virtual OCStackResult GetResourceRepresentation(const std::string& host,
-            const std::string& uri, OCConnectivityType connectivityType,
+        virtual OCStackResult GetResourceRepresentation(
+            const OCDevAddr& devAddr,
+            const std::string& uri,
             const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
             GetCallback& callback, QualityOfService QoS);
 
-        virtual OCStackResult PutResourceRepresentation(const std::string& host,
-            const std::string& uri, OCConnectivityType connectivityType,
+        virtual OCStackResult PutResourceRepresentation(
+            const OCDevAddr& devAddr,
+            const std::string& uri,
             const OCRepresentation& attributes, const QueryParamsMap& queryParams,
             const HeaderOptions& headerOptions, PutCallback& callback, QualityOfService QoS);
 
-        virtual OCStackResult PostResourceRepresentation(const std::string& host,
-            const std::string& uri, OCConnectivityType connectivityType,
+        virtual OCStackResult PostResourceRepresentation(
+            const OCDevAddr& devAddr,
+            const std::string& uri,
             const OCRepresentation& attributes, const QueryParamsMap& queryParams,
             const HeaderOptions& headerOptions, PostCallback& callback, QualityOfService QoS);
 
-        virtual OCStackResult DeleteResource(const std::string& host, const std::string& uri,
-            OCConnectivityType connectivityType, const HeaderOptions& headerOptions,
+        virtual OCStackResult DeleteResource(
+            const OCDevAddr& devAddr,
+            const std::string& uri,
+            const HeaderOptions& headerOptions,
             DeleteCallback& callback, QualityOfService QoS);
 
-        virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
-            const std::string& host, const std::string& uri, OCConnectivityType connectivityType,
+        virtual OCStackResult ObserveResource(
+            ObserveType observeType, OCDoHandle* handle,
+            const OCDevAddr& devAddr,
+            const std::string& uri,
             const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
             ObserveCallback& callback, QualityOfService QoS);
 
-        virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host,
-            const std::string& uri, const HeaderOptions& headerOptions, QualityOfService QoS);
-
-        virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
-            const std::string& resourceType, OCConnectivityType connectivityType,
+        virtual OCStackResult CancelObserveResource(
+            OCDoHandle handle,
+            const std::string& host,
+            const std::string& uri,
+            const HeaderOptions& headerOptions, QualityOfService QoS);
+
+        virtual OCStackResult SubscribePresence(
+            OCDoHandle *handle,
+            const std::string& host,
+            const std::string& resourceType,
+            OCConnectivityType transportFlags,
             SubscribeCallback& presenceHandler);
 
         virtual OCStackResult UnsubscribePresence(OCDoHandle handle);
index 8087a4e..a6e9f35 100644 (file)
@@ -109,37 +109,53 @@ namespace OC
     *  Data structure to provide the configuration.
     *  ServiceType: indicate InProc or OutOfProc
     *  ModeType   : indicate whether we want to do server, client or both
-    *  ipAddress  : ip address of server.
-    *               if you specify 0.0.0.0 : it listens on any interface.
-    *  port       : port of server.
-    *             : if you specify 0 : next available random port is used.
-    *             : if you specify 5683 : client discovery can work even if they don't specify port.
+    *  ServerConnectivity : default flags for server
+    *  ClientConnectivity : default flags for client
     *  QoS        : Quality of Service : CONFIRMABLE or NON CONFIRMABLE.
     */
     struct PlatformConfig
     {
         ServiceType                serviceType;
         ModeType                   mode;
-        std::string                ipAddress;
-        uint16_t                   port;
-
+        OCConnectivityType         serverConnectivity;
+        OCConnectivityType         clientConnectivity;
+        std::string                ipAddress;   // not used
+        uint16_t                   port;        // not used
         QualityOfService           QoS;
 
         public:
             PlatformConfig()
                 : serviceType(ServiceType::InProc),
                 mode(ModeType::Both),
+                serverConnectivity(CT_DEFAULT),
+                clientConnectivity(CT_DEFAULT),
                 ipAddress("0.0.0.0"),
                 port(0),
                 QoS(QualityOfService::NaQos)
         {}
             PlatformConfig(const ServiceType serviceType_,
             const ModeType mode_,
+            OCConnectivityType serverConnectivity_,
+            OCConnectivityType clientConnectivity_,
+            const QualityOfService QoS_)
+                : serviceType(serviceType_),
+                mode(mode_),
+                serverConnectivity(serverConnectivity_),
+                clientConnectivity(clientConnectivity_),
+                ipAddress(""),
+                port(0),
+                QoS(QoS_)
+        {}
+            // for backward compatibility
+            PlatformConfig(const ServiceType serviceType_,
+            const ModeType mode_,
             const std::string& ipAddress_,
             const uint16_t port_,
             const QualityOfService QoS_)
                 : serviceType(serviceType_),
                 mode(mode_),
+                serverConnectivity(CT_DEFAULT),
+                clientConnectivity(CT_DEFAULT),
                 ipAddress(ipAddress_),
                 port(port_),
                 QoS(QoS_)
index 34b092d..83622bb 100644 (file)
@@ -470,7 +470,8 @@ namespace OC
         * @param interfaces - a collection of interfaces that the resource supports/implements
         * @return OCResource::Ptr - a shared pointer to the new resource object
         */
-        OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
+        OCResource::Ptr constructResourceObject(const std::string& host,
+                        const std::string& uri,
                         OCConnectivityType connectivityType, bool isObservable,
                         const std::vector<std::string>& resourceTypes,
                         const std::vector<std::string>& interfaces);
index bc0109c..a86badc 100644 (file)
@@ -441,7 +441,7 @@ namespace OC
 
         /**
         * Function to get the connectivity type of this resource
-        * @return uint8_t connectivity type
+        * @return enum connectivity type (flags and adapter)
         */
         OCConnectivityType connectivityType() const;
 
@@ -507,8 +507,7 @@ namespace OC
         std::weak_ptr<IClientWrapper> m_clientWrapper;
         std::string m_uri;
         OCResourceIdentifier m_resourceId;
-        std::string m_host;
-        OCConnectivityType m_connectivityType;
+        OCDevAddr m_devAddr;
         bool m_isObservable;
         bool m_isCollection;
         std::vector<std::string> m_resourceTypes;
@@ -518,11 +517,18 @@ namespace OC
         HeaderOptions m_headerOptions;
 
     private:
-        OCResource(std::weak_ptr<IClientWrapper> clientWrapper, const std::string& host,
-            const std::string& uri, const std::string& serverId,
-            OCConnectivityType m_connectivityType, bool observable,
-            const std::vector<std::string>& resourceTypes,
-            const std::vector<std::string>& interfaces);
+        OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
+                    const OCDevAddr& devAddr, const std::string& uri,
+                    const std::string& serverId, bool observable,
+                    const std::vector<std::string>& resourceTypes,
+                    const std::vector<std::string>& interfaces);
+
+        OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
+                    const std::string& host, const std::string& uri,
+                    const std::string& serverId,
+                    OCConnectivityType connectivityType, bool observable,
+                    const std::vector<std::string>& resourceTypes,
+                    const std::vector<std::string>& interfaces);
     };
 
 } // namespace OC
index c9e0ce3..96b4b35 100644 (file)
@@ -32,8 +32,8 @@ namespace OC
         private:
         enum class OCSecureType
         {
-            IPv4Secure,
-            IPv4
+            NotSecure,
+            Secure
         };
 
         class ListenResourceContainer
@@ -186,7 +186,7 @@ namespace OC
 
             OCSecureType secureType() const
             {
-                return m_props.m_policy.m_secure?OCSecureType::IPv4Secure :OCSecureType::IPv4;
+                return m_props.m_policy.m_secure ? OCSecureType::Secure : OCSecureType::NotSecure;
             }
 
             int port() const
@@ -214,9 +214,9 @@ namespace OC
                 ar(resources);
             }
         public:
-            ListenOCContainer(std::weak_ptr<IClientWrapper> cw, const OCDevAddr& address,
-                    OCConnectivityType connectivityType, std::stringstream& json):
-                m_clientWrapper(cw), m_address(address), m_connectivityType(connectivityType)
+            ListenOCContainer(std::weak_ptr<IClientWrapper> cw,
+                    const OCDevAddr& devAddr, std::stringstream& json)
+                    : m_clientWrapper(cw), m_devAddr(devAddr)
             {
                 LoadFromJson(json);
             }
@@ -227,59 +227,6 @@ namespace OC
             }
 
         private:
-            std::string ConvertOCAddrToString(OCSecureType sec, int secureport)
-            {
-                uint16_t port;
-                std::ostringstream os;
-
-                if(sec== OCSecureType::IPv4)
-                {
-                    os<<"coap://";
-                }
-                else if(sec == OCSecureType::IPv4Secure)
-                {
-                    os<<"coaps://";
-                }
-                else
-                {
-                    oclog() << "ConvertOCAddrToString():  invalid SecureType"<<std::flush;
-                    throw ResourceInitException(false, false, false, false, false, true);
-                }
-
-                uint8_t a;
-                uint8_t b;
-                uint8_t c;
-                uint8_t d;
-                if(OCDevAddrToIPv4Addr(&m_address, &a, &b, &c, &d) != 0)
-                {
-                    oclog() << "ConvertOCAddrToString(): Invalid Ip"
-                            << std::flush;
-                    throw ResourceInitException(false, false, false, false, false, true);
-                }
-
-                os<<static_cast<int>(a)<<"."<<static_cast<int>(b)
-                        <<"."<<static_cast<int>(c)<<"."<<static_cast<int>(d);
-
-                if(sec == OCSecureType::IPv4Secure && secureport>0 && secureport<=65535)
-                {
-                    port = static_cast<uint16_t>(secureport);
-                }
-                else if(sec == OCSecureType::IPv4 && 0==OCDevAddrToPort(&m_address, &port))
-                {
-                    // nothing to do, this is a successful case
-                }
-                else
-                {
-                    oclog() << "ConvertOCAddrToString() : Invalid Port"
-                            <<std::flush;
-                    throw ResourceInitException(false, false, false, false, true, false);
-                }
-
-                os <<":"<< static_cast<int>(port);
-
-                return os.str();
-            }
-
             void LoadFromJson(std::stringstream& json)
             {
                 cereal::JSONInputArchive archive(json);
@@ -296,9 +243,8 @@ namespace OC
                         if(res.loaded())
                         {
                             m_resources.push_back(std::shared_ptr<OCResource>(
-                                new OCResource(m_clientWrapper,
-                                    ConvertOCAddrToString(res.secureType(),res.port()),
-                                    res.m_uri, res.m_serverId, m_connectivityType, res.observable(),
+                                new OCResource(m_clientWrapper, m_devAddr,
+                                    res.m_uri, res.m_serverId, res.observable(),
                                     res.resourceTypes(), res.interfaces())));
                         }
 
@@ -312,8 +258,6 @@ namespace OC
             }
             std::vector<std::shared_ptr<OC::OCResource>> m_resources;
             std::weak_ptr<IClientWrapper> m_clientWrapper;
-            OCDevAddr m_address;
-            OCConnectivityType m_connectivityType;
+            const OCDevAddr& m_devAddr;
     };
 }
-
index db00d40..6305851 100644 (file)
@@ -33,12 +33,14 @@ namespace OC
         {}
 
         virtual OCStackResult ListenForResource(const std::string& serviceUrl,
-            const std::string& resourceType, OCConnectivityType connectivityType,
+            const std::string& resourceType,
+            OCConnectivityType connectivityType,
             FindCallback& callback, QualityOfService QoS)
             {return OC_STACK_NOTIMPL;}
 
         virtual OCStackResult ListenForDevice(const std::string& serviceUrl,
-            const std::string& deviceURI, OCConnectivityType connectivityType,
+            const std::string& deviceURI,
+            OCConnectivityType connectivityType,
             FindDeviceCallback& callback, QualityOfService QoS)
             {return OC_STACK_NOTIMPL;}
 
@@ -47,44 +49,63 @@ namespace OC
             QualityOfService QoS)
             {return OC_STACK_NOTIMPL;}
 
-        virtual OCStackResult GetResourceRepresentation(const std::string& host,
-            const std::string& uri, OCConnectivityType connectivityType,
+        virtual OCStackResult GetResourceRepresentation(
+            const OCDevAddr& devAddr,
+            const std::string& uri,
             const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
             GetCallback& callback, QualityOfService QoS)
             {return OC_STACK_NOTIMPL;}
 
-        virtual OCStackResult PutResourceRepresentation(const std::string& host,
-            const std::string& uri, OCConnectivityType connectivityType,
+        virtual OCStackResult PutResourceRepresentation(
+            const OCDevAddr& devAddr,
+            const std::string& uri,
             const OCRepresentation& attributes, const QueryParamsMap& queryParams,
             const HeaderOptions& headerOptions, PutCallback& callback,
             QualityOfService QoS)
             {return OC_STACK_NOTIMPL;}
 
-        virtual OCStackResult PostResourceRepresentation(const std::string& host,
-            const std::string& uri, OCConnectivityType connectivityType,
+        virtual OCStackResult PostResourceRepresentation(
+            const OCDevAddr& devAddr,
+            const std::string& uri,
             const OCRepresentation& attributes, const QueryParamsMap& queryParams,
             const HeaderOptions& headerOptions, PostCallback& callback, QualityOfService QoS)
             {return OC_STACK_NOTIMPL;}
 
-        virtual OCStackResult DeleteResource(const std::string& host, const std::string& uri,
-            OCConnectivityType connectivityType, const HeaderOptions& headerOptions,
+        virtual OCStackResult DeleteResource(
+            const OCDevAddr& devAddr,
+            const std::string& uri,
+            const HeaderOptions& headerOptions,
             DeleteCallback& callback, QualityOfService QoS)
             {return OC_STACK_NOTIMPL;}
 
-        virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
-            const std::string& host, const std::string& uri, OCConnectivityType connectivityType,
+        virtual OCStackResult ObserveResource(
+            ObserveType observeType, OCDoHandle* handle,
+            const OCDevAddr& devAddr,
+            const std::string& uri,
             const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
-            ObserveCallback& callback, QualityOfService QoS){return OC_STACK_NOTIMPL;}
-        virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host,
+            ObserveCallback& callback, QualityOfService QoS)
+            {return OC_STACK_NOTIMPL;}
+
+        virtual OCStackResult CancelObserveResource(
+            OCDoHandle handle,
+            const std::string& host,
             const std::string& uri,
-            const HeaderOptions& headerOptions, QualityOfService QoS){return OC_STACK_NOTIMPL;}
-        virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
-            const std::string& resourceType, OCConnectivityType connectivityType,
+            const HeaderOptions& headerOptions, QualityOfService QoS)
+            {return OC_STACK_NOTIMPL;}
+        
+        virtual OCStackResult SubscribePresence(
+            OCDoHandle* handle,
+            const std::string& host,
+            const std::string& resourceType,
+            OCConnectivityType connectivityType,
             SubscribeCallback& presenceHandler)
-        {return OC_STACK_NOTIMPL;}
-        virtual OCStackResult UnsubscribePresence(OCDoHandle handle){return OC_STACK_NOTIMPL;}
+            {return OC_STACK_NOTIMPL;}
 
-        virtual OCStackResult GetDefaultQos(QualityOfService& QoS){return OC_STACK_NOTIMPL;}
+        virtual OCStackResult UnsubscribePresence(OCDoHandle handle)
+            {return OC_STACK_NOTIMPL;}
+
+        virtual OCStackResult GetDefaultQos(QualityOfService& QoS)
+            {return OC_STACK_NOTIMPL;}
     };
 }
 
index aa4991b..f0ffb65 100644 (file)
@@ -38,7 +38,11 @@ namespace OC
 
         if(m_cfg.mode == ModeType::Client)
         {
-            OCStackResult result = OCInit(m_cfg.ipAddress.c_str(), m_cfg.port, OC_CLIENT);
+            OCTransportFlags serverFlags =
+                            static_cast<OCTransportFlags>(m_cfg.serverConnectivity & CT_MASK_FLAGS);
+            OCTransportFlags clientFlags =
+                            static_cast<OCTransportFlags>(m_cfg.clientConnectivity & CT_MASK_FLAGS);
+            OCStackResult result = OCInit1(OC_CLIENT, serverFlags, clientFlags);
 
             if(OC_STACK_OK != result)
             {
@@ -164,8 +168,8 @@ namespace OC
         try
         {
 
-            ListenOCContainer container(clientWrapper, *clientResponse->addr,
-                    clientResponse->connType, requestStream);
+            ListenOCContainer container(clientWrapper, clientResponse->devAddr,
+                                    requestStream);
             // loop to ensure valid construction of all resources
             for(auto resource : container.Resources())
             {
@@ -189,9 +193,11 @@ namespace OC
         return OC_STACK_KEEP_TRANSACTION;
     }
 
-    OCStackResult InProcClientWrapper::ListenForResource(const std::string& serviceUrl,
-        const std::string& resourceType, OCConnectivityType connectivityType,
-        FindCallback& callback, QualityOfService QoS)
+    OCStackResult InProcClientWrapper::ListenForResource(
+            const std::string& serviceUrl,  // unused
+            const std::string& resourceType,
+            OCConnectivityType connectivityType,
+            FindCallback& callback, QualityOfService QoS)
     {
         if(!callback)
         {
@@ -212,7 +218,7 @@ namespace OC
         if(cLock)
         {
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            result = OCDoResource(nullptr, OC_REST_GET,
+            result = OCDoResource(nullptr, OC_REST_DISCOVER,
                                   resourceType.c_str(),
                                   nullptr, nullptr, connectivityType,
                                   static_cast<OCQualityOfService>(QoS),
@@ -248,9 +254,12 @@ namespace OC
         return OC_STACK_KEEP_TRANSACTION;
     }
 
-    OCStackResult InProcClientWrapper::ListenForDevice(const std::string& serviceUrl,
-        const std::string& deviceURI, OCConnectivityType connectivityType,
-        FindDeviceCallback& callback, QualityOfService QoS)
+    OCStackResult InProcClientWrapper::ListenForDevice(
+            const std::string& serviceUrl,  // unused
+            const std::string& deviceURI,
+            OCConnectivityType connectivityType,
+            FindDeviceCallback& callback,
+            QualityOfService QoS)
     {
         if(!callback)
         {
@@ -270,7 +279,7 @@ namespace OC
         if(cLock)
         {
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            result = OCDoResource(nullptr, OC_REST_GET,
+            result = OCDoResource(nullptr, OC_REST_DISCOVER,
                                   deviceURI.c_str(),
                                   nullptr, nullptr, connectivityType,
                                   static_cast<OCQualityOfService>(QoS),
@@ -338,8 +347,9 @@ namespace OC
         return OC_STACK_DELETE_TRANSACTION;
     }
 
-    OCStackResult InProcClientWrapper::GetResourceRepresentation(const std::string& host,
-        const std::string& uri, OCConnectivityType connectivityType,
+    OCStackResult InProcClientWrapper::GetResourceRepresentation(
+        const OCDevAddr& devAddr,
+        const std::string& resourceUri,
         const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
         GetCallback& callback, QualityOfService QoS)
     {
@@ -356,18 +366,19 @@ namespace OC
                 [](void* c){delete static_cast<ClientCallbackContext::GetContext*>(c);}
                 );
 
+        std::string uri = assembleSetResourceUri(resourceUri, queryParams);
+
         auto cLock = m_csdkLock.lock();
 
         if(cLock)
         {
-            std::ostringstream os;
-            os << host << assembleSetResourceUri(uri, queryParams).c_str();
-
             std::lock_guard<std::recursive_mutex> lock(*cLock);
             OCHeaderOption options[MAX_HEADER_OPTIONS];
 
-            result = OCDoResource(nullptr, OC_REST_GET, os.str().c_str(),
-                                  nullptr, nullptr, connectivityType,
+            result = OCDoResource(nullptr, OC_REST_GET,
+                                  uri.c_str(),
+                                  &devAddr, nullptr,
+                                  CT_DEFAULT,
                                   static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
                                   assembleHeaderOptions(options, headerOptions),
@@ -447,8 +458,10 @@ namespace OC
         return ocInfo.getJSONRepresentation(OCInfoFormat::IncludeOC);
     }
 
-    OCStackResult InProcClientWrapper::PostResourceRepresentation(const std::string& host,
-        const std::string& uri, OCConnectivityType connectivityType, const OCRepresentation& rep,
+    OCStackResult InProcClientWrapper::PostResourceRepresentation(
+        const OCDevAddr& devAddr,
+        const std::string& uri,
+        const OCRepresentation& rep,
         const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
         PostCallback& callback, QualityOfService QoS)
     {
@@ -464,10 +477,7 @@ namespace OC
                 [](void* c){delete static_cast<ClientCallbackContext::SetContext*>(c);}
                 );
 
-        // TODO: in the future the cstack should be combining these two strings!
-        ostringstream os;
-        os << host << assembleSetResourceUri(uri, queryParams).c_str();
-        // TODO: end of above
+        std::string url = assembleSetResourceUri(uri, queryParams);
 
         auto cLock = m_csdkLock.lock();
 
@@ -477,8 +487,9 @@ namespace OC
             OCHeaderOption options[MAX_HEADER_OPTIONS];
 
             result = OCDoResource(nullptr, OC_REST_POST,
-                                  os.str().c_str(), nullptr,
-                                  assembleSetResourcePayload(rep).c_str(), connectivityType,
+                                  url.c_str(), &devAddr,
+                                  assembleSetResourcePayload(rep).c_str(),
+                                  CT_DEFAULT,
                                   static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
                                   assembleHeaderOptions(options, headerOptions),
@@ -493,8 +504,10 @@ namespace OC
         return result;
     }
 
-    OCStackResult InProcClientWrapper::PutResourceRepresentation(const std::string& host,
-        const std::string& uri, OCConnectivityType connectivityType, const OCRepresentation& rep,
+    OCStackResult InProcClientWrapper::PutResourceRepresentation(
+        const OCDevAddr& devAddr,
+        const std::string& uri,
+        const OCRepresentation& rep,
         const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
         PutCallback& callback, QualityOfService QoS)
     {
@@ -510,10 +523,7 @@ namespace OC
                 [](void* c){delete static_cast<ClientCallbackContext::SetContext*>(c);}
                 );
 
-        // TODO: in the future the cstack should be combining these two strings!
-        ostringstream os;
-        os << host << assembleSetResourceUri(uri, queryParams).c_str();
-        // TODO: end of above
+        std::string url = assembleSetResourceUri(uri, queryParams).c_str();
 
         auto cLock = m_csdkLock.lock();
 
@@ -524,8 +534,9 @@ namespace OC
             OCHeaderOption options[MAX_HEADER_OPTIONS];
 
             result = OCDoResource(&handle, OC_REST_PUT,
-                                  os.str().c_str(), nullptr,
-                                  assembleSetResourcePayload(rep).c_str(), connectivityType,
+                                  url.c_str(), &devAddr,
+                                  assembleSetResourcePayload(rep).c_str(),
+                                  CT_DEFAULT,
                                   static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
                                   assembleHeaderOptions(options, headerOptions),
@@ -556,8 +567,9 @@ namespace OC
         return OC_STACK_DELETE_TRANSACTION;
     }
 
-    OCStackResult InProcClientWrapper::DeleteResource(const std::string& host,
-        const std::string& uri, OCConnectivityType connectivityType,
+    OCStackResult InProcClientWrapper::DeleteResource(
+        const OCDevAddr& devAddr,
+        const std::string& uri,
         const HeaderOptions& headerOptions, DeleteCallback& callback, QualityOfService QoS)
     {
         if(!callback)
@@ -573,9 +585,6 @@ namespace OC
                 [](void* c){delete static_cast<ClientCallbackContext::DeleteContext*>(c);}
                 );
 
-        ostringstream os;
-        os << host << uri;
-
         auto cLock = m_csdkLock.lock();
 
         if(cLock)
@@ -585,8 +594,9 @@ namespace OC
             std::lock_guard<std::recursive_mutex> lock(*cLock);
 
             result = OCDoResource(nullptr, OC_REST_DELETE,
-                                  os.str().c_str(), nullptr,
-                                  nullptr, connectivityType,
+                                  uri.c_str(), &devAddr,
+                                  nullptr,
+                                  CT_DEFAULT,
                                   static_cast<OCQualityOfService>(m_cfg.QoS),
                                   &cbdata,
                                   assembleHeaderOptions(options, headerOptions),
@@ -633,7 +643,8 @@ namespace OC
     }
 
     OCStackResult InProcClientWrapper::ObserveResource(ObserveType observeType, OCDoHandle* handle,
-        const std::string& host, const std::string& uri, OCConnectivityType connectivityType,
+        const OCDevAddr& devAddr,
+        const std::string& uri,
         const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
         ObserveCallback& callback, QualityOfService QoS)
     {
@@ -665,19 +676,19 @@ namespace OC
             method = OC_REST_OBSERVE_ALL;
         }
 
+        std::string url = assembleSetResourceUri(uri, queryParams).c_str();
+
         auto cLock = m_csdkLock.lock();
 
         if(cLock)
         {
-            std::ostringstream os;
-            os << host << assembleSetResourceUri(uri, queryParams).c_str();
-
             std::lock_guard<std::recursive_mutex> lock(*cLock);
             OCHeaderOption options[MAX_HEADER_OPTIONS];
 
             result = OCDoResource(handle, method,
-                                  os.str().c_str(), nullptr,
-                                  nullptr, connectivityType,
+                                  url.c_str(), &devAddr,
+                                  nullptr,
+                                  CT_DEFAULT,
                                   static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
                                   assembleHeaderOptions(options, headerOptions),
@@ -692,9 +703,12 @@ namespace OC
         return result;
     }
 
-    OCStackResult InProcClientWrapper::CancelObserveResource(OCDoHandle handle,
-        const std::string& host, const std::string& uri, const HeaderOptions& headerOptions,
-        QualityOfService QoS)
+    OCStackResult InProcClientWrapper::CancelObserveResource(
+            OCDoHandle handle,
+            const std::string& host, // unused
+            const std::string& uri,  // unused
+            const HeaderOptions& headerOptions,
+            QualityOfService QoS)
     {
         OCStackResult result;
         auto cLock = m_csdkLock.lock();
@@ -720,32 +734,19 @@ namespace OC
     OCStackApplicationResult subscribePresenceCallback(void* ctx, OCDoHandle handle,
             OCClientResponse* clientResponse)
     {
-        ostringstream os;
-        uint16_t port;
-        uint8_t a;
-        uint8_t b;
-        uint8_t c;
-        uint8_t d;
+        ClientCallbackContext::SubscribePresenceContext* context =
+        static_cast<ClientCallbackContext::SubscribePresenceContext*>(ctx);
 
-        if(OCDevAddrToIPv4Addr(clientResponse->addr, &a, &b, &c, &d) == 0 &&
-                OCDevAddrToPort(clientResponse->addr, &port) == 0)
-        {
-            os<<static_cast<int>(a)<<"."<<static_cast<int>(b)<<"."<<static_cast<int>(c)
-                    <<"."<<static_cast<int>(d)<<":"<<static_cast<int>(port);
+        /*
+         * This a hack while we rethink presence subscription.
+         */
+        std::string url = clientResponse->devAddr.addr;
 
-            ClientCallbackContext::SubscribePresenceContext* context =
-                static_cast<ClientCallbackContext::SubscribePresenceContext*>(ctx);
+        std::thread exec(context->callback, clientResponse->result,
+                    clientResponse->sequenceNumber, url);
 
-            std::thread exec(context->callback, clientResponse->result,
-                    clientResponse->sequenceNumber, os.str());
+        exec.detach();
 
-            exec.detach();
-        }
-        else
-        {
-            oclog() << "subscribePresenceCallback(): OCDevAddrToIPv4Addr() or OCDevAddrToPort() "
-                    <<"failed"<< std::flush;
-        }
         return OC_STACK_KEEP_TRANSACTION;
     }
 
@@ -770,7 +771,7 @@ namespace OC
         auto cLock = m_csdkLock.lock();
 
         std::ostringstream os;
-        os << host << OC_PRESENCE_URI;
+        os << host << "/oc/presence";
 
         if(!resourceType.empty())
         {
@@ -783,8 +784,10 @@ namespace OC
             return OC_STACK_ERROR;
         }
 
-        return OCDoResource(handle, OC_REST_PRESENCE, os.str().c_str(), nullptr, nullptr,
-                            connectivityType, OC_LOW_QOS, &cbdata, NULL, 0);
+        return OCDoResource(handle, OC_REST_PRESENCE,
+                            os.str().c_str(), nullptr,
+                            nullptr, connectivityType,
+                            OC_LOW_QOS, &cbdata, NULL, 0);
     }
 
     OCStackResult InProcClientWrapper::UnsubscribePresence(OCDoHandle handle)
index 769de24..d4f65df 100644 (file)
@@ -262,10 +262,14 @@ namespace OC
         else
         {
             throw InitializeException(OC::InitException::NOT_CONFIGURED_AS_SERVER,
-                                      OC_STACK_INVALID_PARAM);
+                                         OC_STACK_INVALID_PARAM);
         }
 
-        OCStackResult result = OCInit(cfg.ipAddress.c_str(), cfg.port, initType);
+        OCTransportFlags serverFlags =
+                            static_cast<OCTransportFlags>(cfg.serverConnectivity & CT_MASK_FLAGS);
+        OCTransportFlags clientFlags =
+                            static_cast<OCTransportFlags>(cfg.clientConnectivity & CT_MASK_FLAGS);
+        OCStackResult result = OCInit1(initType, serverFlags, clientFlags);
 
         if(OC_STACK_OK != result)
         {
index 8093aa2..4a7bc49 100644 (file)
@@ -77,43 +77,45 @@ namespace OC
                                                 const std::vector<std::string>& resourceTypes,
                                                 const std::vector<std::string>& interfaces)
         {
-            return OCPlatform_impl::Instance().constructResourceObject(host, uri, connectivityType,
+            return OCPlatform_impl::Instance().constructResourceObject(host,
+                                                uri, connectivityType,
                                                 isObservable,
                                                 resourceTypes, interfaces);
         }
 
         OCStackResult findResource(const std::string& host,
-                                                const std::string& resourceName,
-                                                OCConnectivityType connectivityType,
-                                                FindCallback resourceHandler)
+                                            const std::string& resourceName,
+                                            OCConnectivityType connectivityType,
+                                            FindCallback resourceHandler)
         {
             return OCPlatform_impl::Instance().findResource(host, resourceName,
-                   connectivityType, resourceHandler);
+                                    connectivityType, resourceHandler);
         }
 
         OCStackResult findResource(const std::string& host,
-                                                const std::string& resourceName,
-                                                OCConnectivityType connectivityType,
-                                                FindCallback resourceHandler, QualityOfService QoS)
+                                            const std::string& resourceName,
+                                            OCConnectivityType connectivityType,
+                                            FindCallback resourceHandler,
+                                            QualityOfService QoS)
         {
-            return OCPlatform_impl::Instance().findResource(host, resourceName, connectivityType,
-                                                resourceHandler, QoS);
+            return OCPlatform_impl::Instance().findResource(host, resourceName,
+                                    connectivityType, resourceHandler, QoS);
         }
 
         OCStackResult getDeviceInfo(const std::string& host,
-                                                const std::string& deviceURI,
-                                                OCConnectivityType connectivityType,
-                                                FindDeviceCallback deviceInfoHandler)
+                                            const std::string& deviceURI,
+                                            OCConnectivityType connectivityType,
+                                            FindDeviceCallback deviceInfoHandler)
         {
             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI,
                    connectivityType, deviceInfoHandler);
         }
 
         OCStackResult getDeviceInfo(const std::string& host,
-                                                const std::string& deviceURI,
-                                                OCConnectivityType connectivityType,
-                                                FindDeviceCallback deviceInfoHandler,
-                                                QualityOfService QoS)
+                                            const std::string& deviceURI,
+                                            OCConnectivityType connectivityType,
+                                            FindDeviceCallback deviceInfoHandler,
+                                            QualityOfService QoS)
         {
             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, connectivityType,
                     deviceInfoHandler, QoS);
index 230f924..f57ce51 100644 (file)
@@ -171,9 +171,9 @@ namespace OC
     OCStackResult OCPlatform_impl::findResource(const std::string& host,
                                             const std::string& resourceName,
                                             OCConnectivityType connectivityType,
-                                            FindCallback resourceHandler, QualityOfService QoS)
+                                            FindCallback resourceHandler,
+                                            QualityOfService QoS)
     {
-
         return checked_guard(m_client, &IClientWrapper::ListenForResource,
                              host, resourceName, connectivityType, resourceHandler, QoS);
     }
index 2ad836a..e46ef16 100644 (file)
@@ -29,16 +29,15 @@ using OC::nil_guard;
 using OC::result_guard;
 using OC::checked_guard;
 
-OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper, const std::string& host,
-                       const std::string& uri, const std::string& serverId,
-                       OCConnectivityType connectivityType, bool observable,
-                       const std::vector<std::string>& resourceTypes,
-                       const std::vector<std::string>& interfaces)
- :  m_clientWrapper(clientWrapper), m_uri(uri), m_resourceId(serverId, m_uri),
-    m_host(host),
-    m_connectivityType(connectivityType),
-    m_isObservable(observable),
-    m_isCollection(false), m_resourceTypes(resourceTypes), m_interfaces(interfaces),
+OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
+                        const OCDevAddr& devAddr, const std::string& uri,
+                        const std::string& serverId, bool observable,
+                        const std::vector<std::string>& resourceTypes,
+                        const std::vector<std::string>& interfaces)
+ :  m_clientWrapper(clientWrapper), m_uri(uri),
+    m_resourceId(serverId, m_uri), m_devAddr(devAddr),
+    m_isObservable(observable), m_isCollection(false),
+    m_resourceTypes(resourceTypes), m_interfaces(interfaces),
     m_observeHandle(nullptr)
 {
     m_isCollection = std::find(m_interfaces.begin(), m_interfaces.end(), LINK_INTERFACE)
@@ -54,6 +53,43 @@ OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper, const std::s
     }
 }
 
+OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
+                        const std::string& host, const std::string& uri,
+                        const std::string& serverId,
+                        OCConnectivityType connectivityType, bool observable,
+                        const std::vector<std::string>& resourceTypes,
+                        const std::vector<std::string>& interfaces)
+ :  m_clientWrapper(clientWrapper), m_uri(uri),
+    m_resourceId(serverId, m_uri),
+    m_devAddr{ OC_DEFAULT_ADAPTER },
+    m_isObservable(observable), m_isCollection(false),
+    m_resourceTypes(resourceTypes), m_interfaces(interfaces),
+    m_observeHandle(nullptr)
+{
+    m_isCollection = std::find(m_interfaces.begin(), m_interfaces.end(), LINK_INTERFACE)
+                        != m_interfaces.end();
+
+    if (m_uri.empty() ||
+        resourceTypes.empty() ||
+        interfaces.empty()||
+        m_clientWrapper.expired())
+    {
+        throw ResourceInitException(m_uri.empty(), resourceTypes.empty(),
+                interfaces.empty(), m_clientWrapper.expired(), false, false);
+    }
+
+    // construct the devAddr from the pieces we have
+    m_devAddr.adapter = static_cast<OCTransportAdapter>(connectivityType >> CT_ADAPTER_SHIFT);
+    m_devAddr.flags = static_cast<OCTransportFlags>(connectivityType & CT_MASK_FLAGS);
+    size_t len = host.length();
+    if (len >= MAX_ADDR_STR_SIZE)
+    {
+        throw std::length_error("host address is too long.");
+    }
+    host.copy(m_devAddr.addr, len);
+    m_devAddr.addr[len] = '\0';
+}
+
 OCResource::~OCResource()
 {
 }
@@ -61,9 +97,11 @@ OCResource::~OCResource()
 OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap,
                               GetCallback attributeHandler, QualityOfService QoS)
 {
-    return checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetResourceRepresentation,
-                         m_host, m_uri, m_connectivityType, queryParametersMap, m_headerOptions,
-                         attributeHandler, QoS);
+    return checked_guard(m_clientWrapper.lock(),
+                            &IClientWrapper::GetResourceRepresentation,
+                            m_devAddr, m_uri,
+                            queryParametersMap, m_headerOptions,
+                            attributeHandler, QoS);
 }
 
 OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap,
@@ -107,7 +145,7 @@ OCStackResult OCResource::put(const OCRepresentation& rep,
                               QualityOfService QoS)
 {
     return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PutResourceRepresentation,
-                         m_host, m_uri, m_connectivityType, rep, queryParametersMap,
+                         m_devAddr, m_uri, rep, queryParametersMap,
                          m_headerOptions, attributeHandler, QoS);
 }
 
@@ -157,7 +195,7 @@ OCStackResult OCResource::post(const OCRepresentation& rep,
                                QualityOfService QoS)
 {
     return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PostResourceRepresentation,
-                         m_host, m_uri, m_connectivityType, rep, queryParametersMap,
+                         m_devAddr, m_uri, rep, queryParametersMap,
                          m_headerOptions, attributeHandler, QoS);
 }
 
@@ -205,7 +243,7 @@ OCStackResult OCResource::post(const std::string& resourceType,
 OCStackResult OCResource::deleteResource(DeleteCallback deleteHandler, QualityOfService QoS)
 {
     return checked_guard(m_clientWrapper.lock(), &IClientWrapper::DeleteResource,
-                         m_host, m_uri, m_connectivityType, m_headerOptions, deleteHandler, QoS);
+                         m_devAddr, m_uri, m_headerOptions, deleteHandler, QoS);
 }
 
 OCStackResult OCResource::deleteResource(DeleteCallback deleteHandler)
@@ -226,8 +264,8 @@ OCStackResult OCResource::observe(ObserveType observeType,
     }
 
     return checked_guard(m_clientWrapper.lock(), &IClientWrapper::ObserveResource,
-                         observeType, &m_observeHandle, m_host,
-                         m_uri, m_connectivityType, queryParametersMap, m_headerOptions,
+                         observeType, &m_observeHandle, m_devAddr,
+                         m_uri, queryParametersMap, m_headerOptions,
                          observeHandler, QoS);
 }
 
@@ -256,7 +294,7 @@ OCStackResult OCResource::cancelObserve(QualityOfService QoS)
 
     OCStackResult result =  checked_guard(m_clientWrapper.lock(),
             &IClientWrapper::CancelObserveResource,
-            m_observeHandle, m_host, m_uri, m_headerOptions, QoS);
+            m_observeHandle, "", m_uri, m_headerOptions, QoS);
 
     if(result == OC_STACK_OK)
     {
@@ -268,7 +306,7 @@ OCStackResult OCResource::cancelObserve(QualityOfService QoS)
 
 std::string OCResource::host() const
 {
-    return m_host;
+    return std::string(m_devAddr.addr);
 }
 
 std::string OCResource::uri() const
@@ -278,7 +316,8 @@ std::string OCResource::uri() const
 
 OCConnectivityType OCResource::connectivityType() const
 {
-    return m_connectivityType;
+    return static_cast<OCConnectivityType>(
+           (m_devAddr.adapter << CT_ADAPTER_SHIFT) | (m_devAddr.flags & CT_MASK_FLAGS));
 }
 
 bool OCResource::isObservable() const
@@ -286,7 +325,6 @@ bool OCResource::isObservable() const
     return m_isObservable;
 }
 
-
 OCResourceIdentifier OCResource::uniqueIdentifier() const
 {
     return m_resourceId;
@@ -335,7 +373,6 @@ OCResourceIdentifier::OCResourceIdentifier(const std::string& wireServerIdentifi
 
 std::ostream& operator <<(std::ostream& os, const OCResourceIdentifier& ri)
 {
-
     os << ri.m_representation<<ri.m_resourceUri;
 
     return os;
index 993b1d6..e1cb339 100644 (file)
@@ -468,13 +468,13 @@ namespace OCPlatformTest
       std::ostringstream requestURI;
       requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
       EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
-              OC_IPV4, &foundResource));
+              CT_DEFAULT, &foundResource));
     }
 
     TEST(FindResourceTest, FindResourceNullResourceURI)
     {
       EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
-              OC_IPV4, &foundResource));
+              CT_DEFAULT, &foundResource));
     }
 
     TEST(FindResourceTest, FindResourceNullResourceURI1)
@@ -482,7 +482,7 @@ namespace OCPlatformTest
       std::ostringstream requestURI;
       requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
       EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
-              OC_IPV4, &foundResource));
+              CT_DEFAULT, &foundResource));
     }
 
     TEST(FindResourceTest, FindResourceNullHost)
@@ -490,7 +490,7 @@ namespace OCPlatformTest
       std::ostringstream requestURI;
       requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
       EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
-              OC_IPV4, &foundResource));
+              CT_DEFAULT, &foundResource));
     }
 
     TEST(FindResourceTest, FindResourceNullresourceHandler)
@@ -498,7 +498,7 @@ namespace OCPlatformTest
       std::ostringstream requestURI;
       requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
       EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
-              OC_IPV4, NULL), OC::OCException);
+              CT_DEFAULT, NULL), OC::OCException);
     }
 
     TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
@@ -506,7 +506,7 @@ namespace OCPlatformTest
         std::ostringstream requestURI;
         requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
         EXPECT_EQ(OC_STACK_OK,
-                OCPlatform::findResource("", requestURI.str(), OC_IPV4, &foundResource,
+                OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
                         OC::QualityOfService::LowQos));
     }
 
@@ -515,7 +515,7 @@ namespace OCPlatformTest
         std::ostringstream requestURI;
         requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
         EXPECT_EQ(OC_STACK_OK,
-                OCPlatform::findResource("", requestURI.str(), OC_IPV4, &foundResource,
+                OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
                         OC::QualityOfService::MidQos));
     }
 
@@ -524,7 +524,7 @@ namespace OCPlatformTest
         std::ostringstream requestURI;
         requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
         EXPECT_EQ(OC_STACK_OK,
-                OCPlatform::findResource("", requestURI.str(), OC_IPV4, &foundResource,
+                OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
                         OC::QualityOfService::HighQos));
     }
 
@@ -533,7 +533,7 @@ namespace OCPlatformTest
         std::ostringstream requestURI;
         requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
         EXPECT_EQ(OC_STACK_OK,
-                OCPlatform::findResource("", requestURI.str(), OC_IPV4, &foundResource,
+                OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
                         OC::QualityOfService::NaQos));
     }
 
@@ -546,7 +546,7 @@ namespace OCPlatformTest
         std::ostringstream requestURI;
         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
         EXPECT_EQ(OC_STACK_OK,
-                OCPlatform::getDeviceInfo("", requestURI.str(), OC_IPV4, &receivedDeviceInfo));
+                OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
     }
 
     TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
@@ -554,7 +554,7 @@ namespace OCPlatformTest
         PlatformConfig cfg;
         OCPlatform::Configure(cfg);
         EXPECT_ANY_THROW(
-                OCPlatform::getDeviceInfo("", nullptr, OC_IPV4, &receivedDeviceInfo));
+                OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
     }
 
     TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
@@ -565,7 +565,7 @@ namespace OCPlatformTest
         std::ostringstream requestURI;
         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
         EXPECT_THROW(
-                OCPlatform::getDeviceInfo("", requestURI.str(), OC_IPV4, NULL),
+                OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
                 OC::OCException);
     }
 
@@ -577,7 +577,7 @@ namespace OCPlatformTest
         std::ostringstream requestURI;
         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
         EXPECT_EQ(OC_STACK_OK,
-                OCPlatform::getDeviceInfo("", requestURI.str(), OC_IPV4, &receivedDeviceInfo,
+                OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
                         OC::QualityOfService::LowQos));
     }
 
@@ -589,7 +589,7 @@ namespace OCPlatformTest
         std::ostringstream requestURI;
         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
         EXPECT_EQ(OC_STACK_OK,
-                OCPlatform::getDeviceInfo("", requestURI.str(), OC_IPV4, &receivedDeviceInfo,
+                OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
                         OC::QualityOfService::MidQos));
     }
 
@@ -601,7 +601,7 @@ namespace OCPlatformTest
         std::ostringstream requestURI;
         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
         EXPECT_EQ(OC_STACK_OK,
-                OCPlatform::getDeviceInfo("", requestURI.str(), OC_IPV4, &receivedDeviceInfo,
+                OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
                         OC::QualityOfService::HighQos));
     }
 
@@ -613,7 +613,7 @@ namespace OCPlatformTest
         std::ostringstream requestURI;
         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
         EXPECT_EQ(OC_STACK_OK,
-                OCPlatform::getDeviceInfo("", requestURI.str(), OC_IPV4, &receivedDeviceInfo,
+                OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
                         OC::QualityOfService::NaQos));
     }
 
@@ -641,7 +641,7 @@ namespace OCPlatformTest
         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
 
         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
-                 OC_IPV4, &presenceHandler));
+                 CT_DEFAULT, &presenceHandler));
     }
 
     TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
@@ -649,7 +649,7 @@ namespace OCPlatformTest
         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
 
         EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
-                 OC_IPV4, &presenceHandler));
+                 CT_DEFAULT, &presenceHandler));
     }
 
     TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
@@ -657,7 +657,7 @@ namespace OCPlatformTest
         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
 
         EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
-                 OC_IPV4, NULL));
+                 CT_DEFAULT, NULL));
     }
 
     TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
@@ -665,7 +665,7 @@ namespace OCPlatformTest
         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
 
         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
-                OC_MULTICAST_IP, "core.light", OC_IPV4, &presenceHandler));
+                OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
     }
 
     TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
@@ -673,7 +673,7 @@ namespace OCPlatformTest
         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
 
         EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
-                OC_MULTICAST_IP, nullptr, OC_IPV4, &presenceHandler));
+                OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
     }
 
     TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
@@ -681,7 +681,7 @@ namespace OCPlatformTest
         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
 
         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
-                OC_MULTICAST_IP, "core.light", OC_IPV4, &presenceHandler));
+                OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
         EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
     }
 
@@ -696,7 +696,7 @@ namespace OCPlatformTest
         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
 
         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
-                OC_MULTICAST_IP, OC_IPV4, &presenceHandler));
+                OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
         EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
     }
 
index a70eb82..3ea5826 100644 (file)
@@ -89,13 +89,13 @@ namespace OCResourceResponseTest
         OCServerRequest request;
         request.method = OC_REST_GET;
         strncpy(request.query, query, sizeof(query));
-        request.connectivityType = CA_IPV4;
-        strncpy(request.addressInfo.IP.ipAddress, address, sizeof(query));
-        request.addressInfo.IP.port = 5364;
-        request.qos =  OC_LOW_QOS;
+        request.devAddr.flags = OC_DEFAULT_FLAGS;
+        request.devAddr.adapter = OC_DEFAULT_ADAPTER;
+        strncpy(request.devAddr.addr, address, sizeof(query));
+        request.devAddr.port = 5364;
+        request.qos = OC_LOW_QOS;
         request.coapID = 0;
         request.delayedResNeeded = 0;
-        request.secured = 0;
 
         OCRequestHandle handle = static_cast<OCRequestHandle>(&request);
         EXPECT_EQ(NULL, response.getRequestHandle());
index 501857d..bdc870f 100644 (file)
@@ -49,7 +49,7 @@ namespace OCResourceTest
     //Helper method
     OCResource::Ptr ConstructResourceObject(std::string host, std::string uri)
     {
-        OCConnectivityType connectivityType = OC_IPV4;
+        OCConnectivityType connectivityType = CT_DEFAULT;
         std::vector<std::string> types = {"intel.rpost"};
         std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
 
@@ -450,7 +450,7 @@ namespace OCResourceTest
     {
         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
         EXPECT_TRUE(resource != NULL);
-        EXPECT_TRUE(resource->connectivityType() == OC_IPV4);
+        EXPECT_TRUE(resource->connectivityType() == CT_DEFAULT);
     }
 
     //IsObservable Test
index 5a18a0a..ecae22d 100644 (file)
@@ -30,8 +30,8 @@
 #include "ocstack.h"
 #include "logger.h"
 
-//#define OC_TRANSPORT OC_ALL
-#define OC_TRANSPORT OC_IPV4
+//#define OC_TRANSPORT CT_DEFAULT
+#define OC_TRANSPORT CT_ADAPTER_IP
 
 #ifdef __cplusplus
 extern "C" {
index f70948c..38193fc 100644 (file)
@@ -410,7 +410,7 @@ int requestCoordinateeCandidateDiscovery(char *sourceResourceAddress)
     cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
     cbData.cd = NULL;
 
-    result = OCDoResource(&handle, OC_REST_GET, queryUri, OIC_COORDINATING_FLAG, 0,
+    result = OCDoResource(&handle, OC_REST_GET, queryUri, NULL, 0,
             OC_TRANSPORT, OC_LOW_QOS, &cbData, NULL, 0);
     if (result != OC_STACK_OK)
     {
@@ -462,8 +462,6 @@ OCStackResult requestPresence(char *sourceResourceAddress)
 OCStackApplicationResult requestPresenceCB(void *context, OCDoHandle handle,
         OCClientResponse *clientResponse)
 {
-    uint8_t remoteIpAddress[4];
-    uint16_t remotePortNumber;
     char address[OIC_STRING_MAX_VALUE] = { '\0' };
 
     if (context == (void *) DEFAULT_CONTEXT_VALUE)
@@ -472,18 +470,17 @@ OCStackApplicationResult requestPresenceCB(void *context, OCDoHandle handle,
     }
     if (clientResponse)
     {
-        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddress,
-                            remoteIpAddress + 1, remoteIpAddress + 2, remoteIpAddress + 3);
-        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNumber);
         OC_LOG_V(DEBUG, HOSTING_TAG, "\tStackResult: %s",  getResultString(clientResponse->result));
         OC_LOG_V(DEBUG, HOSTING_TAG, "\tStackResult: %d",  clientResponse->result);
         OC_LOG_V(DEBUG, HOSTING_TAG,
-                 "\tPresence Device =============> Presence %s @ %d.%d.%d.%d:%d",
-                 clientResponse->resJSONPayload, remoteIpAddress[0], remoteIpAddress[1],
-                 remoteIpAddress[2], remoteIpAddress[3], remotePortNumber);
-
-        snprintf(address, sizeof(address), "%d.%d.%d.%d:%d", remoteIpAddress[0], remoteIpAddress[1],
-                remoteIpAddress[2], remoteIpAddress[3], remotePortNumber);
+                 "\tPresence Device =============> Presence %s @ %s:%d",
+                 clientResponse->resJSONPayload,
+                 clientResponse->devAddr.addr,
+                 clientResponse->devAddr.port);
+
+        snprintf(address, sizeof(address), "%s:%d",
+                 clientResponse->devAddr.addr,
+                 clientResponse->devAddr.port);
         if (clientResponse->result == OC_STACK_OK)
         {
             requestCoordinateeCandidateDiscovery(address);
@@ -586,16 +583,10 @@ MirrorResourceList *buildMirrorResourceList(OCDoHandle handle, OCClientResponse
 
     MirrorResourceList *retList = createMirrorResourceList();
 
-    uint8_t remoteIpAddr[4];
-    uint16_t remotePortNum;
-
-    OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
-                        remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
-    OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNum);
-
     char sourceaddr[OIC_STRING_MAX_VALUE] = {'\0'};
-    snprintf(sourceaddr, sizeof(sourceaddr), "%d.%d.%d.%d:%d", remoteIpAddr[0], remoteIpAddr[1],
-            remoteIpAddr[2], remoteIpAddr[3], remotePortNum);
+    snprintf(sourceaddr, sizeof(sourceaddr), "%s:%d",
+                                        clientResponse->devAddr.addr,
+                                        clientResponse->devAddr.port);
 
     OC_LOG_V(DEBUG, HOSTING_TAG, "Host Device =============> Discovered %s @ %s",
              clientResponse->resJSONPayload, sourceaddr);
index afb6de4..7e37a1f 100644 (file)
@@ -225,7 +225,7 @@ void foundResource(std::shared_ptr< OCResource > resource)
 
 OCStackResult nmfindResource(const std::string &host , const std::string &resourceName)
 {
-    return OCPlatform::findResource(host , resourceName , OC_ALL, &foundResource);
+    return OCPlatform::findResource(host , resourceName , CT_DEFAULT, &foundResource);
 }
 
 void getRepresentation(std::shared_ptr< OCResource > resource)
index 065b2d4..bb6a079 100644 (file)
@@ -395,7 +395,7 @@ int main(int argc, char *argv[])
         std::cout.setf(std::ios::boolalpha);
         // Find all resources
         requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.fan";
-        OCPlatform::findResource("", requestURI.str(), OC_ALL, &foundResourceFan);
+        OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResourceFan);
         std::cout << "Finding Resource... " << std::endl;
         while (true)
         {
index 7541ee7..2747458 100644 (file)
@@ -78,7 +78,7 @@ void CResourceFinder::presenceHandler(OCStackResult result, const unsigned int n
         case OC_STACK_OK:
             requestURI << "coap://" << hostAddress << "/oc/core?rt=SSManager.Sensor";
 
-            ret = OC::OCPlatform::findResource("", requestURI.str(), OC_ALL,
+            ret = OC::OCPlatform::findResource("", requestURI.str(), CT_DEFAULT,
                                                std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
 
             if (ret != OC_STACK_OK)
@@ -127,14 +127,14 @@ SSMRESULT CResourceFinder::startResourceFinder()
     std::ostringstream multicastPresenceURI;
     multicastPresenceURI << "coap://" << OC_MULTICAST_PREFIX;
 
-    ret = OC::OCPlatform::findResource("", requestURI.str(), OC_ALL,
+    ret = OC::OCPlatform::findResource("", requestURI.str(), CT_DEFAULT,
                                        std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
 
     if (ret != OC_STACK_OK)
         SSM_CLEANUP_ASSERT(SSM_E_FAIL);
 
     ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, multicastPresenceURI.str(),
-                                            "SSManager.Sensor", OC_ALL, std::bind(&CResourceFinder::presenceHandler, this,
+                                            "SSManager.Sensor", CT_DEFAULT, std::bind(&CResourceFinder::presenceHandler, this,
                                                     std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
 
     if (ret != OC_STACK_OK)
@@ -216,7 +216,7 @@ void CResourceFinder::onExecute(void *pArg)
                 m_mapResourcePresenceHandles.end())
             {
                 ret = OC::OCPlatform::subscribePresence(presenceHandle, ((ISSMResource *)pMessage[1])->ip,
-                                                        "SSManager.Sensor", OC_ALL, std::bind(&CResourceFinder::presenceHandler, this,
+                                                        "SSManager.Sensor", CT_DEFAULT, std::bind(&CResourceFinder::presenceHandler, this,
                                                                 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
 
                 if (ret != OC_STACK_OK)
index 413b324..1996e4d 100644 (file)
@@ -485,7 +485,7 @@ int main()
 
                     OCPlatform::findResource("",
                             query,
-                            OC_ALL,
+                            CT_DEFAULT,
                             &foundResource);
 
                     // OCPlatform::findResource("",
@@ -501,7 +501,7 @@ int main()
 
                     OCPlatform::findResource("",
                             query,
-                            OC_ALL,
+                            CT_DEFAULT,
                             &foundResource);
                     // OCPlatform::findResource("",
                     //         query,
index 91e9950..7f72f19 100644 (file)
@@ -118,12 +118,12 @@ int main(int argc, char* argv[])
                 cout << query.str() << endl;
                 result = OCPlatform::findResource("",
                             query.str(),
-                            OC_ALL,
+                            CT_DEFAULT,
                             onFindResource);
 
                 result = OCPlatform::findResource("",
                             "coap://224.0.1.187/oc/core?rt=core.musicplayer",
-                            OC_ALL,
+                            CT_DEFAULT,
                             onFindResource);
 
                 if (OC_STACK_OK == result)
@@ -141,7 +141,7 @@ int main(int argc, char* argv[])
                 query << OC_MULTICAST_DISCOVERY_URI << "?rt=core.speaker";
                 result = OCPlatform::findResource("",
                             query.str(),
-                            OC_ALL,
+                            CT_DEFAULT,
                             onFindResource);
 
                 if (OC_STACK_OK == result)
index cbcc4d0..c8cde5e 100755 (executable)
@@ -229,7 +229,7 @@ OCStackResult GroupManager::findCandidateResources(
 
         OCPlatform::findResource("",
                 query,
-                OC_ALL,
+                CT_DEFAULT,
                 std::function < void(std::shared_ptr < OCResource > resource)
                         > (std::bind(&GroupManager::onFoundResource, this, std::placeholders::_1,
                                 waitsec)));
@@ -362,7 +362,7 @@ void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep,
             result = OCPlatform::subscribePresence(presenceHandle, hostAddress,
                     // resourceType,
                     resourceTypes.front(),
-                    OC_ALL,
+                    CT_DEFAULT,
                     std::function<
                             void(OCStackResult result, const unsigned int nonce,
                                     const std::string& hostAddress) >(
index b60c045..740bf02 100644 (file)
@@ -78,7 +78,7 @@ namespace OIC
             query.append(collectionResourceTypes.at(i));
 
             OCPlatform::findResource("", query,
-                    OC_ALL,
+                    CT_DEFAULT,
                     std::bind(&GroupSynchronization::onFindGroup, this,
                         std::placeholders::_1));
         }
@@ -288,7 +288,7 @@ namespace OIC
         OCResource::Ptr groupSyncResource =
                         OCPlatform::constructResourceObject(host, uri,
 
-                            OC_ALL, false,
+                            CT_DEFAULT, false,
                             resourceTypes, resourceInterface);
 
         // OCResource::Ptr groupSyncResource = OCPlatform::constructResourceObject(host, uri,
@@ -466,7 +466,7 @@ OCStackResult GroupSynchronization::leaveGroup(
 
         OCResource::Ptr groupSyncResource;
         groupSyncResource = OCPlatform::constructResourceObject(host, uri,
-                OC_ALL, false,
+                CT_DEFAULT, false,
                 resourceTypes, resourceInterface);
         // groupSyncResource = OCPlatform::constructResourceObject(host, uri,
         //         OC_WIFI, false, resourceTypes, resourceInterface);
@@ -705,7 +705,7 @@ OCStackResult GroupSynchronization::leaveGroup(
                         resourceRequest = request;
 
                         OCPlatform::findResource("", resourceName,
-                            OC_ALL,
+                            CT_DEFAULT,
                             std::bind(&GroupSynchronization::onFindResource, this,
                                 std::placeholders::_1));
 
index 4ea8804..f390565 100755 (executable)
@@ -326,7 +326,7 @@ namespace OIC
 
             std::string host = getHostFromURI(oit->getUri());
 
-            tempResource = OCPlatform::constructResourceObject(host, uri, OC_IPV4, true,
+            tempResource = OCPlatform::constructResourceObject(host, uri, CT_ADAPTER_IP, true,
                     oit->getResourceTypes(), m_if);
 
             p_resources.push_back(tempResource);