Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / connectivity / api / cacommon.h
index 1060410..00dac16 100644 (file)
@@ -42,6 +42,11 @@ extern "C"
 #define CA_IPADDR_SIZE 16
 
 /**
+ * @brief Remote Access jabber ID length.
+ */
+#define CA_RAJABBERID_SIZE 256
+
+/**
  * @brief Mac address length for BT port
  */
 #define CA_MACADDR_SIZE 18
@@ -75,6 +80,11 @@ extern "C"
 #endif
 
 /**
+ *@brief Maximum length of the remoteEndpoint identity
+ */
+#define CA_MAX_ENDPOINT_IDENTITY_LEN   (32)
+
+/**
  * @brief option types - the highest option number 63
  */
 #define CA_OPTION_IF_MATCH 1
@@ -93,7 +103,7 @@ extern "C"
 /**
  * @brief Payload information from resource model
  */
-typedef char *CAPayload_t;
+typedef uint8_t *CAPayload_t;
 
 /**
  * @brief URI for the OIC base.CA considers relative URI as the URI.
@@ -105,17 +115,53 @@ 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.
+#ifdef RA_ADAPTER
+#define MAX_ADDR_STR_SIZE_CA (256)
+#else
+#define MAX_ADDR_STR_SIZE_CA (40)
+#endif
+
+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
+
+    #ifdef RA_ADAPTER
+    CA_ADAPTER_REMOTE_ACCESS = (1 << 3)   // Remote Access over XMPP.
+    #endif
+} 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
+    // Indication that a message was received by multicast.
+    CA_MULTICAST       = (1 << 7),
+    // 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;
+
+#define CA_IPFAMILY_MASK (CA_IPV6|CA_IPV4)
+#define CA_SCOPE_MASK 0xf     // mask scope bits above
 
 /**
  * @enum CANetworkStatus_t
@@ -127,36 +173,14 @@ typedef enum
     CA_INTERFACE_UP    /**< Connection is Available */
 } CANetworkStatus_t;
 
-/**
- * @brief  Address of the local or remote endpoint
+/*
+ * @brief remoteEndpoint identity
  */
-typedef union
+typedef struct
 {
-    /**
-     * @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;
+    uint16_t id_length;
+    unsigned char id[CA_MAX_ENDPOINT_IDENTITY_LEN];
+} CARemoteId_t;
 
 /**
  * @enum CAMessageType_t
@@ -184,36 +208,18 @@ typedef enum
 } CAMethod_t;
 
 /**
- * @brief Remote endpoint information for connectivities
- */
-typedef struct
-{
-
-    CAURI_t resourceUri;                    /**< Resource URI information **/
-    CAAddress_t addressInfo;                /**< Remote Endpoint address **/
-    CATransportType_t transportType;  /**< Transport Type of the endpoint**/
-    bool isSecured;                     /**< Secure connection**/
-} CARemoteEndpoint_t;
-
-
-/**
- * @brief Group endpoint information for connectivities
+ * @brief Endpoint information for connectivities
+ * Must be identical to OCDevAddr.
  */
 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
@@ -235,6 +241,7 @@ typedef enum
     CA_REQUEST_TIMEOUT,             /**< Request is Timeout */
     CA_DESTINATION_DISCONNECTED,    /**< Destination is disconnected */
     CA_NOT_SUPPORTED,               /**< Not supported */
+    CA_STATUS_NOT_INITIALIZED,      /**< CA layer is not initialized */
     CA_STATUS_FAILED =255           /**< Failure */
     /* Result code - END HERE */
 } CAResult_t;
@@ -250,8 +257,13 @@ typedef enum
     CA_SUCCESS = 200,                /**< Success */
     CA_CREATED = 201,                /**< Created */
     CA_DELETED = 202,                /**< Deleted */
+    CA_VALID = 203,                  /**< Valid */
+    CA_CHANGED = 204,                /**< Changed */
+    CA_CONTENT = 205,                /**< Content */
     CA_BAD_REQ = 400,                /**< Bad Request */
+    CA_UNAUTHORIZED_REQ = 401,       /**< Unauthorized Request */
     CA_BAD_OPT = 402,                /**< Bad Option */
+    CA_FORBIDDEN_REQ = 403,          /**< Forbidden Request */
     CA_NOT_FOUND = 404,              /**< Not found */
     CA_INTERNAL_SERVER_ERROR = 500,  /**< Internal Server Error */
     CA_RETRANSMIT_TIMEOUT = 504      /**< Retransmit timeout */
@@ -289,7 +301,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;
 
 /**
@@ -309,6 +321,8 @@ typedef struct
     CAHeaderOption_t *options;  /** Header Options for the request */
     uint8_t numOptions;         /**< Number of Header options */
     CAPayload_t payload;        /**< payload of the request  */
+    size_t payloadSize;         /**< size in bytes of the payload */
+    CAURI_t resourceUri;        /**< Resource URI information **/
 } CAInfo_t;
 
 /**
@@ -320,6 +334,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;
 
 /**
@@ -333,9 +348,85 @@ typedef struct
     CAInfo_t info;              /**< Information of the response */
 } CAResponseInfo_t;
 
+/**
+ * @brief Error information from CA
+ *        contains error code and message information
+ *
+ * This structure holds error information
+ */
+typedef struct
+{
+    CAResult_t result;  /**< CA API request result  */
+    CAInfo_t info;      /**< message information such as token and payload data
+                             helpful to identify the error */
+} CAErrorInfo_t;
+
+/**
+ * @brief CA Remote Access information for XMPP Client
+ *
+ */
+typedef struct
+{
+    char *hostname;     /**< XMPP server hostname */
+    uint16_t port;      /**< XMPP server serivce port */
+    char *xmpp_domain;  /**< XMPP login domain */
+    char *username;     /**< login username */
+    char *password;     /**< login password */
+    char *resource;     /**< specific resource for login */
+    char *user_jid;     /**< specific JID for login */
+} CARAInfo_t;
+
+
+/**
+ * @brief Hold global variables for CA layer (also used by RI layer)
+ */
+typedef struct
+{
+    int fd;
+    uint16_t port;
+} CASocket_t;
+
+typedef struct
+{
+    CATransportFlags_t clientFlags;
+    CATransportFlags_t serverFlags;
+    bool client;
+    bool server;
+
+    struct sockets
+    {
+        void *threadpool;   // threadpool between Initialize and Start
+        CASocket_t u6;      // unicast   IPv6
+        CASocket_t u6s;     // unicast   IPv6 secure
+        CASocket_t u4;      // unicast   IPv4
+        CASocket_t u4s;     // unicast   IPv4 secure
+        CASocket_t m6;      // multicast IPv6
+        CASocket_t m6s;     // multicast IPv6 secure
+        CASocket_t m4;      // multicast IPv4
+        CASocket_t m4s;     // multicast IPv4 secure
+        int netlinkFd;      // netlink
+        int shutdownFds[2]; // shutdown pipe
+        int selectTimeout;  // in seconds
+        int maxfd;          // highest fd (for select)
+        int numInterfaces;  // number of active interfaces
+        bool started;       // the IP adapter has started
+        bool terminate;     // the IP adapter needs to stop
+        bool ipv6enabled;   // IPv6 enabled by OCInit flags
+        bool ipv4enabled;   // IPv4 enabled by OCInit flags
+    } ip;
+
+    struct calayer
+    {
+        CATransportFlags_t previousRequestFlags; // address family filtering
+        uint16_t previousRequestMessageId;       // address family filtering
+    } ca;
+} CAGlobals_t;
+
+extern CAGlobals_t caglobals;
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
 
-#endif /* CA_COMMON_H_ */
+#endif //#ifndef CA_COMMON_H_